Skip to content

Clear INDEX_SLIDING_WINDOW_SPACE in clearIndexData and related lifecycle paths - #4232

Merged
ScottDugas merged 3 commits into
FoundationDB:mainfrom
ScottDugas:cleanup-window-subspace
May 28, 2026
Merged

ScottDugas merged 3 commits into
FoundationDB:mainfrom
ScottDugas:cleanup-window-subspace

Conversation

@ScottDugas

Copy link
Copy Markdown
Collaborator

FDBRecordStore.clearIndexData did not clear the sliding window subspace, so calling clearAndMarkIndexWriteOnly (which routes through it) left stale window/overflow bookkeeping behind. After a subsequent online rebuild, the window would be from the previous build, which may reference records that do not exist anymore.

This includes 3 production fixes, one referenced above, plus two others that were missed in the original sliding window implementation:

  • FDBRecordStore.clearIndexData: clear indexSlidingWindowSubspace.
  • KeySpaceTreeResolver.resolveNonDirectory: add INDEX_SLIDING_WINDOW_SPACE to the per-index switch so tooling resolves keys under it back to their owning Index.
  • OnlineIndexerTest.clearIndexData test helper: mirror the production fix.

In addition to basic regression tests, testing has expanded to help protect against missing this in the future.

  • SlidingWindowIndexTest: focused regression for clearIndexData leaving the sliding window subspace populated.
  • FDBRecordStoreClearIndexDataTest: forward-looking, parameterized over FDBRecordStoreKeyspace. Categorizes every enum value as non-per-index or per-method "cleared by" so a future per-index keyspace addition fails by design unless explicitly categorized. Pins the lock-preservation contract for INDEX_BUILD_SPACE.
  • KeySpaceTreeResolverTest: parameterized forward-looking coverage for the per-index switch in resolveNonDirectory.

…cle paths

FDBRecordStore.clearIndexData did not clear the sliding window subspace,
so calling clearAndMarkIndexWriteOnly (which routes through it) left
stale window/overflow bookkeeping behind. After a subsequent online
rebuild, queries could observe state that did not reflect record
mutations that occurred while the index was write-only.

Audit-driven fixes:
  - FDBRecordStore.clearIndexData: clear indexSlidingWindowSubspace.
  - KeySpaceTreeResolver.resolveNonDirectory: add INDEX_SLIDING_WINDOW_SPACE
    to the per-index switch so tooling resolves keys under it back to
    their owning Index.
  - OnlineIndexerTest.clearIndexData test helper: mirror the production
    fix.

Tests:
  - SlidingWindowIndexTest: focused regression for clearIndexData
    leaving the sliding window subspace populated.
  - FDBRecordStoreClearIndexDataTest: forward-looking, parameterized
    over FDBRecordStoreKeyspace. Categorizes every enum value as
    non-per-index or per-method "cleared by" so a future per-index
    keyspace addition fails by design unless explicitly categorized.
    Pins the lock-preservation contract for INDEX_BUILD_SPACE.
  - KeySpaceTreeResolverTest: parameterized forward-looking coverage
    for the per-index switch in resolveNonDirectory.
@ScottDugas
ScottDugas requested review from hatyo and jjezra May 27, 2026 20:06
@ScottDugas ScottDugas added the bug fix Change that fixes a bug label May 27, 2026
@ScottDugas
ScottDugas marked this pull request as ready for review May 27, 2026 20:06

@jjezra jjezra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I don't know enough about KeySpaceTreeResolver, so limited my review to the index itself...)

@@ -106,6 +106,7 @@ void clearIndexData(@Nonnull Index index) {

@jjezra jjezra May 27, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since nobody calls this function (and it is not being tested) it might be a good idea to remove it altogether.
(If ever needed, it would be safer to use FDBRecordStore.clearIndexData)

case INDEX_RANGE_SPACE:
case INDEX_UNIQUENESS_VIOLATIONS_SPACE:
case INDEX_BUILD_SPACE:
case INDEX_SLIDING_WINDOW_SPACE:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this correctly, this logic is trying to interpret a given subspace key. And if the first element in the key matches one of the known keys (2 for index, 3 for index secondary subspace and so on). It immediately resolves it to an index, meaning that the key we're trying to resolve must belong to an index. Is that correct?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the next value in the tuple is expected to be an index subspace key.

@ScottDugas
ScottDugas merged commit 63e7766 into FoundationDB:main May 28, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix Change that fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants