jt2594838 commented on code in PR #18557:
URL: https://github.com/apache/iotdb/pull/18557#discussion_r3900291548
##########
iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/SyncStatus.java:
##########
@@ -53,10 +53,15 @@ public synchronized void reloadConfig(IoTConsensusConfig
config) {
* @throws InterruptedException
*/
public synchronized void addNextBatch(Batch batch) throws
InterruptedException {
- while ((pendingBatches.size() >=
config.getReplication().getMaxPendingBatchesNum()
- || !iotConsensusMemoryManager.reserve(batch))
- && !Thread.interrupted()) {
- wait();
+ while (true) {
+ while (pendingBatches.size() >=
config.getReplication().getMaxPendingBatchesNum()) {
+ wait();
+ }
+ if (iotConsensusMemoryManager.reserve(batch)) {
+ break;
+ }
+ // Memory may be freed by another SyncStatus, which cannot notify this
monitor.
+ wait(Math.max(1, config.getReplication().getBasicRetryWaitTimeMs()));
}
Review Comment:
This retry loop fixes a liveness gap after batch memory reservation fails:
memory can be released by another SyncStatus instance without notifying this
monitor, so an unbounded wait could leave the dispatcher stuck. The timed wait
rechecks reservation using the existing basicRetryWaitTimeMs while the separate
pending-batch wait still enforces maxPendingBatchesNum. The change preserves
the synchronized lifecycle and passed the SyncStatusTest and two-replica
concurrent-write integration test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]