chore(unified-storage): add debug log for read after write (#113747)
This commit is contained in:
committed by
GitHub
parent
4e050267c7
commit
b9e39cdfcc
@@ -673,7 +673,7 @@ func (s *server) Create(ctx context.Context, req *resourcepb.CreateRequest) (*re
|
||||
})
|
||||
}
|
||||
|
||||
s.sleepAfterSuccessfulWriteOperation(res, err)
|
||||
s.sleepAfterSuccessfulWriteOperation("Create", req.Key, res, err)
|
||||
|
||||
return res, err
|
||||
}
|
||||
@@ -706,7 +706,7 @@ type responseWithErrorResult interface {
|
||||
// Returns boolean indicating whether the sleep was performed or not (used in testing).
|
||||
//
|
||||
// This sleep is performed to guarantee search-after-write consistency, when rate-limiting updates to search index.
|
||||
func (s *server) sleepAfterSuccessfulWriteOperation(res responseWithErrorResult, err error) bool {
|
||||
func (s *server) sleepAfterSuccessfulWriteOperation(operation string, key *resourcepb.ResourceKey, res responseWithErrorResult, err error) bool {
|
||||
if s.artificialSuccessfulWriteDelay <= 0 {
|
||||
return false
|
||||
}
|
||||
@@ -725,6 +725,14 @@ func (s *server) sleepAfterSuccessfulWriteOperation(res responseWithErrorResult,
|
||||
}
|
||||
}
|
||||
|
||||
s.log.Debug("sleeping after successful write operation",
|
||||
"operation", operation,
|
||||
"delay", s.artificialSuccessfulWriteDelay,
|
||||
"group", key.Group,
|
||||
"resource", key.Resource,
|
||||
"namespace", key.Namespace,
|
||||
"name", key.Name)
|
||||
|
||||
time.Sleep(s.artificialSuccessfulWriteDelay)
|
||||
return true
|
||||
}
|
||||
@@ -760,7 +768,7 @@ func (s *server) Update(ctx context.Context, req *resourcepb.UpdateRequest) (*re
|
||||
})
|
||||
}
|
||||
|
||||
s.sleepAfterSuccessfulWriteOperation(res, err)
|
||||
s.sleepAfterSuccessfulWriteOperation("Update", req.Key, res, err)
|
||||
|
||||
return res, err
|
||||
}
|
||||
@@ -834,7 +842,7 @@ func (s *server) Delete(ctx context.Context, req *resourcepb.DeleteRequest) (*re
|
||||
})
|
||||
}
|
||||
|
||||
s.sleepAfterSuccessfulWriteOperation(res, err)
|
||||
s.sleepAfterSuccessfulWriteOperation("Delete", req.Key, res, err)
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -587,10 +587,13 @@ func newTestServerWithQueue(t *testing.T, maxSizePerTenant int, numWorkers int)
|
||||
}
|
||||
|
||||
func TestArtificialDelayAfterSuccessfulOperation(t *testing.T) {
|
||||
s := &server{artificialSuccessfulWriteDelay: 1 * time.Millisecond}
|
||||
s := &server{
|
||||
artificialSuccessfulWriteDelay: 1 * time.Millisecond,
|
||||
log: slog.Default(),
|
||||
}
|
||||
|
||||
check := func(t *testing.T, expectedSleep bool, res responseWithErrorResult, err error) {
|
||||
slept := s.sleepAfterSuccessfulWriteOperation(res, err)
|
||||
slept := s.sleepAfterSuccessfulWriteOperation("test", &resourcepb.ResourceKey{}, res, err)
|
||||
require.Equal(t, expectedSleep, slept)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user