Skip to content

A SQL range or ORDER BY SELECT that has returned NO row still fails to the caller during a concurrent DROP INDEX: the #9331 retry cannot fire, because the conversion it depends on tests a flag the drop deliberately keeps true #9615

Closed

Description

@ruispereira

Summary

Two independent gaps let a read-only statement that has produced NOTHING fail to the application.

The conversion cannot fire. staleIndexOr turns the page manager's "File with id n was not
found" into the IndexException the retry catches, but only when !typeIndex.isValid().
TypeIndex.drop() drops the sub-indexes FIRST and sets valid = false only afterwards, and its own
comment calls that ordering deliberate ("The wrapper must stay valid during the first step"). The
whole window in which the file is actually gone is therefore a window in which the wrapper still
reports valid, so the conversion is skipped, the retry loop (which catches IndexException only)
never fires, and the raw storage-layer IllegalArgumentException reaches the caller. The conjunct is
self-defeating given the ordering the same codebase documents.

The retry does not cover what it claims to. openResultSet's javadoc says "the planning and the
first batch" are covered, but its try block only wraps new LocalResultSet(plan); the plan is pulled
lazily, so the first batch is actually fetched later, from the application's own hasNext(), outside
the loop. A genuine IndexException raised there escapes too, with no row returned, which the
measurements below show happening.

Both outcomes are the one the project's own regression test asserts must never occur: it tolerates a
bounded number of short answers (wrongRowCounts < max(5, answered / 200)) but asserts
assertThat(failures).isEmpty(), zero exceptions.

Where (HEAD 2b0a7a6)

engine/src/main/java/com/arcadedb/query/sql/executor/FetchFromIndexStep.java:257

  private RuntimeException staleIndexOr(final IllegalArgumentException e) {
    if (index instanceof TypeIndex typeIndex && !typeIndex.isValid() && TypeIndex.isFileNotFound(e))
      return new IndexException("Index '" + indexName + "' was dropped or rebuilt while it was being read", e);
    return e;
  }

The ordering that keeps isValid() true for the whole window,
engine/src/main/java/com/arcadedb/index/TypeIndex.java:409:

    // Order: sub-indexes dropped, then valid = false, then the list cleared. The wrapper must stay valid during the first step
    // (LocalSchema#dropIndex resolves and unregisters the wrapper through its sub-indexes), so until valid = false a reader
    // sees a valid wrapper with some sub-indexes missing ...
    for (final Index index : new ArrayList<>(indexesOnBuckets))
      type.getSchema().dropIndex(index.getName());

    valid = false;

