@@ -138,8 +138,10 @@ func (c *haTracker) checkReplica(ctx context.Context, userID, cluster, replica s
138
138
c .electedLock .RLock ()
139
139
entry , ok := c .elected [key ]
140
140
c .electedLock .RUnlock ()
141
-
142
- if ok && entry .Replica == replica && now .Sub (timestamp .Time (entry .ReceivedAt )) < c .cfg .UpdateTimeout {
141
+ if ok && now .Sub (timestamp .Time (entry .ReceivedAt )) < c .cfg .UpdateTimeout {
142
+ if entry .Replica != replica {
143
+ return replicasNotMatchError (replica , entry .Replica )
144
+ }
143
145
return nil
144
146
}
145
147
return c .checkKVStore (ctx , key , replica , now )
@@ -159,7 +161,7 @@ func (c *haTracker) checkKVStore(ctx context.Context, key, replica string, now t
159
161
// is less than failOver timeout amount of time since the timestamp in the KV store.
160
162
if desc .Replica != replica && now .Sub (timestamp .Time (desc .ReceivedAt )) < c .cfg .FailoverTimeout {
161
163
// Return a 202.
162
- return nil , false , httpgrpc . Errorf ( http . StatusAccepted , "replicas did not match, rejecting sample: %s != %s" , replica , desc .Replica )
164
+ return nil , false , replicasNotMatchError ( replica , desc .Replica )
163
165
}
164
166
}
165
167
@@ -172,6 +174,10 @@ func (c *haTracker) checkKVStore(ctx context.Context, key, replica string, now t
172
174
})
173
175
}
174
176
177
+ func replicasNotMatchError (replica , elected string ) error {
178
+ return httpgrpc .Errorf (http .StatusAccepted , "replicas did not mach, rejecting sample: replica=%s, elected=%s" , replica , elected )
179
+ }
180
+
175
181
// Modifies the labels parameter in place, removing labels that match
176
182
// the replica or cluster label and returning their values. Returns an error
177
183
// if we find one but not both of the labels.
0 commit comments