couchbase 3.0.0.alpha.1 → 3.0.0.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests-6.0.3.yml +49 -0
  3. data/.github/workflows/tests.yml +47 -0
  4. data/.gitmodules +3 -0
  5. data/.idea/dictionaries/gem_terms.xml +5 -0
  6. data/.idea/inspectionProfiles/Project_Default.xml +1 -0
  7. data/.idea/vcs.xml +1 -0
  8. data/Gemfile +1 -0
  9. data/README.md +55 -2
  10. data/Rakefile +18 -0
  11. data/bin/init-cluster +62 -0
  12. data/bin/setup +1 -0
  13. data/couchbase.gemspec +3 -2
  14. data/examples/crud.rb +1 -2
  15. data/examples/managing_buckets.rb +47 -0
  16. data/examples/managing_collections.rb +58 -0
  17. data/examples/managing_query_indexes.rb +63 -0
  18. data/examples/query.rb +3 -2
  19. data/examples/query_with_consistency.rb +76 -0
  20. data/examples/subdocument.rb +23 -1
  21. data/ext/.clang-format +1 -1
  22. data/ext/.idea/dictionaries/couchbase_terms.xml +2 -0
  23. data/ext/.idea/vcs.xml +1 -0
  24. data/ext/CMakeLists.txt +30 -12
  25. data/ext/build_version.hxx.in +26 -0
  26. data/ext/couchbase/bucket.hxx +69 -8
  27. data/ext/couchbase/cluster.hxx +70 -54
  28. data/ext/couchbase/collections_manifest.hxx +3 -3
  29. data/ext/couchbase/configuration.hxx +14 -0
  30. data/ext/couchbase/couchbase.cxx +2044 -383
  31. data/ext/couchbase/{operations/document_id.hxx → document_id.hxx} +5 -4
  32. data/ext/couchbase/io/http_message.hxx +5 -1
  33. data/ext/couchbase/io/http_parser.hxx +2 -1
  34. data/ext/couchbase/io/http_session.hxx +6 -3
  35. data/ext/couchbase/io/{binary_message.hxx → mcbp_message.hxx} +15 -12
  36. data/ext/couchbase/io/mcbp_parser.hxx +99 -0
  37. data/ext/couchbase/io/{key_value_session.hxx → mcbp_session.hxx} +200 -95
  38. data/ext/couchbase/io/session_manager.hxx +37 -22
  39. data/ext/couchbase/mutation_token.hxx +2 -1
  40. data/ext/couchbase/operations.hxx +38 -8
  41. data/ext/couchbase/operations/bucket_create.hxx +138 -0
  42. data/ext/couchbase/operations/bucket_drop.hxx +65 -0
  43. data/ext/couchbase/operations/bucket_flush.hxx +65 -0
  44. data/ext/couchbase/operations/bucket_get.hxx +69 -0
  45. data/ext/couchbase/operations/bucket_get_all.hxx +62 -0
  46. data/ext/couchbase/operations/bucket_settings.hxx +111 -0
  47. data/ext/couchbase/operations/bucket_update.hxx +115 -0
  48. data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +60 -0
  49. data/ext/couchbase/operations/collection_create.hxx +86 -0
  50. data/ext/couchbase/operations/collection_drop.hxx +82 -0
  51. data/ext/couchbase/operations/command.hxx +10 -10
  52. data/ext/couchbase/operations/document_decrement.hxx +80 -0
  53. data/ext/couchbase/operations/document_exists.hxx +80 -0
  54. data/ext/couchbase/operations/{get.hxx → document_get.hxx} +4 -2
  55. data/ext/couchbase/operations/document_get_and_lock.hxx +64 -0
  56. data/ext/couchbase/operations/document_get_and_touch.hxx +64 -0
  57. data/ext/couchbase/operations/document_increment.hxx +80 -0
  58. data/ext/couchbase/operations/document_insert.hxx +74 -0
  59. data/ext/couchbase/operations/{lookup_in.hxx → document_lookup_in.hxx} +2 -2
  60. data/ext/couchbase/operations/{mutate_in.hxx → document_mutate_in.hxx} +11 -2
  61. data/ext/couchbase/operations/{query.hxx → document_query.hxx} +101 -6
  62. data/ext/couchbase/operations/document_remove.hxx +67 -0
  63. data/ext/couchbase/operations/document_replace.hxx +76 -0
  64. data/ext/couchbase/operations/{upsert.hxx → document_touch.hxx} +14 -14
  65. data/ext/couchbase/operations/{remove.hxx → document_unlock.hxx} +12 -10
  66. data/ext/couchbase/operations/document_upsert.hxx +74 -0
  67. data/ext/couchbase/operations/query_index_build_deferred.hxx +85 -0
  68. data/ext/couchbase/operations/query_index_create.hxx +134 -0
  69. data/ext/couchbase/operations/query_index_drop.hxx +108 -0
  70. data/ext/couchbase/operations/query_index_get_all.hxx +106 -0
  71. data/ext/couchbase/operations/scope_create.hxx +81 -0
  72. data/ext/couchbase/operations/scope_drop.hxx +79 -0
  73. data/ext/couchbase/operations/scope_get_all.hxx +72 -0
  74. data/ext/couchbase/protocol/client_opcode.hxx +35 -0
  75. data/ext/couchbase/protocol/client_request.hxx +56 -9
  76. data/ext/couchbase/protocol/client_response.hxx +52 -15
  77. data/ext/couchbase/protocol/cmd_cluster_map_change_notification.hxx +81 -0
  78. data/ext/couchbase/protocol/cmd_decrement.hxx +187 -0
  79. data/ext/couchbase/protocol/cmd_exists.hxx +171 -0
  80. data/ext/couchbase/protocol/cmd_get.hxx +31 -8
  81. data/ext/couchbase/protocol/cmd_get_and_lock.hxx +142 -0
  82. data/ext/couchbase/protocol/cmd_get_and_touch.hxx +142 -0
  83. data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +16 -3
  84. data/ext/couchbase/protocol/cmd_get_collections_manifest.hxx +16 -3
  85. data/ext/couchbase/protocol/cmd_get_error_map.hxx +16 -3
  86. data/ext/couchbase/protocol/cmd_hello.hxx +24 -8
  87. data/ext/couchbase/protocol/cmd_increment.hxx +187 -0
  88. data/ext/couchbase/protocol/cmd_info.hxx +1 -0
  89. data/ext/couchbase/protocol/cmd_insert.hxx +172 -0
  90. data/ext/couchbase/protocol/cmd_lookup_in.hxx +28 -13
  91. data/ext/couchbase/protocol/cmd_mutate_in.hxx +65 -13
  92. data/ext/couchbase/protocol/cmd_remove.hxx +59 -4
  93. data/ext/couchbase/protocol/cmd_replace.hxx +172 -0
  94. data/ext/couchbase/protocol/cmd_sasl_auth.hxx +15 -3
  95. data/ext/couchbase/protocol/cmd_sasl_list_mechs.hxx +15 -3
  96. data/ext/couchbase/protocol/cmd_sasl_step.hxx +15 -3
  97. data/ext/couchbase/protocol/cmd_select_bucket.hxx +14 -2
  98. data/ext/couchbase/protocol/cmd_touch.hxx +102 -0
  99. data/ext/couchbase/protocol/cmd_unlock.hxx +95 -0
  100. data/ext/couchbase/protocol/cmd_upsert.hxx +50 -14
  101. data/ext/couchbase/protocol/durability_level.hxx +67 -0
  102. data/ext/couchbase/protocol/frame_info_id.hxx +187 -0
  103. data/ext/couchbase/protocol/hello_feature.hxx +137 -0
  104. data/ext/couchbase/protocol/server_opcode.hxx +57 -0
  105. data/ext/couchbase/protocol/server_request.hxx +122 -0
  106. data/ext/couchbase/protocol/unsigned_leb128.h +15 -15
  107. data/ext/couchbase/utils/byteswap.hxx +1 -2
  108. data/ext/couchbase/utils/url_codec.hxx +225 -0
  109. data/ext/couchbase/version.hxx +3 -1
  110. data/ext/extconf.rb +4 -1
  111. data/ext/test/main.cxx +37 -113
  112. data/ext/third_party/snappy/.appveyor.yml +36 -0
  113. data/ext/third_party/snappy/.gitignore +8 -0
  114. data/ext/third_party/snappy/.travis.yml +98 -0
  115. data/ext/third_party/snappy/AUTHORS +1 -0
  116. data/ext/third_party/snappy/CMakeLists.txt +345 -0
  117. data/ext/third_party/snappy/CONTRIBUTING.md +26 -0
  118. data/ext/third_party/snappy/COPYING +54 -0
  119. data/ext/third_party/snappy/NEWS +188 -0
  120. data/ext/third_party/snappy/README.md +148 -0
  121. data/ext/third_party/snappy/cmake/SnappyConfig.cmake.in +33 -0
  122. data/ext/third_party/snappy/cmake/config.h.in +59 -0
  123. data/ext/third_party/snappy/docs/README.md +72 -0
  124. data/ext/third_party/snappy/format_description.txt +110 -0
  125. data/ext/third_party/snappy/framing_format.txt +135 -0
  126. data/ext/third_party/snappy/snappy-c.cc +90 -0
  127. data/ext/third_party/snappy/snappy-c.h +138 -0
  128. data/ext/third_party/snappy/snappy-internal.h +315 -0
  129. data/ext/third_party/snappy/snappy-sinksource.cc +121 -0
  130. data/ext/third_party/snappy/snappy-sinksource.h +182 -0
  131. data/ext/third_party/snappy/snappy-stubs-internal.cc +42 -0
  132. data/ext/third_party/snappy/snappy-stubs-internal.h +493 -0
  133. data/ext/third_party/snappy/snappy-stubs-public.h.in +63 -0
  134. data/ext/third_party/snappy/snappy-test.cc +613 -0
  135. data/ext/third_party/snappy/snappy-test.h +526 -0
  136. data/ext/third_party/snappy/snappy.cc +1770 -0
  137. data/ext/third_party/snappy/snappy.h +209 -0
  138. data/ext/third_party/snappy/snappy_compress_fuzzer.cc +60 -0
  139. data/ext/third_party/snappy/snappy_uncompress_fuzzer.cc +58 -0
  140. data/ext/third_party/snappy/snappy_unittest.cc +1512 -0
  141. data/ext/third_party/snappy/testdata/alice29.txt +3609 -0
  142. data/ext/third_party/snappy/testdata/asyoulik.txt +4122 -0
  143. data/ext/third_party/snappy/testdata/baddata1.snappy +0 -0
  144. data/ext/third_party/snappy/testdata/baddata2.snappy +0 -0
  145. data/ext/third_party/snappy/testdata/baddata3.snappy +0 -0
  146. data/ext/third_party/snappy/testdata/fireworks.jpeg +0 -0
  147. data/ext/third_party/snappy/testdata/geo.protodata +0 -0
  148. data/ext/third_party/snappy/testdata/html +1 -0
  149. data/ext/third_party/snappy/testdata/html_x_4 +1 -0
  150. data/ext/third_party/snappy/testdata/kppkn.gtb +0 -0
  151. data/ext/third_party/snappy/testdata/lcet10.txt +7519 -0
  152. data/ext/third_party/snappy/testdata/paper-100k.pdf +600 -2
  153. data/ext/third_party/snappy/testdata/plrabn12.txt +10699 -0
  154. data/ext/third_party/snappy/testdata/urls.10K +10000 -0
  155. data/lib/couchbase/binary_collection.rb +33 -76
  156. data/lib/couchbase/binary_collection_options.rb +94 -0
  157. data/lib/couchbase/bucket.rb +9 -3
  158. data/lib/couchbase/cluster.rb +161 -23
  159. data/lib/couchbase/collection.rb +108 -191
  160. data/lib/couchbase/collection_options.rb +430 -0
  161. data/lib/couchbase/errors.rb +136 -134
  162. data/lib/couchbase/json_transcoder.rb +32 -0
  163. data/lib/couchbase/management/analytics_index_manager.rb +185 -9
  164. data/lib/couchbase/management/bucket_manager.rb +84 -33
  165. data/lib/couchbase/management/collection_manager.rb +166 -1
  166. data/lib/couchbase/management/query_index_manager.rb +261 -0
  167. data/lib/couchbase/management/search_index_manager.rb +291 -0
  168. data/lib/couchbase/management/user_manager.rb +12 -10
  169. data/lib/couchbase/management/view_index_manager.rb +151 -1
  170. data/lib/couchbase/mutation_state.rb +11 -1
  171. data/lib/couchbase/scope.rb +4 -4
  172. data/lib/couchbase/version.rb +1 -1
  173. metadata +113 -18
  174. data/.travis.yml +0 -7
  175. data/ext/couchbase/io/binary_parser.hxx +0 -64
  176. data/lib/couchbase/results.rb +0 -307
