Skip to content

Commit 8f99f41

Browse files
QUEUE-130: Addressed review comments
1 parent e0db960 commit 8f99f41

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

src/main/java/net/openhft/chronicle/queue/impl/single/StoreAppender.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,9 @@ public void normaliseEOFs() {
629629
final WriteLock writeLock = queue.writeLock();
630630
writeLock.lock();
631631
try {
632-
normaliseEOFs0(cycle);
632+
// use the getter, not the raw field: after the construction-time back-scan releases its
633+
// parked store the field is Integer.MIN_VALUE, and the getter resolves that to lastCycle
634+
normaliseEOFs0(cycle());
633635
} finally {
634636
writeLock.unlock();
635637
long tookMillis = (System.nanoTime() - start) / 1_000_000;

src/test/java/net/openhft/chronicle/queue/impl/single/AppenderReleasesParkedStoreTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
package net.openhft.chronicle.queue.impl.single;
55

6-
import net.openhft.chronicle.core.Jvm;
6+
import net.openhft.chronicle.core.io.BackgroundResourceReleaser;
77
import net.openhft.chronicle.queue.util.FileUtil;
88
import org.junit.jupiter.api.Test;
99

@@ -68,15 +68,17 @@ void parkedAppenderDoesNotPinAnOldCycle() {
6868
}
6969
}
7070

71-
// All roll-cycle files, earliest first; the pause lets freshly rolled files appear.
71+
// All roll-cycle files, earliest first.
7272
private List<File> cycleFiles() {
7373
final File[] files = queue.file().listFiles(FileUtil::hasQueueSuffix);
7474
assertNotNull(files, "no queue files found in " + queue.file());
7575
return Stream.of(files).sorted(EARLIEST_FIRST).collect(toList());
7676
}
7777

78-
// Removable candidates, earliest first; the pause lets rolled-off files be released first.
78+
// Removable candidates, earliest first. The parked store's file descriptor is dropped on a
79+
// background thread, so drain the releaser before inspecting open descriptors.
7980
private List<File> removableCandidates() {
81+
BackgroundResourceReleaser.releasePendingResources();
8082
final List<File> candidates = FileUtil.removableRollFileCandidates(queue.file()).collect(toList());
8183
assertEquals(candidates.stream().sorted(EARLIEST_FIRST).collect(toList()), candidates);
8284
return candidates;

src/test/java/net/openhft/chronicle/queue/impl/single/NormaliseEOFsTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,34 @@ public void normaliseShouldResumeFromPreviousNormalisation() {
9898
}
9999
}
100100

101+
// A freshly constructed appender parks on the current cycle during its EOF back-scan and then
102+
// releases that store, leaving its cycle field unset. normaliseEOFs() must still finalise the older
103+
// cycles rather than silently no-op - the watermark it advances is "normalisedEOFsTo" in the table store.
104+
@Test
105+
public void freshlyConstructedAppenderNormalisesWithoutWriting() {
106+
SetTimeProvider setTimeProvider = new SetTimeProvider();
107+
try (final SingleChronicleQueue queue = createQueue(setTimeProvider);
108+
final ExcerptAppender writer = queue.createAppender()) {
109+
writer.writeText("cycle-0");
110+
setTimeProvider.advanceMillis(1_001);
111+
writer.writeText("cycle-1");
112+
setTimeProvider.advanceMillis(1_001);
113+
writer.writeText("cycle-2");
114+
115+
final int firstCycle = queue.firstCycle();
116+
try (final ExcerptAppender fresh = queue.createAppender()) {
117+
final long normalisedBefore = queue.tableStoreAcquire("normalisedEOFsTo", firstCycle).getVolatileValue();
118+
119+
fresh.normaliseEOFs();
120+
121+
final long normalisedAfter = queue.tableStoreAcquire("normalisedEOFsTo", firstCycle).getVolatileValue();
122+
assertTrue(normalisedAfter > normalisedBefore,
123+
"normaliseEOFs on a never-written appender should have advanced the watermark past "
124+
+ normalisedBefore + " but it stayed at " + normalisedAfter);
125+
}
126+
}
127+
}
128+
101129
private void createNewRollCycles(ExcerptAppender appender, SetTimeProvider timeProvider) {
102130
for (int i = 0; i < 10; i++) {
103131
timeProvider.advanceMillis(3_000);

0 commit comments

Comments
 (0)