-
-
Notifications
You must be signed in to change notification settings - Fork 96
fix: leave MVStore's chunk retention and versions-to-keep at H2's defaults #1301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
brettwooldridge
wants to merge
1
commit into
nitrite:main
from
brettwooldridge:fix/mvstore-retention-defaults
+146
−2
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...-mvstore-adapter/src/test/java/org/dizitart/no2/mvstore/MVStoreRetentionDefaultsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /* | ||
| * Copyright (c) 2017-2020. Nitrite author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.dizitart.no2.mvstore; | ||
|
|
||
| import org.dizitart.no2.Nitrite; | ||
| import org.h2.mvstore.MVStore; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| import java.io.File; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertNull; | ||
|
|
||
| /** | ||
| * The adapter must not force MVStore's chunk retention time and versions-to-keep to 0. With both | ||
| * at 0, H2 may reuse a chunk's blocks while the chunk map it writes at close still lists that | ||
| * chunk, and the file then refuses to open with "Double mark" (h2database/h2database#2752, | ||
| * #4083). A soak of a 24-thread workload with a close every 20 seconds hit that on every run at | ||
| * 0/0 and on none with either of H2's defaults in place. | ||
| */ | ||
| public class MVStoreRetentionDefaultsTest { | ||
| private Path directory; | ||
| private Nitrite db; | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| directory = Files.createTempDirectory("nitrite-retention"); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() throws Exception { | ||
| if (db != null && !db.isClosed()) { | ||
| db.close(); | ||
| } | ||
| try (var files = Files.walk(directory)) { | ||
| files.sorted((a, b) -> b.compareTo(a)).map(Path::toFile).forEach(File::delete); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testDefaultsAreLeftToH2() { | ||
| MVStoreModuleBuilder builder = MVStoreModule.withConfig(); | ||
| assertNull(builder.retentionTime()); | ||
| assertNull(builder.versionsToKeep()); | ||
|
|
||
| db = Nitrite.builder().loadModule(builder.filePath(directory.resolve("test.db").toFile()).build()).openOrCreate(); | ||
| MVStore store = mvStore(db); | ||
| assertEquals(45_000, store.getRetentionTime()); | ||
| assertEquals(5, store.getVersionsToKeep()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConfiguredValuesAreApplied() { | ||
| MVStoreModule module = MVStoreModule.withConfig() | ||
| .filePath(directory.resolve("test.db").toFile()) | ||
| .retentionTime(1_000) | ||
| .versionsToKeep(2) | ||
| .build(); | ||
| db = Nitrite.builder().loadModule(module).openOrCreate(); | ||
| MVStore store = mvStore(db); | ||
| assertEquals(1_000, store.getRetentionTime()); | ||
| assertEquals(2, store.getVersionsToKeep()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConfigCloneCarriesTheOptions() { | ||
| MVStoreConfig config = new MVStoreConfig(); | ||
| config.retentionTime(7); | ||
| config.versionsToKeep(3); | ||
| MVStoreConfig clone = config.clone(); | ||
| assertEquals(Integer.valueOf(7), clone.retentionTime()); | ||
| assertEquals(Integer.valueOf(3), clone.versionsToKeep()); | ||
| } | ||
|
|
||
| private static MVStore mvStore(Nitrite db) { | ||
| try { | ||
| var field = NitriteMVStore.class.getDeclaredField("mvStore"); | ||
| field.setAccessible(true); | ||
| return (MVStore) field.get(db.getStore()); | ||
| } catch (ReflectiveOperationException e) { | ||
| throw new AssertionError(e); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: nitrite/nitrite-java
Length of output: 8671
🏁 Script executed:
Repository: nitrite/nitrite-java
Length of output: 7017
🤖 get_repo_knowledge executed:
get_repo_knowledge nitrite/nitrite-java /tmp/coderabbit-repo-knowledge/nitrite-nitrite-java-ee794b6f/conventionsLength of output: 1763
🏁 Script executed:
Repository: nitrite/nitrite-java
Length of output: 36881
🏁 Script executed:
Repository: nitrite/nitrite-java
Length of output: 22843
Reject negative
versionsToKeepvalues before forwarding them toMVStore.getOldestVersionToKeep()computesv - versionsToKeep. A negative value advances the oldest retained version and can makedropUnusedChunks()consider newer chunks eligible for overwrite. Keepnulland0valid. Do not reject negativeretentionTime; the bundled implementation uses it for direct-overwrite mode.🤖 Prompt for AI Agents
Sources: Coding guidelines, MCP tools