@@ -0,0 +1,187 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 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
+ #pragma once
19
+
20
+ namespace couchbase::protocol
21
+ {
22
+ enum class request_frame_info_id : uint8_t {
23
+ /**
24
+ * No commands may be executed in parallel (received on the same connection) as this command (the command before MUST be completed
25
+ * before execution of this command is started, and this command MUST be completed before execution of the next command is started).
26
+ * FrameInfo encoded as:
27
+ *
28
+ * Byte/ 0 |
29
+ * / |
30
+ * |0 1 2 3 4 5 6 7|
31
+ * +---------------+
32
+ * 0| ID:0 | Len:0 |
33
+ */
34
+ barrier = 0x00,
35
+
36
+ /**
37
+ * This command contains durability requirements. FrameInfo encoded as:
38
+ *
39
+ * Byte/ 0 |
40
+ * / |
41
+ * | 0 1 2 3 4 5 6 7 |
42
+ * +--------------------+
43
+ * 0| ID:1 | Len:1 or 3 |
44
+ *
45
+ * The size of the durability requirement is variable length. The first byte contains the durability level by using the following table:
46
+ *
47
+ * 0x01 = majority
48
+ * 0x02 = majority and persist on master
49
+ * 0x03 = persist to majority
50
+ *
51
+ * The (optional) 2nd and 3rd byte contains the timeout specified in milliseconds (network byte order). If the timeout is omitted the
52
+ * default timeout value configured on the server will be used.
53
+ *
54
+ * If timeout is specified, the valid range is 1..65535. Values 0x0 and 0xffff are reserved and will result in the request failing with
55
+ * invalid_argument (0x4) if used.
56
+ */
57
+ durability_requirement = 0x01,
58
+
59
+ /**
60
+ * This command contains a DCP stream-ID as per the stream-request which created the stream.
61
+ *
62
+ * Byte/ 0 |
63
+ * / |
64
+ * |0 1 2 3 4 5 6 7|
65
+ * +---------------+
66
+ * 0| ID:2 | Len:2 |
67
+ *
68
+ * The 2nd and 3rd byte contain a network byte order (uint16) storing the stream ID value which was specified in the DCP stream-request
69
+ * that created the stream.
70
+ */
71
+ dcp_stream_id = 0x02,
72
+
73
+ /**
74
+ * Request the server to submit trace information by using the supplied context information as the parent span. The context must be
75
+ * present (length > 0)
76
+ */
77
+ open_tracing_context = 0x03,
78
+
79
+ /**
80
+ * Request the server to execute the command as the provided user username (must be present) to identify users defined outside Couchbase
81
+ * (ldap) the username must be prefixed with ^ (ex: ^trond). Local users do not need a prefix.
82
+ *
83
+ * The authenticated user must possess the impersonate privilege in order to utilize the feature (otherwise an error will be returned),
84
+ * and the effective privilege set when executing the command is an intersection of the authenticated users privilege set and the
85
+ * impersonated persons privilege set.
86
+ */
87
+ impersonate_user = 0x04,
88
+
89
+ /**
90
+ * If the request modifies an existing document the expiry time from the existing document should be used instead of the TTL provided.
91
+ * If document don't exist the provided TTL should be used. The frame info contains no value (length = 0).
92
+ */
93
+ preserve_ttl = 0x1f,
94
+ };
95
+
96
+ constexpr inline bool
97
+ is_valid_request_frame_info_id(uint8_t value)
98
+ {
99
+ switch (static_cast<request_frame_info_id>(value)) {
100
+ case request_frame_info_id::barrier:
101
+ case request_frame_info_id::durability_requirement:
102
+ case request_frame_info_id::dcp_stream_id:
103
+ case request_frame_info_id::open_tracing_context:
104
+ case request_frame_info_id::impersonate_user:
105
+ case request_frame_info_id::preserve_ttl:
106
+ return true;
107
+ }
108
+ return false;
109
+ }
110
+
111
+ enum class response_frame_info_id : uint8_t {
112
+ /**
113
+ * Time (in microseconds) server spent on the operation. Measured from receiving header from OS to when response given to OS. Size: 2
114
+ * bytes; encoded as variable-precision value (see below)
115
+ *
116
+ * FrameInfo encoded as:
117
+ *
118
+ * Byte/ 0 | 1 | 2 |
119
+ * / | | |
120
+ * |0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|
121
+ * +---------------+---------------+---------------+
122
+ * 0| ID:0 | Len:2 | Server Recv->Send Duration |
123
+ *
124
+ * The duration in micros is encoded as:
125
+ *
126
+ * encoded = (micros * 2) ^ (1.0 / 1.74)
127
+ * decoded = (encoded ^ 1.74) / 2
128
+ */
129
+ server_duration = 0x00,
130
+ };
131
+
132
+ constexpr inline bool
133
+ is_valid_response_frame_info_id(uint8_t value)
134
+ {
135
+ switch (static_cast<response_frame_info_id>(value)) {
136
+ case response_frame_info_id::server_duration:
137
+ return true;
138
+ }
139
+ return false;
140
+ }
141
+
142
+ } // namespace couchbase::protocol
143
+
144
+ template<>
145
+ struct fmt::formatter<couchbase::protocol::request_frame_info_id> : formatter<string_view> {
146
+ template<typename FormatContext>
147
+ auto format(couchbase::protocol::request_frame_info_id opcode, FormatContext& ctx)
148
+ {
149
+ string_view name = "unknown";
150
+ switch (opcode) {
151
+ case couchbase::protocol::request_frame_info_id::barrier:
152
+ name = "barrier";
153
+ break;
154
+ case couchbase::protocol::request_frame_info_id::durability_requirement:
155
+ name = "durability_requirement";
156
+ break;
157
+ case couchbase::protocol::request_frame_info_id::dcp_stream_id:
158
+ name = "dcp_stream_id";
159
+ break;
160
+ case couchbase::protocol::request_frame_info_id::open_tracing_context:
161
+ name = "open_tracing_context";
162
+ break;
163
+ case couchbase::protocol::request_frame_info_id::impersonate_user:
164
+ name = "impersonate_user";
165
+ break;
166
+ case couchbase::protocol::request_frame_info_id::preserve_ttl:
167
+ name = "preserve_ttl";
168
+ break;
169
+ }
170
+ return formatter<string_view>::format(name, ctx);
171
+ }
172
+ };
173
+
174
+ template<>
175
+ struct fmt::formatter<couchbase::protocol::response_frame_info_id> : formatter<string_view> {
176
+ template<typename FormatContext>
177
+ auto format(couchbase::protocol::response_frame_info_id opcode, FormatContext& ctx)
178
+ {
179
+ string_view name = "unknown";
180
+ switch (opcode) {
181
+ case couchbase::protocol::response_frame_info_id::server_duration:
182
+ name = "server_duration";
183
+ break;
184
+ }
185
+ return formatter<string_view>::format(name, ctx);
186
+ }
187
+ };
@@ -22,20 +22,129 @@
22
22
  namespace couchbase::protocol
