Skip to content

Commit fe419da

Browse files
committed
Revert "Fix IoTConsensus batch accumulation latency (#18522)"
This reverts commit ebd9c20.
1 parent 1486d88 commit fe419da

7 files changed

Lines changed: 10 additions & 374 deletions

File tree

‎iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public class IoTConsensus implements IConsensus {
108108
private final RegisterManager registerManager = new RegisterManager();
109109
private final UserDataTransferAuditHandler userDataTransferAuditHandler;
110110
private final UserDataTransferAuditClassifier userDataTransferAuditClassifier;
111-
private volatile IoTConsensusConfig config;
111+
private IoTConsensusConfig config;
112112

113113
/**
114114
* Optional callback invoked after a new local peer is created via {@link #createLocalPeer}. Used
@@ -549,9 +549,6 @@ public String getRegionDirFromConsensusGroupId(ConsensusGroupId groupId) {
549549
public void reloadConsensusConfig(ConsensusConfig consensusConfig) {
550550
config = consensusConfig.getIotConsensusConfig();
551551

552-
IoTConsensusMemoryManager.getInstance()
553-
.updateMaxMemoryRatioForQueue(config.getReplication().getMaxMemoryRatioForQueue());
554-
555552
for (IoTConsensusServerImpl impl : stateMachineMap.values()) {
556553
impl.reloadConsensusConfig(config);
557554
}

‎iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensusServerImpl.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public class IoTConsensusServerImpl {
152152
private final Set<Peer> configuration = ConcurrentHashMap.newKeySet();
153153
private final AtomicLong searchIndex;
154154
private final LogDispatcher logDispatcher;
155-
private volatile IoTConsensusConfig config;
155+
private IoTConsensusConfig config;
156156
private final ConsensusReqReader consensusReqReader;
157157
private volatile boolean active;
158158
private String newSnapshotDirName;
@@ -1474,7 +1474,6 @@ public String getConsensusGroupId() {
14741474
/** This method is used for hot reload of IoTConsensusConfig. */
14751475
public void reloadConsensusConfig(IoTConsensusConfig config) {
14761476
this.config = config;
1477-
logDispatcher.reloadConfig(config);
14781477
}
14791478

14801479
/**

‎iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/IoTConsensusMemoryManager.java‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class IoTConsensusMemoryManager {
3737
private final AtomicLong syncMemorySizeInByte = new AtomicLong(0);
3838
private IMemoryBlock memoryBlock =
3939
new AtomicLongMemoryBlock("Consensus-Default", null, Runtime.getRuntime().maxMemory() / 10);
40-
private volatile double maxMemoryRatioForQueue = 0.6;
40+
private Double maxMemoryRatioForQueue = 0.6;
4141

4242
private IoTConsensusMemoryManager() {
4343
MetricService.getInstance().addMetricSet(new IoTConsensusMemoryManagerMetrics(this));
@@ -158,10 +158,6 @@ public void init(IMemoryBlock memoryBlock, double maxMemoryRatioForQueue) {
158158
this.maxMemoryRatioForQueue = maxMemoryRatioForQueue;
159159
}
160160

161-
public void updateMaxMemoryRatioForQueue(double maxMemoryRatioForQueue) {
162-
this.maxMemoryRatioForQueue = maxMemoryRatioForQueue;
163-
}
164-
165161
@TestOnly
166162
public void reset() {
167163
this.memoryBlock.release(this.memoryBlock.getUsedMemoryInBytes());

‎iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/LogDispatcher.java‎

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -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

‎iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/SyncStatus.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
public class SyncStatus {
3333

3434
private static final Logger LOGGER = LoggerFactory.getLogger(SyncStatus.class);
35-
private IoTConsensusConfig config;
35+
private final IoTConsensusConfig config;
3636
private final IndexController controller;
3737
private final LinkedList<Batch> pendingBatches = new LinkedList<>();
3838
private final IoTConsensusMemoryManager iotConsensusMemoryManager =
@@ -43,11 +43,6 @@ public SyncStatus(IndexController controller, IoTConsensusConfig config) {
4343
this.config = config;
4444
}
4545

46-
public synchronized void reloadConfig(IoTConsensusConfig config) {
47-
this.config = config;
48-
notifyAll();
49-
}
50-
5146
/**
5247
* we may block here if the synchronization pipeline is full.
5348
*

‎iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/logdispatcher/IoTConsensusMemoryManagerTest.java‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,11 @@
4141
public class IoTConsensusMemoryManagerTest {
4242

4343
private IMemoryBlock previousMemoryBlock;
44-
private double previousMaxMemoryRatioForQueue;
4544
private long memoryBlockSize = 16 * 1024L;
4645

4746
@Before
4847
public void setUp() throws Exception {
4948
previousMemoryBlock = IoTConsensusMemoryManager.getInstance().getMemoryBlock();
50-
previousMaxMemoryRatioForQueue =
51-
IoTConsensusMemoryManager.getInstance().getMaxMemoryRatioForQueue();
5249
IoTConsensusMemoryManager.getInstance()
5350
.setMemoryBlock(new AtomicLongMemoryBlock("Test", null, memoryBlockSize));
5451
IoTConsensusMemoryManager.getInstance().reset();
@@ -58,8 +55,6 @@ public void setUp() throws Exception {
5855
public void tearDown() throws Exception {
5956
IoTConsensusMemoryManager.getInstance().reset();
6057
IoTConsensusMemoryManager.getInstance().setMemoryBlock(previousMemoryBlock);
61-
IoTConsensusMemoryManager.getInstance()
62-
.updateMaxMemoryRatioForQueue(previousMaxMemoryRatioForQueue);
6358
}
6459

6560
@Test
@@ -126,23 +121,6 @@ public void testClearUnserializedRequest() {
126121
assertEquals(0L, request.getRetainedMemorySize());
127122
}
128123

129-
@Test
130-
public void testUpdateMaxMemoryRatioForQueue() {
131-
final IndexedConsensusRequest request =
132-
new IndexedConsensusRequest(
133-
1,
134-
Collections.singletonList(
135-
new ByteBufferConsensusRequest(ByteBuffer.allocate((int) (memoryBlockSize / 3)))));
136-
request.buildSerializedRequests();
137-
138-
IoTConsensusMemoryManager.getInstance().updateMaxMemoryRatioForQueue(0.25);
139-
assertFalse(IoTConsensusMemoryManager.getInstance().reserve(request));
140-
141-
IoTConsensusMemoryManager.getInstance().updateMaxMemoryRatioForQueue(0.5);
142-
assertTrue(IoTConsensusMemoryManager.getInstance().reserve(request));
143-
IoTConsensusMemoryManager.getInstance().free(request);
144-
}
145-
146124
private void testReserveAndRelease(int numReservation) {
147125
int allocationSize = 1;
148126
long allocatedSize = 0;

0 commit comments

Comments
 (0)