|
22 | 22 | import com.automq.stream.utils.Threads;
|
23 | 23 | import java.util.Collection;
|
24 | 24 | import java.util.LinkedList;
|
25 |
| -import java.util.PriorityQueue; |
26 | 25 | import java.util.Queue;
|
27 | 26 | import java.util.concurrent.BlockingQueue;
|
28 | 27 | import java.util.concurrent.ExecutorService;
|
29 | 28 | import java.util.concurrent.LinkedBlockingQueue;
|
| 29 | +import java.util.concurrent.PriorityBlockingQueue; |
30 | 30 | import java.util.concurrent.ScheduledExecutorService;
|
31 | 31 | import java.util.concurrent.TimeUnit;
|
32 | 32 | import java.util.concurrent.atomic.AtomicBoolean;
|
@@ -71,7 +71,7 @@ public class SlidingWindowService {
|
71 | 71 | /**
|
72 | 72 | * Blocks that are being written.
|
73 | 73 | */
|
74 |
| - private final Queue<Long> writingBlocks = new PriorityQueue<>(); |
| 74 | + private final Queue<Long> writingBlocks = new PriorityBlockingQueue<>(); |
75 | 75 | /**
|
76 | 76 | * Whether the service is initialized.
|
77 | 77 | * After the service is initialized, data in {@link #windowCoreData} is valid.
|
@@ -331,23 +331,10 @@ private BlockBatch pollBlocksLocked() {
|
331 | 331 | * Finish the given block batch, and return the start offset of the first block which has not been flushed yet.
|
332 | 332 | */
|
333 | 333 | private long wroteBlocks(BlockBatch wroteBlocks) {
|
334 |
| - blockLock.lock(); |
335 |
| - try { |
336 |
| - return wroteBlocksLocked(wroteBlocks); |
337 |
| - } finally { |
338 |
| - blockLock.unlock(); |
339 |
| - } |
340 |
| - } |
341 |
| - |
342 |
| - /** |
343 |
| - * Finish the given block batch, and return the start offset of the first block which has not been flushed yet. |
344 |
| - * Note: this method is NOT thread safe, and it should be called with {@link #blockLock} locked. |
345 |
| - */ |
346 |
| - private long wroteBlocksLocked(BlockBatch wroteBlocks) { |
347 | 334 | boolean removed = writingBlocks.remove(wroteBlocks.startOffset());
|
348 | 335 | assert removed;
|
349 | 336 | if (writingBlocks.isEmpty()) {
|
350 |
| - return getCurrentBlockLocked().startOffset(); |
| 337 | + return wroteBlocks.startOffset() + WALUtil.alignLargeByBlockSize(wroteBlocks.blockBatchSize()); |
351 | 338 | }
|
352 | 339 | return writingBlocks.peek();
|
353 | 340 | }
|
|
0 commit comments