@cryptotaxi247 / kubo / commits / 2df7727be

bump repo version, remove support for old config

License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed May 20, 2017 at 00:12 UTC 2df7727be8db01b5179d324e3f76d44a4cea10f7
5 files changed +14 -97
repo/config/init.go
+4 -6
@@ -21,10 +21,7 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
21 return nil, err
22 }
23
24 - datastore, err := datastoreConfig()
25 - if err != nil {
26 - return nil, err
27 - }
24 + datastore := DefaultDatastoreConfig()
25
26 conf := &Config{
27
@@ -79,7 +76,8 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
76 return conf, nil
77 }
78
82 -func datastoreConfig() (*Datastore, error) {
79 +// DatastoreConfig is an internal function exported to aid in testing.
80 +func DefaultDatastoreConfig() *Datastore {
81 return &Datastore{
82 StorageMax: "10GB",
83 StorageGCWatermark: 90, // 90%
@@ -111,7 +109,7 @@ func datastoreConfig() (*Datastore, error) {
109 },
110 },
111 },
114 - }, nil
112 + }
113 }
114
115 // identityConfig initializes a new identity.
repo/fsrepo/defaultds.go deleted
-74
@@ -1,74 +0,0 @@
1 -package fsrepo
2 -
3 -import (
4 - "fmt"
5 - "path"
6 -
7 - repo "github.com/ipfs/go-ipfs/repo"
8 - config "github.com/ipfs/go-ipfs/repo/config"
9 - "github.com/ipfs/go-ipfs/thirdparty/dir"
10 -
11 - levelds "gx/ipfs/QmPdvXuXWAR6gtxxqZw42RtSADMwz4ijVmYHGS542b6cMz/go-ds-leveldb"
12 - measure "gx/ipfs/QmSb95iHExSSb47zpmyn5CyY5PZidVWSjyKyDqgYQrnKor/go-ds-measure"
13 - flatfs "gx/ipfs/QmUTshC2PP4ZDqkrFfDU4JGJFMWjYnunxPgkQ6ZCA2hGqh/go-ds-flatfs"
14 - ds "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore"
15 - mount "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore/syncmount"
16 - ldbopts "gx/ipfs/QmbBhyDKsY4mbY6xsKt3qu9Y7FPvMJ6qbD8AMjYYvPRw1g/goleveldb/leveldb/opt"
17 -)
18 -
19 -const (
20 - leveldbDirectory = "datastore"
21 - flatfsDirectory = "blocks"
22 -)
23 -
24 -func openDefaultDatastore(r *FSRepo) (repo.Datastore, error) {
25 - leveldbPath := path.Join(r.path, leveldbDirectory)
26 -
27 - // save leveldb reference so it can be neatly closed afterward
28 - leveldbDS, err := levelds.NewDatastore(leveldbPath, &levelds.Options{
29 - Compression: ldbopts.NoCompression,
30 - })
31 - if err != nil {
32 - return nil, fmt.Errorf("unable to open leveldb datastore: %v", err)
33 - }
34 -
35 - syncfs := !r.config.Datastore.NoSync
36 -
37 - // 2 characters of base32 suffix gives us 10 bits of freedom.
38 - // Leaving us with 10 bits, or 1024 way sharding
39 - blocksDS, err := flatfs.CreateOrOpen(path.Join(r.path, flatfsDirectory), flatfs.NextToLast(2), syncfs)
40 - if err != nil {
41 - return nil, fmt.Errorf("unable to open flatfs datastore: %v", err)
42 - }
43 -
44 - prefix := "ipfs.fsrepo.datastore."
45 - metricsBlocks := measure.New(prefix+"blocks", blocksDS)
46 - metricsLevelDB := measure.New(prefix+"leveldb", leveldbDS)
47 - mountDS := mount.New([]mount.Mount{
48 - {
49 - Prefix: ds.NewKey("/blocks"),
50 - Datastore: metricsBlocks,
51 - },
52 - {
53 - Prefix: ds.NewKey("/"),
54 - Datastore: metricsLevelDB,
55 - },
56 - })
57 -
58 - return mountDS, nil
59 -}
60 -
61 -func initDefaultDatastore(repoPath string, conf *config.Config) error {
62 - // The actual datastore contents are initialized lazily when Opened.
63 - // During Init, we merely check that the directory is writeable.
64 - leveldbPath := path.Join(repoPath, leveldbDirectory)
65 - if err := dir.Writable(leveldbPath); err != nil {
66 - return fmt.Errorf("datastore: %s", err)
67 - }
68 -
69 - flatfsPath := path.Join(repoPath, flatfsDirectory)
70 - if err := dir.Writable(flatfsPath); err != nil {
71 - return fmt.Errorf("datastore: %s", err)
72 - }
73 - return nil
74 -}
repo/fsrepo/fsrepo.go
+4 -11
@@ -32,7 +32,7 @@ import (
32 var log = logging.Logger("fsrepo")
33
34 // version number that we are currently expecting to see
35 -var RepoVersion = 5
35 +var RepoVersion = 6
36
37 var migrationInstructions = `See https://github.com/ipfs/fs-repo-migrations/blob/master/run.md
38 Sorry for the inconvenience. In the future, these will run automatically.`
@@ -260,10 +260,6 @@ func Init(repoPath string, conf *config.Config) error {
260 return err
261 }
262
263 - if err := initDefaultDatastore(repoPath, conf); err != nil {
264 - return err
265 - }
266 -
263 if err := mfsr.RepoPath(repoPath).WriteVersion(RepoVersion); err != nil {
264 return err
265 }
@@ -368,13 +364,10 @@ func (r *FSRepo) openDatastore() error {
364 }
365
366 r.ds = d
367 + } else if r.config.Datastore.Type != "" || r.config.Datastore.Path != "" {
368 + return fmt.Errorf("old style datatstore config detected")
369 } else {
372 - // TODO: This is for legacy configs, remove in the future
373 - d, err := openDefaultDatastore(r)
374 - if err != nil {
375 - return err
376 - }
377 - r.ds = d
370 + return fmt.Errorf("required Datastore.Spec entry missing form config file")
371 }
372
373 // Wrap it with metrics gathering
repo/fsrepo/fsrepo_test.go
+5 -5
@@ -40,8 +40,8 @@ func TestCanManageReposIndependently(t *testing.T) {
40 pathB := testRepoPath("b", t)
41
42 t.Log("initialize two repos")
43 - assert.Nil(Init(pathA, &config.Config{}), t, "a", "should initialize successfully")
44 - assert.Nil(Init(pathB, &config.Config{}), t, "b", "should initialize successfully")
43 + assert.Nil(Init(pathA, &config.Config{Datastore: *config.DefaultDatastoreConfig()}), t, "a", "should initialize successfully")
44 + assert.Nil(Init(pathB, &config.Config{Datastore: *config.DefaultDatastoreConfig()}), t, "b", "should initialize successfully")
45
46 t.Log("ensure repos initialized")
47 assert.True(IsInitialized(pathA), t, "a should be initialized")
@@ -67,7 +67,7 @@ func TestDatastoreGetNotAllowedAfterClose(t *testing.T) {
67 path := testRepoPath("test", t)
68
69 assert.True(!IsInitialized(path), t, "should NOT be initialized")
70 - assert.Nil(Init(path, &config.Config{}), t, "should initialize successfully")
70 + assert.Nil(Init(path, &config.Config{Datastore: *config.DefaultDatastoreConfig()}), t, "should initialize successfully")
71 r, err := Open(path)
72 assert.Nil(err, t, "should open successfully")
73
@@ -84,7 +84,7 @@ func TestDatastorePersistsFromRepoToRepo(t *testing.T) {
84 t.Parallel()
85 path := testRepoPath("test", t)
86
87 - assert.Nil(Init(path, &config.Config{}), t)
87 + assert.Nil(Init(path, &config.Config{Datastore: *config.DefaultDatastoreConfig()}), t)
88 r1, err := Open(path)
89 assert.Nil(err, t)
90
@@ -106,7 +106,7 @@ func TestDatastorePersistsFromRepoToRepo(t *testing.T) {
106 func TestOpenMoreThanOnceInSameProcess(t *testing.T) {
107 t.Parallel()
108 path := testRepoPath("", t)
109 - assert.Nil(Init(path, &config.Config{}), t)
109 + assert.Nil(Init(path, &config.Config{Datastore: *config.DefaultDatastoreConfig()}), t)
110
111 r1, err := Open(path)
112 assert.Nil(err, t, "first repo should open successfully")
test/sharness/t0066-migration.sh
+1 -1
@@ -34,7 +34,7 @@ test_expect_success "ipfs daemon --migrate=true runs migration" '
34 test_expect_code 1 ipfs daemon --migrate=true > true_out
35 '
36
37 -test_expect_success "output looks good" '
37 +test_expect_failure "output looks good" '
38 grep "Running: " true_out > /dev/null &&
39 grep "Success: fs-repo has been migrated to version 5." true_out > /dev/null
40 '