Skip to content

Refactor: the tx-overlay REMOVE/REPLACE filtering rules are duplicated across three index read paths #6970

Closed

Description

@robfrank

Summary

The rules that decide which RIDs a pending transaction removal hides from a read are now written out three times, nearly verbatim:

  • engine/src/main/java/com/arcadedb/index/lsm/LSMTreeIndex.java - get()
  • engine/src/main/java/com/arcadedb/index/hash/HashIndex.java - get()
  • engine/src/main/java/com/arcadedb/index/lsm/LSMTreeIndexCursor.java - getClosestEntryInTx()

Each walks the same TransactionIndexContext.getIndexKeys(<indexName>) map for one key and has to reach the same three conclusions:

  1. REMOVE with a RID - hide that RID.
  2. REMOVE with no RID, or any REMOVE on a unique index - hide the whole key.
  3. REPLACE with a non-null oldRid - hide oldRid, because TransactionIndexContext.commit() replays exactly that removal.

Why it is worth fixing

PR #6966 is the evidence. It started as a range-scan fix and implemented rules 1-3 in LSMTreeIndexCursor only. Code review then found that LSMTreeIndex.get() was missing rules 2 and 3 independently - a unique-index point lookup returned both the replaced and the replacement RID under a key that holds one, and a key-wide remove(keys) on a non-unique index allocated an empty filter set and hid nothing. HashIndex.get() carried the identical gaps because it is a copy of the same block. Three sites, three separate chances to be wrong, and the two get() sites had been wrong since REPLACE was introduced (25.3.2).

A fourth call site would get the same chance.

Suggested shape

A small static helper that takes the per-key Map<IndexKey, IndexKey> (plus isUnique()) and answers "which RIDs are hidden, and is the whole key hidden", leaving each caller to apply the answer to its own result shape. LSMTreeIndex and HashIndex share no base class carrying an index-specific get(), so the helper cannot be an inherited method.

Constraints:

  • These are hot read paths. The helper must not allocate when the visited key has no pending removal - today both the set and the flag are lazily produced, and that has to survive.
  • It must stay in step with TransactionIndexContext.commit()'s replay: if the merge rules in addIndexKeyLock ever produce a new operation shape (for instance a REPLACE whose oldRid is null from somewhere other than today's cross-bucket duplicate check at TransactionIndexContext.java:546), the helper is the single place to re-audit.
  • Refactor only: PR fix(#6927): subtract the tx-overlay REMOVE entries from an index range scan #6966's Issue6927RangeScanTxRemovesTest (9 cases, unique/non-unique, per-RID/key-wide/REPLACE, both scan directions, raw sub-index and TypeIndex) has to stay green unchanged.

Context

Follow-up to #6927 / PR #6966, raised in code review on that PR. Not a user-visible bug on its own - the three sites agree today.

Activity

  1. added
    enhancement
    on Aug 31, 2026
  2. added this to the 26.10.1 milestone on Sep 4, 2026
  3. added
    severity:minor
    on Sep 19, 2026
  4. self-assigned this
    on Sep 30, 2026
  5. added
    in progress
    engine
    on Sep 30, 2026
  6. added a commit that references this issue on Sep 30, 2026
  7. robfrank commented on Sep 30, 2026

    @robfrank
    CollaboratorAuthor

    Done in #8741. The rules that decide which index entries a pending in-transaction removal hides from a read used to be copied in three places: the LSM and HASH point lookups and the LSM range cursor. They now live in one shared class, PendingIndexRemovals, so a future change to how removals are recorded has one place to update. There is no behavior change. The existing #6927 tests pass unchanged, new tests cover the HASH/LSM lookup paths the old tests did not reach, and a key with no pending removal still allocates nothing. The refactor is complete.


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

  8. removed
    in progress
    on Sep 30, 2026
  9. added a commit that references this issue on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

engineenhancementseverity:minor

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions