Iterator with SinceTs reads the tables whose max version equals SinceTs
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
Research direction
The bug is in the table selection used by the iterator: start with pickTable and pickTables, and compare them with Iterator.parseItem, which drops versions <= SinceTs. Change the skip condition so a table whose MaxVersion() equals SinceTs is skipped, then add a regression test with a table whose max version is 10 and SinceTs is 10. Done when that test passes and the iterator still returns versions above SinceTs.
Written by the indexing model from the issue text.
Description
Describe the bug
IteratorOptions.SinceTs is documented as "Only read data that has version > SinceTs", and
Iterator.parseItem drops every version <= SinceTs. But pickTable and pickTables only skip a
table when MaxVersion() < SinceTs: a table whose max version is exactly SinceTs is still picked,
although it cannot hold a single version the iterator returns. All its entries are then read and
discarded one by one.
The case where it hurts is an incremental backup taken with since = the version returned by the
previous backup, right after that full backup or right after a restore (DB.Load): every table of
the store then has MaxVersion() == since, so the "incremental" backup iterates the whole store to
find the few entries written since.
To Reproduce
- Open a DB, write a few hundred thousand keys, close and reopen it (or restore it with
DB.Load). since, _ := db.Backup(full, 0).- Write a handful of keys, then
db.Backup(incr, since). - The incremental backup reads every table of the store, not only the ones holding the new keys.
At the unit level: build a table whose max version is 10; IteratorOptions{SinceTs: 10}.pickTable(t)
returns true, and pickTables keeps it.
On a store of 1.6M entries (131 MB backup), the first incremental backup after a restore took
180-360 ms wall and 1.2-1.6 s CPU; skipping those tables brings it to 22-40 ms.
Expected behavior
A table whose MaxVersion() is <= SinceTs is skipped, like the older ones: it holds no version
above SinceTs.
Environment
- OS: Linux (Debian bookworm container) and Windows 11
- Language: Go 1.27
- Version: v4.9.6, and
mainat 78b99b8
Additional context
The fix is a one-character comparison in pickTable and pickTables (< to <=), with a
regression test; I am opening a pull request for it.
- Dominant language
- Go
- Stars
- 15.8k
- Forks
- 1.4k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dgraph-io/badger
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
kind/bug Stale
Difficulty 2/5 Under an hour Newbie friendliness 75/100
-
Missing value log fsync on MemTableFlush and vlog rotation results in dangling value pointers after a crashPossibly taken @sli67 claimed this today. Open
Difficulty 3/5 1-2 days Newbie friendliness 20/100
-
Missing syncDir on value log rotation and L0 table flush breaks crash consistencyPossibly taken @hcrosse claimed this 4 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
All issues in dgraph-io/badger
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
hivecommons/hive#19912 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
siyuan-note/siyuan#21692 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
rudderlabs/rudder-server#7641 · 1 comment ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ossf/package-analysis#1222 ·
Maintainers usually reply within 1 day