-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathschemas.go
115 lines (99 loc) · 2.33 KB
/
schemas.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package solr
import (
"errors"
"fmt"
"log"
"net/http"
"net/url"
"strconv"
"strings"
)
type SolrZK interface {
GetZookeepers() string
GetClusterState() (ClusterState, error)
GetClusterProps() (ClusterProps, error)
Listen() error
Listening() bool
GetSolrLocator() SolrLocator
UseHTTPS() (bool, error)
}
type SolrLocator interface {
GetLeaders(docID string) ([]string, error)
GetReplicaUris() ([]string, error)
GetReplicasFromRoute(route string) ([]string, error)
GetShardFromRoute(route string) (string, error)
GetLeadersAndReplicas(docID string) ([]string, error)
}
type SolrHTTP interface {
Select(nodeUris []string, opts ...func(url.Values)) (SolrResponse, error)
Update(nodeUris []string, singleDoc bool, doc interface{}, opts ...func(url.Values)) error
Logger() Logger
}
type Logger interface {
Error(err error)
Info(v ...interface{})
Debug(v ...interface{})
Printf(format string, v ...interface{})
}
type SolrLogger struct {
*log.Logger
}
func (l *SolrLogger) Error(err error) {
log.Println(err)
}
func (l *SolrLogger) Info(v ...interface{}) {
log.Println(v...)
}
func (l *SolrLogger) Debug(v ...interface{}) {
log.Println(v...)
}
func (l *SolrLogger) Printf(format string, v ...interface{}) {
l.Debug(fmt.Sprintf(format, v...))
}
type HTTPer interface {
Do(*http.Request) (*http.Response, error)
}
type CompositeKey struct {
ShardKey string
DocID string
Bits uint
}
type HashRange struct {
Low int32
High int32
}
func NewCompositeKey(id string) (CompositeKey, error) {
keys := strings.Split(id, "!")
if len(keys) == 1 {
if strings.Index(id, "!") < 0 {
return CompositeKey{DocID: keys[0]}, nil
} else {
return CompositeKey{ShardKey: id}, nil
}
}
if len(keys) == 2 {
shard := keys[0]
bitShift := 0
var err error
i := strings.Index(shard, "/")
if i > 0 {
bits := strings.Split(shard, "/")
shard = bits[0]
bitShift, err = strconv.Atoi(bits[1])
if err != nil {
return CompositeKey{}, err
}
}
if bitShift > 16 {
return CompositeKey{}, errors.New(shard + " contains a bit greater than 16")
}
return CompositeKey{ShardKey: keys[0], DocID: shard, Bits: uint(bitShift)}, nil
}
if len(keys) > 2 {
return CompositeKey{}, fmt.Errorf("Cant deal with composite keys %s", id)
}
panic("failed all cases")
}
type ClusterProps struct {
UrlScheme string `json:"urlScheme"`
}