Skip to content

Commit

Permalink
add db sync
Browse files Browse the repository at this point in the history
  • Loading branch information
roseduan committed Apr 9, 2022
1 parent 9e6d2b8 commit c41a0e9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (cf *ColumnFamily) IsClosed() bool {
return atomic.LoadUint32(&cf.closed) == 1
}

// Sync syncs the content of current colun family to disk.
// Sync syncs the content of current column family to disk.
func (cf *ColumnFamily) Sync() error {
if err := cf.activeMem.syncWAL(); err != nil {
return err
Expand Down
10 changes: 10 additions & 0 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ func (db *LotusDB) Close() error {
return nil
}

// Sync syncs the content of all column families to disk.
func (db *LotusDB) Sync() error {
for _, cf := range db.cfs {
if err := cf.Sync(); err != nil {
return err
}
}
return nil
}

// Put put to default column family.
func (db *LotusDB) Put(key, value []byte) error {
return db.PutWithOptions(key, value, nil)
Expand Down
4 changes: 3 additions & 1 deletion db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func TestLotusDB_DeleteAfterFlush(t *testing.T) {
}
}

func TestLotusDB_Close(t *testing.T) {
func TestLotusDB_SyncAndClose(t *testing.T) {
opts := DefaultOptions("/tmp" + separator + "lotusdb")
db, err := Open(opts)
assert.Nil(t, err)
Expand All @@ -365,6 +365,8 @@ func TestLotusDB_Close(t *testing.T) {
assert.Nil(t, err)
}

err = db.Sync()
assert.Nil(t, err)
err = db.Close()
assert.Nil(t, err)
}
Expand Down

0 comments on commit c41a0e9

Please sign in to comment.