The retry that only wraps plan construction,
engine/src/main/java/com/arcadedb/query/sql/parser/SelectStatement.java:230:

        plan = attempt == 1 ? firstPlanner.apply(context) : createExecutionPlanNoCache(context);
        return new LocalResultSet(plan);
      } catch (final IndexException e) {

and the unguarded read that raises during lazy iteration,
engine/src/main/java/com/arcadedb/query/sql/executor/FetchFromIndexStep.java:248:

  boolean isIndexUnique() {
    return index != null && index.isUnique();
  }

reached from GetValueFromIndexEntryStep.fetchNextItem, where TypeIndex.isUnique() runs
checkIsValid() and throws.

Repro

A document type Person with 5,000 rows in 8 buckets and a LONG id. Four threads run
SELECT FROM Person WHERE id >= ? AND id < ? (50 rows expected), two run WHERE id = ?, two run
WHERE id = ? ORDER BY id, while the main thread runs 40
CREATE INDEX ON Person (id) NOTUNIQUE / DROP INDEX Person[id] cycles. Each failure records how
many rows had already been handed to the application before it:

correct=1507  shortAnswer=22  threwWithZeroRowsReturned=2   threwPartway=78
correct=707   shortAnswer=4   threwWithZeroRowsReturned=1   threwPartway=69
correct=520   shortAnswer=6   threwWithZeroRowsReturned=5   threwPartway=59
correct=621   shortAnswer=6   threwWithZeroRowsReturned=5   threwPartway=67

The zero-row failures, which are the ones the retry exists to prevent, broken down:

   2  eq+ORDER BY                | rowsReturnedBeforeThrow=0 | IllegalArgumentException
   2  eq+ORDER BY                | rowsReturnedBeforeThrow=0 | IndexException
   3  range id>=? AND id<?       | rowsReturnedBeforeThrow=0 | IllegalArgumentException
   1  range id>=? AND id<?       | rowsReturnedBeforeThrow=0 | IndexException

They reproduce on every run. The IllegalArgumentException rows are the conversion gap; the
IndexException rows are the lazy-iteration gap, an exception of exactly the type the retry catches,
escaping because it is raised after openResultSet returned. A representative stack for the second:

com.arcadedb.index.IndexException: Index 'Person[id]' is not valid. Probably has been drop or rebuilt
	at com.arcadedb.index.TypeIndex.checkIsValid(TypeIndex.java:802)
	at com.arcadedb.index.TypeIndex.isUnique(TypeIndex.java:450)
	at com.arcadedb.query.sql.executor.FetchFromIndexStep.isIndexUnique(FetchFromIndexStep.java:249)
	at com.arcadedb.query.sql.executor.GetValueFromIndexEntryStep$2.fetchNextItem(GetValueFromIndexEntryStep.java:395)
	at com.arcadedb.query.sql.executor.GetValueFromIndexEntryStep$2.hasNext(GetValueFromIndexEntryStep.java:306)
	at com.arcadedb.query.sql.executor.FilterByTypeStep$1.hasNext(FilterByTypeStep.java:97)
	at com.arcadedb.query.sql.parser.LocalResultSet.hasNext(LocalResultSet.java:57)

The three surfaces the committed test does cover answered over a million times across these runs with
no exception at all, which is what isolates the two uncovered shapes.

Suggested fix

Drop the !typeIndex.isValid() conjunct from staleIndexOr: while an index is being read, a
"File with id n was not found" is by construction a dropped or rebuilt index, and the drop ordering
guarantees the flag is stale exactly when the conversion is needed. If a narrower condition is
wanted, test that the schema no longer registers this index under indexName, or that any sub-index
is UNAVAILABLE, rather than the wrapper-level flag. The second call site at
FetchFromIndexStep:310 carries the same conjunct and needs the same treatment.

Separately, either move the first batch inside openResultSet's try block so the javadoc's claim
becomes true, or guard the metadata reads on the lazy path (isIndexUnique and its neighbours in
GetValueFromIndexEntryStep) the way TypeIndex.filterReadyForQueries guards the planner's, so an
index that goes away mid-iteration ends the cursor rather than throwing. The regression test should
grow a range predicate and an ORDER BY, since those are the two shapes that still fail.

Scope / confidence

Reproduced; all counts above are real, from an engine built at this HEAD, and the zero-row failures
appeared in every run. What I tried to refute it with: (a) that this is the accepted window
openResultSet documents ("an index dropped after the first rows were returned ... beats a silently
short answer") - the harness records the rows handed over before each failure precisely to separate
the two, and the failures reported here had returned ZERO rows, so the retry's own precondition held
and it still did not fire; the 59 to 78 failures per run that DID return rows first are excluded from
the finding; (b) that this is the short-answer window TypeIndex.drop() declares acceptable - that
comment covers missing rows, not exceptions, and the committed test encodes the distinction by
tolerating short answers while asserting zero failures; (c) that it is the closed #9331 itself - that
fix is on the tree and its three covered surfaces are clean here across more than a million answers,
while the two shapes it does not exercise fail; (d) that the CREATE side might be at fault rather
than the DROP - the exception comes from FileManager.getFile on a deleted file and from
checkIsValid on an invalidated wrapper, both drop-side; (e) that it might be one machine's timing -
the rate moves between runs but never reaches zero across four runs. Not run: HA or a replicated
cluster, REBUILD INDEX in place of DROP, and anything over a wire protocol; all of this is embedded
and single process.

Activity

  1. added
    concurrency
    engine
    severity:minor
    on Oct 10, 2026
  2. added this to the 26.11.1 milestone on Oct 10, 2026
  3. added
    in progress
    on Oct 11, 2026
  4. self-assigned this
    on Oct 11, 2026
  5. added 6 commits that reference this issue on Oct 11, 2026
  6. lvca commented on Oct 11, 2026

    @lvca
    Member

    Fixed in #9740 (release 26.11.1).

    A SQL SELECT that used an index could fail with no row returned while another thread was running DROP INDEX on it. There were two causes:

    • the error raised while the drop was still deleting the index files was not recognized as "index went away", so the query was not re-planned
    • under a tight create/drop loop, each re-plan could pick the freshly recreated index, which was then dropped again, until the retries ran out

    Now a query that has not returned any row yet is re-planned in both cases. If the index keeps disappearing, the last attempt answers with a scan of the type instead of the index (slower, same rows, logged as a warning). Full-text, geospatial and vector indexes are still used on that last attempt, because a scan would answer their predicates differently.

    A query that had already returned rows when its index was dropped still reports the error, as before, rather than silently returning a partial result.


    ❤️ 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.

  7. removed
    in progress
    on Oct 11, 2026
  8. added a commit that references this issue on Oct 12, 2026
  9. added 6 commits that reference this issue on Oct 21, 2026
  10. added a commit that references this issue on Nov 4, 2026
  11. added a commit that references this issue on Nov 5, 2026
  12. added a commit that references this issue on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugconcurrencyengineseverity:minorsql

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions