Skip to content

Commit

Permalink
Fix a potential race condition which could delete a segment file afte…
Browse files Browse the repository at this point in the history
…r it's brought back into service.
  • Loading branch information
broneill committed Oct 20, 2024
1 parent f73c3fb commit 5bbedbb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/cojen/tupl/repl/FileTermLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,11 @@ Segment segmentForWriting(SegmentWriter writer, long position) throws IOExceptio
if (startPosition != startSegment.mStartPosition || startSegment.mMaxLength != 0) {
throw new AssertionError(startSegment);
}
// Wait for all work tasks to complete, ensuring that the truncate operation
// against the segment is finished before attempting to untruncate it.
synchronized (mWorker) {
mWorker.join(false);
}
startSegment.untruncate(maxLength);
segment = startSegment;
}
Expand Down

0 comments on commit 5bbedbb

Please sign in to comment.