From 826a612a82fcf9ac74546be69f2a5a4785881c30 Mon Sep 17 00:00:00 2001 From: cfzjywxk Date: Fri, 11 Aug 2023 16:59:56 +0800 Subject: [PATCH] use atomic to read epoch Signed-off-by: cfzjywxk --- internal/locate/region_request.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/locate/region_request.go b/internal/locate/region_request.go index b5546f769..371148bd4 100644 --- a/internal/locate/region_request.go +++ b/internal/locate/region_request.go @@ -253,6 +253,10 @@ type replica struct { deadlineErrUsingConfTimeout bool } +func (r *replica) getEpoch() uint32 { + return atomic.LoadUint32(&r.epoch) +} + func (r *replica) isEpochStale() bool { return r.epoch != atomic.LoadUint32(&r.store.epoch) } @@ -324,7 +328,7 @@ func (s *replicaSelector) String() string { replica.store.storeID, replica.isEpochStale(), replica.attempts, - replica.epoch, + replica.getEpoch(), atomic.LoadUint32(&replica.store.epoch), replica.store.getResolveState(), replica.store.getLivenessState(),