Skip to content

fix: inactivity rebuild timer should consult the rebuild threshold - #6510

Merged
lvca merged 3 commits into
ArcadeData:mainfrom
waterWang:fix/inactivity-rebuild-threshold
Aug 20, 2026
Merged

lvca merged 3 commits into
ArcadeData:mainfrom
waterWang:fix/inactivity-rebuild-threshold

Conversation

@waterWang

Copy link
Copy Markdown
Contributor

Problem: The inactivity rebuild timer never consults the rebuild threshold. It arms and fires on pending > 0 alone, so a single insert into a large settled LSM_VECTOR index triggers a full O(N) graph rebuild about 15 seconds later (issue #6496).

Fix: Add an inactivityRebuildIsWorthIt() helper that checks the same effective rebuild threshold the search path uses, with a floor of max(threshold/10, 1) so a trickle of writes is still eventually absorbed rather than deferred forever. Both the arming path in scheduleInactivityRebuild() and the firing path in the TimerTask now consult this helper.

Fixes #6496

The inactivity rebuild timer used to arm and fire on `pending > 0` alone,
so a single insert into a large settled LSM_VECTOR index triggered a full
O(N) graph rebuild about 15 seconds later (issue ArcadeData#6496).

This commit adds an `inactivityRebuildIsWorthIt()` helper that checks the
same effective rebuild threshold the search path uses, with a floor of
`max(threshold/10, 1)` so a trickle of writes is still eventually absorbed
rather than deferred forever. Both the arming path in
`scheduleInactivityRebuild()` and the firing path in the TimerTask now
consult this helper.

Fixes ArcadeData#6496
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@mergify

mergify Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@lvca
lvca self-requested a review August 20, 2026 18:52
@lvca lvca added the in progress The team is actively working on this issue label Aug 20, 2026
…uild path

The PR's inactivityRebuildIsWorthIt() applied the threshold/floor gate to every
graph size, but a rebuild is only expensive once the graph has grown past
ASYNC_REBUILD_MIN_GRAPH_SIZE (1000 vectors); below that, rebuildGraphBeforeSearch()
already rebuilds synchronously and unconditionally on the search path because
it's cheap enough not to matter. Gating the timer uniformly meant a small,
low-volume index (well under the floor) never got its pending vectors flushed by
the inactivity timer at all, breaking the documented guarantee that buffered
vectors don't sit in the linear-scan delta buffer indefinitely - confirmed by
running LSMVectorIndexRebuildTest against the unmodified PR branch, where
deltaBufferShouldFlushAfterInactivityTimeout, timerShouldResetOnNewMutations and
skippedInactivityRebuildShouldRetryUntilServed each hang for the full 11-minute
Awaitility ceiling before failing.

The threshold/floor check now only applies once the graph is large enough that a
rebuild is genuinely O(index size); small graphs keep the prior "any pending
mutation is worth flushing" behavior. Added Issue6496InactivityRebuildThresholdTest
to reproduce the reported scenario directly (large settled index, single insert
must not trigger a full rebuild on inactivity, but pending mutations at/above the
floor still get rebuilt). All 15 tests in LSMVectorIndexRebuildTest and both new
tests pass; the full com.arcadedb.index.vector package was run and the only
failure (LSMVectorIndexAutoCompactionTest#anAttemptWhoseTaskIsNeverEnqueuedReleasesItsSlot)
reproduces identically on unmodified main, unrelated to this change.
@lvca
lvca merged commit 665b9e1 into ArcadeData:main Aug 20, 2026
19 of 21 checks passed
@lvca lvca removed the in progress The team is actively working on this issue label Aug 20, 2026
@lvca lvca added this to the 26.9.1 milestone Aug 20, 2026
tae898 pushed a commit to humemai/arcadedb-embedded-python that referenced this pull request Aug 28, 2026
…graph as a small one

The graph loads lazily on the first search, so `graphIndex == null` carries three
meanings and only two of them mean "a rebuild here is cheap": no graph was ever
built, the graph is genuinely tiny, or a large graph is fully persisted and this
session has simply never loaded it. `inactivityRebuildIsWorthIt()` and the timer
task's sync/async arm choice read the third as the first two, so the mutation
threshold was skipped entirely and one insert into a reopened index rebuilt every
vector, synchronously, on the timer thread.

Ingest-then-idle - open, write, go quiet - is the ordinary shape of a loader
process, and it is the one shape that never loads the graph. This is the same
conflation ArcadeData#6772 fixed for a session that searches; that fix works by loading the
persisted graph inside `ensureGraphAvailable()`, which the timer never calls.

Both call sites now ask `inactivityRebuildScopeSize()` how many vectors a rebuild
would actually cover. When nothing is resident and nothing has resolved what is on
disk yet, the answer is the LIVE vector count rather than the persisted graph's
node count: `buildGraphFromScratch()` covers the live set, so that is the direct
measure of the cost being gated, and it gives the right answer where the two
diverge - a large persisted graph whose vectors have since been deleted really is
cheap to rebuild, and keeps being flushed promptly.

Confined to the case `graphNotYetMaterialised()` identifies, so everything
downstream of a resolution answers exactly as before, including the window where a
rebuild nulls the resident graph before publishing its replacement.
`rebuildGraphBeforeSearch()` is deliberately left reading `graphIndex` directly:
`ensureGraphAvailable()` always runs immediately before it, and routing a search
down the large-graph arm would hand it the async rebuild and an empty result set
instead of a slow but correct one.

New `persistedGraphNodeCount` stat, so "no graph exists" and "no graph is loaded"
can be told apart from outside - the distinction the whole fix rests on.

Regression test pins three behaviours, because fixing only the first is what broke
three existing tests the last time this gate was touched (ArcadeData#6510 for ArcadeData#6496): one
insert into a large-but-unloaded index rebuilds nothing; reaching the floor still
rebuilds, so nothing is deferred forever; and a genuinely small persisted index
still flushes on any pending mutation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inactivity rebuild timer ignores the rebuild threshold: one insert into a settled index costs a full graph rebuild

2 participants