-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathexport_test.go
More file actions
262 lines (240 loc) · 7.5 KB
/
Copy pathexport_test.go
File metadata and controls
262 lines (240 loc) · 7.5 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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*+*****************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2022 QuestDB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
package questdb
import "github.com/coder/websocket"
type (
Buffer = buffer
ConfigData = configData
TcpLineSender = tcpLineSender
LineSenderConfig = lineSenderConfig
SenderType = senderType
)
// QwpSfClassify exposes the internal status-byte → Category mapping
// for cross-language regression tests in the questdb_test package.
func QwpSfClassify(status QwpStatusCode) Category { return qwpSfClassify(status) }
// QwpSfDefaultPolicyFor exposes the spec-default Category → Policy
// mapping for unit tests.
func QwpSfDefaultPolicyFor(c Category) Policy { return qwpSfDefaultPolicyFor(c) }
// QwpSfIsTerminalCloseCode exposes the WS terminal close-code
// classifier for unit tests.
func QwpSfIsTerminalCloseCode(code websocket.StatusCode) bool {
return qwpSfIsTerminalCloseCode(code)
}
var (
GlobalTransport = globalTransport
NoSenderType SenderType = noSenderType
HttpSenderType SenderType = httpSenderType
TcpSenderType SenderType = tcpSenderType
QwpSenderType SenderType = qwpSenderType
DefaultAutoFlushInterval = defaultAutoFlushInterval
DefaultAutoFlushRows = defaultAutoFlushRows
)
func NewBuffer(initBufSize int, maxBufSize int, fileNameLimit int) Buffer {
return newBuffer(initBufSize, maxBufSize, fileNameLimit)
}
func ParseConfigStr(conf string) (configData, error) {
return parseConfigStr(conf)
}
// ConfFromStr parses a connect string into a *LineSenderConfig. The
// returned config has NOT been sanitized — call SanitizeConf for the
// post-sanitize shape (defaults applied, endpoints back-filled from
// address, transport-specific validation run).
func ConfFromStr(conf string) (*LineSenderConfig, error) {
return confFromStr(conf)
}
// SanitizeConf dispatches to the per-transport sanitizer. Exposed for
// tests that need to apply post-parse defaults (e.g. authTimeoutMs,
// QWP endpoints) without going through the full newLineSender path
// (which would attempt a dial).
func SanitizeConf(c *LineSenderConfig) error {
switch c.senderType {
case tcpSenderType:
return sanitizeTcpConf(c)
case httpSenderType:
return sanitizeHttpConf(c)
case qwpSenderType:
return sanitizeQwpConf(c)
}
return nil
}
// unwrapPooledQwp reaches the delegate behind a facade pool lease so the
// switch helpers below can dispatch on the concrete sender type. A stale lease
// no longer owns its slot, so inspecting the delegate would read a re-borrowed
// slot's state — panic with a clear message instead (test-helper contract,
// mirroring the "unexpected struct" arms).
func unwrapPooledQwp(s LineSender) LineSender {
ps, ok := s.(*qwpPooledSender)
if !ok {
return s
}
if !ps.live() {
panic("stale qwpPooledSender lease: slot returned or re-borrowed")
}
return ps.slot.delegate
}
func Messages(s LineSender) []byte {
if ps, ok := s.(*pooledSender); ok {
s = ps.wrapped
}
s = unwrapPooledQwp(s)
if hs, ok := s.(*httpLineSender); ok {
return hs.Messages()
}
if hs, ok := s.(*httpLineSenderV2); ok {
return hs.Messages()
}
if hs, ok := s.(*httpLineSenderV3); ok {
return hs.Messages()
}
if ts, ok := s.(*tcpLineSender); ok {
return ts.Messages()
}
if ts, ok := s.(*tcpLineSenderV2); ok {
return ts.Messages()
}
if ts, ok := s.(*tcpLineSenderV3); ok {
return ts.Messages()
}
if _, ok := s.(*qwpLineSender); ok {
panic("Messages() is not applicable to QWP senders: QWP has no ILP message buffer")
}
panic("unexpected struct")
}
func MsgCount(s LineSender) int {
if ps, ok := s.(*pooledSender); ok {
s = ps.wrapped
}
s = unwrapPooledQwp(s)
if hs, ok := s.(*httpLineSender); ok {
return hs.MsgCount()
}
if hs, ok := s.(*httpLineSenderV2); ok {
return hs.MsgCount()
}
if hs, ok := s.(*httpLineSenderV3); ok {
return hs.MsgCount()
}
if ts, ok := s.(*tcpLineSender); ok {
return ts.MsgCount()
}
if ts, ok := s.(*tcpLineSenderV2); ok {
return ts.MsgCount()
}
if ts, ok := s.(*tcpLineSenderV3); ok {
return ts.MsgCount()
}
if qs, ok := s.(*qwpLineSender); ok {
return qs.pendingRowCount
}
panic("unexpected struct")
}
func BufLen(s LineSender) int {
if ps, ok := s.(*pooledSender); ok {
s = ps.wrapped
}
s = unwrapPooledQwp(s)
if hs, ok := s.(*httpLineSender); ok {
return hs.BufLen()
}
if hs, ok := s.(*httpLineSenderV2); ok {
return hs.BufLen()
}
if hs, ok := s.(*httpLineSenderV3); ok {
return hs.BufLen()
}
if ts, ok := s.(*tcpLineSender); ok {
return ts.BufLen()
}
if ts, ok := s.(*tcpLineSenderV2); ok {
return ts.BufLen()
}
if ts, ok := s.(*tcpLineSenderV3); ok {
return ts.BufLen()
}
if qs, ok := s.(*qwpLineSender); ok {
total := 0
for _, tb := range qs.tableBuffers {
total += tb.approxDataSize()
}
return total
}
panic("unexpected struct")
}
func ProtocolVersion(s LineSender) protocolVersion {
if ps, ok := s.(*pooledSender); ok {
s = ps.wrapped
}
s = unwrapPooledQwp(s)
if _, ok := s.(*httpLineSender); ok {
return ProtocolVersion1
}
if _, ok := s.(*httpLineSenderV2); ok {
return ProtocolVersion2
}
if _, ok := s.(*httpLineSenderV3); ok {
return ProtocolVersion3
}
if _, ok := s.(*tcpLineSender); ok {
return ProtocolVersion1
}
if _, ok := s.(*tcpLineSenderV2); ok {
return ProtocolVersion2
}
if _, ok := s.(*tcpLineSenderV3); ok {
return ProtocolVersion3
}
if _, ok := s.(*qwpLineSender); ok {
panic("ProtocolVersion() is not applicable to QWP senders: QWP is not an ILP protocol")
}
panic("unexpected struct")
}
func NewLineSenderConfig(t SenderType) *LineSenderConfig {
return newLineSenderConfig(t)
}
// ConfigEndpoints returns the multi-host failover list parsed by
// sanitizeQwpConf. Each entry is rendered as host:port (IPv6 hosts
// are bracketed) so tests can compare against literals. Returns nil
// for non-QWP senders.
func ConfigEndpoints(c *LineSenderConfig) []string {
if c == nil || len(c.endpoints) == 0 {
return nil
}
out := make([]string, len(c.endpoints))
for i, e := range c.endpoints {
out[i] = e.String()
}
return out
}
// ConfigAuthTimeoutMs returns the effective auth_timeout_ms after
// sanitization (default 15000).
func ConfigAuthTimeoutMs(c *LineSenderConfig) int { return c.authTimeoutMs }
// ConfigZone returns the parsed zone= value (silently stored but
// unused on SF ingress).
func ConfigZone(c *LineSenderConfig) string { return c.zone }
// ConfigTarget returns the parsed target= value as a string
// (any/primary/replica).
func ConfigTarget(c *LineSenderConfig) string { return c.target.String() }
func SetLittleEndian(littleEndian bool) {
isLittleEndian = littleEndian
}