couchbase 3.1.1-universal-darwin-20 → 3.2.0-universal-darwin-20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/CMakeLists.txt +3 -1
  4. data/ext/build_version.hxx.in +1 -1
  5. data/ext/cmake/Testing.cmake +1 -0
  6. data/ext/cmake/ThirdPartyDependencies.cmake +6 -0
  7. data/ext/cmake/VersionInfo.cmake +3 -0
  8. data/ext/couchbase/bucket.hxx +47 -28
  9. data/ext/couchbase/cbsasl/client.h +1 -1
  10. data/ext/couchbase/cbsasl/context.cc +1 -1
  11. data/ext/couchbase/cbsasl/context.h +3 -3
  12. data/ext/couchbase/cbsasl/mechanism.cc +5 -8
  13. data/ext/couchbase/cbsasl/mechanism.h +1 -4
  14. data/ext/couchbase/cbsasl/plain/plain.cc +1 -1
  15. data/ext/couchbase/cbsasl/scram-sha/scram-sha.cc +30 -36
  16. data/ext/couchbase/cluster.hxx +40 -22
  17. data/ext/couchbase/cluster_options.hxx +7 -1
  18. data/ext/couchbase/configuration.hxx +37 -16
  19. data/ext/couchbase/couchbase.cxx +1145 -291
  20. data/ext/couchbase/error_map.hxx +1 -1
  21. data/ext/couchbase/errors.hxx +25 -17
  22. data/ext/couchbase/io/dns_client.hxx +3 -3
  23. data/ext/couchbase/io/dns_codec.hxx +4 -5
  24. data/ext/couchbase/io/dns_config.hxx +5 -6
  25. data/ext/couchbase/io/dns_message.hxx +3 -3
  26. data/ext/couchbase/io/http_command.hxx +70 -35
  27. data/ext/couchbase/io/http_session.hxx +4 -3
  28. data/ext/couchbase/io/http_session_manager.hxx +28 -19
  29. data/ext/couchbase/io/mcbp_command.hxx +51 -19
  30. data/ext/couchbase/io/mcbp_context.hxx +1 -1
  31. data/ext/couchbase/io/mcbp_parser.hxx +4 -4
  32. data/ext/couchbase/io/mcbp_session.hxx +91 -101
  33. data/ext/couchbase/io/query_cache.hxx +2 -2
  34. data/ext/couchbase/io/retry_orchestrator.hxx +2 -4
  35. data/ext/couchbase/io/retry_reason.hxx +2 -2
  36. data/ext/couchbase/io/retry_strategy.hxx +1 -6
  37. data/ext/couchbase/io/streams.hxx +7 -7
  38. data/ext/couchbase/metrics/logging_meter.hxx +228 -0
  39. data/ext/couchbase/metrics/logging_meter_options.hxx +28 -0
  40. data/ext/couchbase/metrics/meter.hxx +49 -0
  41. data/ext/couchbase/metrics/noop_meter.hxx +43 -0
  42. data/ext/couchbase/operations.hxx +4 -0
  43. data/ext/couchbase/operations/analytics_dataset_create.hxx +16 -12
  44. data/ext/couchbase/operations/analytics_dataset_drop.hxx +11 -11
  45. data/ext/couchbase/operations/analytics_dataset_get_all.hxx +6 -6
  46. data/ext/couchbase/operations/analytics_dataverse_create.hxx +10 -11
  47. data/ext/couchbase/operations/analytics_dataverse_drop.hxx +10 -11
  48. data/ext/couchbase/operations/analytics_get_pending_mutations.hxx +9 -11
  49. data/ext/couchbase/operations/analytics_index_create.hxx +14 -13
  50. data/ext/couchbase/operations/analytics_index_drop.hxx +18 -12
  51. data/ext/couchbase/operations/analytics_index_get_all.hxx +8 -6
  52. data/ext/couchbase/operations/analytics_link.hxx +39 -0
  53. data/ext/couchbase/operations/analytics_link_azure_blob_external.hxx +145 -0
  54. data/ext/couchbase/operations/analytics_link_connect.hxx +14 -12
  55. data/ext/couchbase/operations/analytics_link_couchbase_remote.hxx +220 -0
  56. data/ext/couchbase/operations/analytics_link_create.hxx +128 -0
  57. data/ext/couchbase/operations/analytics_link_disconnect.hxx +11 -12
  58. data/ext/couchbase/operations/analytics_link_drop.hxx +130 -0
  59. data/ext/couchbase/operations/analytics_link_get_all.hxx +160 -0
  60. data/ext/couchbase/operations/analytics_link_replace.hxx +128 -0
  61. data/ext/couchbase/operations/analytics_link_s3_external.hxx +122 -0
  62. data/ext/couchbase/operations/bucket_create.hxx +8 -8
  63. data/ext/couchbase/operations/bucket_drop.hxx +5 -5
  64. data/ext/couchbase/operations/bucket_flush.hxx +5 -5
  65. data/ext/couchbase/operations/bucket_get.hxx +7 -7
  66. data/ext/couchbase/operations/bucket_get_all.hxx +7 -5
  67. data/ext/couchbase/operations/bucket_settings.hxx +40 -49
  68. data/ext/couchbase/operations/bucket_update.hxx +8 -8
  69. data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +7 -7
  70. data/ext/couchbase/operations/collection_create.hxx +11 -11
  71. data/ext/couchbase/operations/collection_drop.hxx +12 -10
  72. data/ext/couchbase/operations/collections_manifest_get.hxx +3 -3
  73. data/ext/couchbase/operations/design_document.hxx +2 -2
  74. data/ext/couchbase/operations/document_analytics.hxx +29 -36
  75. data/ext/couchbase/operations/document_append.hxx +3 -3
  76. data/ext/couchbase/operations/document_decrement.hxx +3 -3
  77. data/ext/couchbase/operations/document_exists.hxx +2 -2
  78. data/ext/couchbase/operations/document_get.hxx +3 -3
  79. data/ext/couchbase/operations/document_get_and_lock.hxx +5 -3
  80. data/ext/couchbase/operations/document_get_and_touch.hxx +5 -3
  81. data/ext/couchbase/operations/document_get_projected.hxx +10 -11
  82. data/ext/couchbase/operations/document_increment.hxx +3 -3
  83. data/ext/couchbase/operations/document_insert.hxx +3 -3
  84. data/ext/couchbase/operations/document_lookup_in.hxx +12 -18
  85. data/ext/couchbase/operations/document_mutate_in.hxx +13 -18
  86. data/ext/couchbase/operations/document_prepend.hxx +3 -3
  87. data/ext/couchbase/operations/document_query.hxx +39 -41
  88. data/ext/couchbase/operations/document_remove.hxx +3 -3
  89. data/ext/couchbase/operations/document_replace.hxx +3 -3
  90. data/ext/couchbase/operations/document_search.hxx +56 -61
  91. data/ext/couchbase/operations/document_touch.hxx +3 -3
  92. data/ext/couchbase/operations/document_unlock.hxx +3 -3
  93. data/ext/couchbase/operations/document_upsert.hxx +3 -3
  94. data/ext/couchbase/operations/document_view.hxx +23 -23
  95. data/ext/couchbase/operations/group_drop.hxx +5 -5
  96. data/ext/couchbase/operations/group_get.hxx +7 -7
  97. data/ext/couchbase/operations/group_get_all.hxx +6 -6
  98. data/ext/couchbase/operations/group_upsert.hxx +11 -11
  99. data/ext/couchbase/operations/http_noop.hxx +6 -6
  100. data/ext/couchbase/operations/mcbp_noop.hxx +3 -3
  101. data/ext/couchbase/operations/query_index_build_deferred.hxx +6 -6
  102. data/ext/couchbase/operations/query_index_create.hxx +10 -8
  103. data/ext/couchbase/operations/query_index_drop.hxx +8 -8
  104. data/ext/couchbase/operations/query_index_get_all.hxx +43 -39
  105. data/ext/couchbase/operations/rbac.hxx +40 -63
  106. data/ext/couchbase/operations/role_get_all.hxx +6 -6
  107. data/ext/couchbase/operations/scope_create.hxx +10 -10
  108. data/ext/couchbase/operations/scope_drop.hxx +9 -9
  109. data/ext/couchbase/operations/scope_get_all.hxx +8 -8
  110. data/ext/couchbase/operations/search_get_stats.hxx +5 -3
  111. data/ext/couchbase/operations/search_index.hxx +6 -15
  112. data/ext/couchbase/operations/search_index_analyze_document.hxx +11 -11
  113. data/ext/couchbase/operations/search_index_control_ingest.hxx +9 -9
  114. data/ext/couchbase/operations/search_index_control_plan_freeze.hxx +9 -9
  115. data/ext/couchbase/operations/search_index_control_query.hxx +9 -9
  116. data/ext/couchbase/operations/search_index_drop.hxx +11 -9
  117. data/ext/couchbase/operations/search_index_get.hxx +11 -9
  118. data/ext/couchbase/operations/search_index_get_all.hxx +11 -11
  119. data/ext/couchbase/operations/search_index_get_documents_count.hxx +10 -10
  120. data/ext/couchbase/operations/search_index_get_stats.hxx +10 -8
  121. data/ext/couchbase/operations/search_index_upsert.hxx +12 -10
  122. data/ext/couchbase/operations/user_drop.hxx +5 -5
  123. data/ext/couchbase/operations/user_get.hxx +7 -7
  124. data/ext/couchbase/operations/user_get_all.hxx +6 -6
  125. data/ext/couchbase/operations/user_upsert.hxx +9 -9
  126. data/ext/couchbase/operations/view_index_drop.hxx +10 -10
  127. data/ext/couchbase/operations/view_index_get.hxx +13 -15
  128. data/ext/couchbase/operations/view_index_get_all.hxx +17 -20
  129. data/ext/couchbase/operations/view_index_upsert.hxx +9 -7
  130. data/ext/couchbase/origin.hxx +14 -10
  131. data/ext/couchbase/platform/backtrace.c +1 -1
  132. data/ext/couchbase/platform/base64.cc +5 -5
  133. data/ext/couchbase/platform/base64.h +2 -5
  134. data/ext/couchbase/protocol/client_opcode.hxx +7 -4
  135. data/ext/couchbase/protocol/client_request.hxx +2 -2
  136. data/ext/couchbase/protocol/client_response.hxx +41 -16
  137. data/ext/couchbase/protocol/cmd_append.hxx +17 -16
  138. data/ext/couchbase/protocol/cmd_cluster_map_change_notification.hxx +4 -4
  139. data/ext/couchbase/protocol/cmd_decrement.hxx +10 -11
  140. data/ext/couchbase/protocol/cmd_exists.hxx +12 -15
  141. data/ext/couchbase/protocol/cmd_get.hxx +11 -14
  142. data/ext/couchbase/protocol/cmd_get_and_lock.hxx +10 -12
  143. data/ext/couchbase/protocol/cmd_get_and_touch.hxx +10 -12
  144. data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +13 -18
  145. data/ext/couchbase/protocol/cmd_get_collection_id.hxx +12 -15
  146. data/ext/couchbase/protocol/cmd_get_collections_manifest.hxx +12 -16
  147. data/ext/couchbase/protocol/cmd_get_error_map.hxx +14 -17
  148. data/ext/couchbase/protocol/cmd_hello.hxx +8 -10
  149. data/ext/couchbase/protocol/cmd_increment.hxx +9 -10
  150. data/ext/couchbase/protocol/cmd_insert.hxx +9 -9
  151. data/ext/couchbase/protocol/cmd_lookup_in.hxx +12 -13
  152. data/ext/couchbase/protocol/cmd_mutate_in.hxx +11 -11
  153. data/ext/couchbase/protocol/cmd_noop.hxx +16 -20
  154. data/ext/couchbase/protocol/cmd_prepend.hxx +9 -10
  155. data/ext/couchbase/protocol/cmd_remove.hxx +10 -13
  156. data/ext/couchbase/protocol/cmd_replace.hxx +7 -7
  157. data/ext/couchbase/protocol/cmd_sasl_auth.hxx +8 -10
  158. data/ext/couchbase/protocol/cmd_sasl_list_mechs.hxx +10 -15
  159. data/ext/couchbase/protocol/cmd_sasl_step.hxx +10 -12
  160. data/ext/couchbase/protocol/cmd_select_bucket.hxx +14 -18
  161. data/ext/couchbase/protocol/cmd_touch.hxx +8 -11
  162. data/ext/couchbase/protocol/cmd_unlock.hxx +10 -14
  163. data/ext/couchbase/protocol/cmd_upsert.hxx +8 -8
  164. data/ext/couchbase/protocol/datatype.hxx +3 -3
  165. data/ext/couchbase/protocol/durability_level.hxx +2 -2
  166. data/ext/couchbase/protocol/frame_info_id.hxx +4 -4
  167. data/ext/couchbase/protocol/hello_feature.hxx +2 -2
  168. data/ext/couchbase/protocol/magic.hxx +2 -2
  169. data/ext/couchbase/protocol/server_opcode.hxx +2 -2
  170. data/ext/couchbase/protocol/server_request.hxx +1 -1
  171. data/ext/couchbase/protocol/status.hxx +4 -7
  172. data/ext/couchbase/protocol/unsigned_leb128.h +5 -20
  173. data/ext/couchbase/service_type.hxx +4 -4
  174. data/ext/couchbase/tracing/constants.hxx +261 -0
  175. data/ext/couchbase/tracing/noop_tracer.hxx +50 -0
  176. data/ext/couchbase/tracing/request_tracer.hxx +77 -0
  177. data/ext/couchbase/tracing/threshold_logging_options.hxx +64 -0
  178. data/ext/couchbase/tracing/threshold_logging_tracer.hxx +366 -0
  179. data/ext/couchbase/utils/byteswap.hxx +1 -1
  180. data/ext/couchbase/utils/connection_string.hxx +21 -1
  181. data/ext/couchbase/utils/name_codec.hxx +41 -0
  182. data/ext/couchbase/utils/url_codec.hxx +236 -0
  183. data/ext/couchbase/version.hxx +1 -1
  184. data/ext/test/CMakeLists.txt +1 -0
  185. data/ext/test/test_native_trivial_query.cxx +60 -0
  186. data/ext/third_party/hdr_histogram_c/CMakeLists.txt +84 -0
  187. data/ext/third_party/hdr_histogram_c/COPYING.txt +121 -0
  188. data/ext/third_party/hdr_histogram_c/LICENSE.txt +41 -0
  189. data/ext/third_party/hdr_histogram_c/config.cmake.in +6 -0
  190. data/ext/third_party/hdr_histogram_c/src/CMakeLists.txt +83 -0
  191. data/ext/third_party/hdr_histogram_c/src/hdr_atomic.h +146 -0
  192. data/ext/third_party/hdr_histogram_c/src/hdr_encoding.c +322 -0
  193. data/ext/third_party/hdr_histogram_c/src/hdr_encoding.h +79 -0
  194. data/ext/third_party/hdr_histogram_c/src/hdr_endian.h +116 -0
  195. data/ext/third_party/hdr_histogram_c/src/hdr_histogram.c +1196 -0
  196. data/ext/third_party/hdr_histogram_c/src/hdr_histogram.h +516 -0
  197. data/ext/third_party/hdr_histogram_c/src/hdr_histogram_log.c +1290 -0
  198. data/ext/third_party/hdr_histogram_c/src/hdr_histogram_log.h +236 -0
  199. data/ext/third_party/hdr_histogram_c/src/hdr_histogram_log_no_op.c +171 -0
  200. data/ext/third_party/hdr_histogram_c/src/hdr_interval_recorder.c +227 -0
  201. data/ext/third_party/hdr_histogram_c/src/hdr_interval_recorder.h +109 -0
  202. data/ext/third_party/hdr_histogram_c/src/hdr_malloc.h +19 -0
  203. data/ext/third_party/hdr_histogram_c/src/hdr_tests.h +22 -0
  204. data/ext/third_party/hdr_histogram_c/src/hdr_thread.c +108 -0
  205. data/ext/third_party/hdr_histogram_c/src/hdr_thread.h +55 -0
  206. data/ext/third_party/hdr_histogram_c/src/hdr_time.c +98 -0
  207. data/ext/third_party/hdr_histogram_c/src/hdr_time.h +49 -0
  208. data/ext/third_party/hdr_histogram_c/src/hdr_writer_reader_phaser.c +143 -0
  209. data/ext/third_party/hdr_histogram_c/src/hdr_writer_reader_phaser.h +51 -0
  210. data/lib/couchbase/cluster.rb +1 -0
  211. data/lib/couchbase/errors.rb +3 -0
  212. data/lib/couchbase/libcouchbase.bundle +0 -0
  213. data/lib/couchbase/management/analytics_index_manager.rb +920 -226
  214. data/lib/couchbase/management/bucket_manager.rb +207 -69
  215. data/lib/couchbase/management/collection_manager.rb +173 -61
  216. data/lib/couchbase/management/query_index_manager.rb +357 -169
  217. data/lib/couchbase/options.rb +75 -3
  218. data/lib/couchbase/scope.rb +102 -0
  219. data/lib/couchbase/utils/time.rb +4 -0
  220. data/lib/couchbase/version.rb +6 -6
  221. metadata +48 -5
