-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproxy_select.go
More file actions
83 lines (71 loc) · 1.94 KB
/
proxy_select.go
File metadata and controls
83 lines (71 loc) · 1.94 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"github.com/tarantool/go-tarantool"
)
func (p *ProxyConnection) executeRequestSelect(requestType uint32, requestID uint32,
reader IprotoReader) (flags uint32, response *tarantool.Response, err error) {
//|--------------- header ----------------|---------------request_body ---------------------...|
// <request_type><body_length><request_id> <space_no><index_no><offset><limit><count><tuple>+
var (
spaceNo uint32
indexNo uint32
offset uint32
limit uint32
count uint32
cardinality uint32
args []interface{}
param interface{}
)
unpackUint32(reader, &spaceNo)
unpackUint32(reader, &indexNo)
unpackUint32(reader, &offset)
unpackUint32(reader, &limit)
unpackUint32(reader, &count)
flags = FlagReturnTuple
space, err := p.schema.GetSpaceInfo(spaceNo)
if err != nil {
return
}
indexName, err := space.GetIndexName(indexNo)
if err != nil {
return
}
indexDefs, err := space.GetIndexDefs(indexNo)
if err != nil {
return
}
// далее лежат упакованные iproto tuple-ы
for i := uint32(0); i < count; i++ {
err = unpackUint32(reader, &cardinality)
if err != nil {
return
}
for fieldNo := uint32(0); fieldNo < cardinality; fieldNo++ {
param, err = p.unpackFieldByDefs(reader, requestType, fieldNo, indexDefs[fieldNo])
if err != nil {
return
}
args = append(args, param)
} //end for
} //end for
//sharding for key0
tnt16 := p.getTnt16(args[0])
response, err = tnt16.Select(space.name, indexName, offset, limit, tarantool.IterEq, args)
if err == nil {
p.statsdClient.Incr("select", 1)
return
}
// make fault tollerance requests
for _, tnt16i := range p.getTnt16Pool(args[0]) {
if tnt16i == tnt16 {
continue
}
response, err = tnt16i.Select(space.name, indexName, offset, limit, tarantool.IterEq, args)
if err == nil {
p.statsdClient.Incr("select", 1)
break
}
}
p.statsdClient.Incr("error_16", 1)
return
}