Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-ds-leveldb
Commits
d7c8228c
Commit
d7c8228c
authored
Dec 02, 2019
by
Adin Schmahmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: datastore now uses synchronous writes which was the expected behavior
parent
e56d27d0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
10 deletions
+13
-10
datastore.go
datastore.go
+13
-10
No files found.
datastore.go
View file @
d7c8228c
...
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment