fix: make data syncer run configurable on mode (2->3) change (#104401)

This commit is contained in:
Mustafa Sencer Özcan
2025-04-25 13:43:35 +02:00
committed by GitHub
parent 43d0053c80
commit ebf3a8d205
7 changed files with 23 additions and 1 deletions
+4
View File
@@ -164,6 +164,10 @@ func SetDualWritingMode(
return Mode0, errDualWriterSetCurrentMode
}
case cfg.Mode >= Mode3 && currentMode < Mode3:
if cfg.SkipDataSync {
return currentMode, nil
}
// Transitioning to Mode3 or higher requires data synchronization.
cfgModeTmp := cfg.Mode
// Before running the sync, set the syncer config to the current mode, as we have to run the syncer
+1
View File
@@ -36,6 +36,7 @@ type SyncerConfig struct {
LegacyStorage Storage
Storage Storage
ServerLockService ServerLockService
SkipDataSync bool
DataSyncerInterval time.Duration
DataSyncerRecordsLimit int
+9
View File
@@ -20,6 +20,7 @@ func TestSetDualWritingMode(t *testing.T) {
kvStore *fakeNamespacedKV
desiredMode DualWriterMode
expectedMode DualWriterMode
skipDataSync bool
serverLockError error
}
tests :=
@@ -61,6 +62,13 @@ func TestSetDualWritingMode(t *testing.T) {
expectedMode: Mode2,
serverLockError: fmt.Errorf("lock already exists"),
},
{
name: "should keep mode2 when trying to go from mode2 to mode3 and migration is disabled",
kvStore: &fakeNamespacedKV{data: map[string]string{"playlist.grafana.app/playlists": "2"}, namespace: "storage.dualwriting"},
desiredMode: Mode3,
expectedMode: Mode2,
skipDataSync: true,
},
}
for _, tt := range tests {
@@ -86,6 +94,7 @@ func TestSetDualWritingMode(t *testing.T) {
Storage: us,
Kind: "playlist.grafana.app/playlists",
Mode: tt.desiredMode,
SkipDataSync: tt.skipDataSync,
ServerLockService: serverLockSvc,
RequestInfo: &request.RequestInfo{},
Reg: p,