Repository navigation
Description
Summary
After rebase_branch, the branch's commit head moves to the new chain, but its index head can stay on the index built from its pre-rebase chain. The next load reads that stale index for everything at or below its t, and replays only new-chain commits above it. The source's commits at or below that t go missing, and the branch's pre-rebase state shows through.
Nothing fails: the rebase reports success and later reads are silently wrong.
Cause
prepare_rebase replaces the branch's index through copy_source_index (fluree-db-api/src/rebase.rs:844). It copies the source's index artifacts, then calls publish_index(branch, source.index_t, …). Two cases leave the branch's own index in place:
- The source has no index (
index_head_idisNone): nothing is published. - The source's
index_tis at or below the branch's:publish_indexis monotonic on every nameservice backend (memory, file, storage) and silently ignores the older publish.
The second case is probably the common one. A branch that sees more activity than its source is indexed further ahead.
The in-memory state the rebase produces is correct: it is the source's state plus the replays. The stale index only takes effect on the next load, which is when the wrong data appears.
Reproduction
mydb:main, t=1: insert Alice.create_branch("mydb", "dev", None, None).mydb:dev, t=2: insert Dave.- Index
dev, givingindex_t = 2. Use the background indexer, orrebuild_index_from_commitsoverbranched_content_store(seereindexfails on any branch: it reads commits through the flat store and misses the ones before the fork #1984 for whyreindexcan't do it). mydb:main, t=2: insert Carol.mainstays unindexed.rebase_branch("mydb", "dev", TakeBoth). This reportsreplayed = 1;devnow hascommit_t = 3andindex_t = 2.
Result:
- Querying
mydb:devfor names returns Alice and Dave; Carol is missing. This holds on a fresh load and afterdisconnect_ledger. create_branch("mydb", "x", Some("dev"), Some(TimeSpec::AtT(2)))resolvest=2to the discarded pre-rebase commit, then fails with a 404 saying the commit is not on the line of commits.
Controls: the same scenario returns Alice, Carol and Dave, with t:1–t:3 all on the new chain, when:
devis not indexed before the rebase, ordevis reindexed after it.
Suggested fix
Make the rebase set the branch's index head outright, instead of publishing through the monotonic path:
- to the source's copied index when the source has one;
- otherwise to no index, so the branch replays from genesis until the indexer catches up.
reset_head with an NsRecordSnapshot already restores both heads for the rebase's rollback path.
Other paths:
- Raft: the apply path (
AdvanceRefthrough consensus) needs the same change. - Fast-forward: this path uses the same
copy_source_index. It looks safe, because a branch with no commits of its own can only have indexed the source's chain, but a test should pin that.
Tests: a source with no index, and a source indexed below the branch. Each should assert the branch's data after a reload, not from the cache the rebase leaves behind.
Found while checking a claim in #1969.
Activity