forked from couchbase/gocbcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kvmuxstate.go
146 lines (115 loc) · 3.67 KB
/
kvmuxstate.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package gocbcore
import (
"fmt"
)
type kvMuxState struct {
pipelines []*memdPipeline
deadPipe *memdPipeline
routeCfg routeConfig
bucketCapabilities map[BucketCapability]BucketCapabilityStatus
collectionsSupported bool
kvServerList []routeEndpoint
tlsConfig *dynTLSConfig
authMechanisms []AuthMechanism
auth AuthProvider
}
func newKVMuxState(cfg *routeConfig, kvServerList []routeEndpoint, tlsConfig *dynTLSConfig,
authMechanisms []AuthMechanism, auth AuthProvider, pipelines []*memdPipeline, deadpipe *memdPipeline) *kvMuxState {
mux := &kvMuxState{
pipelines: pipelines,
deadPipe: deadpipe,
routeCfg: *cfg,
bucketCapabilities: map[BucketCapability]BucketCapabilityStatus{
BucketCapabilityDurableWrites: BucketCapabilityStatusUnknown,
BucketCapabilityCreateAsDeleted: BucketCapabilityStatusUnknown,
BucketCapabilityReplaceBodyWithXattr: BucketCapabilityStatusUnknown,
},
collectionsSupported: cfg.ContainsBucketCapability("collections"),
kvServerList: kvServerList,
tlsConfig: tlsConfig,
authMechanisms: authMechanisms,
auth: auth,
}
// We setup with a fake config, this means that durability support is still unknown.
if cfg.revID > -1 {
if cfg.ContainsBucketCapability("durableWrite") {
mux.bucketCapabilities[BucketCapabilityDurableWrites] = BucketCapabilityStatusSupported
} else {
mux.bucketCapabilities[BucketCapabilityDurableWrites] = BucketCapabilityStatusUnsupported
}
if cfg.ContainsBucketCapability("tombstonedUserXAttrs") {
mux.bucketCapabilities[BucketCapabilityCreateAsDeleted] = BucketCapabilityStatusSupported
} else {
mux.bucketCapabilities[BucketCapabilityCreateAsDeleted] = BucketCapabilityStatusUnsupported
}
if cfg.ContainsBucketCapability("subdoc.ReplaceBodyWithXattr") {
mux.bucketCapabilities[BucketCapabilityReplaceBodyWithXattr] = BucketCapabilityStatusSupported
} else {
mux.bucketCapabilities[BucketCapabilityReplaceBodyWithXattr] = BucketCapabilityStatusUnsupported
}
}
return mux
}
func (mux *kvMuxState) RouteConfig() *routeConfig {
return &mux.routeCfg
}
func (mux *kvMuxState) RevID() int64 {
return mux.routeCfg.revID
}
func (mux *kvMuxState) VBMap() *vbucketMap {
return mux.routeCfg.vbMap
}
func (mux *kvMuxState) UUID() string {
return mux.routeCfg.uuid
}
func (mux *kvMuxState) KetamaMap() *ketamaContinuum {
return mux.routeCfg.ketamaMap
}
func (mux *kvMuxState) BucketType() bucketType {
return mux.routeCfg.bktType
}
func (mux *kvMuxState) KVEps() []string {
var epList []string
for _, s := range mux.kvServerList {
epList = append(epList, s.Address)
}
return epList
}
func (mux *kvMuxState) NumPipelines() int {
return len(mux.pipelines)
}
func (mux *kvMuxState) GetPipeline(index int) *memdPipeline {
if index < 0 || index >= len(mux.pipelines) {
return mux.deadPipe
}
return mux.pipelines[index]
}
func (mux *kvMuxState) HasBucketCapabilityStatus(cap BucketCapability, status BucketCapabilityStatus) bool {
st, ok := mux.bucketCapabilities[cap]
if !ok {
return status == BucketCapabilityStatusUnsupported
}
return st == status
}
func (mux *kvMuxState) BucketCapabilityStatus(cap BucketCapability) BucketCapabilityStatus {
st, ok := mux.bucketCapabilities[cap]
if !ok {
return BucketCapabilityStatusUnsupported
}
return st
}
// nolint: unused
func (mux *kvMuxState) debugString() string {
var outStr string
for i, n := range mux.pipelines {
outStr += fmt.Sprintf("Pipeline %d:\n", i)
outStr += reindentLog(" ", n.debugString()) + "\n"
}
outStr += "Dead Pipeline:\n"
if mux.deadPipe != nil {
outStr += reindentLog(" ", mux.deadPipe.debugString()) + "\n"
} else {
outStr += " Disabled\n"
}
return outStr
}