couchbase 3.0.0.alpha.1-universal-darwin-19 → 3.0.0.alpha.2-universal-darwin-19

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
@@ -18,7 +18,7 @@
18
18
  #pragma once
19
19
 
20
20
  #include <gsl/gsl_assert>
21
- #include <operations/document_id.hxx>
21
+ #include <document_id.hxx>
22
22
  #include <protocol/cmd_lookup_in.hxx>
23
23
 
24
24
  namespace couchbase::operations
@@ -82,4 +82,4 @@ make_response(std::error_code ec, lookup_in_request& request, lookup_in_request:
82
82
  return response;
83
83
  }
84
84
 
85
- } // namespace couchbase::operations
85
+ } // namespace couchbase::operations
@@ -18,7 +18,7 @@
18
18
  #pragma once
19
19
 
20
20
  #include <gsl/gsl_assert>
21
- #include <operations/document_id.hxx>
21
+ #include <document_id.hxx>
22
22
  #include <protocol/cmd_mutate_in.hxx>
23
23
 
24
24
  namespace couchbase::operations
@@ -34,6 +34,7 @@ struct mutate_in_response {
34
34
  document_id id;
35
35
  std::error_code ec{};
36
36
  std::uint64_t cas{};
37
+ mutation_token token{};
37
38
  std::vector<field> fields{};
38
39
  std::optional<std::size_t> first_error_index{};
39
40
  };
@@ -47,6 +48,8 @@ struct mutate_in_request {
47
48
  uint32_t opaque{};
48
49
  bool access_deleted{ false };
49
50
  protocol::mutate_in_request_body::mutate_in_specs specs{};
51
+ protocol::durability_level durability_level{ protocol::durability_level::none };
52
+ std::optional<std::uint16_t> durability_timeout{};
50
53
 
51
54
  void encode_to(encoded_request_type& encoded)
52
55
  {
@@ -55,6 +58,9 @@ struct mutate_in_request {
55
58
  encoded.body().id(id);
56
59
  encoded.body().access_deleted(access_deleted);
57
60
  encoded.body().specs(specs);
61
+ if (durability_level != protocol::durability_level::none) {
62
+ encoded.body().durability(durability_level, durability_timeout);
63
+ }
58
64
  }
59
65
  };
60
66
 
@@ -64,6 +70,9 @@ make_response(std::error_code ec, mutate_in_request& request, mutate_in_request:
64
70
  mutate_in_response response{ request.id, ec };
65
71
  if (!ec) {
66
72
  response.cas = encoded.cas();
73
+ response.token = encoded.body().token();
74
+ response.token.partition_id = request.partition;
75
+ response.token.bucket_name = response.id.bucket;
67
76
  response.fields.resize(request.specs.entries.size());
68
77
  for (size_t i = 0; i < request.specs.entries.size(); ++i) {
69
78
  auto& req_entry = request.specs.entries[i];
@@ -84,4 +93,4 @@ make_response(std::error_code ec, mutate_in_request& request, mutate_in_request:
84
93
  return response;
85
94
  }
86
95
 
87
- } // namespace couchbase::operations
96
+ } // namespace couchbase::operations
@@ -53,7 +53,6 @@ struct query_response_payload {
53
53
 
54
54
  query_meta_data meta_data{};
55
55
  std::vector<std::string> rows{};
56
- std::string body;
57
56
  };
58
57
  } // namespace couchbase::operations
59
58
 
@@ -125,21 +124,27 @@ struct traits {
125
124
  }
126
125
  };
127
126
  } // namespace tao::json
127
+
128
128
  namespace couchbase::operations
