Repository navigation
Description
Summary
LSMTreeFullTextIndex.computeCorpusCounters scans the whole type, accumulates docs and sumLen into two locals, and then writes them over the shared counters with ftMetadata.setCounters(docs, sumLen). Those same counters are bumped concurrently by every indexing transaction through FullTextIndexMetadata.addDocument. A document indexed while the scan is running has already incremented totalDocs and sumDocLength, and the absolute overwrite discards that increment, so the corpus is left permanently smaller than the data.
The second half is what makes it hard to notice: setCounters also sets countersValid = true AND staleChecked.set(true), with the comment "freshly computed counters are by definition consistent with the live data". That consumes the once-per-session drift check in ensureCounters(), the very mechanism that would otherwise have compared countType(typeName, false) against getTotalDocs() and self-healed. After a racing recompute the index reports itself exact and will not re-validate for the rest of the session.
The codebase already knows this failure mode and closed only half of it. RebuildIndexStatement guards the statsOnly branch against the ASYNC EXECUTOR with waitForAsyncCompletion() and quiesceAsync(), and its comment describes the defect exactly:
The statsOnly branch is worse ... it recomputes the BM25 corpus counters by scanning the type and then OVERWRITES the counters with what the scan found. Run inside the window it finds nothing committed and writes "0 documents" over counters the records had already bumped when they were saved, so the corpus size stays 0 for a type full of documents and every BM25 score is computed against it until somebody recomputes again. That one does not heal itself
quiesceAsync() parks the async workers and nothing else: it resolves to executor.quiesceWorkers() on the async field and returns NO_ASYNC_TO_QUIESCE when no executor exists. An ordinary begin() / save() / commit() on another thread is not parked by it, is not excluded by any lock, and hits precisely the window the comment describes. The query-path caller has no quiesce at all.
Where
engine/src/main/java/com/arcadedb/index/fulltext/LSMTreeFullTextIndex.java:907:
private void computeCorpusCounters(final boolean persist) {
...
long docs = 0L;
long sumLen = 0L;
final Iterator<Record> it = db.iterateType(typeName, true);
while (it.hasNext()) {
...
++docs;
sumLen += len;
}
ftMetadata.setCounters(docs, sumLen);engine/src/main/java/com/arcadedb/schema/FullTextIndexMetadata.java:668:
public void setCounters(final long totalDocs, final long sumDocLength) {
this.totalDocs.set(totalDocs);
this.sumDocLength.set(sumDocLength);
this.countersValid = true;
this.staleChecked.set(true); // freshly computed counters are by definition consistent with the live data
}against the concurrent writer at FullTextIndexMetadata.java:692, which the javadoc above it says may be called "on the shared metadata" by "concurrent indexing transactions" and is "adjusted at index put/remove time, BEFORE the transaction commits":
public void addDocument(final long docLength) {
sumDocLength.addAndGet(docLength);
totalDocs.incrementAndGet();
}Two callers reach the scan, and neither excludes an ordinary committer:
engine/src/main/java/com/arcadedb/query/sql/parser/RebuildIndexStatement.java:155, the SQLREBUILD INDEX <name> {statsOnly: true}path, which wraps the call inquiesceAsync()only:
try (final AsyncQuiesce asyncPaused = ((DatabaseInternal) database).quiesceAsync()) {
return recomputeStatistics(database, result);
}reaching TypeIndex.java:650 then LSMTreeFullTextIndex.recomputeStatistics at :894.
engine/src/main/java/com/arcadedb/index/fulltext/LSMTreeFullTextIndex.java:860, the lazy self-heal on the QUERY path:
if (ftMetadata.claimStaleCheck()) {
...
if (liveCount != persisted) {
...
computeCorpusCounters(false);
}This one holds no lock of any kind and runs on an ordinary read path, so it races every writer on the database.
engine/src/main/java/com/arcadedb/database/LocalDatabase.java:547 is why the quiesce does not help:
public AsyncQuiesce quiesceAsync() {
final DatabaseAsyncExecutorImpl executor = async;
if (executor == null)
return NO_ASYNC_TO_QUIESCE;
return executor.quiesceWorkers();
}Repro
Shape, on a type with a BM25 full-text index: start a REBUILD INDEX <name> {statsOnly: true} on a corpus large enough that the scan takes a visible amount of time, and commit N ordinary single-document inserts on another thread while it runs. Afterwards EXPLAIN's corpus size (or FullTextIndexMetadata.getTotalDocs()) is short by the number of documents committed after the scan passed their bucket, while SELECT count(*) FROM <type> is correct. Re-running a query does NOT correct it: ensureCounters() has already had its staleChecked flag consumed by the same setCounters call, so the liveCount != persisted branch that would have repaired it never runs again in that JVM session.
The degenerate version of this is already in the test suite for the async half: Issue6281AsyncBatchIndexBuildTest#aStatsRecomputeOverAnIdleAsyncExecutorStillCountsItsUncommittedBatch records "0 of 200 documents counted" with the barrier removed. The same arithmetic applies to an ordinary transaction, which no barrier covers.
Suggested fix
Make the publication a delta rather than an absolute set, which is what the structure's own concurrency model already assumes everywhere else (the counters are AtomicLong precisely so writers can bump them lock-free):
final long docsAtStart = ftMetadata.getTotalDocs();
final long lenAtStart = ftMetadata.getSumDocLength();
// ... scan ...
ftMetadata.setCounters(docs + (ftMetadata.getTotalDocs() - docsAtStart),
sumLen + (ftMetadata.getSumDocLength() - lenAtStart));Failing that, give the recompute the certificate the structure is missing: if either counter moved between the start and the end of the scan, do NOT consume staleChecked, so the next query re-validates against countType and repairs. A one-line change in setCounters (an overload that leaves staleChecked alone) is enough for that half.
The same reasoning applies to the removeDocument side: a delete committed during the scan is also discarded by the overwrite, in the opposite direction.
Scope / confidence
Read off the code at HEAD; the window is open on any server that takes a BM25 full-text index and writes to the indexed type concurrently, which is the ordinary case for a live corpus. The consequence is BM25 ranking quality (N for IDF and avgdl are both computed from these counters), not data loss, and it is silent: the counters mark themselves valid and disable the session's own drift detection. The async-executor instance of this was fixed in #6281 and #6303, so the defect shape is already accepted as real; what is left is the ordinary-transaction instance and the unguarded query-path self-heal.
openCypher temporal and duration cluster (#8384, #8385, #8386, #8387)
Fix validation: openCypher temporal / duration family
Verified at de3e6d9a89. The engine was built and every assertion below was executed, not read.
Modules grpc-client and grpcw were NOT built or exercised (protobuf-java is missing from the
offline repository here); nothing in this report depends on them.
Activity
Merge pull request #9393 from ArcadeData/worktree-issues-9337-9336-93…
lvca commentedon Oct 7, 2026
Fixed in #9393 (26.11.1). Rebuilding the BM25 statistics while documents were being indexed could lose the new documents from the corpus counters, and the index would then skip its own self-check. The scan result is now merged with concurrent changes, and when writers were active the next query re-validates and repairs the counters.
❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.
fix: BM25 counter publish as delta (ArcadeData#9337), DST-safe hourly…
fix: BM25 counter publish as delta (#9337), DST-safe hourly retention (…