From 19fce0ea19fe4029a47ce155a2ad0dc1002ddfeb Mon Sep 17 00:00:00 2001 From: Arjun Nair Date: Thu, 19 Jan 2023 16:50:37 -0500 Subject: [PATCH] replay: fix race in WorkloadCollector WorkloadCollector.clean can be called before WorkloadCollector.Start is called. Therefore, WorkloadCollector.Start must acquire WorkloadCollector.mu. --- replay/workload_capture.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/replay/workload_capture.go b/replay/workload_capture.go index 95247dba09..15e417e048 100644 --- a/replay/workload_capture.go +++ b/replay/workload_capture.go @@ -353,8 +353,11 @@ func (w *WorkloadCollector) copySSTables(pending []string) { // corresponding manifests are copied to the provided destination path on the // provided FS. func (w *WorkloadCollector) Start(destFS vfs.FS, destPath string) { + w.mu.Lock() + defer w.mu.Unlock() + // If the collector not is running then that means w.enabled == 0 so swap it - // to 1 and continue else return since it is not running. + // to 1 and continue else return since it is already running. if !atomic.CompareAndSwapUint32(&w.atomic.enabled, 0, 1) { return }