@@ -183,10 +183,6 @@ public synchronized void checkAndFlushIndex() {
183183 impl .checkAndUpdateSafeDeletedSearchIndex ();
184184 }
185185
186- public synchronized void reloadConfig (IoTConsensusConfig config ) {
187- threads .forEach (thread -> thread .reloadConfig (config ));
188- }
189-
190186 public void offer (IndexedConsensusRequest request ) {
191187 offer (request , true );
192188 }
@@ -234,7 +230,7 @@ public class LogDispatcherThread implements Runnable {
234230
235231 private static final long PENDING_REQUEST_TAKING_TIME_OUT_IN_MS = 10_000L ;
236232 private static final long START_INDEX = 1 ;
237- private volatile IoTConsensusConfig config ;
233+ private final IoTConsensusConfig config ;
238234 private final Peer peer ;
239235 private final IndexController controller ;
240236 // A sliding window class that manages asynchronous pendingBatches
@@ -293,11 +289,6 @@ public IoTConsensusConfig getConfig() {
293289 return config ;
294290 }
295291
296- private void reloadConfig (IoTConsensusConfig config ) {
297- this .config = config ;
298- syncStatus .reloadConfig (config );
299- }
300-
301292 public int getPendingEntriesSize () {
302293 return pendingEntries .size ();
303294 }
@@ -384,16 +375,11 @@ public void run() {
384375 IndexedConsensusRequest request =
385376 pendingEntries .poll (calculateIdlePollTimeoutInMs (), TimeUnit .MILLISECONDS );
386377 if (request != null ) {
387- final IoTConsensusConfig currentConfig = config ;
388- final boolean shouldWaitForBatchAccumulation =
389- pendingEntries .size ()
390- <= currentConfig .getReplication ().getMaxLogEntriesNumPerBatch ()
391- && bufferedEntries .isEmpty ();
392378 bufferedEntries .add (request );
393379 // If write pressure is low, we simply sleep a little to reduce the number of RPC
394- if (shouldWaitForBatchAccumulation ) {
395- waitForBatchAccumulation (
396- currentConfig .getReplication ().getMaxWaitingTimeForAccumulatingBatchInMs ());
380+ if (pendingEntries . size () <= config . getReplication (). getMaxLogEntriesNumPerBatch ()
381+ && bufferedEntries . isEmpty ()) {
382+ Thread . sleep ( config .getReplication ().getMaxWaitingTimeForAccumulatingBatchInMs ());
397383 }
398384 } else {
399385 maybeSendIdleWriterSafeTimeBarrier ();
@@ -426,32 +412,6 @@ public void run() {
426412 logger .info (IoTConsensusMessages .DISPATCHER_EXITS , impl .getThisNode (), peer );
427413 }
428414
429- void waitForBatchAccumulation (long waitingTimeInMs ) throws InterruptedException {
430- if (waitingTimeInMs <= 0 ) {
431- return ;
432- }
433-
434- final long deadlineNanos = System .nanoTime () + TimeUnit .MILLISECONDS .toNanos (waitingTimeInMs );
435- final int maxLogEntriesNumPerBatch = config .getReplication ().getMaxLogEntriesNumPerBatch ();
436-
437- // Keep collecting while the batch is below its entry limit. A plain sleep makes the
438- // dispatcher wait for the full accumulation interval even when the batch becomes full
439- // immediately, which unnecessarily throttles IoTConsensus under sustained write load.
440- while (bufferedEntries .size () < maxLogEntriesNumPerBatch ) {
441- final long remainingNanos = deadlineNanos - System .nanoTime ();
442- if (remainingNanos <= 0 ) {
443- return ;
444- }
445-
446- final IndexedConsensusRequest request =
447- pendingEntries .poll (remainingNanos , TimeUnit .NANOSECONDS );
448- if (request == null ) {
449- return ;
450- }
451- bufferedEntries .add (request );
452- }
453- }
454-
455415 public void updateSafelyDeletedSearchIndex () {
456416 // update safely deleted search index to delete outdated info,
457417 // indicating that insert nodes whose search index are before this value can be deleted
@@ -468,7 +428,6 @@ public void updateSafelyDeletedSearchIndex() {
468428
469429 public Batch getBatch () {
470430
471- final IoTConsensusConfig currentConfig = config ;
472431 long startIndex = syncStatus .getNextSendingIndex ();
473432 long maxIndex ;
474433 synchronized (impl .getIndexObject ()) {
@@ -483,7 +442,7 @@ public Batch getBatch() {
483442 // Use drainTo instead of poll to reduce lock overhead
484443 pendingEntries .drainTo (
485444 bufferedEntries ,
486- currentConfig .getReplication ().getMaxLogEntriesNumPerBatch () - bufferedEntries .size ());
445+ config .getReplication ().getMaxLogEntriesNumPerBatch () - bufferedEntries .size ());
487446 }
488447 // remove all request that searchIndex < startIndex
489448 Iterator <IndexedConsensusRequest > iterator = bufferedEntries .iterator ();
@@ -497,7 +456,7 @@ public Batch getBatch() {
497456 }
498457 }
499458
500- Batch batches = new Batch (currentConfig );
459+ Batch batches = new Batch (config );
501460 // This condition will be executed in several scenarios:
502461 // 1. restart
503462 // 2. The getBatch() is invoked immediately at the moment the PendingEntries are consumed
0 commit comments