From 90bdb171ab97573a4aa1adc9ee4a480e300aed49 Mon Sep 17 00:00:00 2001 From: "cai.zhang" Date: Thu, 5 Sep 2024 04:07:10 +0800 Subject: [PATCH] fix: Fix data race for clustering compaction writer (#35957) issue: #35950 Signed-off-by: Cai Zhang --- internal/datanode/compaction/clustering_compactor.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/datanode/compaction/clustering_compactor.go b/internal/datanode/compaction/clustering_compactor.go index 49c4558726..7b19bf9370 100644 --- a/internal/datanode/compaction/clustering_compactor.go +++ b/internal/datanode/compaction/clustering_compactor.go @@ -458,7 +458,9 @@ func (t *clusteringCompactionTask) mapping(ctx context.Context, func (t *clusteringCompactionTask) getBufferTotalUsedMemorySize() int64 { var totalBufferSize int64 = 0 for _, buffer := range t.clusterBuffers { + t.clusterBufferLocks.Lock(buffer.id) totalBufferSize = totalBufferSize + int64(buffer.writer.WrittenMemorySize()) + buffer.bufferMemorySize.Load() + t.clusterBufferLocks.Unlock(buffer.id) } return totalBufferSize }