Unverified Commit 133948da authored by Adin Schmahmann's avatar Adin Schmahmann Committed by GitHub

Merge pull request #77 from ipfs/feat/ds-update

update datastore Interface
parents a4193bf7 937ab757
...@@ -29,6 +29,8 @@ type Datastore struct { ...@@ -29,6 +29,8 @@ type Datastore struct {
gcDiscardRatio float64 gcDiscardRatio float64
gcSleep time.Duration gcSleep time.Duration
gcInterval time.Duration gcInterval time.Duration
syncWrites bool
} }
// Implements the datastore.Txn interface, enabling transaction support for // Implements the datastore.Txn interface, enabling transaction support for
...@@ -125,6 +127,7 @@ func NewDatastore(path string, options *Options) (*Datastore, error) { ...@@ -125,6 +127,7 @@ func NewDatastore(path string, options *Options) (*Datastore, error) {
gcDiscardRatio: gcDiscardRatio, gcDiscardRatio: gcDiscardRatio,
gcSleep: gcSleep, gcSleep: gcSleep,
gcInterval: gcInterval, gcInterval: gcInterval,
syncWrites: opt.SyncWrites,
} }
// Start the GC process if requested. // Start the GC process if requested.
...@@ -200,6 +203,20 @@ func (d *Datastore) Put(key ds.Key, value []byte) error { ...@@ -200,6 +203,20 @@ func (d *Datastore) Put(key ds.Key, value []byte) error {
return txn.commit() return txn.commit()
} }
func (d *Datastore) Sync(prefix ds.Key) error {
d.closeLk.RLock()
defer d.closeLk.RUnlock()
if d.closed {
return ErrClosed
}
if d.syncWrites {
return nil
}
return d.DB.Sync()
}
func (d *Datastore) PutWithTTL(key ds.Key, value []byte, ttl time.Duration) error { func (d *Datastore) PutWithTTL(key ds.Key, value []byte, ttl time.Duration) error {
d.closeLk.RLock() d.closeLk.RLock()
defer d.closeLk.RUnlock() defer d.closeLk.RUnlock()
...@@ -381,6 +398,16 @@ func (t *txn) put(key ds.Key, value []byte) error { ...@@ -381,6 +398,16 @@ func (t *txn) put(key ds.Key, value []byte) error {
return t.txn.Set(key.Bytes(), value) return t.txn.Set(key.Bytes(), value)
} }
func (t *txn) Sync(prefix ds.Key) error {
t.ds.closeLk.RLock()
defer t.ds.closeLk.RUnlock()
if t.ds.closed {
return ErrClosed
}
return nil
}
func (t *txn) PutWithTTL(key ds.Key, value []byte, ttl time.Duration) error { func (t *txn) PutWithTTL(key ds.Key, value []byte, ttl time.Duration) error {
t.ds.closeLk.RLock() t.ds.closeLk.RLock()
defer t.ds.closeLk.RUnlock() defer t.ds.closeLk.RUnlock()
......
...@@ -2,7 +2,7 @@ module github.com/ipfs/go-ds-badger ...@@ -2,7 +2,7 @@ module github.com/ipfs/go-ds-badger
require ( require (
github.com/dgraph-io/badger v1.6.0 github.com/dgraph-io/badger v1.6.0
github.com/ipfs/go-datastore v0.2.0 github.com/ipfs/go-datastore v0.3.0
github.com/ipfs/go-log v0.0.1 github.com/ipfs/go-log v0.0.1
github.com/jbenet/goprocess v0.1.3 github.com/jbenet/goprocess v0.1.3
) )
......
...@@ -27,8 +27,8 @@ github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= ...@@ -27,8 +27,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/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/ipfs/go-datastore v0.2.0 h1:5Wjw6YXzZmtqU1MSrlws64+oLmSqea7gEajTcJickh8= github.com/ipfs/go-datastore v0.3.0 h1:9au0tYi/+n7xeUnGHG6davnS8x9hWbOzP/388Vx3CMs=
github.com/ipfs/go-datastore v0.2.0/go.mod h1:w38XXW9kVFNp57Zj5knbKWM2T+KOZCGDRVNdgPHtbHw= 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/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
github.com/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc= github.com/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc=
github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM=
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment