Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 39e5e72

Browse files
committed
proxy: rename Request.Start to UnixNano to avoid misunderstanding
1 parent 9bf8b7d commit 39e5e72

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

pkg/proxy/request.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ import (
1313

1414
type Request struct {
1515
Multi []*redis.Resp
16-
Start int64
1716
Batch *sync.WaitGroup
1817
Group *sync.WaitGroup
1918

19+
Broken *atomic2.Bool
20+
2021
OpStr string
2122
OpFlag
2223

2324
Database int32
24-
Broken *atomic2.Bool
25+
UnixNano int64
2526

2627
*redis.Resp
2728
Err error
@@ -37,20 +38,20 @@ func (r *Request) MakeSubRequest(n int) []Request {
3738
var sub = make([]Request, n)
3839
for i := range sub {
3940
x := &sub[i]
40-
x.Start = r.Start
4141
x.Batch = r.Batch
4242
x.OpStr = r.OpStr
4343
x.OpFlag = r.OpFlag
44-
x.Database = r.Database
4544
x.Broken = r.Broken
45+
x.Database = r.Database
46+
x.UnixNano = r.UnixNano
4647
}
4748
return sub
4849
}
4950

5051
const GOLDEN_RATIO_PRIME_32 = 0x9e370001
5152

5253
func (r *Request) Seed16() uint {
53-
h32 := uint32(r.Start) + uint32(uintptr(unsafe.Pointer(r)))
54+
h32 := uint32(r.UnixNano) + uint32(uintptr(unsafe.Pointer(r)))
5455
h32 *= GOLDEN_RATIO_PRIME_32
5556
return uint(h32 >> 16)
5657
}

pkg/proxy/session.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ func (s *Session) loopReader(tasks chan<- *Request, d *Router) (err error) {
166166

167167
r := &Request{}
168168
r.Multi = multi
169-
r.Start = start.UnixNano()
170169
r.Batch = &sync.WaitGroup{}
171170
r.Database = s.database
171+
r.UnixNano = start.UnixNano()
172172

173173
if len(tasks) == cap(tasks) {
174174
return ErrTooManyPipelinedRequests
@@ -635,7 +635,7 @@ func (s *Session) getOpStats(opstr string) *opStats {
635635
func (s *Session) incrOpStats(r *Request, t redis.RespType) {
636636
e := s.getOpStats(r.OpStr)
637637
e.calls.Incr()
638-
e.nsecs.Add(time.Now().UnixNano() - r.Start)
638+
e.nsecs.Add(time.Now().UnixNano() - r.UnixNano)
639639
switch t {
640640
case redis.TypeError:
641641
e.redis.errors.Incr()

0 commit comments

Comments
 (0)