129
129
  {
130
-
131
130
  struct query_response {
132
- uuid::uuid_t client_context_id;
131
+ std::string client_context_id;
133
132
  std::error_code ec;
134
133
  query_response_payload payload{};
135
134
  };
136
135
 
137
136
  struct query_request {
137
+ using response_type = query_response;
138
138
  using encoded_request_type = io::http_request;
139
139
  using encoded_response_type = io::http_response;
140
140
 
141
+ enum class scan_consistency_type { not_bounded, request_plus };
142
+
143
+ static const inline service_type type = service_type::query;
144
+
145
+ std::uint64_t timeout{ 75'000 }; // milliseconds
141
146
  std::string statement;
142
- uuid::uuid_t client_context_id{ uuid::random() };
147
+ std::string client_context_id{ uuid::to_string(uuid::random()) };
143
148
 
144
149
  bool adhoc{ true };
145
150
  bool metrics{ false };
@@ -147,8 +152,11 @@ struct query_request {
147
152
 
148
153
  std::optional<std::uint64_t> max_parallelism{};
149
154
  std::optional<std::uint64_t> scan_cap{};
155
+ std::optional<std::uint64_t> scan_wait{};
150
156
  std::optional<std::uint64_t> pipeline_batch{};
151
157
  std::optional<std::uint64_t> pipeline_cap{};
158
+ std::optional<scan_consistency_type> scan_consistency{};
159
+ std::vector<mutation_token> mutation_state{};
152
160
 
153
161
  enum class profile_mode {
154
162
  off,
@@ -165,7 +173,8 @@ struct query_request {
165
173
  {
166
174
  encoded.headers["content-type"] = "application/json";
167
175
  tao::json::value body{ { "statement", statement },
168
- { "client_context_id", uuid::to_string(client_context_id) } };
176
+ { "client_context_id", client_context_id },
177
+ { "timeout", fmt::format("{}ms", timeout) } };
169
178
  if (positional_parameters.empty()) {
170
179
  for (auto& param : named_parameters) {
171
180
  Expects(param.first.empty() == false);
@@ -206,12 +215,43 @@ struct query_request {
206
215
  if (readonly) {
207
216
  body["readonly"] = true;
208
217
  }
218
+ bool check_scan_wait = false;
219
+ if (scan_consistency) {
220
+ switch (scan_consistency.value()) {
221
+ case scan_consistency_type::not_bounded:
222
+ body["scan_consistency"] = "not_bounded";
223
+ break;
224
+ case scan_consistency_type::request_plus:
225
+ check_scan_wait = true;
226
+ body["scan_consistency"] = "request_plus";
227
+ break;
228
+ }
229
+ } else if (!mutation_state.empty()) {
230
+ check_scan_wait = true;
231
+ body["scan_consistency"] = "at_plus";
232
+ tao::json::value scan_vectors = tao::json::empty_object;
233
+ for (const auto& token : mutation_state) {
234
+ auto* bucket = scan_vectors.find(token.bucket_name);
235
+ if (!bucket) {
236
+ scan_vectors[token.bucket_name] = tao::json::empty_object;
237
+ bucket = scan_vectors.find(token.bucket_name);
238
+ }
239
+ auto& bucket_obj = bucket->get_object();
240
+ bucket_obj[std::to_string(token.partition_id)] =
241
+ std::vector<tao::json::value>{ token.sequence_number, std::to_string(token.partition_uuid) };
242
+ }
243
+ body["scan_vectors"] = scan_vectors;
244
+ }
245
+ if (check_scan_wait && scan_wait) {
246
+ body["scan_wait"] = scan_wait.value();
247
+ }
209
248
  for (auto& param : raw) {
210
249
  body[param.first] = param.second;
211
250
  }
212
251
  encoded.method = "POST";
213
252
  encoded.path = "/query/service";
214
253
  encoded.body = tao::json::to_string(body);
254
+ spdlog::trace("query request: {}", encoded.body);
215
255
  }
216
256
  };
217
257
 
@@ -222,7 +262,62 @@ make_response(std::error_code ec, query_request& request, query_request::encoded
222
262
  if (!ec) {
223
263
  spdlog::trace("query response: {}", encoded.body);
224
264
  response.payload = tao::json::from_string(encoded.body).as<query_response_payload>();
225
- Expects(response.payload.meta_data.client_context_id == uuid::to_string(request.client_context_id));
265
+ Expects(response.payload.meta_data.client_context_id == request.client_context_id);
266
+ if (response.payload.meta_data.status != "success") {
267
+ bool prepared_statement_failure = false;
268
+ bool index_not_found = false;
269
+ bool index_failure = false;
270
+ bool planning_failure = false;
271
+ bool syntax_error = false;
272
+ bool server_timeout = false;
273
+
274
+ if (response.payload.meta_data.errors) {
275
+ for (const auto& error : *response.payload.meta_data.errors) {
276
+ switch (error.code) {
277
+ case 1080: /* IKey: "timeout" */
278
+ server_timeout = true;
279
+ break;
280
+ case 3000: /* IKey: "parse.syntax_error" */
281
+ syntax_error = true;
282
+ break;
283
+ case 4040: /* IKey: "plan.build_prepared.no_such_name" */
284
+ case 4050: /* IKey: "plan.build_prepared.unrecognized_prepared" */
285
+ case 4060: /* IKey: "plan.build_prepared.no_such_name" */
286
+ case 4070: /* IKey: "plan.build_prepared.decoding" */
287
+ case 4080: /* IKey: "plan.build_prepared.name_encoded_plan_mismatch" */
288
+ case 4090: /* IKey: "plan.build_prepared.name_not_in_encoded_plan" */
289
+ prepared_statement_failure = true;
290
+ break;
291
+ case 12004: /* IKey: "datastore.couchbase.primary_idx_not_found" */
292
+ case 12016: /* IKey: "datastore.couchbase.index_not_found" */
293
+ index_not_found = true;
294
+ break;
295
+ default:
296
+ if ((error.code >= 12000 && error.code < 13000) || (error.code >= 14000 && error.code < 15000)) {
297
+ index_failure = true;
298
+ } else if (error.code >= 4000 && error.code < 5000) {
299
+ planning_failure = true;
300
+ }
301
+ break;
302
+ }
303
+ }
304
+ }
305
+ if (syntax_error) {
306
+ response.ec = std::make_error_code(error::common_errc::parsing_failure);
307
+ } else if (server_timeout) {
308
+ response.ec = std::make_error_code(error::common_errc::unambiguous_timeout);
309
+ } else if (prepared_statement_failure) {
310
+ response.ec = std::make_error_code(error::query_errc::prepared_statement_failure);
311
+ } else if (index_failure) {
312
+ response.ec = std::make_error_code(error::query_errc::index_failure);
313
+ } else if (planning_failure) {
314
+ response.ec = std::make_error_code(error::query_errc::planning_failure);
315
+ } else if (index_not_found) {
316
+ response.ec = std::make_error_code(error::common_errc::index_not_found);
317
+ } else {
318
+ response.ec = std::make_error_code(error::common_errc::internal_server_failure);
319
+ }
320
+ }
226
321
  }
227
322
  return response;
228
323
  }
@@ -0,0 +1,67 @@
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 <document_id.hxx>
21
+ #include <protocol/cmd_remove.hxx>
22
+
23
+ namespace couchbase::operations
24
+ {
25
+
26
+ struct remove_response {
27
+ document_id id;
28
+ std::error_code ec{};
29
+ std::uint64_t cas{};
30
+ mutation_token token{};
31
+ };
32
+
33
+ struct remove_request {
34
+ using encoded_request_type = protocol::client_request<protocol::remove_request_body>;
35
+ using encoded_response_type = protocol::client_response<protocol::remove_response_body>;
36
+
37
+ document_id id;
38
+ uint16_t partition{};
39
+ uint32_t opaque{};
40
+ protocol::durability_level durability_level{ protocol::durability_level::none };
41
+ std::optional<std::uint16_t> durability_timeout{};
42
+
43
+ void encode_to(encoded_request_type& encoded)
44
+ {
45
+ encoded.opaque(opaque);
46
+ encoded.partition(partition);
47
+ encoded.body().id(id);
48
+ if (durability_level != protocol::durability_level::none) {
49
+ encoded.body().durability(durability_level, durability_timeout);
50
+ }
51
+ }
52
+ };
53
+
54
+ remove_response
55
+ make_response(std::error_code ec, remove_request& request, remove_request::encoded_response_type encoded)
56
+ {
57
+ remove_response response{ request.id, ec };
58
+ if (!ec) {
59
+ response.cas = encoded.cas();
60
+ response.token = encoded.body().token();
61
+ response.token.partition_id = request.partition;
62
+ response.token.bucket_name = response.id.bucket;
63
+ }
64
+ return response;
65
+ }
66
+
67
+ } // namespace couchbase::operations
@@ -0,0 +1,76 @@
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 <document_id.hxx>
21
+ #include <protocol/cmd_replace.hxx>
22
+ #include <protocol/durability_level.hxx>
23
+
24
+ namespace couchbase::operations
25
+ {
26
+
27
+ struct replace_response {
28
+ document_id id;
29
+ std::error_code ec{};
30
+ std::uint64_t cas{};
31
+ mutation_token token{};
32
+ };
33
+
34
+ struct replace_request {
35
+ using encoded_request_type = protocol::client_request<protocol::replace_request_body>;
36
+ using encoded_response_type = protocol::client_response<protocol::replace_response_body>;
37
+
38
+ document_id id;
39
+ std::string value;
40
+ uint16_t partition{};
41
+ uint32_t opaque{};
42
+ uint32_t flags{ 0 };
43
+ uint32_t expiration{ 0 };
44
+ uint64_t cas{ 0 };
45
+ protocol::durability_level durability_level{ protocol::durability_level::none };
46
+ std::optional<std::uint16_t> durability_timeout{};
47
+
48
+ void encode_to(encoded_request_type& encoded)
49
+ {
50
+ encoded.opaque(opaque);
51
+ encoded.partition(partition);
52
+ encoded.cas(cas);
53
+ encoded.body().id(id);
54
+ encoded.body().expiration(expiration);
55
+ encoded.body().flags(flags);
56
+ encoded.body().content(value);
57
+ if (durability_level != protocol::durability_level::none) {
58
+ encoded.body().durability(durability_level, durability_timeout);
59
+ }
60
+ }
61
+ };
62
+
63
+ replace_response
64
+ make_response(std::error_code ec, replace_request& request, replace_request::encoded_response_type encoded)
65
+ {
66
+ replace_response response{ request.id, ec };
67
+ if (!ec) {
68
+ response.cas = encoded.cas();
69
+ response.token = encoded.body().token();
70
+ response.token.partition_id = request.partition;
71
+ response.token.bucket_name = response.id.bucket;
72
+ }
73
+ return response;
74
+ }
75
+
76
+ } // namespace couchbase::operations
@@ -17,44 +17,44 @@
17
17
 
18
18
  #pragma once
19
19
 
20
- #include <operations/document_id.hxx>
21
- #include <protocol/cmd_upsert.hxx>
20
+ #include <document_id.hxx>
21
+ #include <protocol/cmd_touch.hxx>
22
22
 
23
23
  namespace couchbase::operations
24
24
  {
25
25
 
26
- struct upsert_response {
26
+ struct touch_response {
27
27
  document_id id;
28
28
  std::error_code ec{};
29
29
  std::uint64_t cas{};
30
30
  };
31
31
 
32
- struct upsert_request {
33
- using encoded_request_type = protocol::client_request<protocol::upsert_request_body>;
34
- using encoded_response_type = protocol::client_response<protocol::upsert_response_body>;
32
+ struct touch_request {
33
+ using encoded_request_type = protocol::client_request<protocol::touch_request_body>;
34
+ using encoded_response_type = protocol::client_response<protocol::touch_response_body>;
35
35
 
36
36
  document_id id;
37
- std::string value;
38
- uint16_t partition{};
39
- uint32_t opaque{};
37
+ std::uint16_t partition{};
38
+ std::uint32_t opaque{};
39
+ std::uint32_t expiration{};
40
40
 
41
41
  void encode_to(encoded_request_type& encoded)
42
42
  {
43
43
  encoded.opaque(opaque);
44
44
  encoded.partition(partition);
45
45
  encoded.body().id(id);
46
- encoded.body().content(value);
46
+ encoded.body().expiration(expiration);
47
47
  }
48
48
  };
49
49
 
50
- upsert_response
51
- make_response(std::error_code ec, upsert_request& request, upsert_request::encoded_response_type encoded)
50
+ touch_response
51
+ make_response(std::error_code ec, touch_request& request, touch_request::encoded_response_type encoded)
52
52
  {
53
- upsert_response response{ request.id, ec };
53
+ touch_response response{ request.id, ec };
54
54
  if (!ec) {
55
55
  response.cas = encoded.cas();
56
56
  }
57
57
  return response;
58
58
  }
59
59
 
60
- } // namespace couchbase::operations
60
+ } // namespace couchbase::operations
@@ -17,42 +17,44 @@
17
17
 
18
18
  #pragma once
19
19
 
20
- #include <operations/document_id.hxx>
21
- #include <protocol/cmd_remove.hxx>
20
+ #include <document_id.hxx>
21
+ #include <protocol/cmd_unlock.hxx>
22
22
 
23
23
  namespace couchbase::operations
24
24
  {
25
25
 
26
- struct remove_response {
26
+ struct unlock_response {
27
27
  document_id id;
28
28
  std::error_code ec{};
29
29
  std::uint64_t cas{};
30
30
  };
31
31
 
32
- struct remove_request {
33
- using encoded_request_type = protocol::client_request<protocol::remove_request_body>;
34
- using encoded_response_type = protocol::client_response<protocol::remove_response_body>;
32
+ struct unlock_request {
33
+ using encoded_request_type = protocol::client_request<protocol::unlock_request_body>;
34
+ using encoded_response_type = protocol::client_response<protocol::unlock_response_body>;
35
35
 
36
36
  document_id id;
37
37
  uint16_t partition{};
38
38
  uint32_t opaque{};
39
+ uint64_t cas{};
39
40
 
40
41
  void encode_to(encoded_request_type& encoded)
41
42
  {
42
43
  encoded.opaque(opaque);
43
44
  encoded.partition(partition);
44
45
  encoded.body().id(id);
46
+ encoded.cas(cas);
45
47
  }
46
48
  };
47
49
 
48
- remove_response
49
- make_response(std::error_code ec, remove_request& request, remove_request::encoded_response_type encoded)
50
+ unlock_response
51
+ make_response(std::error_code ec, unlock_request& request, unlock_request::encoded_response_type encoded)
50
52
  {
51
- remove_response response{ request.id, ec };
53
+ unlock_response response{ request.id, ec };
52
54
  if (!ec) {
53
55
  response.cas = encoded.cas();
54
56
  }
55
57
  return response;
56
58
  }
57
59
 
58
- } // namespace couchbase::operations
60
+ } // namespace couchbase::operations