A RocksDB iterator loop that never checks status returns a short result with no error
Symptom#
A scan over a RocksDB column family returns fewer rows than the database holds. No error shows up. In one case a scan returned 2,477 rows out of 236,026. The log held only Too many open files.
Cause#
for (it->Seek(p); it->Valid(); it->Next()) ends when Valid() is false. Valid() is also false when the iterator hit an error, for example an open file limit while it opened many SST files. Code that does not read it->status() after the loop cannot tell the end of data from an error.
Fix#
Check it->status() after every scan loop and turn a non-OK status into an error. Send all scans through one helper that does this, so no loop skips the check. Treat NotFound as "absent" only for point lookups, never for scans. Test it: damage one SST file and check that every reader reports an error. With the check removed, 6 of 7 reader cases failed that test.
Evidence#
- dftracer-utils: a spill of 689 small runs made a scan open all their SST files at once and hit the open file limit.
- 7 scan loops had no status check (index writer, rollup reads, aggregation dictionary, shard merge).
- Fix:
scan_prefix.hhelper plus testindex/test_scan_errors.
Also found by searching
- Too many open files
- a RocksDB scan returns fewer rows than were written and gives no error
- why does a RocksDB iterator loop return a short result
- how do I find a silent partial read in RocksDB