提交 2df7727b 作者: Kevin Atkinson 提交者: Jeromy

bump repo version, remove support for old config

License: MIT
Signed-off-by: 's avatarKevin Atkinson <k@kevina.org>
上级 0f8b6032
...@@ -21,10 +21,7 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) { ...@@ -21,10 +21,7 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
return nil, err return nil, err
} }
datastore, err := datastoreConfig() datastore := DefaultDatastoreConfig()
if err != nil {
return nil, err
}
conf := &Config{ conf := &Config{
...@@ -79,7 +76,8 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) { ...@@ -79,7 +76,8 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
return conf, nil return conf, nil
} }
func datastoreConfig() (*Datastore, error) { // DatastoreConfig is an internal function exported to aid in testing.
func DefaultDatastoreConfig() *Datastore {
return &Datastore{ return &Datastore{
StorageMax: "10GB", StorageMax: "10GB",
StorageGCWatermark: 90, // 90% StorageGCWatermark: 90, // 90%
...@@ -111,7 +109,7 @@ func datastoreConfig() (*Datastore, error) { ...@@ -111,7 +109,7 @@ func datastoreConfig() (*Datastore, error) {
}, },
}, },
}, },
}, nil }
} }
// identityConfig initializes a new identity. // identityConfig initializes a new identity.
......
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
}
...@@ -32,7 +32,7 @@ import ( ...@@ -32,7 +32,7 @@ import (
var log = logging.Logger("fsrepo") var log = logging.Logger("fsrepo")
// version number that we are currently expecting to see // 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 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.` Sorry for the inconvenience. In the future, these will run automatically.`
...@@ -260,10 +260,6 @@ func Init(repoPath string, conf *config.Config) error { ...@@ -260,10 +260,6 @@ func Init(repoPath string, conf *config.Config) error {
return err return err
} }
if err := initDefaultDatastore(repoPath, conf); err != nil {
return err
}
if err := mfsr.RepoPath(repoPath).WriteVersion(RepoVersion); err != nil { if err := mfsr.RepoPath(repoPath).WriteVersion(RepoVersion); err != nil {
return err return err
} }
...@@ -368,13 +364,10 @@ func (r *FSRepo) openDatastore() error { ...@@ -368,13 +364,10 @@ func (r *FSRepo) openDatastore() error {
} }
r.ds = d r.ds = d
} else if r.config.Datastore.Type != "" || r.config.Datastore.Path != "" {
return fmt.Errorf("old style datatstore config detected")
} else { } else {
// TODO: This is for legacy configs, remove in the future return fmt.Errorf("required Datastore.Spec entry missing form config file")
d, err := openDefaultDatastore(r)
if err != nil {
return err
}
r.ds = d
} }
// Wrap it with metrics gathering // Wrap it with metrics gathering
......
...@@ -40,8 +40,8 @@ func TestCanManageReposIndependently(t *testing.T) { ...@@ -40,8 +40,8 @@ func TestCanManageReposIndependently(t *testing.T) {
pathB := testRepoPath("b", t) pathB := testRepoPath("b", t)
t.Log("initialize two repos") t.Log("initialize two repos")
assert.Nil(Init(pathA, &config.Config{}), t, "a", "should initialize successfully") assert.Nil(Init(pathA, &config.Config{Datastore: *config.DefaultDatastoreConfig()}), t, "a", "should initialize successfully")
assert.Nil(Init(pathB, &config.Config{}), t, "b", "should initialize successfully") assert.Nil(Init(pathB, &config.Config{Datastore: *config.DefaultDatastoreConfig()}), t, "b", "should initialize successfully")
t.Log("ensure repos initialized") t.Log("ensure repos initialized")
assert.True(IsInitialized(pathA), t, "a should be initialized") assert.True(IsInitialized(pathA), t, "a should be initialized")
...@@ -67,7 +67,7 @@ func TestDatastoreGetNotAllowedAfterClose(t *testing.T) { ...@@ -67,7 +67,7 @@ func TestDatastoreGetNotAllowedAfterClose(t *testing.T) {
path := testRepoPath("test", t) path := testRepoPath("test", t)
assert.True(!IsInitialized(path), t, "should NOT be initialized") 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) r, err := Open(path)
assert.Nil(err, t, "should open successfully") assert.Nil(err, t, "should open successfully")
...@@ -84,7 +84,7 @@ func TestDatastorePersistsFromRepoToRepo(t *testing.T) { ...@@ -84,7 +84,7 @@ func TestDatastorePersistsFromRepoToRepo(t *testing.T) {
t.Parallel() t.Parallel()
path := testRepoPath("test", t) 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) r1, err := Open(path)
assert.Nil(err, t) assert.Nil(err, t)
...@@ -106,7 +106,7 @@ func TestDatastorePersistsFromRepoToRepo(t *testing.T) { ...@@ -106,7 +106,7 @@ func TestDatastorePersistsFromRepoToRepo(t *testing.T) {
func TestOpenMoreThanOnceInSameProcess(t *testing.T) { func TestOpenMoreThanOnceInSameProcess(t *testing.T) {
t.Parallel() t.Parallel()
path := testRepoPath("", t) path := testRepoPath("", t)
assert.Nil(Init(path, &config.Config{}), t) assert.Nil(Init(path, &config.Config{Datastore: *config.DefaultDatastoreConfig()}), t)
r1, err := Open(path) r1, err := Open(path)
assert.Nil(err, t, "first repo should open successfully") assert.Nil(err, t, "first repo should open successfully")
......
...@@ -34,7 +34,7 @@ test_expect_success "ipfs daemon --migrate=true runs migration" ' ...@@ -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_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 "Running: " true_out > /dev/null &&
grep "Success: fs-repo has been migrated to version 5." true_out > /dev/null grep "Success: fs-repo has been migrated to version 5." true_out > /dev/null
' '
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论