Skip to content

Commit

Permalink
Merge branch 'use-regular-delete-in-rocksdb' into release-2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lni committed Apr 4, 2019
2 parents 013c628 + 5705e94 commit 91f71b3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
32 changes: 30 additions & 2 deletions internal/logdb/kv_rocksdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,36 @@ func (r *rocksdbKV) Compaction(firstKey []byte, lastKey []byte) error {
}

func (r *rocksdbKV) deleteRange(firstKey []byte, lastKey []byte) error {
iter := r.db.NewIterator(r.ro)
defer iter.Close()
toDelete := make([][]byte, 0)
for iter.Seek(firstKey); iteratorIsValid(iter); iter.Next() {
if done := func() bool {
key, ok := iter.OKey()
if !ok {
panic("failed to get key")
}
defer key.Free()
kd := key.Data()
if bytes.Compare(kd, lastKey) >= 0 {
return true
} else {
v := make([]byte, len(kd))
copy(v, kd)
toDelete = append(toDelete, v)
}
return false
}(); done {
break
}
}
wb := gorocksdb.NewWriteBatch()
defer wb.Destroy()
wb.DeleteRange(firstKey, lastKey)
return r.db.Write(r.wo, wb)
for _, key := range toDelete {
wb.Delete(key)
}
if wb.Count() > 0 {
return r.db.Write(r.wo, wb)
}
return nil
}
2 changes: 1 addition & 1 deletion internal/logdb/kv_rocksdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func testCompactRangeWithCompactionFilterWorks(t *testing.T,
t.Fatalf("failed to get db size %v", err)
}
if sz > initialSz/10 {
t.Errorf("sz %d > initialSz/10", sz)
t.Errorf("sz %d > initialSz/10 (%d)", sz, initialSz/10)
}
}

Expand Down

0 comments on commit 91f71b3

Please sign in to comment.