Skip to content

fix(index): validate preconditions before replacing a scalar index - #5316

Open
hello-peter-tang wants to merge 1 commit into
lance-format:mainfrom
hello-peter-tang:fix/scalar-index-validate-before-replace
Open

hello-peter-tang wants to merge 1 commit into
lance-format:mainfrom
hello-peter-tang:fix/scalar-index-validate-before-replace

Conversation

@hello-peter-tang

Copy link
Copy Markdown

Problem

create_scalar_index validated preconditions on both sides of the destructive driver-side drop_index call used by the legacy IndexConfig workflow. With replace=True, a check that ran after the drop destroyed the existing index and then raised, leaving the dataset with no index and no rebuild.

The string index types now go through the distributed segment workflow, which defers replacement to the workers and therefore happens to be safe for the fragment_ids=[999] repro. The legacy IndexConfig path still drops on the driver first, and that path reproduces the issue:

lr.create_scalar_index(uri=path, column="id", index_type="BTREE", name="my_idx")
lr.create_scalar_index(
    uri=path, column="id", index_type=IndexConfig("SCALAR", {}),
    name="my_idx", fragment_ids=[999], replace=True,
)
# ValueError: Fragment IDs {999} do not exist in dataset
# and my_idx is gone

Fix

Hoist every non-destructive check above the replacement block:

  • fragment existence (Dataset contains no fragments),
  • fragment_ids membership,
  • num_segments adjustment.

The drop is now the last thing that can happen before the build, so validation failures never touch the existing index. When the legacy workflow does drop and reload the dataset, fragments are re-read from the reloaded version (data fragments are unchanged by an index drop).

Tests

test_failed_validation_keeps_existing_index is parametrized over both workflows (BTREE segment workflow and IndexConfig legacy workflow). It pre-creates an index, calls replace=True with a nonexistent fragment id, asserts ValueError, and asserts the original index is still present. The legacy case fails without this change (1 failed, 1 passed) and passes with it.

Closes #5249

create_scalar_index ran the fragment and num_segments checks after the
driver-side drop_index call used by the legacy IndexConfig workflow, so a
call that failed validation left the dataset without its previous index.

Run all non-destructive checks (fragment existence, fragment_ids membership,
num_segments adjustment) before the replacement block, so the drop is the
last thing that can happen. Add a regression test that pre-creates an index,
calls replace=True with a nonexistent fragment id, and asserts the index is
still listed for both the segment and legacy workflows.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added the bug Something isn't working label Nov 3, 2026
@hello-peter-tang

Copy link
Copy Markdown
Author

Heads-up: the PR Test Suite / PR Checks run for this branch is sitting in action_required, so the PR shows no CI results at all. GitHub is holding fork runs until a maintainer approves them ("Approve and run"). @maintainers, could someone approve the pending run so this gets tested?

@hello-peter-tang

Copy link
Copy Markdown
Author

PR Checks for this branch is still in action_required, so I ran the same three jobs locally on the PR head cbbccd8:

ruff check              -> All checks passed!
ruff format --check .   -> 36 files already formatted
mypy                    -> Success: no issues found in 34 source files
pytest -q               -> 400 passed, 1 skipped, 11 warnings in 371.45s (0:06:11)

That includes tests/test_distributed_indexing.py, where the new precondition cases live. Environment: Linux x86_64, Python 3.11.6, deps from the committed uv.lock, local /tmp storage. This is not a substitute for CI (different Python, and CI may use a different Ray/pylance pin), but there is nothing locally reproducible that fails.

@hello-peter-tang

Copy link
Copy Markdown
Author

Follow-up: the PR Checks run on head cbbccd8 is still in action_required (GitHub has been holding the fork run since Nov 3), so the PR still shows no CI results.

Could a maintainer approve the pending workflow run when you have a moment? The same jobs pass locally on this head — ruff check / ruff format --check, mypy, and the full pytest suite (400 passed, 1 skipped), as noted above — but I'd prefer real CI before this is seriously reviewed.

No rush, and I'm happy to address anything it surfaces once the run goes through.

@hello-peter-tang

Copy link
Copy Markdown
Author

The PR Checks run for this fork PR has been pending workflow approval (action_required) since Nov 3. Could a maintainer approve it when convenient? Happy to address any failures. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create_scalar_index: replace=True drops the existing index before some preconditions are validated

1 participant