Skip to content

Commit db614fb

Browse files
authoredMar 19, 2025··
IoTConsensusV2: Fix concurrency bug when client traffic is extremely high (#15129)
* fix npe * fix comment * fix review
1 parent 50a48ce commit db614fb

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed
 

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/protocol/pipeconsensus/PipeConsensusReceiver.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -1145,13 +1145,13 @@ private class PipeConsensusTsFileWriter {
11451145
private final ConsensusPipeName consensusPipeName;
11461146
private final int index;
11471147
private File localWritingDir;
1148+
private File writingFile;
1149+
private RandomAccessFile writingFileWriter;
11481150
// whether this buffer is used. this will be updated when first transfer tsFile piece or
11491151
// when transfer seal.
1150-
private boolean isUsed = false;
1152+
private volatile boolean isUsed = false;
11511153
// If isUsed is true, this variable will be set to the TCommitId of holderEvent
1152-
private TCommitId commitIdOfCorrespondingHolderEvent;
1153-
private File writingFile;
1154-
private RandomAccessFile writingFileWriter;
1154+
private volatile TCommitId commitIdOfCorrespondingHolderEvent;
11551155

11561156
public PipeConsensusTsFileWriter(int index, ConsensusPipeName consensusPipeName) {
11571157
this.index = index;
@@ -1247,12 +1247,17 @@ public void setUsed(boolean used) {
12471247

12481248
public void returnSelf(ConsensusPipeName consensusPipeName)
12491249
throws DiskSpaceInsufficientException, IOException {
1250-
this.isUsed = false;
1251-
this.commitIdOfCorrespondingHolderEvent = null;
12521250
// if config multi-disks, tsFileWriter will roll to new writing path.
1251+
// must roll before set used to false, because the writing file may be deleted if other event
1252+
// uses this tsfileWriter.
12531253
if (receiveDirs.size() > 1) {
12541254
rollToNextWritingPath();
12551255
}
1256+
// must set used to false after set commitIdOfCorrespondingHolderEvent to null to avoid the
1257+
// situation that tsfileWriter is used by other event before set
1258+
// commitIdOfCorrespondingHolderEvent to null
1259+
this.commitIdOfCorrespondingHolderEvent = null;
1260+
this.isUsed = false;
12561261
LOGGER.info(
12571262
"PipeConsensus-PipeName-{}: tsFileWriter-{} returned self",
12581263
consensusPipeName.toString(),

0 commit comments

Comments
 (0)
Please sign in to comment.