Invalid data returned when iterating
- Dominant language
- C++
- Stars
- 32.1k
- Forks
- 6.9k
- Avg merge
- 32m
- Merged PRs (30d)
- 1
Description
### Expected behavior
When accessing the same value via an iterator or the `get` method I expect to get the same value, but it seems I get a stale value in case an iterator is used in my configuration.
I've included the following minmal example, which shows the observed behaviour:
```java
import org.rocksdb.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class MinimalEx {
public static void main(String[] args) throws Exception {
ColumnFamilyOptions cfoptions = new ColumnFamilyOptions();
cfoptions.optimizeLevelStyleCompaction(128 * 1024 * 1024)
.optimizeForPointLookup(50)
.optimizeFiltersForHits();
final List cfDescriptors = Arrays.asList(
new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, new ColumnFamilyOptions()),
new ColumnFamilyDescriptor("urls".getBytes(), cfoptions)
);
final List columnFamilyHandleList = new ArrayList<>();
final DBOptions options = new DBOptions()
.setCreateIfMissing(true)
.setCreateMissingColumnFamilies(true)
.setStatsDumpPeriodSec(5 * 60);
RocksDB db = RocksDB.openReadOnly(options, "test-db", cfDescriptors, columnFamilyHandleList);
RocksIterator it = db.newIterator(columnFamilyHandleList.get(1));
it.seek(new byte[16]);
//it.seekToFirst();
for (; it.isValid(); it.next()) {
byte[] reread = db.get(columnFamilyHandleList.get(1), it.key());
if (!Arrays.equals(reread, it.value())) {
System.err.println(Arrays.toString(reread));
System.err.println(Arrays.toString(it.value()));
System.exit(0);
}
}
}
}
```
For this example we quickly get different values for the same key. This is unexpected.
If I change `it.seek(new byte[16])` to `it.seekToFirst()` or remove `.optimizeForPointLookup(50)` RocksDB behaves as expected.
Note: Access via iteration is only used on startup, therefore I choose optimizeForPointLookup.
This was tested with the latests RocksDB JNI release (5.17.2), even though the database was created with an older release.
Contributor guide
Assessment
This issue has not been assessed yet.