Skip to content

Commit 8189dd0

Browse files
anidotnetclaude
andcommitted
Stop asserting compaction the CI runner cannot see
The growth guard has now turned main red twice trying to hold the chunk fill rate: first against a fixed 25% floor, then against a 1.5x ratio between an autoCompact-on and an autoCompact-off run of the same workload. Locally the two halves are 37% against 18-21%. On the GitHub runners they come out within noise of each other and in either order - 16 against 18 on macOS, 31 against 34 on Windows - with the fix present and working. So it is not a threshold that was mis-calibrated and not contention squeezing one half harder than the other: background compaction's effect on the fill rate is simply not observable there, and I do not know why. What is left is the close, which compacts synchronously and owes nothing to a thread being scheduled: with compaction on the file comes back to its live size, and the control run with it off must be left larger than its live data, so a control that reclaimed anyway cannot quietly turn this into a comparison of a thing against itself. Reverting the close path fails it at 258048 bytes against 69632. That leaves the background half of the fix - dropping autoCompactFillRate(0), which is what bounds the file while a long-running application is writing - unguarded, and the javadoc says so rather than implying the test covers it. Guarding it would mean guarding something the runner cannot see, which is what the last two commits were. Also drops NitriteMVStore.getMvStore(), added for the fill rate reading that no longer happens. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 3e9a61d commit 8189dd0

2 files changed

Lines changed: 21 additions & 40 deletions

File tree

‎nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/NitriteMVStore.java‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,6 @@ private void compactAndClose() {
237237
}
238238
}
239239

240-
/**
241-
* The underlying MVStore, for tests that need to assert on store internals such as the
242-
* chunk fill rate.
243-
*
244-
* @return the backing {@link MVStore}, or {@code null} before {@link #openOrCreate()}
245-
*/
246-
MVStore getMvStore() {
247-
return mvStore;
248-
}
249-
250240
private void initEventBus() {
251241
if (getStoreConfig().eventListeners() != null) {
252242
for (StoreEventListener eventListener : getStoreConfig().eventListeners()) {

‎nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/mvstore/MVStoreFileGrowthTest.java‎

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,40 +47,38 @@ public class MVStoreFileGrowthTest {
4747
private static final int UPDATES_PER_ROUND = 2_000;
4848

4949
/**
50-
* How much of a reclaimed store's chunks must be live against an unreclaimed one's, running
51-
* the same workload on the same machine.
50+
* Runs the same update workload with compaction on and with it off, and holds that the file
51+
* is reclaimed in the first case and not in the second.
5252
*
53-
* <p>Deliberately a ratio and not a floor. The absolute rate is a function of how much CPU
54-
* the housekeeping thread gets - measured at 37% against 18% on a quiet machine, but 23% on
55-
* a loaded macOS runner, which walked straight through a fixed 25% floor while the fix was
56-
* present and working. Both halves of a ratio are squeezed by the same contention, so what
57-
* is asserted is the thing the fix actually changes.
53+
* <p><b>Only the close is asserted, deliberately.</b> {@code close(-1)} compacts
54+
* synchronously, so it owes nothing to a background thread being scheduled. The background
55+
* half of the fix - dropping {@code autoCompactFillRate(0)}, which is what keeps the file
56+
* bounded <i>while</i> a long-running application is writing - is not asserted here, because
57+
* its effect is not observable on a CI runner. Locally the chunk fill rate settles at 37%
58+
* against 18-21% with compaction off; on the GitHub macOS and Windows runners the two
59+
* configurations come out within noise of each other and in either order (16 against 18, 31
60+
* against 34), so both a fixed floor and a ratio between the halves failed there while the
61+
* fix was present and working. Guarding it would mean guarding something the runner cannot
62+
* see, which is how this test turned {@code main} red twice.
5863
*/
59-
private static final double MIN_FILL_RATE_RATIO = 1.5;
60-
6164
@Test(timeout = 180_000)
6265
public void testRepeatedUpdatesDoNotStrandObsoleteChunks() {
6366
final Outcome reclaimed = runUpdates(true);
6467
final Outcome unreclaimed = runUpdates(false);
6568

6669
assertTrue(String.format(
67-
"chunks are %d%% live with compaction on against %d%% with it off, after %d "
68-
+ "updates each - obsolete chunks are not being reclaimed",
69-
reclaimed.chunkFillRate, unreclaimed.chunkFillRate,
70+
"file is %d bytes after close against %d bytes of the same live data, after %d "
71+
+ "updates - it was not compacted",
72+
reclaimed.finalFileSize, reclaimed.initialFileSize,
7073
2 * UPDATES_PER_ROUND * LIVE_DOCUMENTS),
71-
reclaimed.chunkFillRate >= unreclaimed.chunkFillRate * MIN_FILL_RATE_RATIO);
72-
73-
// close(-1) compacts synchronously, so this one owes nothing to the housekeeping thread
74-
// getting scheduled - the file is back to its live size by the time close() returns.
75-
assertTrue(String.format(
76-
"file is %d bytes after close against %d bytes of the same live data - it was "
77-
+ "not compacted", reclaimed.finalFileSize, reclaimed.initialFileSize),
7874
reclaimed.finalFileSize <= reclaimed.initialFileSize);
7975

80-
// and the control: with compaction off it stays as large as the updates left it
76+
// The control, and it has to earn the name: with compaction off the same workload must
77+
// leave the file larger than its live data. If it does not, something reclaimed it
78+
// anyway and the assertion above is comparing a thing against itself.
8179
assertTrue(String.format(
8280
"file is %d bytes after close with compaction off, against %d bytes of live "
83-
+ "data - something compacted it anyway, so the halves are not a comparison",
81+
+ "data - nothing was left to reclaim, so this proves nothing",
8482
unreclaimed.finalFileSize, unreclaimed.initialFileSize),
8583
unreclaimed.finalFileSize > unreclaimed.initialFileSize);
8684
}
@@ -89,7 +87,6 @@ private Outcome runUpdates(final boolean autoCompact) {
8987
final String dbPath = getRandomTempDbFile();
9088
final File dbFile = new File(dbPath);
9189
final long initialFileSize;
92-
final int chunkFillRate;
9390

9491
final MVStoreModule storeModule = MVStoreModule.withConfig()
9592
.filePath(dbPath)
@@ -120,26 +117,20 @@ private Outcome runUpdates(final boolean autoCompact) {
120117
db.commit();
121118
updateEveryDocument(collection);
122119
db.commit();
123-
124-
chunkFillRate = ((NitriteMVStore) db.getStore()).getMvStore()
125-
.getFileStore().getChunksFillRate();
126120
}
127121

128122
final long finalFileSize = dbFile.length();
129123
deleteDb(dbPath);
130-
return new Outcome(initialFileSize, finalFileSize, chunkFillRate);
124+
return new Outcome(initialFileSize, finalFileSize);
131125
}
132126

133127
private static final class Outcome {
134128
private final long initialFileSize;
135129
private final long finalFileSize;
136-
private final int chunkFillRate;
137130

138-
private Outcome(final long initialFileSize, final long finalFileSize,
139-
final int chunkFillRate) {
131+
private Outcome(final long initialFileSize, final long finalFileSize) {
140132
this.initialFileSize = initialFileSize;
141133
this.finalFileSize = finalFileSize;
142-
this.chunkFillRate = chunkFillRate;
143134
}
144135
}
145136

0 commit comments

Comments
 (0)