Skip to content

Commit 177c3c7

Browse files
committed
fix(rdb): prevent concurrent backup operations with mutex
1 parent 948a4ab commit 177c3c7

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

internal/namespaces/rdb/v1/custom_benchmark_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const (
3636
var (
3737
sharedInstance *rdbSDK.Instance
3838
sharedInstanceMu sync.Mutex
39+
backupOpMu sync.Mutex
3940
)
4041

4142
// TestMain ensures shared instance cleanup
@@ -326,7 +327,11 @@ func BenchmarkBackupGet(b *testing.B) {
326327

327328
meta["Instance"] = rdb.CreateInstanceResult{Instance: instance}
328329

329-
if err := createBackupDirect("Backup")(ctx); err != nil {
330+
backupOpMu.Lock()
331+
err := createBackupDirect("Backup")(ctx)
332+
backupOpMu.Unlock()
333+
334+
if err != nil {
330335
b.Fatalf("Failed to create backup: %v", err)
331336
}
332337

@@ -387,10 +392,16 @@ func BenchmarkBackupList(b *testing.B) {
387392

388393
meta["Instance"] = rdb.CreateInstanceResult{Instance: instance}
389394

390-
if err := createBackupDirect("Backup1")(ctx); err != nil {
395+
backupOpMu.Lock()
396+
err := createBackupDirect("Backup1")(ctx)
397+
if err != nil {
398+
backupOpMu.Unlock()
391399
b.Fatalf("Failed to create backup 1: %v", err)
392400
}
393-
if err := createBackupDirect("Backup2")(ctx); err != nil {
401+
err = createBackupDirect("Backup2")(ctx)
402+
backupOpMu.Unlock()
403+
404+
if err != nil {
394405
b.Fatalf("Failed to create backup 2: %v", err)
395406
}
396407

0 commit comments

Comments
 (0)