Skip to content

Commit ffc2ad3

Browse files
authored
Fix write fallback logic when use advanced writing mode but only db is available (#7200)
* Fix write fallback logic when use advanced writing mode but only db is available * Fix test based on new behavior
1 parent af2cfb8 commit ffc2ad3

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

common/persistence/visibility_hybrid_manager.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,17 @@ func (v *visibilityHybridManager) chooseVisibilityManagerForWrite(ctx context.Co
243243
if err := visFunc(mode); err != nil {
244244
errors = append(errors, err.Error())
245245
}
246-
} else if ok && mgr == nil && mode != dbVisStoreName && !strings.Contains(writeMode, dbVisStoreName) {
247-
// if advanced visibility is not available, fall back to db
246+
} else if mode != dbVisStoreName && !strings.Contains(writeMode, dbVisStoreName) {
247+
// If requested mode is not available and it's not already "db", fall back to "db"
248248
// when write mode already includes db, skip this step since it will perform the write in another loop
249-
v.logger.Warn("advanced visibility is not available to write, fall back to basic visibility")
249+
v.logger.Warn("requested visibility mode is not available, falling back to db", tag.Value(mode))
250250
if err := visFunc(dbVisStoreName); err != nil {
251251
errors = append(errors, err.Error())
252252
}
253253
} else {
254-
errors = append(errors, fmt.Sprintf("Unknown visibility writing mode: %s", mode))
254+
// If the mode is "db" but not available, this is an error
255+
// This is the else case - when mode is "db" but the manager is not available
256+
errors = append(errors, fmt.Sprintf("DB visibility mode is not available: %s", mode))
255257
}
256258
}
257259

common/persistence/visibility_hybrid_manager_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func TestVisibilityHybridRecordWorkflowExecutionClosed(t *testing.T) {
255255
writeVisibilityStoreName dynamicproperties.StringPropertyFn
256256
expectedError error
257257
}{
258-
"Case0-1: error case with writeVisibilityStoreName is nil": {
258+
"Case0-1: success case with writeVisibilityStoreName is nil - should fall back to db": {
259259
context: context.Background(),
260260
request: request,
261261
mockDBVisibilityManager: NewMockVisibilityManager(ctrl),
@@ -266,7 +266,7 @@ func TestVisibilityHybridRecordWorkflowExecutionClosed(t *testing.T) {
266266
mockPinotVisibilityManagerAffordance: func(mockPinotVisibilityManager *MockVisibilityManager) {
267267
mockPinotVisibilityManager.EXPECT().RecordWorkflowExecutionClosed(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
268268
},
269-
expectedError: fmt.Errorf("error"),
269+
expectedError: nil, // Should succeed by falling back to db
270270
},
271271
"Case0-2: error case with ES has errors in dual mode": {
272272
context: context.Background(),

0 commit comments

Comments
 (0)