Skip to content

Fix spatial index access after reopening MVStore files - #1334

Merged
anidotnet merged 1 commit into
nitrite:mainfrom
sfkamath:fix/mvstore-spatial-index-reopen
Oct 20, 2026
Merged

anidotnet merged 1 commit into
nitrite:mainfrom
sfkamath:fix/mvstore-spatial-index-reopen

Conversation

@sfkamath

@sfkamath sfkamath commented Oct 19, 2026 •

Copy link
Copy Markdown

Reopening an MVStore file with a spatial index can cause a ClassCastException from DefaultSpatial to MVSpatialKey. H2 reconstructs persisted keys using its own Spatial implementation; this change accepts those keys when querying and comparing bounds.

I encountered this while working on Micronaut Data Nitrite, which integrates Nitrite with Micronaut Data repositories. This fixes the failure covered by its persisted spatial-index regression test.

Adds ReopenedRTreeTest to cover queries, updates and removals after reopening, followed by a second reopen. The on-disk format is unchanged.

Validation: mvn -pl nitrite-mvstore-adapter -am -Dtest=ReopenedRTreeTest -Dsurefire.failIfNoSpecifiedTests=false test — passed, 1 test with no failures or skips.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed spatial queries and updates after reopening a database, so persisted entries can be found, moved, and removed correctly.
  • Documentation
    • Added an Unreleased changelog entry for the reopened spatial-index fix.

- Read persisted R-tree cursor keys through H2's Spatial interface.
- Compare MVSpatialKey bounds with H2's deserialized spatial keys without unsafe casts.
- Verify intersecting and contained queries, updates, removals and a second reopen on a real file.
- Record the fix under Unreleased while preserving the on-disk format and public signatures.
- Validate all 5455 MVStore adapter tests with zero failures or errors and one skip.

Co-Authored-By: GPT-6.1-Sol high <noreply@openai.com>
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dc436e03-9ccb-4bb6-9caa-04fed87aa24e
📥 Commits

Reviewing files that changed from the base of the PR and between b053694 and 76c2b6a.

📒 Files selected for processing: 4
  • CHANGELOG.md
  • nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVSpatialKey.java
  • nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/NitriteMVRTreeMap.java
  • nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/mvstore/ReopenedRTreeTest.java

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Walkthrough

The MVStore R-tree now handles H2-reconstructed Spatial keys in comparisons, queries, updates, removals, and cursor iteration. A regression test covers these operations after reopening the database.

Changes: Reopened R-tree key compatibility

Layer / File(s) Summary
Spatial key comparison and R-tree operations
nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/MVSpatialKey.java, nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/NitriteMVRTreeMap.java, nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/mvstore/ReopenedRTreeTest.java, CHANGELOG.md
equalsIgnoringId compares bounds for other Spatial implementations. R-tree operations and cursor iteration use Spatial keys. The regression test checks queries, updates, and removals across database reopenings. The changelog records the fix and notes that the on-disk format and public method signatures are unchanged.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 76c2b

The reopened spatial-index operations have regression coverage, with no identified issue requiring a fix before merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 3 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: fixing spatial index access after reopening MVStore files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 3 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@anidotnet
anidotnet merged commit cf99451 into nitrite:main Oct 20, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants