Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
fix: close upon batch write erroro
Browse files Browse the repository at this point in the history
chore: removed duplicated line, added comments about read / write options
  • Loading branch information
iproudhon committed Jan 20, 2022
1 parent b1a497b commit 0fe06fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
6 changes: 3 additions & 3 deletions rdb/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func (b *rdbBatch) Write() error {
}
var cerr *C.char
C.rocksdb_write(b.db.db, b.db.wopts, b.b, &cerr)
b.Close()
if cerr != nil {
return cerror(cerr)
}
b.Close()
return nil
}

Expand All @@ -68,10 +68,10 @@ func (b *rdbBatch) WriteSync() error {
}
var cerr *C.char
C.rocksdb_write(b.db.db, b.db.wsopts, b.b, &cerr)
b.Close()
if cerr != nil {
return cerror(cerr)
}
b.Close()
return nil
}

Expand All @@ -81,10 +81,10 @@ func (b *rdbBatch) WriteLowPri() error {
}
var cerr *C.char
C.rocksdb_write(b.db.db, b.db.wlpopts, b.b, &cerr)
b.Close()
if cerr != nil {
return cerror(cerr)
}
b.Close()
return nil
}

Expand Down
34 changes: 16 additions & 18 deletions rdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import (
)

type RDB struct {
name string
fn string
db *C.rocksdb_t
opts *C.rocksdb_options_t
ropts *C.rocksdb_readoptions_t
wopts *C.rocksdb_writeoptions_t
wsopts *C.rocksdb_writeoptions_t
wlpopts *C.rocksdb_writeoptions_t
name string
fn string
db *C.rocksdb_t
opts *C.rocksdb_options_t
ropts *C.rocksdb_readoptions_t // read options
wopts *C.rocksdb_writeoptions_t // write options
wsopts *C.rocksdb_writeoptions_t // sync write options
wlpopts *C.rocksdb_writeoptions_t // low priority write options
}

type rdbIterator struct {
Expand Down Expand Up @@ -69,7 +69,6 @@ func NewDB(name string, dir string) (*RDB, error) {
C.rocksdb_options_set_create_if_missing(opts, 1)
C.rocksdb_options_increase_parallelism(opts, C.int(runtime.NumCPU()))
C.rocksdb_options_optimize_level_style_compaction(opts, 512*1024*1024)
C.rocksdb_options_optimize_level_style_compaction(opts, 512*1024*1024)
C.rocksdb_options_set_enable_pipelined_write(opts, 1)

ropts := C.rocksdb_readoptions_create()
Expand All @@ -88,13 +87,13 @@ func NewDB(name string, dir string) (*RDB, error) {
return nil, cerror(cerr)
}
return &RDB{
name: name,
fn: fn,
db: db,
opts: opts,
ropts: ropts,
wopts: wopts,
wsopts: wsopts,
name: name,
fn: fn,
db: db,
opts: opts,
ropts: ropts,
wopts: wopts,
wsopts: wsopts,
wlpopts: wlpopts,
}, nil
}
Expand All @@ -109,8 +108,7 @@ func (db *RDB) Get(key []byte) ([]byte, error) {
ck := b2c(key)
cv := C.rocksdb_get(db.db, db.ropts, ck, C.size_t(len(key)), &cvl, &cerr)
if cerr != nil {
err := cerror(cerr)
return nil, err
return nil, cerror(cerr)
}
if cv == nil {
return nil, nil
Expand Down

0 comments on commit 0fe06fc

Please sign in to comment.