23
23
  {
24
24
  enum class hello_feature : uint16_t {
25
+ /**
26
+ * The client wants to TLS and send STARTTLS
27
+ */
25
28
  tls = 0x02,
29
+
30
+ /**
31
+ * The client requests the server to set TCP NODELAY on the socket used by this connection.
32
+ */
26
33
  tcp_nodelay = 0x03,
34
+
35
+ /**
36
+ * The client requests the server to add the sequence number for a mutation to the response packet used in mutations.
37
+ */
27
38
  mutation_seqno = 0x04,
39
+
40
+ /**
41
+ * The client requests the server to set TCP DELAY on the socket used by this connection
42
+ */
43
+ tcp_delay = 0x05,
44
+
45
+ /**
46
+ * The client requests the server to add XATTRs to the stream for commands where it makes sense (GetWithMeta, SetWithMeta, DcpMutation
47
+ * etc)
48
+ */
28
49
  xattr = 0x06,
50
+
51
+ /**
52
+ * The client requests the server to send extended error codes instead of disconnecting the client when new errors occur (note that some
53
+ * errors may be remapped to more generic error codes instead of disconnecting)
54
+ */
29
55
  xerror = 0x07,
56
+
57
+ /**
58
+ * This is purely informational (it does not enable/disable anything on the server). It may be used from the client to know if it should
59
+ * be able to run select bucket or not (select bucket was a privileged command pre-spock. In spock all users may run select bucket, but
60
+ * only to a bucket they have access to).
61
+ */
30
62
  select_bucket = 0x08,
63
+
64
+ /**
65
+ * The client wants to enable support for Snappy compression. A client with support for Snappy compression must update the datatype
66
+ * filed in the requests with the bit representing SNAPPY when sending snappy compressed data to the server. It must be able to receive
67
+ * data from the server compressed with SNAPPY identified by the bit being set in the datatype field
68
+ */
31
69
  snappy = 0x0a,
70
+
71
+ /**
72
+ * The client wants to enable support for JSON. The client must set this bit when storing JSON documents on the server. The server will
73
+ * set the appropriate bit in the datatype field when returning such documents to the client
74
+ */
32
75
  json = 0x0b,
76
+
77
+ /**
78
+ * The client allows for full duplex on the socket. This means that the server may send requests back to the client. These messages is
79
+ * identified by the magic values of 0x82 (request) and 0x83 (response). See the document Duplex for more information.
80
+ *
81
+ * https://github.com/couchbase/kv_engine/blob/master/docs/Duplex.md
82
+ */
33
83
  duplex = 0x0c,
84
+
85
+ /**
86
+ * The client wants the server to notify the client with new cluster maps whenever ns_server push them to memcached. (note that this
87
+ * notification is subject to deduplication of the vbucket map received as part of not my vbucket)
88
+ */
34
89
  clustermap_change_notification = 0x0d,
90
+
91
+ /**
92
+ * The client allows the server to reorder the execution of commands. See the document UnorderedExecution for more information
93
+ *
94
+ * https://github.com/couchbase/kv_engine/blob/master/docs/UnorderedExecution.md
95
+ */
35
96
  unordered_execution = 0x0e,
97
+
98
+ /**
99
+ * The client wants the server to include tracing information in the response packet
100
+ */
101
+ tracing = 0x0f,
102
+
103
+ /**
104
+ * This is purely informational (it does not enable/disable anything on the server). It may be used from the client to know if it may
105
+ * send the alternative request packet (magic 0x08) containing FrameInfo segments.
106
+ */
36
107
  alt_request_support = 0x10,
108
+
109
+ /**
110
+ * This is purely informational (it does not enable/disable anything on the server). It may be used from the client to know if it may
111
+ * use synchronous replication tags in the mutation requests.
112
+ */
37
113
  sync_replication = 0x11,
114
+
115
+ /**
116
+ * The client wants to enable support for Collections
117
+ */
118
+ collections = 0x12,
119
+
120
+ /**
121
+ * This is purely informational (it does not enable / disable anything on the server). It may be used from the client to figure out if
122
+ * the server supports OpenTracing or not.)
123
+ */
124
+ open_tracing = 0x13,
125
+
126
+ /**
127
+ * This is purely informational (it does not enable / disable anything on the server). It may be used from the client to know if it may
128
+ * use PreserveTtl in the operations who carries the TTL for a document
129
+ */
130
+ preserve_ttl = 0x14,
131
+
132
+ /**
133
+ * This is purely information (it does not enable / disable anything on the server). It may be used from the client to determine if the
134
+ * server supports VATTRs in a generic way (can request $ and will either succeed or fail with SubdocXattrUnknownVattr). Requires XATTR.
135
+ */
38
136
  vattr = 0x15,
137
+
138
+ /**
139
+ * This is purely information (it does not enable / disable anything on the server). It may be used from the client to determine if the
140
+ * server supports Point in Time Recovery
141
+ */
142
+ point_in_time_recovery = 0x16,
143
+
144
+ /**
145
+ * Does the server support the subdoc mutation flag create_as_deleted
146
+ */
147
+ subdoc_create_as_deleted = 0x17,
39
148
  };
40
149
 
41
150
  constexpr inline bool
@@ -56,6 +165,13 @@ is_valid_hello_feature(uint16_t code)
56
165
  case hello_feature::alt_request_support:
57
166
  case hello_feature::sync_replication:
58
167
  case hello_feature::vattr:
168
+ case hello_feature::collections:
169
+ case hello_feature::open_tracing:
170
+ case hello_feature::preserve_ttl:
171
+ case hello_feature::point_in_time_recovery:
172
+ case hello_feature::tcp_delay:
173
+ case hello_feature::tracing:
174
+ case hello_feature::subdoc_create_as_deleted:
59
175
  return true;
60
176
  }
