File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -314,7 +314,9 @@ type clusterNode struct {
314314 generation uint32 // atomic
315315 failing uint32 // atomic
316316
317- lastLatencyMeasurement int64
317+ // last time the latency measurement was performed for the node, stored in nanoseconds
318+ // from epoch
319+ lastLatencyMeasurement int64 // atomic
318320}
319321
320322func newClusterNode (clOpt * ClusterOptions , addr string ) * clusterNode {
@@ -411,7 +413,7 @@ func (n *clusterNode) SetGeneration(gen uint32) {
411413func (n * clusterNode ) SetLastLatencyMeasurement (t time.Time ) {
412414 for {
413415 v := atomic .LoadInt64 (& n .lastLatencyMeasurement )
414- if t .Unix () < v || atomic .CompareAndSwapInt64 (& n .lastLatencyMeasurement , v , t .Unix ()) {
416+ if t .UnixNano () < v || atomic .CompareAndSwapInt64 (& n .lastLatencyMeasurement , v , t .UnixNano ()) {
415417 break
416418 }
417419 }
@@ -508,7 +510,7 @@ func (c *clusterNodes) GC(generation uint32) {
508510 for addr , node := range c .nodes {
509511 if node .Generation () >= generation {
510512 c .activeAddrs = append (c .activeAddrs , addr )
511- if c .opt .RouteByLatency && node .LastLatencyMeasurement () < now .Add (- minLatencyMeasurementInterval ).Unix () {
513+ if c .opt .RouteByLatency && node .LastLatencyMeasurement () < now .Add (- minLatencyMeasurementInterval ).UnixNano () {
512514 go node .updateLatency ()
513515 }
514516 continue
You can’t perform that action at this time.
0 commit comments