@@ -31,7 +31,7 @@ struct view_index_drop_request {
31
31
  using encoded_response_type = io::http_response;
32
32
  using error_context_type = error_context::http;
33
33
 
34
- static const inline service_type type = service_type::views;
34
+ static const inline service_type type = service_type::view;
35
35
 
36
36
  std::string client_context_id{ uuid::to_string(uuid::random()) };
37
37
  std::chrono::milliseconds timeout{ timeout_defaults::management_timeout };
@@ -40,7 +40,7 @@ struct view_index_drop_request {
40
40
  std::string document_name;
41
41
  design_document::name_space name_space;
42
42
 
43
- [[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context&)
43
+ [[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& /* context */) const
44
44
  {
45
45
  encoded.method = "DELETE";
46
46
  encoded.path =
@@ -50,16 +50,16 @@ struct view_index_drop_request {
50
50
  };
51
51
 
52
52
  view_index_drop_response
53
- make_response(error_context::http&& ctx, view_index_drop_request&, view_index_drop_request::encoded_response_type&& encoded)
53
+ make_response(error_context::http&& ctx,
54
+ const view_index_drop_request& /* request */,
55
+ view_index_drop_request::encoded_response_type&& encoded)
54
56
  {
55
- view_index_drop_response response{ ctx };
57
+ view_index_drop_response response{ std::move(ctx) };
56
58
  if (!response.ctx.ec) {
57
- if (encoded.status_code == 200) {
58
-
59
- } else if (encoded.status_code == 404) {
60
- response.ctx.ec = std::make_error_code(error::view_errc::design_document_not_found);
61
- } else {
62
- response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
59
+ if (encoded.status_code == 404) {
60
+ response.ctx.ec = error::view_errc::design_document_not_found;
61
+ } else if (encoded.status_code != 200) {
62
+ response.ctx.ec = error::common_errc::internal_server_failure;
63
63
  }
64
64
  }
65
65
  return response;
@@ -33,7 +33,7 @@ struct view_index_get_request {
33
33
  using encoded_response_type = io::http_response;
34
34
  using error_context_type = error_context::http;
35
35
 
36
- static const inline service_type type = service_type::views;
36
+ static const inline service_type type = service_type::view;
37
37
 
38
38
  std::string client_context_id{ uuid::to_string(uuid::random()) };
39
39
  std::chrono::milliseconds timeout{ timeout_defaults::management_timeout };
@@ -42,7 +42,7 @@ struct view_index_get_request {
42
42
  std::string document_name;
43
43
  design_document::name_space name_space;
44
44
 
45
- [[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context&)
45
+ [[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& /* context */) const
46
46
  {
47
47
  encoded.method = "GET";
48
48
  encoded.path =
@@ -52,9 +52,9 @@ struct view_index_get_request {
52
52
  };
53
53
 
54
54
  view_index_get_response
55
- make_response(error_context::http&& ctx, view_index_get_request& request, view_index_get_request::encoded_response_type&& encoded)
55
+ make_response(error_context::http&& ctx, const view_index_get_request& request, view_index_get_request::encoded_response_type&& encoded)
56
56
  {
57
- view_index_get_response response{ ctx };
57
+ view_index_get_response response{ std::move(ctx) };
58
58
  if (!response.ctx.ec) {
59
59
  if (encoded.status_code == 200) {
60
60
  response.document.name = request.document_name;
@@ -63,22 +63,20 @@ make_response(error_context::http&& ctx, view_index_get_request& request, view_i
63
63
  tao::json::value payload{};
64
64
  try {
65
65
  payload = tao::json::from_string(encoded.body);
66
- } catch (tao::json::pegtl::parse_error& e) {
67
- response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
66
+ } catch (const tao::json::pegtl::parse_error& e) {
67
+ response.ctx.ec = error::common_errc::parsing_failure;
68
68
  return response;
69
69
  }
70
70
  const auto* views = payload.find("views");
71
71
  if (views != nullptr && views->is_object()) {
72
- for (const auto& view_entry : views->get_object()) {
72
+ for (const auto& [name, view_entry] : views->get_object()) {
73
73
  couchbase::operations::design_document::view view;
74
- view.name = view_entry.first;
75
- if (view_entry.second.is_object()) {
76
- const auto* map = view_entry.second.find("map");
77
- if (map != nullptr && map->is_string()) {
74
+ view.name = name;
75
+ if (view_entry.is_object()) {
76
+ if (const auto* map = view_entry.find("map"); map != nullptr && map->is_string()) {
78
77
  view.map = map->get_string();
79
78
  }
80
- const auto* reduce = view_entry.second.find("reduce");
81
- if (reduce != nullptr && reduce->is_string()) {
79
+ if (const auto* reduce = view_entry.find("reduce"); reduce != nullptr && reduce->is_string()) {
82
80
  view.reduce = reduce->get_string();
83
81
  }
84
82
  }
@@ -86,9 +84,9 @@ make_response(error_context::http&& ctx, view_index_get_request& request, view_i
86
84
  }
87
85
  }
88
86
  } else if (encoded.status_code == 404) {
89
- response.ctx.ec = std::make_error_code(error::view_errc::design_document_not_found);
87
+ response.ctx.ec = error::view_errc::design_document_not_found;
90
88
  } else {
91
- response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
89
+ response.ctx.ec = error::common_errc::internal_server_failure;
92
90
  }
93
91
  }
94
92
  return response;
@@ -41,7 +41,7 @@ struct view_index_get_all_request {
41
41
  std::string bucket_name;
42
42
  design_document::name_space name_space;
43
43
 
44
- [[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context&)
44
+ [[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& /* context */) const
45
45
  {
46
46
  encoded.method = "GET";
47
47
  encoded.path = fmt::format("/pools/default/buckets/{}/ddocs", bucket_name);
@@ -50,16 +50,18 @@ struct view_index_get_all_request {
50
50
  };
51
51
 
52
52
  view_index_get_all_response
53
- make_response(error_context::http&& ctx, view_index_get_all_request& request, view_index_get_all_request::encoded_response_type&& encoded)
53
+ make_response(error_context::http&& ctx,
54
+ const view_index_get_all_request& request,
55
+ view_index_get_all_request::encoded_response_type&& encoded)
54
56
  {
55
- view_index_get_all_response response{ ctx };
57
+ view_index_get_all_response response{ std::move(ctx) };
56
58
  if (!response.ctx.ec) {
57
59
  if (encoded.status_code == 200) {
58
60
  tao::json::value payload{};
59
61
  try {
60
62
  payload = tao::json::from_string(encoded.body);
61
- } catch (tao::json::pegtl::parse_error& e) {
62
- response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
63
+ } catch (const tao::json::pegtl::parse_error& e) {
64
+ response.ctx.ec = error::common_errc::parsing_failure;
63
65
  return response;
64
66
  }
65
67
  auto* rows = payload.find("rows");
@@ -77,14 +79,12 @@ make_response(error_context::http&& ctx, view_index_get_all_request& request, vi
77
79
  design_document document{};
78
80
  document.rev = meta->at("rev").get_string();
79
81
  auto id = meta->at("id").get_string();
80
- static const std::string prefix = "_design/";
81
- if (id.find(prefix) == 0) {
82
+ if (static const std::string prefix = "_design/"; id.find(prefix) == 0) {
82
83
  document.name = id.substr(prefix.size());
83
84
  } else {
84
85
  document.name = id; // fall back, should not happen
85
86
  }
86
- static const std::string name_space_prefix = "dev_";
87
- if (document.name.find(name_space_prefix) == 0) {
87
+ if (static const std::string name_space_prefix = "dev_"; document.name.find(name_space_prefix) == 0) {
88
88
  document.name = document.name.substr(name_space_prefix.size());
89
89
  document.ns = couchbase::operations::design_document::name_space::development;
90
90
  } else {
@@ -98,18 +98,15 @@ make_response(error_context::http&& ctx, view_index_get_all_request& request, vi
98
98
  if (json == nullptr || !json->is_object()) {
99
99
  continue;
100
100
  }
101
- const auto* views = json->find("views");
102
- if (views != nullptr && views->is_object()) {
103
- for (const auto& view_entry : views->get_object()) {
101
+ if (const auto* views = json->find("views"); views != nullptr && views->is_object()) {
102
+ for (const auto& [name, view_entry] : views->get_object()) {
104
103
  couchbase::operations::design_document::view view;
105
- view.name = view_entry.first;
106
- if (view_entry.second.is_object()) {
107
- const auto* map = view_entry.second.find("map");
108
- if (map != nullptr && map->is_string()) {
104
+ view.name = name;
105
+ if (view_entry.is_object()) {
106
+ if (const auto* map = view_entry.find("map"); map != nullptr && map->is_string()) {
109
107
  view.map = map->get_string();
110
108
  }
111
- const auto* reduce = view_entry.second.find("reduce");
112
- if (reduce != nullptr && reduce->is_string()) {
109
+ if (const auto* reduce = view_entry.find("reduce"); reduce != nullptr && reduce->is_string()) {
113
110
  view.reduce = reduce->get_string();
114
111
  }
115
112
  }
@@ -121,9 +118,9 @@ make_response(error_context::http&& ctx, view_index_get_all_request& request, vi
121
118
  }
122
119
  }
123
120
  } else if (encoded.status_code == 404) {
124
- response.ctx.ec = std::make_error_code(error::common_errc::bucket_not_found);
121
+ response.ctx.ec = error::common_errc::bucket_not_found;
125
122
  } else {
126
- response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
123
+ response.ctx.ec = error::common_errc::internal_server_failure;
127
124
  }
128
125
  }
129
126
  return response;
@@ -31,7 +31,7 @@ struct view_index_upsert_request {
31
31
  using encoded_response_type = io::http_response;
32
32
  using error_context_type = error_context::http;
33
33
 
34
- static const inline service_type type = service_type::views;
34
+ static const inline service_type type = service_type::view;
35
35
 
36
36
  std::string client_context_id{ uuid::to_string(uuid::random()) };
37
37
  std::chrono::milliseconds timeout{ timeout_defaults::management_timeout };
@@ -39,7 +39,7 @@ struct view_index_upsert_request {
39
39
  std::string bucket_name;
40
40
  design_document document;
41
41
 
42
- [[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context&)
42
+ [[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& /* context */) const
43
43
  {
44
44
  tao::json::value body;
45
45
  body["views"] = tao::json::empty_object;
@@ -64,22 +64,24 @@ struct view_index_upsert_request {
64
64
  };
65
65
 
66
66
  view_index_upsert_response
67
- make_response(error_context::http&& ctx, view_index_upsert_request&, view_index_upsert_request::encoded_response_type&& encoded)
67
+ make_response(error_context::http&& ctx,
68
+ const view_index_upsert_request& /* request */,
69
+ view_index_upsert_request::encoded_response_type&& encoded)
68
70
  {
69
- view_index_upsert_response response{ ctx };
71
+ view_index_upsert_response response{ std::move(ctx) };
70
72
  if (!response.ctx.ec) {
71
73
  switch (encoded.status_code) {
72
74
  case 200:
73
75
  case 201:
74
76
  break;
75
77
  case 400:
76
- response.ctx.ec = std::make_error_code(error::common_errc::invalid_argument);
78
+ response.ctx.ec = error::common_errc::invalid_argument;
77
79
  break;
78
80
  case 404:
79
- response.ctx.ec = std::make_error_code(error::view_errc::design_document_not_found);
81
+ response.ctx.ec = error::view_errc::design_document_not_found;
80
82
  break;
81
83
  default:
82
- response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
84
+ response.ctx.ec = error::common_errc::internal_server_failure;
83
85
  }
84
86
  }
85
87
  return response;
@@ -19,6 +19,7 @@
19
19
 
20
20
  #include <string>
21
21
 
22
+ #include <utility>
22
23
  #include <utils/connection_string.hxx>
23
24
 
24
25
  namespace couchbase
@@ -28,7 +29,7 @@ struct cluster_credentials {
28
29
  std::string password{};
29
30
  std::string certificate_path{};
30
31
  std::string key_path{};
31
- std::vector<std::string> allowed_sasl_mechanisms{};
32
+ std::vector<std::string> allowed_sasl_mechanisms{ "SCRAM-SHA512", "SCRAM-SHA256", "SCRAM-SHA1", "PLAIN" };
32
33
 
33
34
  [[nodiscard]] bool uses_certificate() const
34
35
  {
@@ -42,26 +43,28 @@ struct origin {
42
43
 
43
44
  origin() = default;
44
45
 
46
+ ~origin() = default;
47
+
45
48
  origin(origin&& other) = default;
46
49
 
47
50
  origin(const origin& other)
48
51
  : options_(other.options_)
49
- , credentials_(std::move(other.credentials_))
52
+ , credentials_(other.credentials_)
50
53
  , nodes_(other.nodes_)
51
54
  , next_node_(nodes_.begin())
52
55
  {
53
56
  }
54
57
 
55
- origin(cluster_credentials auth, const std::string& hostname, std::uint16_t port, const cluster_options& options)
56
- : options_(options)
58
+ origin(cluster_credentials auth, const std::string& hostname, std::uint16_t port, cluster_options options)
59
+ : options_(std::move(options))
57
60
  , credentials_(std::move(auth))
58
61
  , nodes_{ { hostname, std::to_string(port) } }
59
62
  , next_node_(nodes_.begin())
60
63
  {
61
64
  }
62
65
 
63
- origin(cluster_credentials auth, const std::string& hostname, const std::string& port, const cluster_options& options)
64
- : options_(options)
66
+ origin(cluster_credentials auth, const std::string& hostname, const std::string& port, cluster_options options)
67
+ : options_(std::move(options))
65
68
  , credentials_(std::move(auth))
66
69
  , nodes_{ { hostname, port } }
67
70
  , next_node_(nodes_.begin())
@@ -74,12 +77,13 @@ struct origin {
74
77
  {
75
78
  nodes_.reserve(connstr.bootstrap_nodes.size());
76
79
  for (const auto& node : connstr.bootstrap_nodes) {
77
- nodes_.emplace_back(
78
- std::make_pair(node.address, node.port > 0 ? std::to_string(node.port) : std::to_string(connstr.default_port)));
80
+ nodes_.emplace_back(std::pair(node.address, node.port > 0 ? std::to_string(node.port) : std::to_string(connstr.default_port)));
79
81
  }
80
82
  next_node_ = nodes_.begin();
81
83
  }
82
84
 
85
+ origin& operator=(origin&& other) = default;
86
+
83
87
  origin& operator=(const origin& other)
84
88
  {
85
89
  if (this != &other) {
@@ -116,8 +120,8 @@ struct origin {
116
120
  {
117
121
  std::vector<std::string> res;
118
122
  res.reserve(nodes_.size());
119
- for (const auto& node : nodes_) {
120
- res.emplace_back(fmt::format("\"{}:{}\"", node.first, node.second));
123
+ for (const auto& [hostname, port] : nodes_) {
124
+ res.emplace_back(fmt::format("\"{}:{}\"", hostname, port));
121
125
  }
122
126
  return res;
123
127
  }
@@ -62,7 +62,7 @@ describe_address(char* msg, size_t len, void* addr)
62
62
  // No symbol found.
63
63
  snprintf(msg, len, "[0x%p]", addr);
64
64
  }
65
- #else // !WIN32
65
+ #else // !WIN32
66
66
  Dl_info info;
67
67
  int status = dladdr(addr, &info);
68
68
 
@@ -121,19 +121,19 @@ encode_triplet(const std::uint8_t* s, std::string& str)
121
121
  static int
122
122
  decode_quad(const std::uint8_t* s, std::string& d)
123
123
  {
124
- uint32_t value = code2val(static_cast<std::uint8_t>(s[0])) << 18U;
125
- value |= code2val(static_cast<std::uint8_t>(s[1])) << 12U;
124
+ uint32_t value = code2val(s[0]) << 18U;
125
+ value |= code2val(s[1]) << 12U;
126
126
 
127
127
  int ret = 3;
128
128
 
129
129
  if (s[2] == '=') {
130
130
  ret = 1;
131
131
  } else {
132
- value |= code2val(static_cast<std::uint8_t>(s[2])) << 6U;
132
+ value |= code2val(s[2]) << 6U;
133
133
  if (s[3] == '=') {
134
134
  ret = 2;
135
135
  } else {
136
- value |= code2val(static_cast<std::uint8_t>(s[3]));
136
+ value |= code2val(s[3]);
137
137
  }
138
138
  }
139
139
 
@@ -171,7 +171,7 @@ encode(const std::string_view blob, bool prettyprint)
171
171
  result.reserve(chunks * 4);
172
172
  }
173
173
 
174
- const std::uint8_t* in = reinterpret_cast<const std::uint8_t*>(blob.data());
174
+ const auto* in = reinterpret_cast<const std::uint8_t*>(blob.data());
175
175
 
176
176
  chunks = 0;
177
177
  for (size_t ii = 0; ii < triplets; ++ii) {
@@ -19,9 +19,7 @@
19
19
  #include <string>
20
20
  #include <vector>
21
21
 
22
- namespace couchbase
23
- {
24
- namespace base64
22
+ namespace couchbase::base64
25
23
  {
26
24
 
27
25
  /**
@@ -43,5 +41,4 @@ encode(std::string_view blob, bool prettyprint = false);
43
41
  std::string
44
42
  decode(std::string_view blob);
45
43
 
46
- } // namespace base64
47
- } // namespace couchbase
44
+ } // namespace couchbase::base64
@@ -249,10 +249,10 @@ enum class subdoc_opcode : uint8_t {
249
249
  replace_body_with_xattr = 0xd3,
250
250
  };
251
251
 
252
- constexpr inline bool
252
+ constexpr bool
253
253
  is_valid_client_opcode(uint8_t code)
254
254
  {
255
- switch (static_cast<client_opcode>(code)) {
255
+ switch (client_opcode(code)) {
256
256
  case client_opcode::get:
257
257
  case client_opcode::upsert:
258
258
  case client_opcode::insert:
@@ -328,10 +328,10 @@ is_valid_client_opcode(uint8_t code)
328
328
  return false;
329
329
  }
330
330
 
331
- constexpr inline bool
331
+ constexpr bool
332
332
  is_valid_subdoc_opcode(uint8_t code)
333
333
  {
334
- switch (static_cast<subdoc_opcode>(code)) {
334
+ switch (subdoc_opcode(code)) {
335
335
  case subdoc_opcode::get:
336
336
  case subdoc_opcode::exists:
337
337
  case subdoc_opcode::dict_add:
@@ -352,6 +352,9 @@ is_valid_subdoc_opcode(uint8_t code)
352
352
  }
353
353
  return false;
354
354
  }
355
+
356
+ const inline static std::vector<std::uint8_t> empty_buffer;
357
+ const inline static std::string empty_string;
355
358
  } // namespace couchbase::protocol
356
359
 
357
360
  template<>
@@ -50,7 +50,7 @@ class client_request
50
50
  std::vector<std::uint8_t> payload_;
51
51
 
52
52
  public:
53
- client_opcode opcode()
53
+ [[nodiscard]] client_opcode opcode() const
54
54
  {
55
55
  return opcode_;
56
56
  }
@@ -65,7 +65,7 @@ class client_request
65
65
  cas_ = utils::byte_swap_64(val);
66
66
  }
67
67
 
68
- std::uint32_t opaque()
68
+ [[nodiscard]] std::uint32_t opaque() const
69
69
  {
70
70
  return opaque_;
71
71
  }
@@ -33,6 +33,34 @@
33
33
  namespace couchbase::protocol
34
34
  {
35
35
 
36
+ double
37
+ parse_server_duration_us(const io::mcbp_message& msg)
38
+ {
39
+ if (msg.header.magic != static_cast<std::uint8_t>(magic::alt_client_response)) {
40
+ return 0;
41
+ }
42
+ std::uint8_t framing_extras_size = static_cast<std::uint8_t>(msg.header.keylen & 0xfU);
43
+ if (framing_extras_size == 0) {
44
+ return 0;
45
+ }
46
+ std::size_t offset = 0;
47
+ while (offset < framing_extras_size) {
48
+ std::uint8_t frame_size = static_cast<std::uint8_t>(msg.body[offset] & 0xfU);
49
+ std::uint8_t frame_id = static_cast<std::uint8_t>((static_cast<std::uint32_t>(msg.body[offset]) >> 4U) & 0xfU);
50
+ offset++;
51
+ if (frame_id == static_cast<std::uint8_t>(response_frame_info_id::server_duration)) {
52
+ if (frame_size == 2 && framing_extras_size - offset >= frame_size) {
53
+ std::uint16_t encoded_duration{};
54
+ std::memcpy(&encoded_duration, msg.body.data() + offset, sizeof(encoded_duration));
55
+ encoded_duration = ntohs(encoded_duration);
56
+ return std::pow(encoded_duration, 1.74) / 2;
57
+ }
58
+ }
59
+ offset += frame_size;
60
+ }
61
+ return 0;
62
+ }
63
+
36
64
  template<typename Body>
37
65
  class client_response
38
66
  {
@@ -55,7 +83,7 @@ class client_response
55
83
 
56
84
  public:
57
85
  client_response() = default;
58
- explicit client_response(io::mcbp_message& msg)
86
+ explicit client_response(io::mcbp_message&& msg)
59
87
  {
60
88
  header_ = msg.header_data();
61
89
  data_ = std::move(msg.body);
@@ -108,15 +136,15 @@ class client_response
108
136
  Expects(header_[0] == static_cast<std::uint8_t>(magic::alt_client_response) ||
109
137
  header_[0] == static_cast<std::uint8_t>(magic::client_response));
110
138
  Expects(header_[1] == static_cast<std::uint8_t>(Body::opcode));
111
- magic_ = static_cast<magic>(header_[0]);
112
- opcode_ = static_cast<client_opcode>(header_[1]);
139
+ magic_ = magic(header_[0]);
140
+ opcode_ = client_opcode(header_[1]);
113
141
  data_type_ = header_[5];
114
142
 
115
143
  uint16_t status = 0;
116
144
  memcpy(&status, header_.data() + 6, sizeof(status));
117
145
  status = ntohs(status);
118
146
  Expects(protocol::is_valid_status(status));
119
- status_ = static_cast<protocol::status>(status);
147
+ status_ = protocol::status(status);
120
148
 
121
149
  extras_size_ = header_[4];
122
150
  if (magic_ == magic::alt_client_response) {
@@ -143,7 +171,7 @@ class client_response
143
171
  return error_;
144
172
  }
145
173
 
146
- [[nodiscard]] std::string error_message()
174
+ [[nodiscard]] std::string error_message() const
147
175
  {
148
176
  if (error_) {
149
177
  return fmt::format(R"(magic={}, opcode={}, status={}, error={})", magic_, opcode_, status_, *error_);
@@ -161,12 +189,10 @@ class client_response
161
189
  auto& err_obj = error["error"];
162
190
  if (err_obj.is_object()) {
163
191
  enhanced_error_info err{};
164
- auto& ref = err_obj["ref"];
165
- if (ref.is_string()) {
192
+ if (auto& ref = err_obj["ref"]; ref.is_string()) {
166
193
  err.reference = ref.get_string();
167
194
  }
168
- auto& ctx = err_obj["context"];
169
- if (ctx.is_string()) {
195
+ if (auto& ctx = err_obj["context"]; ctx.is_string()) {
170
196
  err.context = ctx.get_string();
171
197
  }
172
198
  error_.emplace(err);
@@ -185,13 +211,12 @@ class client_response
185
211
  std::uint8_t frame_size = data_[offset] & 0xfU;
186
212
  std::uint8_t frame_id = (static_cast<std::uint32_t>(data_[offset]) >> 4U) & 0xfU;
187
213
  offset++;
188
- if (frame_id == static_cast<std::uint8_t>(response_frame_info_id::server_duration)) {
189
- if (frame_size == 2 && framing_extras_size_ - offset >= frame_size) {
190
- std::uint16_t encoded_duration{};
191
- std::memcpy(&encoded_duration, data_.data() + offset, sizeof(encoded_duration));
192
- encoded_duration = ntohs(encoded_duration);
193
- info_.server_duration_us = std::pow(encoded_duration, 1.74) / 2;
194
- }
214
+ if (frame_id == static_cast<std::uint8_t>(response_frame_info_id::server_duration) && frame_size == 2 &&
215
+ framing_extras_size_ - offset >= frame_size) {
216
+ std::uint16_t encoded_duration{};
217
+ std::memcpy(&encoded_duration, data_.data() + offset, sizeof(encoded_duration));
218
+ encoded_duration = ntohs(encoded_duration);
219
+ info_.server_duration_us = std::pow(encoded_duration, 1.74) / 2;
195
220
  }
196
221
  offset += frame_size;
197
222
  }