From 311778a284d1eba2891d4477af534f3e1219c2b1 Mon Sep 17 00:00:00 2001 From: Keuin Date: Mon, 23 Oct 2023 02:47:01 +0800 Subject: bugfix: batch write collect time is unbounded --- src/main/java/com/keuin/blame/SubmitWorker.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/keuin/blame/SubmitWorker.java b/src/main/java/com/keuin/blame/SubmitWorker.java index 8eba940..a704c7b 100644 --- a/src/main/java/com/keuin/blame/SubmitWorker.java +++ b/src/main/java/com/keuin/blame/SubmitWorker.java @@ -59,9 +59,13 @@ public class SubmitWorker { * @throws InterruptedException The buffer may be empty or non-empty. */ private void accumulateBuffer(List buffer) throws InterruptedException { + long accumulateStart = -1; while (true) { - if (buffer.size() >= batchSize) { - // buffer is full, flush it + if ( + buffer.size() >= batchSize || + (accumulateStart > 0 && System.currentTimeMillis() - accumulateStart > maxWaitMillis) + ) { + // buffer is full, or max accumulate time reached, flush it break; } var el = queue.poll(); @@ -79,6 +83,9 @@ public class SubmitWorker { break; } buffer.add(el); + if (accumulateStart < 0) { + accumulateStart = System.currentTimeMillis(); + } } } -- cgit v1.2.3