@@ -107,9 +107,9 @@ public class SlidingWindowService {
107
107
private volatile long lastWriteTimeNanos = 0 ;
108
108
109
109
/**
110
- * The maximum offset currently written into writeBlocks .*
110
+ * The maximum alignment offset in {@link #writingBlocks} .*
111
111
*/
112
- private long maxWriteBlockOffset = 0 ;
112
+ private long maxAlignWriteBlockOffset = 0 ;
113
113
114
114
public SlidingWindowService (WALChannel walChannel , int ioThreadNums , long upperLimit , long scaleUnit ,
115
115
long blockSoftLimit , int writeRateLimit , WALHeaderFlusher flusher ) {
@@ -321,14 +321,18 @@ private BlockBatch pollBlocksLocked() {
321
321
}
322
322
}
323
323
324
+ if (pendingBlocks .isEmpty ()) {
325
+ return null ;
326
+ }
324
327
Collection <Block > blocks = new LinkedList <>();
328
+ Block leastBlock = null ;
325
329
while (!pendingBlocks .isEmpty ()) {
326
- blocks .add (pendingBlocks .poll ());
330
+ leastBlock = pendingBlocks .poll ();
331
+ blocks .add (leastBlock );
327
332
}
328
-
329
333
BlockBatch blockBatch = new BlockBatch (blocks );
330
334
writingBlocks .add (blockBatch .startOffset ());
331
- maxWriteBlockOffset = blockBatch . endOffset ( );
335
+ maxAlignWriteBlockOffset = nextBlockStartOffset ( leastBlock );
332
336
333
337
return blockBatch ;
334
338
}
@@ -352,7 +356,7 @@ private long wroteBlocksLocked(BlockBatch wroteBlocks) {
352
356
boolean removed = writingBlocks .remove (wroteBlocks .startOffset ());
353
357
assert removed ;
354
358
if (writingBlocks .isEmpty ()) {
355
- return this .maxWriteBlockOffset ;
359
+ return this .maxAlignWriteBlockOffset ;
356
360
}
357
361
return writingBlocks .peek ();
358
362
}
0 commit comments