From f3754d9fc838f5854610f85de751f4f254c748fe Mon Sep 17 00:00:00 2001 From: Sarah Christoff Date: Wed, 21 Apr 2021 14:12:05 -0500 Subject: [PATCH] add v1, source to src, remove sys --- go.mod | 3 +-- go.sum | 4 +--- v2/bolt_store.go | 14 +++++++------- v2/bolt_store_test.go | 23 +++++++++++------------ 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index a1e1d62..65f1577 100644 --- a/go.mod +++ b/go.mod @@ -6,5 +6,4 @@ require ( github.com/boltdb/bolt v1.3.1 github.com/hashicorp/go-msgpack v0.5.5 github.com/hashicorp/raft v1.1.0 - golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988 // indirect -) + ) diff --git a/go.sum b/go.sum index 02d1658..ca41d0a 100644 --- a/go.sum +++ b/go.sum @@ -40,6 +40,4 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988 h1:EjgCl+fVlIaPJSori0ikSz3uV0DOHKWOJFpv1sAAhBM= -golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= \ No newline at end of file diff --git a/v2/bolt_store.go b/v2/bolt_store.go index b935ca0..8bdbbdb 100644 --- a/v2/bolt_store.go +++ b/v2/bolt_store.go @@ -6,7 +6,7 @@ import ( "os" "time" - boltdbbolt "github.com/boltdb/bolt" + v1 "github.com/boltdb/bolt" "github.com/hashicorp/raft" "go.etcd.io/bbolt" ) @@ -271,7 +271,7 @@ func (b *BoltStore) Sync() error { return b.conn.Sync() } -// MigratetoV2 reads in the source file path of a BoltDB file +// MigratetoV2 reads in the source file path of a BoltDB file // and outputs all the data migrated to a Bbolt destination file func MigratetoV2(source, destination string) (*BoltStore, error) { _, err := os.Stat(destination) @@ -279,7 +279,7 @@ func MigratetoV2(source, destination string) (*BoltStore, error) { return nil, fmt.Errorf("file exists in destination %v", destination) } - sourceDb, err := boltdbbolt.Open(source, dbFileMode, &boltdbbolt.Options{ + srcDb, err := v1.Open(source, dbFileMode, &v1.Options{ ReadOnly: true, Timeout: 1 * time.Minute, }) @@ -288,11 +288,11 @@ func MigratetoV2(source, destination string) (*BoltStore, error) { } //Start a connection to the source - sourcetx, err := sourceDb.Begin(false) + srctx, err := srcDb.Begin(false) if err != nil { return nil, fmt.Errorf("failed connecting to source database: %v", err) } - defer sourcetx.Rollback() + defer srctx.Rollback() //Create the destination destDb, err := New(Options{Path: destination}) @@ -312,9 +312,9 @@ func MigratetoV2(source, destination string) (*BoltStore, error) { //Loop over both old buckets and set them in the new buckets := [][]byte{dbConf, dbLogs} for _, b := range buckets { - sourceB := sourcetx.Bucket(b) + srcB := srctx.Bucket(b) destB := desttx.Bucket(b) - err = sourceB.ForEach(func(k, v []byte) error { + err = srcB.ForEach(func(k, v []byte) error { return destB.Put(k, v) }) if err != nil { diff --git a/v2/bolt_store_test.go b/v2/bolt_store_test.go index 617a961..65d37f0 100644 --- a/v2/bolt_store_test.go +++ b/v2/bolt_store_test.go @@ -425,16 +425,15 @@ func TestBoltStore_MigratetoV2(t *testing.T) { } defer os.RemoveAll(dir) - var sourceFile, destFile string - sourceFile = filepath.Join(dir, "/sourcepath") - destFile = filepath.Join(dir, "/destpath") + srcFile := filepath.Join(dir, "/sourcepath") + destFile := filepath.Join(dir, "/destpath") // Successfully creates and returns a store - sourceDb, err := v1.NewBoltStore(sourceFile) + srcDb, err := v1.NewBoltStore(srcFile) if err != nil { t.Fatalf("failed creating source database: %s", err) } - defer sourceDb.Close() + defer srcDb.Close() // Set a mock raft log logs := []*raft.Log{ @@ -444,19 +443,19 @@ func TestBoltStore_MigratetoV2(t *testing.T) { } //Store logs source - if err := sourceDb.StoreLogs(logs); err != nil { + if err := srcDb.StoreLogs(logs); err != nil { t.Fatalf("failed storing logs in source database: %s", err) } - sourceResult := new(raft.Log) - if err := sourceDb.GetLog(2, sourceResult); err != nil { + srcResult := new(raft.Log) + if err := srcDb.GetLog(2, srcResult); err != nil { t.Fatalf("failed getting log from source database: %s", err) } - if err := sourceDb.Close(); err != nil { + if err := srcDb.Close(); err != nil { t.Fatalf("failed closing source database: %s", err) } - destDb, err := MigratetoV2(sourceFile, destFile) + destDb, err := MigratetoV2(srcFile, destFile) if err != nil { t.Fatalf("did not migrate successfully, err %v", err) } @@ -467,8 +466,8 @@ func TestBoltStore_MigratetoV2(t *testing.T) { t.Fatalf("failed getting log from destination database: %s", err) } - if !reflect.DeepEqual(sourceResult, destResult) { - t.Errorf("BoltDB log did not equal Bbolt log, Boltdb %v, Bbolt: %v", sourceResult, destResult) + if !reflect.DeepEqual(srcResult, destResult) { + t.Errorf("BoltDB log did not equal Bbolt log, Boltdb %v, Bbolt: %v", srcResult, destResult) } }