Iterator with SinceTs reads the tables whose max version equals SinceTs

Open Beginner friendly
#2,358 0 comments 0 reactions 0 assignees View on GitHub

@BenSouchet is already working on this.

Since Oct 31, 2026.

  • #2359 by @BenSouchet — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
database

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

  1. Open a DB, write a few hundred thousand keys, close and reopen it (or restore it with DB.Load).
  2. since, _ := db.Backup(full, 0).
  3. Write a handful of keys, then db.Backup(incr, since).
  4. 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 main at 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dgraph-io/badger

All issues in dgraph-io/badger

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.