forked from apache/cassandra-gocql-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_executor.go
65 lines (51 loc) · 1.09 KB
/
query_executor.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
57
58
59
60
61
62
63
64
65
package gocql
import (
"time"
)
type ExecutableQuery interface {
execute(conn *Conn) *Iter
attempt(time.Duration)
retryPolicy() RetryPolicy
GetRoutingKey() ([]byte, error)
RetryableQuery
}
type queryExecutor struct {
pool *policyConnPool
policy HostSelectionPolicy
}
func (q *queryExecutor) executeQuery(qry ExecutableQuery) (*Iter, error) {
rt := qry.retryPolicy()
hostIter := q.policy.Pick(qry)
var iter *Iter
for hostResponse := hostIter(); hostResponse != nil; hostResponse = hostIter() {
host := hostResponse.Info()
if !host.IsUp() {
continue
}
pool, ok := q.pool.getPool(host.Peer())
if !ok {
continue
}
conn := pool.Pick()
if conn == nil {
continue
}
start := time.Now()
iter = qry.execute(conn)
qry.attempt(time.Since(start))
// Update host
hostResponse.Mark(iter.err)
// Exit for loop if the query was successful
if iter.err == nil {
return iter, nil
}
if rt == nil || !rt.Attempt(qry) {
// What do here? Should we just return an error here?
break
}
}
if iter == nil {
return nil, ErrNoConnections
}
return iter, nil
}