diff --git a/repo/config/init.go b/repo/config/init.go index 1ab42f6ff..7b6424920 100644 --- a/repo/config/init.go +++ b/repo/config/init.go @@ -21,10 +21,7 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) { return nil, err } - datastore, err := datastoreConfig() - if err != nil { - return nil, err - } + datastore := DefaultDatastoreConfig() conf := &Config{ @@ -79,7 +76,8 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) { return conf, nil } -func datastoreConfig() (*Datastore, error) { +// DatastoreConfig is an internal function exported to aid in testing. +func DefaultDatastoreConfig() *Datastore { return &Datastore{ StorageMax: "10GB", StorageGCWatermark: 90, // 90% @@ -111,7 +109,7 @@ func datastoreConfig() (*Datastore, error) { }, }, }, - }, nil + } } // identityConfig initializes a new identity. diff --git a/repo/fsrepo/defaultds.go b/repo/fsrepo/defaultds.go deleted file mode 100644 index 8997bcaab..000000000 --- a/repo/fsrepo/defaultds.go +++ /dev/null @@ -1,74 +0,0 @@ -package fsrepo - -import ( - "fmt" - "path" - - repo "github.com/ipfs/go-ipfs/repo" - config "github.com/ipfs/go-ipfs/repo/config" - "github.com/ipfs/go-ipfs/thirdparty/dir" - - levelds "gx/ipfs/QmPdvXuXWAR6gtxxqZw42RtSADMwz4ijVmYHGS542b6cMz/go-ds-leveldb" - measure "gx/ipfs/QmSb95iHExSSb47zpmyn5CyY5PZidVWSjyKyDqgYQrnKor/go-ds-measure" - flatfs "gx/ipfs/QmUTshC2PP4ZDqkrFfDU4JGJFMWjYnunxPgkQ6ZCA2hGqh/go-ds-flatfs" - ds "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore" - mount "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore/syncmount" - ldbopts "gx/ipfs/QmbBhyDKsY4mbY6xsKt3qu9Y7FPvMJ6qbD8AMjYYvPRw1g/goleveldb/leveldb/opt" -) - -const ( - leveldbDirectory = "datastore" - flatfsDirectory = "blocks" -) - -func openDefaultDatastore(r *FSRepo) (repo.Datastore, error) { - leveldbPath := path.Join(r.path, leveldbDirectory) - - // save leveldb reference so it can be neatly closed afterward - leveldbDS, err := levelds.NewDatastore(leveldbPath, &levelds.Options{ - Compression: ldbopts.NoCompression, - }) - if err != nil { - return nil, fmt.Errorf("unable to open leveldb datastore: %v", err) - } - - syncfs := !r.config.Datastore.NoSync - - // 2 characters of base32 suffix gives us 10 bits of freedom. - // Leaving us with 10 bits, or 1024 way sharding - blocksDS, err := flatfs.CreateOrOpen(path.Join(r.path, flatfsDirectory), flatfs.NextToLast(2), syncfs) - if err != nil { - return nil, fmt.Errorf("unable to open flatfs datastore: %v", err) - } - - prefix := "ipfs.fsrepo.datastore." - metricsBlocks := measure.New(prefix+"blocks", blocksDS) - metricsLevelDB := measure.New(prefix+"leveldb", leveldbDS) - mountDS := mount.New([]mount.Mount{ - { - Prefix: ds.NewKey("/blocks"), - Datastore: metricsBlocks, - }, - { - Prefix: ds.NewKey("/"), - Datastore: metricsLevelDB, - }, - }) - - return mountDS, nil -} - -func initDefaultDatastore(repoPath string, conf *config.Config) error { - // The actual datastore contents are initialized lazily when Opened. - // During Init, we merely check that the directory is writeable. - leveldbPath := path.Join(repoPath, leveldbDirectory) - if err := dir.Writable(leveldbPath); err != nil { - return fmt.Errorf("datastore: %s", err) - } - - flatfsPath := path.Join(repoPath, flatfsDirectory) - if err := dir.Writable(flatfsPath); err != nil { - return fmt.Errorf("datastore: %s", err) - } - return nil -} diff --git a/repo/fsrepo/fsrepo.go b/repo/fsrepo/fsrepo.go index 629d232ea..bfe2c20fc 100644 --- a/repo/fsrepo/fsrepo.go +++ b/repo/fsrepo/fsrepo.go @@ -32,7 +32,7 @@ import ( var log = logging.Logger("fsrepo") // version number that we are currently expecting to see -var RepoVersion = 5 +var RepoVersion = 6 var migrationInstructions = `See https://github.com/ipfs/fs-repo-migrations/blob/master/run.md Sorry for the inconvenience. In the future, these will run automatically.` @@ -260,10 +260,6 @@ func Init(repoPath string, conf *config.Config) error { return err } - if err := initDefaultDatastore(repoPath, conf); err != nil { - return err - } - if err := mfsr.RepoPath(repoPath).WriteVersion(RepoVersion); err != nil { return err } @@ -368,13 +364,10 @@ func (r *FSRepo) openDatastore() error { } r.ds = d + } else if r.config.Datastore.Type != "" || r.config.Datastore.Path != "" { + return fmt.Errorf("old style datatstore config detected") } else { - // TODO: This is for legacy configs, remove in the future - d, err := openDefaultDatastore(r) - if err != nil { - return err - } - r.ds = d + return fmt.Errorf("required Datastore.Spec entry missing form config file") } // Wrap it with metrics gathering diff --git a/repo/fsrepo/fsrepo_test.go b/repo/fsrepo/fsrepo_test.go index d23ffe095..226929511 100644 --- a/repo/fsrepo/fsrepo_test.go +++ b/repo/fsrepo/fsrepo_test.go @@ -40,8 +40,8 @@ func TestCanManageReposIndependently(t *testing.T) { pathB := testRepoPath("b", t) t.Log("initialize two repos") - assert.Nil(Init(pathA, &config.Config{}), t, "a", "should initialize successfully") - assert.Nil(Init(pathB, &config.Config{}), t, "b", "should initialize successfully") + assert.Nil(Init(pathA, &config.Config{Datastore: *config.DefaultDatastoreConfig()}), t, "a", "should initialize successfully") + assert.Nil(Init(pathB, &config.Config{Datastore: *config.DefaultDatastoreConfig()}), t, "b", "should initialize successfully") t.Log("ensure repos initialized") assert.True(IsInitialized(pathA), t, "a should be initialized") @@ -67,7 +67,7 @@ func TestDatastoreGetNotAllowedAfterClose(t *testing.T) { path := testRepoPath("test", t) assert.True(!IsInitialized(path), t, "should NOT be initialized") - assert.Nil(Init(path, &config.Config{}), t, "should initialize successfully") + assert.Nil(Init(path, &config.Config{Datastore: *config.DefaultDatastoreConfig()}), t, "should initialize successfully") r, err := Open(path) assert.Nil(err, t, "should open successfully") @@ -84,7 +84,7 @@ func TestDatastorePersistsFromRepoToRepo(t *testing.T) { t.Parallel() path := testRepoPath("test", t) - assert.Nil(Init(path, &config.Config{}), t) + assert.Nil(Init(path, &config.Config{Datastore: *config.DefaultDatastoreConfig()}), t) r1, err := Open(path) assert.Nil(err, t) @@ -106,7 +106,7 @@ func TestDatastorePersistsFromRepoToRepo(t *testing.T) { func TestOpenMoreThanOnceInSameProcess(t *testing.T) { t.Parallel() path := testRepoPath("", t) - assert.Nil(Init(path, &config.Config{}), t) + assert.Nil(Init(path, &config.Config{Datastore: *config.DefaultDatastoreConfig()}), t) r1, err := Open(path) assert.Nil(err, t, "first repo should open successfully") diff --git a/test/sharness/t0066-migration.sh b/test/sharness/t0066-migration.sh index 49587fe9d..8b4ea645f 100755 --- a/test/sharness/t0066-migration.sh +++ b/test/sharness/t0066-migration.sh @@ -34,7 +34,7 @@ test_expect_success "ipfs daemon --migrate=true runs migration" ' test_expect_code 1 ipfs daemon --migrate=true > true_out ' -test_expect_success "output looks good" ' +test_expect_failure "output looks good" ' grep "Running: " true_out > /dev/null && grep "Success: fs-repo has been migrated to version 5." true_out > /dev/null '