Commit 937ab757 authored by Adin Schmahmann's avatar Adin Schmahmann

update datastore interface to support asynchronous writes

parent a4193bf7
......@@ -29,6 +29,8 @@ type Datastore struct {
gcDiscardRatio float64
gcSleep time.Duration
gcInterval time.Duration
syncWrites bool
}
// Implements the datastore.Txn interface, enabling transaction support for
......@@ -125,6 +127,7 @@ func NewDatastore(path string, options *Options) (*Datastore, error) {
gcDiscardRatio: gcDiscardRatio,
gcSleep: gcSleep,
gcInterval: gcInterval,
syncWrites: opt.SyncWrites,
}
// Start the GC process if requested.
......@@ -200,6 +203,20 @@ func (d *Datastore) Put(key ds.Key, value []byte) error {
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 {
d.closeLk.RLock()
defer d.closeLk.RUnlock()
......@@ -381,6 +398,16 @@ func (t *txn) put(key ds.Key, value []byte) error {
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 {
t.ds.closeLk.RLock()
defer t.ds.closeLk.RUnlock()
......
......@@ -2,7 +2,7 @@ module github.com/ipfs/go-ds-badger
require (
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/jbenet/goprocess v0.1.3
)
......
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