From d00a3d7439c3bc2826a4423866069826befc1d09 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Tue, 26 Nov 2019 12:01:13 -0500 Subject: [PATCH 1/3] update datastore interface --- datastore.go | 4 ++++ ds_test.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/datastore.go b/datastore.go index b017230..6eee181 100644 --- a/datastore.go +++ b/datastore.go @@ -79,6 +79,10 @@ func (a *accessor) Put(key ds.Key, value []byte) (err error) { return a.ldb.Put(key.Bytes(), value, nil) } +func (a *accessor) Sync(prefix ds.Key) error { + return nil +} + func (a *accessor) Get(key ds.Key) (value []byte, err error) { val, err := a.ldb.Get(key.Bytes(), nil) if err != nil { diff --git a/ds_test.go b/ds_test.go index b2a6fad..1f642ac 100644 --- a/ds_test.go +++ b/ds_test.go @@ -30,7 +30,7 @@ var testcases = map[string]string{ // d, close := newDS(t) // defer close() func newDS(t *testing.T) (*Datastore, func()) { - path, err := ioutil.TempDir("/tmp", "testing_leveldb_") + path, err := ioutil.TempDir("", "testing_leveldb_") if err != nil { t.Fatal(err) } diff --git a/go.mod b/go.mod index 652f1c9..23c7580 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/ipfs/go-ds-leveldb require ( - github.com/ipfs/go-datastore v0.2.0 + github.com/ipfs/go-datastore v0.3.0 github.com/syndtr/goleveldb v1.0.0 ) diff --git a/go.sum b/go.sum index 852bef9..30135d8 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,8 @@ github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/ipfs/go-datastore v0.2.0 h1:5Wjw6YXzZmtqU1MSrlws64+oLmSqea7gEajTcJickh8= -github.com/ipfs/go-datastore v0.2.0/go.mod h1:w38XXW9kVFNp57Zj5knbKWM2T+KOZCGDRVNdgPHtbHw= +github.com/ipfs/go-datastore v0.3.0 h1:9au0tYi/+n7xeUnGHG6davnS8x9hWbOzP/388Vx3CMs= +github.com/ipfs/go-datastore v0.3.0/go.mod h1:w38XXW9kVFNp57Zj5knbKWM2T+KOZCGDRVNdgPHtbHw= github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8 h1:bspPhN+oKYFk5fcGNuQzp6IGzYQSenLEgH3s6jkXrWw= github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8/go.mod h1:Ly/wlsjFq/qrU3Rar62tu1gASgGw6chQbSh/XgIIXCY= From e56d27d01b50ccefdf7cd4dd33909f2549081ce9 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Wed, 27 Nov 2019 13:07:32 -0500 Subject: [PATCH 2/3] gx: remove gx Makefile --- Makefile | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 5415256..0000000 --- a/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -export IPFS_API ?= v04x.ipfs.io - -gx: - go get -u github.com/whyrusleeping/gx - go get -u github.com/whyrusleeping/gx-go - -deps: gx - gx --verbose install --global - gx-go rewrite From d7c8228cb839c83a1082b98b9a18647d74484d6e Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Mon, 2 Dec 2019 09:31:30 -0500 Subject: [PATCH 3/3] fix: datastore now uses synchronous writes which was the expected behavior --- datastore.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/datastore.go b/datastore.go index 6eee181..6d516a8 100644 --- a/datastore.go +++ b/datastore.go @@ -53,7 +53,7 @@ func NewDatastore(path string, opts *Options) (*Datastore, error) { } return &Datastore{ - accessor: &accessor{ldb: db}, + accessor: &accessor{ldb: db, syncWrites: true}, DB: db, path: path, }, nil @@ -72,11 +72,12 @@ type levelDbOps interface { // Datastore operations using either the DB or a transaction as the backend. type accessor struct { - ldb levelDbOps + ldb levelDbOps + syncWrites bool } func (a *accessor) Put(key ds.Key, value []byte) (err error) { - return a.ldb.Put(key.Bytes(), value, nil) + return a.ldb.Put(key.Bytes(), value, &opt.WriteOptions{Sync: a.syncWrites}) } func (a *accessor) Sync(prefix ds.Key) error { @@ -103,7 +104,7 @@ func (d *accessor) GetSize(key ds.Key) (size int, err error) { } func (a *accessor) Delete(key ds.Key) (err error) { - return a.ldb.Delete(key.Bytes(), nil) + return a.ldb.Delete(key.Bytes(), &opt.WriteOptions{Sync: a.syncWrites}) } func (a *accessor) Query(q dsq.Query) (dsq.Results, error) { @@ -184,14 +185,16 @@ func (d *Datastore) Close() (err error) { } type leveldbBatch struct { - b *leveldb.Batch - db *leveldb.DB + b *leveldb.Batch + db *leveldb.DB + syncWrites bool } func (d *Datastore) Batch() (ds.Batch, error) { return &leveldbBatch{ - b: new(leveldb.Batch), - db: d.DB, + b: new(leveldb.Batch), + db: d.DB, + syncWrites: d.syncWrites, }, nil } @@ -201,7 +204,7 @@ func (b *leveldbBatch) Put(key ds.Key, value []byte) error { } func (b *leveldbBatch) Commit() error { - return b.db.Write(b.b, nil) + return b.db.Write(b.b, &opt.WriteOptions{Sync: b.syncWrites}) } func (b *leveldbBatch) Delete(key ds.Key) error { @@ -228,6 +231,6 @@ func (d *Datastore) NewTransaction(readOnly bool) (ds.Txn, error) { if err != nil { return nil, err } - accessor := &accessor{tx} + accessor := &accessor{ldb: tx, syncWrites: false} return &transaction{accessor, tx}, nil }