61
177
  return false;
@@ -112,6 +228,27 @@ struct fmt::formatter : formatter
112
228
  case couchbase::protocol::hello_feature::vattr:
113
229
  name = "vattr";
114
230
  break;
231
+ case couchbase::protocol::hello_feature::collections:
232
+ name = "collections";
233
+ break;
234
+ case couchbase::protocol::hello_feature::open_tracing:
235
+ name = "open_tracing";
236
+ break;
237
+ case couchbase::protocol::hello_feature::preserve_ttl:
238
+ name = "preserve_ttl";
239
+ break;
240
+ case couchbase::protocol::hello_feature::point_in_time_recovery:
241
+ name = "point_in_time_recovery";
242
+ break;
243
+ case couchbase::protocol::hello_feature::tcp_delay:
244
+ name = "tcp_delay";
245
+ break;
246
+ case couchbase::protocol::hello_feature::tracing:
247
+ name = "tracing";
248
+ break;
249
+ case couchbase::protocol::hello_feature::subdoc_create_as_deleted:
250
+ name = "subdoc_create_as_deleted";
251
+ break;
115
252
  }
116
253
  return formatter<string_view>::format(name, ctx);
117
254
  }
@@ -0,0 +1,57 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 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
+ #pragma once
19
+
20
+ namespace couchbase::protocol
21
+ {
22
+ enum class server_opcode : uint8_t {
23
+ cluster_map_change_notification = 0x01,
24
+ invalid = 0xff,
25
+ };
26
+
27
+ constexpr inline bool
28
+ is_valid_server_request_opcode(uint8_t code)
29
+ {
30
+ switch (static_cast<server_opcode>(code)) {
31
+ case server_opcode::cluster_map_change_notification:
32
+ return true;
33
+ case server_opcode::invalid:
34
+ break;
35
+ }
36
+ return false;
37
+ }
38
+
39
+ } // namespace couchbase::protocol
40
+
41
+ template<>
42
+ struct fmt::formatter<couchbase::protocol::server_opcode> : formatter<string_view> {
43
+ template<typename FormatContext>
44
+ auto format(couchbase::protocol::server_opcode opcode, FormatContext& ctx)
45
+ {
46
+ string_view name = "unknown";
47
+ switch (opcode) {
48
+ case couchbase::protocol::server_opcode::cluster_map_change_notification:
49
+ name = "cluster_map_change_notification";
50
+ break;
51
+ case couchbase::protocol::server_opcode::invalid:
52
+ name = "invalid";
53
+ break;
54
+ }
55
+ return formatter<string_view>::format(name, ctx);
56
+ }
57
+ };
@@ -0,0 +1,122 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 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
+ #pragma once
19
+
20
+ #include <gsl/gsl_assert>
21
+
22
+ #include <tao/json.hpp>
23
+ #include <tao/json/contrib/traits.hpp>
24
+
25
+ #include <protocol/server_opcode.hxx>
26
+ #include <protocol/magic.hxx>
27
+ #include <protocol/status.hxx>
28
+ #include <protocol/datatype.hxx>
29
+ #include <protocol/cmd_info.hxx>
30
+
31
+ namespace couchbase::protocol
32
+ {
33
+
34
+ template<typename Body>
35
+ class server_request
36
+ {
37
+ private:
38
+ static const inline magic magic_ = magic::server_request;
39
+
40
+ Body body_;
41
+ server_opcode opcode_{ server_opcode::invalid };
42
+ header_buffer header_;
43
+ uint8_t data_type_;
44
+ std::vector<std::uint8_t> data_;
45
+ std::size_t body_size_;
46
+ std::uint32_t opaque_;
47
+ std::uint64_t cas_;
48
+ cmd_info info_;
49
+
50
+ public:
51
+ server_request() = default;
52
+ explicit server_request(io::mcbp_message& msg)
53
+ {
54
+ std::memcpy(header_.data(), &msg.header, sizeof(msg.header));
55
+ verify_header();
56
+ data_ = std::move(msg.body);
57
+ parse_body();
58
+ }
59
+
60
+ [[nodiscard]] server_opcode opcode() const
61
+ {
62
+ return opcode_;
63
+ }
64
+
65
+ [[nodiscard]] std::size_t body_size() const
66
+ {
67
+ return body_size_;
68
+ }
69
+
70
+ [[nodiscard]] std::uint64_t cas() const
71
+ {
72
+ return cas_;
73
+ }
74
+
75
+ [[nodiscard]] std::uint32_t opaque() const
76
+ {
77
+ return opaque_;
78
+ }
79
+
80
+ Body& body()
81
+ {
82
+ return body_;
83
+ }
84
+
85
+ cmd_info& info()
86
+ {
87
+ return info_;
88
+ }
89
+
90
+ [[nodiscard]] header_buffer& header()
91
+ {
92
+ return header_;
93
+ }
94
+
95
+ void verify_header()
96
+ {
97
+ Expects(header_[0] == static_cast<std::uint8_t>(magic_));
98
+ Expects(header_[1] == static_cast<std::uint8_t>(Body::opcode));
99
+ opcode_ = static_cast<server_opcode>(header_[1]);
100
+ data_type_ = header_[5];
101
+
102
+ uint32_t field = 0;
103
+ memcpy(&field, header_.data() + 8, sizeof(field));
104
+ body_size_ = ntohl(field);
105
+ data_.resize(body_size_);
106
+
107
+ memcpy(&opaque_, header_.data() + 12, sizeof(opaque_));
108
+
109
+ memcpy(&cas_, header_.data() + 16, sizeof(cas_));
110
+ }
111
+
112
+ void parse_body()
113
+ {
114
+ body_.parse(header_, data_, info_);
115
+ }
116
+
117
+ [[nodiscard]] std::vector<std::uint8_t>& data()
118
+ {
119
+ return data_;
120
+ }
121
+ };
122
+ } // namespace couchbase::protocol