forked from CodisLabs/codis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.go
56 lines (44 loc) · 1009 Bytes
/
request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2016 CodisLabs. All Rights Reserved.
// Licensed under the MIT (MIT-LICENSE.txt) license.
package proxy
import (
"sync"
"unsafe"
"github.com/CodisLabs/codis/pkg/proxy/redis"
"github.com/CodisLabs/codis/pkg/utils/sync2/atomic2"
)
type Request struct {
Multi []*redis.Resp
Start int64
Batch *sync.WaitGroup
Group *sync.WaitGroup
OpStr string
OpFlag
Database int32
Broken *atomic2.Bool
*redis.Resp
Err error
Coalesce func() error
}
func (r *Request) IsBroken() bool {
return r.Broken != nil && r.Broken.Get()
}
func (r *Request) MakeSubRequest(n int) []Request {
var sub = make([]Request, n)
for i := range sub {
x := &sub[i]
x.Start = r.Start
x.Batch = r.Batch
x.OpStr = r.OpStr
x.OpFlag = r.OpFlag
x.Database = r.Database
x.Broken = r.Broken
}
return sub
}
const GOLDEN_RATIO_PRIME_32 = 0x9e370001
func (r *Request) Seed16() uint {
h32 := uint32(r.Start) + uint32(uintptr(unsafe.Pointer(r)))
h32 *= GOLDEN_RATIO_PRIME_32
return uint(h32 >> 16)
}