libcouchbase 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +1 -1
- data/ext/libcouchbase/CMakeLists.txt +8 -6
- data/ext/libcouchbase/README.markdown +2 -2
- data/ext/libcouchbase/RELEASE_NOTES.markdown +0 -86
- data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +0 -11
- data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +0 -2
- data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +1 -2
- data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
- data/ext/libcouchbase/cmake/config-cmake.h.in +0 -2
- data/ext/libcouchbase/cmake/defs.mk.in +2 -0
- data/ext/libcouchbase/cmake/source_files.cmake +5 -21
- data/ext/libcouchbase/include/libcouchbase/auth.h +0 -10
- data/ext/libcouchbase/include/libcouchbase/cntl.h +1 -27
- data/ext/libcouchbase/include/libcouchbase/error.h +1 -15
- data/ext/libcouchbase/include/libcouchbase/n1ql.h +1 -13
- data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +1 -1
- data/ext/libcouchbase/include/libcouchbase/subdoc.h +0 -9
- data/ext/libcouchbase/include/libcouchbase/views.h +1 -7
- data/ext/libcouchbase/include/libcouchbase/visibility.h +0 -1
- data/ext/libcouchbase/include/memcached/protocol_binary.h +1131 -29
- data/ext/libcouchbase/include/memcached/vbucket.h +42 -0
- data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
- data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +2 -3
- data/ext/libcouchbase/src/README.md +2 -0
- data/ext/libcouchbase/src/auth-priv.h +0 -1
- data/ext/libcouchbase/src/auth.cc +4 -10
- data/ext/libcouchbase/src/bootstrap.c +269 -0
- data/ext/libcouchbase/src/bootstrap.h +39 -50
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +117 -84
- data/ext/libcouchbase/src/bucketconfig/bc_file.c +347 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.c +630 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.h +25 -50
- data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +150 -0
- data/ext/libcouchbase/src/bucketconfig/clconfig.h +386 -407
- data/ext/libcouchbase/src/bucketconfig/confmon.c +474 -0
- data/ext/libcouchbase/src/cbft.cc +27 -22
- data/ext/libcouchbase/src/cntl.cc +19 -30
- data/ext/libcouchbase/src/connspec.cc +1 -48
- data/ext/libcouchbase/src/connspec.h +0 -27
- data/ext/libcouchbase/src/dump.cc +2 -2
- data/ext/libcouchbase/src/getconfig.cc +33 -7
- data/ext/libcouchbase/src/handler.cc +2 -0
- data/ext/libcouchbase/src/hostlist.cc +36 -0
- data/ext/libcouchbase/src/hostlist.h +62 -41
- data/ext/libcouchbase/src/http/http-priv.h +112 -125
- data/ext/libcouchbase/src/http/http.cc +30 -15
- data/ext/libcouchbase/src/http/http.h +34 -1
- data/ext/libcouchbase/src/http/http_io.cc +26 -22
- data/ext/libcouchbase/src/instance.cc +23 -94
- data/ext/libcouchbase/src/internal.h +26 -52
- data/ext/libcouchbase/src/jsparse/parser.cc +202 -146
- data/ext/libcouchbase/src/jsparse/parser.h +98 -91
- data/ext/libcouchbase/src/lcbht/lcbht.c +282 -0
- data/ext/libcouchbase/src/lcbht/lcbht.h +163 -174
- data/ext/libcouchbase/src/lcbio/connect.c +557 -0
- data/ext/libcouchbase/src/lcbio/connect.h +2 -9
- data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
- data/ext/libcouchbase/src/lcbio/iotable.h +16 -61
- data/ext/libcouchbase/src/lcbio/ioutils.h +1 -1
- data/ext/libcouchbase/src/lcbio/manager.c +2 -2
- data/ext/libcouchbase/src/mc/mcreq.h +2 -9
- data/ext/libcouchbase/src/mcserver/mcserver.cc +34 -143
- data/ext/libcouchbase/src/mcserver/mcserver.h +12 -7
- data/ext/libcouchbase/src/mcserver/negotiate.cc +38 -132
- data/ext/libcouchbase/src/n1ql/ixmgmt.cc +2 -1
- data/ext/libcouchbase/src/n1ql/n1ql.cc +32 -56
- data/ext/libcouchbase/src/newconfig.cc +6 -6
- data/ext/libcouchbase/src/nodeinfo.cc +2 -2
- data/ext/libcouchbase/src/operations/{cbflush.cc → cbflush.c} +15 -7
- data/ext/libcouchbase/src/operations/{counter.cc → counter.c} +0 -0
- data/ext/libcouchbase/src/operations/durability.cc +26 -6
- data/ext/libcouchbase/src/operations/durability_internal.h +3 -6
- data/ext/libcouchbase/src/operations/{get.cc → get.c} +26 -24
- data/ext/libcouchbase/src/operations/{observe.cc → observe.c} +93 -68
- data/ext/libcouchbase/src/operations/{pktfwd.cc → pktfwd.c} +0 -0
- data/ext/libcouchbase/src/operations/{remove.cc → remove.c} +0 -0
- data/ext/libcouchbase/src/operations/stats.cc +8 -3
- data/ext/libcouchbase/src/operations/{store.cc → store.c} +32 -27
- data/ext/libcouchbase/src/operations/subdoc.cc +18 -38
- data/ext/libcouchbase/src/operations/{touch.cc → touch.c} +0 -0
- data/ext/libcouchbase/src/packetutils.c +37 -0
- data/ext/libcouchbase/src/packetutils.h +2 -2
- data/ext/libcouchbase/src/probes.d +1 -1
- data/ext/libcouchbase/src/{retrychk.cc → retrychk.c} +3 -2
- data/ext/libcouchbase/src/retryq.cc +4 -4
- data/ext/libcouchbase/src/settings.c +0 -3
- data/ext/libcouchbase/src/settings.h +0 -5
- data/ext/libcouchbase/src/simplestring.c +211 -0
- data/ext/libcouchbase/src/simplestring.h +228 -0
- data/ext/libcouchbase/src/ssl/ssl_c.c +0 -1
- data/ext/libcouchbase/src/ssl/ssl_common.c +0 -2
- data/ext/libcouchbase/src/ssl/ssl_e.c +1 -0
- data/ext/libcouchbase/src/ssobuf.h +82 -0
- data/ext/libcouchbase/src/trace.h +4 -4
- data/ext/libcouchbase/src/vbucket/vbucket.c +1 -0
- data/ext/libcouchbase/src/views/{docreq.cc → docreq.c} +54 -48
- data/ext/libcouchbase/src/views/docreq.h +30 -24
- data/ext/libcouchbase/src/views/viewreq.c +358 -0
- data/ext/libcouchbase/src/views/viewreq.h +13 -43
- data/ext/libcouchbase/tests/basic/t_connstr.cc +50 -89
- data/ext/libcouchbase/tests/basic/t_host.cc +75 -67
- data/ext/libcouchbase/tests/basic/t_jsparse.cc +78 -27
- data/ext/libcouchbase/tests/basic/t_string.cc +112 -0
- data/ext/libcouchbase/tests/htparse/t_basic.cc +78 -58
- data/ext/libcouchbase/tests/iotests/mock-environment.h +1 -2
- data/ext/libcouchbase/tests/iotests/t_confmon.cc +114 -96
- data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
- data/ext/libcouchbase/tools/cbc-pillowfight.cc +1 -1
- data/lib/libcouchbase/ext/tasks.rb +6 -2
- data/lib/libcouchbase/query_view.rb +1 -1
- data/lib/libcouchbase/results_fiber.rb +6 -6
- data/lib/libcouchbase/version.rb +1 -1
- metadata +26 -26
- data/ext/libcouchbase/src/bootstrap.cc +0 -216
- data/ext/libcouchbase/src/bucketconfig/bc_file.cc +0 -281
- data/ext/libcouchbase/src/bucketconfig/bc_http.cc +0 -528
- data/ext/libcouchbase/src/bucketconfig/bc_mcraw.cc +0 -115
- data/ext/libcouchbase/src/bucketconfig/confmon.cc +0 -378
- data/ext/libcouchbase/src/dns-srv.cc +0 -142
- data/ext/libcouchbase/src/errmap.cc +0 -107
- data/ext/libcouchbase/src/errmap.h +0 -113
- data/ext/libcouchbase/src/lcbht/lcbht.cc +0 -177
- data/ext/libcouchbase/src/lcbio/connect.cc +0 -562
- data/ext/libcouchbase/src/lcbio/timer-cxx.h +0 -87
- data/ext/libcouchbase/src/mctx-helper.h +0 -51
- data/ext/libcouchbase/src/views/viewreq.cc +0 -318
- data/ext/libcouchbase/tests/iotests/t_errmap.cc +0 -97
@@ -0,0 +1,228 @@
|
|
1
|
+
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* Copyright 2013 Couchbase, Inc.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*/
|
17
|
+
|
18
|
+
#ifndef LCB_STRING_H
|
19
|
+
#define LCB_STRING_H
|
20
|
+
|
21
|
+
#include <libcouchbase/couchbase.h>
|
22
|
+
#include <stdarg.h>
|
23
|
+
|
24
|
+
#include "config.h"
|
25
|
+
#include "assert.h"
|
26
|
+
#include "ringbuffer.h"
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Simple string type.
|
30
|
+
*
|
31
|
+
* This structure is designed mainly for ease of use when dealing with actual
|
32
|
+
* "string" data - i.e. data which must be null-terminated and contiguous.
|
33
|
+
*
|
34
|
+
* This won't replace the ringbuffer structure as this string's removal and
|
35
|
+
* copying operations are comparatively expensive.
|
36
|
+
*
|
37
|
+
* Note that all API functions which update the position of the buffer ALSO
|
38
|
+
* add a trailing NUL byte at the end.
|
39
|
+
*/
|
40
|
+
typedef struct lcb_string_st {
|
41
|
+
/** Buffer that's allocated */
|
42
|
+
char *base;
|
43
|
+
|
44
|
+
/** Number of bytes allocated */
|
45
|
+
lcb_size_t nalloc;
|
46
|
+
|
47
|
+
/** Number of bytes used */
|
48
|
+
lcb_size_t nused;
|
49
|
+
#ifdef __cplusplus
|
50
|
+
typedef char *iterator;
|
51
|
+
typedef const char *const_iterator;
|
52
|
+
|
53
|
+
iterator begin() { return base; };
|
54
|
+
iterator end() { return base + nused; }
|
55
|
+
const_iterator begin() const { return base; }
|
56
|
+
const_iterator end() const { return base + nused; }
|
57
|
+
size_t size() const { return nused; }
|
58
|
+
size_t capacity() const { return nalloc; }
|
59
|
+
const char *c_str() const { return base; }
|
60
|
+
|
61
|
+
inline void insert(iterator p, const char *first, const char *last);
|
62
|
+
#endif
|
63
|
+
} lcb_string;
|
64
|
+
|
65
|
+
#ifdef __cplusplus
|
66
|
+
extern "C" {
|
67
|
+
#endif
|
68
|
+
|
69
|
+
int lcb_string_init(lcb_string *str);
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Free any storage associated with the string. The string's state will be
|
73
|
+
* empty as if string_init() had just been called.
|
74
|
+
*/
|
75
|
+
void lcb_string_release(lcb_string *str);
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Clear the contents of the string, but don't free the underlying buffer
|
79
|
+
*/
|
80
|
+
void lcb_string_clear(lcb_string *str);
|
81
|
+
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Indicate that bytes have been added to the string. This is used in conjunction
|
85
|
+
* with reserve(). As such, the number of bytes added should not exceed the
|
86
|
+
* number of bytes passed to reserver.
|
87
|
+
*
|
88
|
+
* @param str the string
|
89
|
+
* @param nbytes the number of bytes added
|
90
|
+
*/
|
91
|
+
void lcb_string_added(lcb_string *str, lcb_size_t nbytes);
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Reserve an amount of free bytes within the string. When this is done,
|
95
|
+
* up to @c size bytes may be added to the string starting at @c base+str->nbytes
|
96
|
+
*/
|
97
|
+
int lcb_string_reserve(lcb_string *str, lcb_size_t size);
|
98
|
+
|
99
|
+
|
100
|
+
/**
|
101
|
+
* Adds data to the string.
|
102
|
+
* @param str the string to append to
|
103
|
+
* @param data the data to copy
|
104
|
+
* @param size the size of data to copy
|
105
|
+
*/
|
106
|
+
int lcb_string_append(lcb_string *str, const void *data, lcb_size_t size);
|
107
|
+
|
108
|
+
/**
|
109
|
+
* Adds a C-style string
|
110
|
+
* @param str the target lcb_string
|
111
|
+
* @param zstr a NUL-terminated string to add
|
112
|
+
*/
|
113
|
+
int lcb_string_appendz(lcb_string *str, const char *zstr);
|
114
|
+
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Appends a list of pointer-length pairs. Useful if you need to concatenate
|
118
|
+
* many small buffers
|
119
|
+
* @param str The string to append to. This should be followed by a list of
|
120
|
+
* `pointer, size` arguments (where `size` is `size_t`). If the length is
|
121
|
+
* `-1` then `strlen(pointer)` will be called to determine the length.
|
122
|
+
*
|
123
|
+
* A terminal `NULL` should be placed at the end of the argument list
|
124
|
+
*
|
125
|
+
* @return 0 if appended, nonzero on memory error
|
126
|
+
*/
|
127
|
+
int lcb_string_appendv(lcb_string *str, ...);
|
128
|
+
|
129
|
+
/**
|
130
|
+
* Adds a string from a ringbuffer structure. This copies the contents
|
131
|
+
* of the ringbuffer into a string.
|
132
|
+
* @param str the target string
|
133
|
+
* @param rb the source ringbuffer
|
134
|
+
* @param rbadvance whether to advance the ringbuffer's read head
|
135
|
+
*/
|
136
|
+
int lcb_string_rbappend(lcb_string *str, ringbuffer_t *rb, int rbadvance);
|
137
|
+
|
138
|
+
/**
|
139
|
+
* Removes bytes from the end of the string. The resultant string will be
|
140
|
+
* NUL-terminated
|
141
|
+
* @param str the string to operate on
|
142
|
+
* @param to_remove the number of bytes to trim from the end
|
143
|
+
*/
|
144
|
+
void lcb_string_erase_end(lcb_string *str, lcb_size_t to_remove);
|
145
|
+
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Removes bytes from the beginning of the string. The resultant string will
|
149
|
+
* be NUL-terminated.
|
150
|
+
* @param str the string to operate on
|
151
|
+
* @param to_remove the number of bytes to remove from the beginning of
|
152
|
+
* the string.
|
153
|
+
*/
|
154
|
+
void lcb_string_erase_beginning(lcb_string *str, lcb_size_t to_remove);
|
155
|
+
|
156
|
+
/**
|
157
|
+
* Transfers ownership of the underlying buffer contained within the structure
|
158
|
+
* 'to' to the structure 'from', as such, 'from' becomes a newly initialized
|
159
|
+
* empty string structure and 'to' contains the existing buffer.
|
160
|
+
*
|
161
|
+
* @param from the string which contains the existing buffer
|
162
|
+
* @param to a new string structure which contains no buffer. It will receive
|
163
|
+
* from's buffer
|
164
|
+
*/
|
165
|
+
void lcb_string_transfer(lcb_string *from, lcb_string *to);
|
166
|
+
|
167
|
+
/**
|
168
|
+
* Inserts a string at a given position
|
169
|
+
* @param str the string object
|
170
|
+
* @param at position at which to insert
|
171
|
+
* @param src the string to insert
|
172
|
+
* @param len length of string to insert
|
173
|
+
*/
|
174
|
+
int lcb_string_insert(lcb_string *str, size_t at, const char *src, size_t len);
|
175
|
+
|
176
|
+
#define lcb_string_tail(str) ((str)->base + (str)->nused)
|
177
|
+
|
178
|
+
#ifdef __cplusplus
|
179
|
+
}
|
180
|
+
|
181
|
+
#include <stdexcept>
|
182
|
+
#include <new>
|
183
|
+
void
|
184
|
+
lcb_string_st::insert(iterator p, const char *first, const char *last) {
|
185
|
+
size_t at = p - base;
|
186
|
+
size_t n = last - first;
|
187
|
+
if (lcb_string_insert(this, at, first, n) != 0) {
|
188
|
+
throw std::bad_alloc();
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
namespace lcb {
|
193
|
+
class AutoString : public lcb_string_st {
|
194
|
+
public:
|
195
|
+
AutoString() {
|
196
|
+
lcb_string_init(this);
|
197
|
+
}
|
198
|
+
~AutoString() {
|
199
|
+
lcb_string_release(this);
|
200
|
+
}
|
201
|
+
|
202
|
+
char *take(size_t& len, size_t& cap) {
|
203
|
+
char *ret = base;
|
204
|
+
len = nused;
|
205
|
+
cap = nalloc;
|
206
|
+
|
207
|
+
base = NULL;
|
208
|
+
nalloc = 0;
|
209
|
+
nused = 0;
|
210
|
+
return ret;
|
211
|
+
}
|
212
|
+
char *take(size_t& len) {
|
213
|
+
size_t dummy;
|
214
|
+
return take(len, dummy);
|
215
|
+
}
|
216
|
+
char *take() {
|
217
|
+
size_t dummy;
|
218
|
+
return take(dummy, dummy);
|
219
|
+
}
|
220
|
+
|
221
|
+
private:
|
222
|
+
AutoString(lcb_string_st&);
|
223
|
+
AutoString(const lcb_string_st&);
|
224
|
+
};
|
225
|
+
}
|
226
|
+
|
227
|
+
#endif /** __cplusplus */
|
228
|
+
#endif /* LCB_STRING_H */
|
@@ -156,9 +156,7 @@ iotssl_log_errors(lcbio_XSSL *xs)
|
|
156
156
|
if (ERR_GET_LIB(curerr) == ERR_LIB_SSL) {
|
157
157
|
switch (ERR_GET_REASON(curerr)) {
|
158
158
|
case SSL_R_CERTIFICATE_VERIFY_FAILED:
|
159
|
-
#ifdef SSL_R_MISSING_VERIFY_MESSAGE
|
160
159
|
case SSL_R_MISSING_VERIFY_MESSAGE:
|
161
|
-
#endif
|
162
160
|
xs->errcode = LCB_SSL_CANTVERIFY;
|
163
161
|
break;
|
164
162
|
|
@@ -0,0 +1,82 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2015 Couchbase, Inc.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Implementation of dynamic arrays or strings suitable for one or more than
|
19
|
+
* one element. If only a single element is used, extra memory is not allocated
|
20
|
+
* via malloc.
|
21
|
+
*/
|
22
|
+
|
23
|
+
#include "simplestring.h"
|
24
|
+
|
25
|
+
#define LCB_SSOBUF_DECLARE(T) \
|
26
|
+
struct { \
|
27
|
+
unsigned count; \
|
28
|
+
union { \
|
29
|
+
lcb_string alloc; \
|
30
|
+
T single; \
|
31
|
+
} u;\
|
32
|
+
} \
|
33
|
+
|
34
|
+
#define LCB_SSOBUF_ALLOC(p, o, T) do { \
|
35
|
+
if ((o)->count == 0) { /* Only allocate a single element */ \
|
36
|
+
*(p) = &(o)->u.single; \
|
37
|
+
(o)->count++; \
|
38
|
+
} else if ((o)->count == 1) { /* Switch over to malloc */ \
|
39
|
+
T ssobuf__tmp = (o)->u.single; \
|
40
|
+
(o)->u.alloc.nused = 0; \
|
41
|
+
(o)->u.alloc.nalloc = 0; \
|
42
|
+
(o)->u.alloc.base = NULL; \
|
43
|
+
if (-1 == lcb_string_reserve(&(o)->u.alloc, sizeof(T) * 2)) { \
|
44
|
+
*(p) = NULL; \
|
45
|
+
} else { \
|
46
|
+
memcpy((o)->u.alloc.base, &ssobuf__tmp, sizeof(T)); \
|
47
|
+
lcb_string_added(&(o)->u.alloc, sizeof(T)); \
|
48
|
+
*(p) = (T*) ((o)->u.alloc.base + (o)->u.alloc.nused); \
|
49
|
+
lcb_string_added(&(o)->u.alloc, sizeof(T)); \
|
50
|
+
} \
|
51
|
+
(o)->count++; \
|
52
|
+
} else if (-1 == lcb_string_reserve(&(o)->u.alloc, sizeof(T))) { \
|
53
|
+
*(p) = NULL; \
|
54
|
+
} else { \
|
55
|
+
*(p) = (T*) ((o)->u.alloc.base + (o)->u.alloc.nused); \
|
56
|
+
lcb_string_added(&(o)->u.alloc, sizeof(T)); \
|
57
|
+
(o)->count++; \
|
58
|
+
} \
|
59
|
+
} while (0);
|
60
|
+
|
61
|
+
#define LCB_SSOBUF_ALLOC_N(p, o, T, n) do { \
|
62
|
+
if (n == 1) { \
|
63
|
+
LCB_SSOBUF_ALLOC(p, o, T); \
|
64
|
+
} else if (n > 1) { \
|
65
|
+
if (-1 == lcb_string_reserve(&(o)->u.alloc, sizeof(T) * (n) )) { \
|
66
|
+
*(p) = NULL; \
|
67
|
+
} else { \
|
68
|
+
lcb_string_added(&(o)->u.alloc, sizeof(T) * (n) ); \
|
69
|
+
*(p) = (T*)(o)->u.alloc.base; \
|
70
|
+
(o)->count = n; \
|
71
|
+
} \
|
72
|
+
} \
|
73
|
+
} while (0);
|
74
|
+
|
75
|
+
#define LCB_SSOBUF_CLEAN(o) do { \
|
76
|
+
if ((o)->count > 1) { \
|
77
|
+
lcb_string_release(&(o)->u.alloc); \
|
78
|
+
} \
|
79
|
+
} while (0);
|
80
|
+
|
81
|
+
#define LCB_SSOBUF_ARRAY(o, t) \
|
82
|
+
((o)->count > 1 ? ((t*)(o)->u.alloc.base) : &(o)->u.single)
|
@@ -40,11 +40,11 @@
|
|
40
40
|
|
41
41
|
#define TRACE_BEGIN_COMMON(TGT, req, cmd, ...) \
|
42
42
|
TGT((req)->request.opaque, ntohs((req)->request.vbucket), (req)->request.opcode, \
|
43
|
-
(
|
43
|
+
(cmd)->key.contig.bytes, (cmd)->key.contig.nbytes, ## __VA_ARGS__)
|
44
44
|
|
45
45
|
#define TRACE_BEGIN_SIMPLE(TGT, req, cmd) \
|
46
46
|
TGT((req)->request.opaque, ntohs((req)->request.vbucket), (req)->request.opcode, \
|
47
|
-
(
|
47
|
+
(cmd)->key.contig.bytes, (cmd)->key.contig.nbytes)
|
48
48
|
|
49
49
|
#define TRACE_END_COMMON(TGT, mcresp, resp, ...) \
|
50
50
|
TGT(mcresp->opaque(), 0, mcresp->opcode(), (resp)->rc, (const char *)(resp)->key, (resp)->nkey, \
|
@@ -58,7 +58,7 @@
|
|
58
58
|
|
59
59
|
#define TRACE_GET_END(mcresp, resp) \
|
60
60
|
TRACE(TRACE_END_COMMON(LIBCOUCHBASE_GET_END, mcresp, resp, \
|
61
|
-
(
|
61
|
+
(char*)(resp)->value, (resp)->nvalue, (resp)->itmflags, (resp)->cas, \
|
62
62
|
mcresp->datatype()))
|
63
63
|
|
64
64
|
#define TRACE_UNLOCK_BEGIN(req, cmd) TRACE(TRACE_BEGIN_SIMPLE(LIBCOUCHBASE_UNLOCK_BEGIN, req, cmd))
|
@@ -66,7 +66,7 @@
|
|
66
66
|
|
67
67
|
#define TRACE_STORE_BEGIN(req, cmd) \
|
68
68
|
TRACE(TRACE_BEGIN_COMMON(LIBCOUCHBASE_STORE_BEGIN, req, cmd, \
|
69
|
-
(
|
69
|
+
( (cmd)->value.vtype == LCB_KV_IOV ? NULL : (cmd)->value.u_buf.contig.bytes ),\
|
70
70
|
( (cmd)->value.vtype == LCB_KV_IOV ? 0 : (cmd)->value.u_buf.contig.nbytes ),\
|
71
71
|
(cmd)->flags, (cmd)->cas, (req)->request.datatype, (cmd)->exptime))
|
72
72
|
|
@@ -2,53 +2,56 @@
|
|
2
2
|
#include "internal.h"
|
3
3
|
#include "sllist-inl.h"
|
4
4
|
|
5
|
-
using namespace lcb::docreq;
|
6
|
-
|
7
5
|
static void docreq_handler(void *arg);
|
8
|
-
static void invoke_pending(
|
6
|
+
static void invoke_pending(lcb_DOCQUEUE*);
|
9
7
|
static void doc_callback(lcb_t,int, const lcb_RESPBASE *);
|
10
8
|
|
11
9
|
#define MAX_PENDING_DOCREQ 10
|
12
10
|
#define MIN_SCHED_SIZE 5
|
13
11
|
#define DOCQ_DELAY_US 200000
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
memset(&pending_gets, 0, sizeof pending_gets);
|
29
|
-
memset(&cb_queue, 0, sizeof cb_queue);
|
13
|
+
#define DOCQ_REF(q) (q)->refcount++
|
14
|
+
#define DOCQ_UNREF(q) if (!--(q)->refcount) { docq_free(q); }
|
15
|
+
|
16
|
+
lcb_DOCQUEUE *
|
17
|
+
lcbdocq_create(lcb_t instance)
|
18
|
+
{
|
19
|
+
lcb_DOCQUEUE *q = calloc(1, sizeof *q);
|
20
|
+
q->timer = lcbio_timer_new(instance->iotable, q, docreq_handler);
|
21
|
+
q->refcount = 1;
|
22
|
+
q->instance = instance;
|
23
|
+
q->max_pending_response = MAX_PENDING_DOCREQ;
|
24
|
+
q->min_batch_size = MIN_SCHED_SIZE;
|
25
|
+
return q;
|
30
26
|
}
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
static void
|
29
|
+
docq_free(lcb_DOCQUEUE *q)
|
30
|
+
{
|
31
|
+
lcbdocq_cancel(q);
|
32
|
+
lcbio_timer_destroy(q->timer);
|
33
|
+
free(q);
|
35
34
|
}
|
36
35
|
|
37
|
-
void
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
void
|
37
|
+
lcbdocq_unref(lcb_DOCQUEUE *q)
|
38
|
+
{
|
39
|
+
DOCQ_UNREF(q);
|
41
40
|
}
|
42
41
|
|
43
|
-
void
|
44
|
-
|
42
|
+
void
|
43
|
+
lcbdocq_cancel(lcb_DOCQUEUE *q)
|
44
|
+
{
|
45
|
+
if (!q->cancelled) {
|
46
|
+
q->cancelled = 1;
|
47
|
+
}
|
45
48
|
}
|
46
49
|
|
47
50
|
/* Calling this function ensures that the request will be scheduled in due
|
48
51
|
* time. This may be done at the next event loop iteration, or after a delay
|
49
52
|
* depending on how many items are actually found within the queue. */
|
50
53
|
static void
|
51
|
-
docq_poke(
|
54
|
+
docq_poke(lcb_DOCQUEUE *q)
|
52
55
|
{
|
53
56
|
if (q->n_awaiting_response < q->max_pending_response) {
|
54
57
|
if (q->n_awaiting_schedule > q->min_batch_size) {
|
@@ -62,26 +65,27 @@ docq_poke(Queue *q)
|
|
62
65
|
}
|
63
66
|
}
|
64
67
|
|
65
|
-
void
|
68
|
+
void
|
69
|
+
lcbdocq_add(lcb_DOCQUEUE *q, lcb_DOCQREQ *req)
|
66
70
|
{
|
67
|
-
sllist_append(&pending_gets, &req->slnode);
|
68
|
-
n_awaiting_schedule++;
|
69
|
-
req->parent =
|
71
|
+
sllist_append(&q->pending_gets, &req->slnode);
|
72
|
+
q->n_awaiting_schedule++;
|
73
|
+
req->parent = q;
|
70
74
|
req->ready = 0;
|
71
|
-
|
72
|
-
docq_poke(
|
75
|
+
DOCQ_REF(q);
|
76
|
+
docq_poke(q);
|
73
77
|
}
|
74
78
|
|
75
79
|
static void
|
76
80
|
docreq_handler(void *arg)
|
77
81
|
{
|
78
|
-
|
82
|
+
lcb_DOCQUEUE *q = arg;
|
79
83
|
sllist_iterator iter;
|
80
84
|
lcb_t instance = q->instance;
|
81
85
|
|
82
86
|
lcb_sched_enter(instance);
|
83
87
|
SLLIST_ITERFOR(&q->pending_gets, &iter) {
|
84
|
-
|
88
|
+
lcb_DOCQREQ *cont = SLLIST_ITEM(iter.cur, lcb_DOCQREQ, slnode);
|
85
89
|
|
86
90
|
if (q->n_awaiting_response > q->max_pending_response) {
|
87
91
|
lcbio_timer_rearm(q->timer, DOCQ_DELAY_US);
|
@@ -132,12 +136,13 @@ docreq_handler(void *arg)
|
|
132
136
|
/* Invokes the callback on all requests which are ready, until a request which
|
133
137
|
* is not yet ready is reached. */
|
134
138
|
static void
|
135
|
-
invoke_pending(
|
139
|
+
invoke_pending(lcb_DOCQUEUE *q)
|
136
140
|
{
|
137
141
|
sllist_iterator iter = { NULL };
|
138
|
-
|
142
|
+
|
143
|
+
DOCQ_REF(q);
|
139
144
|
SLLIST_ITERFOR(&q->cb_queue, &iter) {
|
140
|
-
|
145
|
+
lcb_DOCQREQ *dreq = SLLIST_ITEM(iter.cur, lcb_DOCQREQ, slnode);
|
141
146
|
void *bufh = NULL;
|
142
147
|
|
143
148
|
if (dreq->ready == 0) {
|
@@ -152,21 +157,21 @@ invoke_pending(Queue *q)
|
|
152
157
|
|
153
158
|
q->cb_ready(q, dreq);
|
154
159
|
if (bufh) {
|
155
|
-
lcb_backbuf_unref(
|
160
|
+
lcb_backbuf_unref(bufh);
|
156
161
|
}
|
157
|
-
q
|
162
|
+
DOCQ_UNREF(q);
|
158
163
|
}
|
159
|
-
q
|
164
|
+
DOCQ_UNREF(q);
|
160
165
|
}
|
161
166
|
|
162
167
|
static void
|
163
|
-
doc_callback(lcb_t, int, const lcb_RESPBASE *rb)
|
168
|
+
doc_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
|
164
169
|
{
|
165
170
|
const lcb_RESPGET *rg = (const lcb_RESPGET *)rb;
|
166
|
-
|
167
|
-
|
171
|
+
lcb_DOCQREQ *dreq = rb->cookie;
|
172
|
+
lcb_DOCQUEUE *q = dreq->parent;
|
168
173
|
|
169
|
-
q
|
174
|
+
DOCQ_REF(q);
|
170
175
|
|
171
176
|
q->n_awaiting_response--;
|
172
177
|
dreq->docresp = *rg;
|
@@ -177,12 +182,13 @@ doc_callback(lcb_t, int, const lcb_RESPBASE *rb)
|
|
177
182
|
/* Reference the response data, since we might not be invoking this right
|
178
183
|
* away */
|
179
184
|
if (rg->rc == LCB_SUCCESS) {
|
180
|
-
lcb_backbuf_ref(
|
185
|
+
lcb_backbuf_ref(dreq->docresp.bufh);
|
181
186
|
}
|
182
187
|
|
183
188
|
/* Ensure the invoke_pending doesn't destroy us */
|
184
189
|
invoke_pending(q);
|
185
190
|
docq_poke(q);
|
186
191
|
|
187
|
-
q
|
192
|
+
DOCQ_UNREF(q);
|
193
|
+
(void)instance; (void)cbtype;
|
188
194
|
}
|