couchbase 3.4.3 → 3.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/couchbase/CMakeLists.txt +15 -1
  4. data/ext/couchbase/core/bucket.cxx +183 -152
  5. data/ext/couchbase/core/bucket.hxx +17 -4
  6. data/ext/couchbase/core/cluster.hxx +34 -13
  7. data/ext/couchbase/core/cluster_options.hxx +3 -0
  8. data/ext/couchbase/core/crud_component.cxx +51 -22
  9. data/ext/couchbase/core/error_context/key_value.cxx +2 -1
  10. data/ext/couchbase/core/error_context/key_value.hxx +10 -12
  11. data/ext/couchbase/core/impl/build_deferred_query_indexes.cxx +115 -50
  12. data/ext/couchbase/core/impl/cluster.cxx +6 -0
  13. data/ext/couchbase/core/impl/create_bucket.cxx +155 -0
  14. data/ext/couchbase/core/impl/create_query_index.cxx +172 -59
  15. data/ext/couchbase/core/impl/dns_srv_tracker.cxx +2 -1
  16. data/ext/couchbase/core/impl/drop_bucket.cxx +66 -0
  17. data/ext/couchbase/core/impl/drop_query_index.cxx +138 -59
  18. data/ext/couchbase/core/impl/flush_bucket.cxx +66 -0
  19. data/ext/couchbase/core/impl/get_all_buckets.cxx +163 -0
  20. data/ext/couchbase/core/impl/get_all_query_indexes.cxx +67 -37
  21. data/ext/couchbase/core/impl/get_bucket.cxx +153 -0
  22. data/ext/couchbase/core/impl/internal_manager_error_context.cxx +113 -0
  23. data/ext/couchbase/core/impl/internal_manager_error_context.hxx +60 -0
  24. data/ext/couchbase/core/impl/key_value_error_category.cxx +2 -4
  25. data/ext/couchbase/core/impl/key_value_error_context.cxx +98 -0
  26. data/ext/couchbase/core/impl/lookup_in.cxx +1 -0
  27. data/ext/couchbase/core/impl/lookup_in_all_replicas.cxx +176 -0
  28. data/ext/couchbase/core/impl/lookup_in_all_replicas.hxx +80 -0
  29. data/ext/couchbase/core/impl/lookup_in_any_replica.cxx +167 -0
  30. data/ext/couchbase/core/impl/lookup_in_any_replica.hxx +75 -0
  31. data/ext/couchbase/core/impl/lookup_in_replica.cxx +97 -0
  32. data/ext/couchbase/core/impl/lookup_in_replica.hxx +67 -0
  33. data/ext/couchbase/core/impl/manager_error_context.cxx +100 -0
  34. data/ext/couchbase/core/impl/query.cxx +1 -0
  35. data/ext/couchbase/core/impl/query_error_context.cxx +75 -0
  36. data/ext/couchbase/core/impl/update_bucket.cxx +130 -0
  37. data/ext/couchbase/core/impl/watch_query_indexes.cxx +53 -29
  38. data/ext/couchbase/core/io/dns_client.cxx +111 -40
  39. data/ext/couchbase/core/io/dns_config.cxx +5 -4
  40. data/ext/couchbase/core/io/http_session.hxx +24 -1
  41. data/ext/couchbase/core/io/mcbp_command.hxx +9 -2
  42. data/ext/couchbase/core/io/mcbp_session.cxx +80 -43
  43. data/ext/couchbase/core/io/mcbp_session.hxx +4 -3
  44. data/ext/couchbase/core/logger/custom_rotating_file_sink.cxx +1 -1
  45. data/ext/couchbase/core/logger/logger.cxx +80 -20
  46. data/ext/couchbase/core/logger/logger.hxx +31 -0
  47. data/ext/couchbase/core/meta/features.hxx +25 -0
  48. data/ext/couchbase/core/operations/document_lookup_in_all_replicas.hxx +192 -0
  49. data/ext/couchbase/core/operations/document_lookup_in_any_replica.hxx +188 -0
  50. data/ext/couchbase/core/operations/document_query.cxx +11 -0
  51. data/ext/couchbase/core/operations/document_query.hxx +1 -0
  52. data/ext/couchbase/core/operations.hxx +2 -0
  53. data/ext/couchbase/core/origin.cxx +270 -0
  54. data/ext/couchbase/core/origin.hxx +2 -0
  55. data/ext/couchbase/core/protocol/client_response.hxx +1 -0
  56. data/ext/couchbase/core/protocol/cmd_hello.hxx +1 -0
  57. data/ext/couchbase/core/protocol/cmd_lookup_in_replica.cxx +107 -0
  58. data/ext/couchbase/core/protocol/cmd_lookup_in_replica.hxx +137 -0
  59. data/ext/couchbase/core/protocol/hello_feature.hxx +6 -0
  60. data/ext/couchbase/core/protocol/hello_feature_fmt.hxx +3 -0
  61. data/ext/couchbase/core/protocol/status.cxx +2 -2
  62. data/ext/couchbase/core/range_scan_options.cxx +3 -27
  63. data/ext/couchbase/core/range_scan_options.hxx +13 -17
  64. data/ext/couchbase/core/range_scan_orchestrator.cxx +388 -170
  65. data/ext/couchbase/core/range_scan_orchestrator.hxx +13 -2
  66. data/ext/couchbase/core/range_scan_orchestrator_options.hxx +5 -3
  67. data/ext/couchbase/core/scan_options.hxx +0 -19
  68. data/ext/couchbase/core/scan_result.cxx +19 -5
  69. data/ext/couchbase/core/scan_result.hxx +5 -2
  70. data/ext/couchbase/core/timeout_defaults.hxx +2 -3
  71. data/ext/couchbase/core/topology/capabilities.hxx +3 -0
  72. data/ext/couchbase/core/topology/capabilities_fmt.hxx +8 -0
  73. data/ext/couchbase/core/topology/collections_manifest_fmt.hxx +1 -1
  74. data/ext/couchbase/core/topology/configuration.hxx +15 -0
  75. data/ext/couchbase/core/topology/configuration_json.hxx +6 -1
  76. data/ext/couchbase/core/utils/connection_string.cxx +62 -47
  77. data/ext/couchbase/core/utils/connection_string.hxx +1 -0
  78. data/ext/couchbase/couchbase/analytics_error_context.hxx +1 -1
  79. data/ext/couchbase/couchbase/behavior_options.hxx +19 -2
  80. data/ext/couchbase/couchbase/bucket_manager.hxx +135 -0
  81. data/ext/couchbase/couchbase/build_query_index_options.hxx +0 -30
  82. data/ext/couchbase/couchbase/cluster.hxx +14 -0
  83. data/ext/couchbase/couchbase/collection.hxx +111 -0
  84. data/ext/couchbase/couchbase/collection_query_index_manager.hxx +7 -48
  85. data/ext/couchbase/couchbase/create_bucket_options.hxx +41 -0
  86. data/ext/couchbase/couchbase/create_primary_query_index_options.hxx +0 -29
  87. data/ext/couchbase/couchbase/create_query_index_options.hxx +0 -33
  88. data/ext/couchbase/couchbase/drop_bucket_options.hxx +41 -0
  89. data/ext/couchbase/couchbase/drop_primary_query_index_options.hxx +0 -30
  90. data/ext/couchbase/couchbase/drop_query_index_options.hxx +0 -31
  91. data/ext/couchbase/couchbase/error_codes.hxx +1 -2
  92. data/ext/couchbase/couchbase/error_context.hxx +10 -2
  93. data/ext/couchbase/couchbase/flush_bucket_options.hxx +41 -0
  94. data/ext/couchbase/{core/topology/error_map_fmt.hxx → couchbase/fmt/key_value_error_map_attribute.hxx} +21 -21
  95. data/ext/couchbase/couchbase/get_all_buckets_options.hxx +44 -0
  96. data/ext/couchbase/couchbase/get_all_query_indexes_options.hxx +0 -30
  97. data/ext/couchbase/couchbase/get_and_lock_options.hxx +2 -2
  98. data/ext/couchbase/couchbase/get_and_touch_options.hxx +2 -2
  99. data/ext/couchbase/couchbase/get_bucket_options.hxx +43 -0
  100. data/ext/couchbase/couchbase/get_options.hxx +2 -2
  101. data/ext/couchbase/couchbase/insert_options.hxx +3 -3
  102. data/ext/couchbase/couchbase/key_value_error_context.hxx +7 -2
  103. data/ext/couchbase/couchbase/lookup_in_all_replicas_options.hxx +109 -0
  104. data/ext/couchbase/couchbase/lookup_in_any_replica_options.hxx +101 -0
  105. data/ext/couchbase/couchbase/lookup_in_options.hxx +2 -2
  106. data/ext/couchbase/couchbase/lookup_in_replica_result.hxx +74 -0
  107. data/ext/couchbase/couchbase/lookup_in_result.hxx +26 -0
  108. data/ext/couchbase/couchbase/management/bucket_settings.hxx +116 -0
  109. data/ext/couchbase/couchbase/manager_error_context.hxx +29 -53
  110. data/ext/couchbase/couchbase/mutate_in_options.hxx +2 -2
  111. data/ext/couchbase/couchbase/query_error_context.hxx +3 -1
  112. data/ext/couchbase/couchbase/query_index_manager.hxx +16 -83
  113. data/ext/couchbase/couchbase/query_options.hxx +18 -0
  114. data/ext/couchbase/couchbase/remove_options.hxx +2 -2
  115. data/ext/couchbase/couchbase/replace_options.hxx +3 -3
  116. data/ext/couchbase/couchbase/security_options.hxx +15 -0
  117. data/ext/couchbase/couchbase/subdocument_error_context.hxx +4 -2
  118. data/ext/couchbase/couchbase/touch_options.hxx +2 -2
  119. data/ext/couchbase/couchbase/unlock_options.hxx +2 -2
  120. data/ext/couchbase/couchbase/update_bucket_options.hxx +41 -0
  121. data/ext/couchbase/couchbase/upsert_options.hxx +3 -3
  122. data/ext/couchbase/couchbase/watch_query_indexes_options.hxx +0 -31
  123. data/ext/couchbase/test/CMakeLists.txt +1 -0
  124. data/ext/couchbase/test/test_integration_collections.cxx +6 -0
  125. data/ext/couchbase/test/test_integration_crud.cxx +5 -0
  126. data/ext/couchbase/test/test_integration_examples.cxx +137 -1
  127. data/ext/couchbase/test/test_integration_management.cxx +709 -266
  128. data/ext/couchbase/test/test_integration_query.cxx +19 -7
  129. data/ext/couchbase/test/test_integration_range_scan.cxx +351 -112
  130. data/ext/couchbase/test/test_integration_search.cxx +10 -1
  131. data/ext/couchbase/test/test_integration_subdoc.cxx +655 -0
  132. data/ext/couchbase/test/test_transaction_public_async_api.cxx +13 -12
  133. data/ext/couchbase/test/test_transaction_public_blocking_api.cxx +27 -21
  134. data/ext/couchbase/test/test_unit_connection_string.cxx +29 -0
  135. data/ext/couchbase/test/test_unit_query.cxx +75 -0
  136. data/ext/couchbase.cxx +583 -29
  137. data/ext/revisions.rb +3 -3
  138. data/lib/couchbase/cluster.rb +1 -1
  139. data/lib/couchbase/collection.rb +108 -0
  140. data/lib/couchbase/collection_options.rb +100 -0
  141. data/lib/couchbase/errors.rb +5 -0
  142. data/lib/couchbase/key_value_scan.rb +125 -0
  143. data/lib/couchbase/options.rb +151 -0
  144. data/lib/couchbase/scope.rb +1 -1
  145. data/lib/couchbase/utils/time.rb +14 -1
  146. data/lib/couchbase/version.rb +1 -1
  147. metadata +41 -7
  148. data/ext/couchbase/core/impl/collection_query_index_manager.cxx +0 -93
@@ -0,0 +1,155 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020-Present 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
+ #include <couchbase/manager_error_context.hxx>
19
+ #include <utility>
20
+
21
+ #include "core/cluster.hxx"
22
+ #include "couchbase/bucket_manager.hxx"
23
+
24
+ namespace couchbase
25
+ {
26
+ template<typename Response>
27
+ static manager_error_context
28
+ build_context(Response& resp)
29
+ {
30
+ return manager_error_context(internal_manager_error_context{ resp.ctx.ec,
31
+ resp.ctx.last_dispatched_to,
32
+ resp.ctx.last_dispatched_from,
33
+ resp.ctx.retry_attempts,
34
+ std::move(resp.ctx.retry_reasons),
35
+ std::move(resp.ctx.client_context_id),
36
+ resp.ctx.http_status,
37
+ std::move(resp.ctx.http_body),
38
+ std::move(resp.ctx.path) });
39
+ }
40
+
41
+ static core::operations::management::bucket_create_request
42
+ build_create_bucket_request(couchbase::core::management::cluster::bucket_settings bucket_settings,
43
+ const create_bucket_options::built& options)
44
+ {
45
+ core::operations::management::bucket_create_request request{ std::move(bucket_settings), {}, options.timeout };
46
+ return request;
47
+ }
48
+
49
+ static couchbase::core::management::cluster::bucket_settings
50
+ map_bucket_settings(const couchbase::management::cluster::bucket_settings& bucket)
51
+ {
52
+
53
+ couchbase::core::management::cluster::bucket_settings bucket_settings{};
54
+
55
+ bucket_settings.name = bucket.name;
56
+ bucket_settings.ram_quota_mb = bucket.ram_quota_mb;
57
+ bucket_settings.max_expiry = bucket.max_expiry;
58
+ bucket_settings.minimum_durability_level = bucket.minimum_durability_level;
59
+ bucket_settings.num_replicas = bucket.num_replicas;
60
+ bucket_settings.replica_indexes = bucket.replica_indexes;
61
+ bucket_settings.flush_enabled = bucket.flush_enabled;
62
+ switch (bucket.conflict_resolution_type) {
63
+ case management::cluster::bucket_conflict_resolution::unknown:
64
+ bucket_settings.conflict_resolution_type = core::management::cluster::bucket_conflict_resolution::unknown;
65
+ break;
66
+ case management::cluster::bucket_conflict_resolution::timestamp:
67
+ bucket_settings.conflict_resolution_type = core::management::cluster::bucket_conflict_resolution::timestamp;
68
+ break;
69
+ case management::cluster::bucket_conflict_resolution::sequence_number:
70
+ bucket_settings.conflict_resolution_type = core::management::cluster::bucket_conflict_resolution::sequence_number;
71
+ break;
72
+ case management::cluster::bucket_conflict_resolution::custom:
73
+ bucket_settings.conflict_resolution_type = core::management::cluster::bucket_conflict_resolution::custom;
74
+ break;
75
+ }
76
+ switch (bucket.eviction_policy) {
77
+ case management::cluster::bucket_eviction_policy::unknown:
78
+ bucket_settings.eviction_policy = core::management::cluster::bucket_eviction_policy::unknown;
79
+ break;
80
+ case management::cluster::bucket_eviction_policy::full:
81
+ bucket_settings.eviction_policy = core::management::cluster::bucket_eviction_policy::full;
82
+ break;
83
+ case management::cluster::bucket_eviction_policy::value_only:
84
+ bucket_settings.eviction_policy = core::management::cluster::bucket_eviction_policy::value_only;
85
+ break;
86
+ case management::cluster::bucket_eviction_policy::no_eviction:
87
+ bucket_settings.eviction_policy = core::management::cluster::bucket_eviction_policy::no_eviction;
88
+ break;
89
+ case management::cluster::bucket_eviction_policy::not_recently_used:
90
+ bucket_settings.eviction_policy = core::management::cluster::bucket_eviction_policy::not_recently_used;
91
+ break;
92
+ }
93
+ switch (bucket.compression_mode) {
94
+ case management::cluster::bucket_compression::unknown:
95
+ bucket_settings.compression_mode = core::management::cluster::bucket_compression::unknown;
96
+ break;
97
+ case management::cluster::bucket_compression::active:
98
+ bucket_settings.compression_mode = core::management::cluster::bucket_compression::active;
99
+ break;
100
+ case management::cluster::bucket_compression::passive:
101
+ bucket_settings.compression_mode = core::management::cluster::bucket_compression::passive;
102
+ break;
103
+ case management::cluster::bucket_compression::off:
104
+ bucket_settings.compression_mode = core::management::cluster::bucket_compression::off;
105
+ break;
106
+ }
107
+ switch (bucket.bucket_type) {
108
+ case management::cluster::bucket_type::unknown:
109
+ bucket_settings.bucket_type = core::management::cluster::bucket_type::unknown;
110
+ break;
111
+ case management::cluster::bucket_type::couchbase:
112
+ bucket_settings.bucket_type = core::management::cluster::bucket_type::couchbase;
113
+ break;
114
+ case management::cluster::bucket_type::memcached:
115
+ bucket_settings.bucket_type = core::management::cluster::bucket_type::memcached;
116
+ break;
117
+ case management::cluster::bucket_type::ephemeral:
118
+ bucket_settings.bucket_type = core::management::cluster::bucket_type::ephemeral;
119
+ break;
120
+ }
121
+ switch (bucket.storage_backend) {
122
+ case management::cluster::bucket_storage_backend::unknown:
123
+ bucket_settings.storage_backend = core::management::cluster::bucket_storage_backend::unknown;
124
+ break;
125
+ case management::cluster::bucket_storage_backend::magma:
126
+ bucket_settings.storage_backend = core::management::cluster::bucket_storage_backend::magma;
127
+ break;
128
+ case management::cluster::bucket_storage_backend::couchstore:
129
+ bucket_settings.storage_backend = core::management::cluster::bucket_storage_backend::couchstore;
130
+ break;
131
+ }
132
+ return bucket_settings;
133
+ }
134
+
135
+ void
136
+ bucket_manager::create_bucket(const management::cluster::bucket_settings& bucket_settings,
137
+ const create_bucket_options& options,
138
+ create_bucket_handler&& handler) const
139
+ {
140
+ auto request = build_create_bucket_request(map_bucket_settings(bucket_settings), options.build());
141
+
142
+ core_->execute(std::move(request), [handler = std::move(handler)](core::operations::management::bucket_create_response resp) mutable {
143
+ return handler(build_context(resp));
144
+ });
145
+ }
146
+
147
+ auto
148
+ bucket_manager::create_bucket(const management::cluster::bucket_settings& bucket_settings, const create_bucket_options& options) const
149
+ -> std::future<manager_error_context>
150
+ {
151
+ auto barrier = std::make_shared<std::promise<manager_error_context>>();
152
+ create_bucket(bucket_settings, options, [barrier](auto ctx) mutable { barrier->set_value(std::move(ctx)); });
153
+ return barrier->get_future();
154
+ }
155
+ } // namespace couchbase
@@ -21,41 +21,36 @@
21
21
  #include "core/cluster.hxx"
22
22
  #include "core/operations/management/query_index_create.hxx"
23
23
 
24
- namespace couchbase::core::impl
24
+ namespace couchbase
25
25
  {
26
26
  template<typename Response>
27
27
  static manager_error_context
28
28
  build_context(Response& resp)
29
29
  {
30
- return { resp.ctx.ec,
31
- resp.ctx.last_dispatched_to,
32
- resp.ctx.last_dispatched_from,
33
- resp.ctx.retry_attempts,
34
- std::move(resp.ctx.retry_reasons),
35
- std::move(resp.ctx.client_context_id),
36
- resp.ctx.http_status,
37
- std::move(resp.ctx.http_body),
38
- std::move(resp.ctx.path) };
30
+ return manager_error_context(internal_manager_error_context{ resp.ctx.ec,
31
+ resp.ctx.last_dispatched_to,
32
+ resp.ctx.last_dispatched_from,
33
+ resp.ctx.retry_attempts,
34
+ std::move(resp.ctx.retry_reasons),
35
+ std::move(resp.ctx.client_context_id),
36
+ resp.ctx.http_status,
37
+ std::move(resp.ctx.http_body),
38
+ std::move(resp.ctx.path) });
39
39
  }
40
40
 
41
- void
42
- initiate_create_query_index(std::shared_ptr<couchbase::core::cluster> core,
43
- std::string bucket_name,
44
- std::string index_name,
45
- std::vector<std::string> fields,
46
- couchbase::create_query_index_options::built options,
47
- query_context query_ctx,
48
- std::string collection_name,
49
- create_query_index_handler&& handler)
41
+ static core::operations::management::query_index_create_request
42
+ build_create_index_request(std::string bucket_name,
43
+ std::string index_name,
44
+ std::vector<std::string> fields,
45
+ create_query_index_options::built options)
50
46
  {
51
- core->execute(
52
- operations::management::query_index_create_request{
53
- bucket_name,
47
+ core::operations::management::query_index_create_request request{
48
+ std::move(bucket_name),
49
+ "",
54
50
  "",
55
- collection_name,
56
- index_name,
57
- fields,
58
- query_ctx,
51
+ std::move(index_name),
52
+ std::move(fields),
53
+ {},
59
54
  false,
60
55
  options.ignore_if_exists,
61
56
  options.condition,
@@ -63,39 +58,70 @@ initiate_create_query_index(std::shared_ptr<couchbase::core::cluster> core,
63
58
  options.num_replicas,
64
59
  {},
65
60
  options.timeout,
66
- },
67
- [core, bucket_name, options = std::move(options), handler = std::move(handler)](
68
- operations::management::query_index_create_response resp) { handler(build_context(resp)); });
61
+ };
62
+ return request;
69
63
  }
70
64
 
71
- void
72
- initiate_create_query_index(std::shared_ptr<couchbase::core::cluster> core,
73
- std::string bucket_name,
74
- std::string index_name,
75
- std::vector<std::string> fields,
76
- couchbase::create_query_index_options::built options,
77
- create_query_index_handler&& handler)
65
+ static core::operations::management::query_index_create_request
66
+ build_create_primary_index_request(std::string bucket_name, create_primary_query_index_options::built options)
78
67
  {
79
- initiate_create_query_index(
80
- core, std::move(bucket_name), std::move(index_name), std::move(fields), options, {}, "", std::move(handler));
68
+ core::operations::management::query_index_create_request request{
69
+ std::move(bucket_name),
70
+ "",
71
+ "",
72
+ options.index_name.value_or(""),
73
+ {},
74
+ {},
75
+ true,
76
+ options.ignore_if_exists,
77
+ {},
78
+ options.deferred,
79
+ options.num_replicas,
80
+ {},
81
+ options.timeout,
82
+ };
83
+ return request;
81
84
  }
82
85
 
83
- void
84
- initiate_create_primary_query_index(std::shared_ptr<couchbase::core::cluster> core,
85
- std::string bucket_name,
86
- couchbase::create_primary_query_index_options::built options,
87
- query_context query_ctx,
88
- std::string collection_name,
89
- create_primary_query_index_handler&& handler)
86
+ static core::operations::management::query_index_create_request
87
+ build_create_index_request(std::string bucket_name,
88
+ std::string scope_name,
89
+ std::string collection_name,
90
+ std::string index_name,
91
+ std::vector<std::string> fields,
92
+ create_query_index_options::built options)
93
+ {
94
+ core::operations::management::query_index_create_request request{
95
+ "",
96
+ "",
97
+ std::move(collection_name),
98
+ std::move(index_name),
99
+ std::move(fields),
100
+ core::query_context(std::move(bucket_name), std::move(scope_name)),
101
+ false,
102
+ options.ignore_if_exists,
103
+ options.condition,
104
+ options.deferred,
105
+ options.num_replicas,
106
+ {},
107
+ options.timeout,
108
+ };
109
+ return request;
110
+ }
111
+
112
+ static core::operations::management::query_index_create_request
113
+ build_create_primary_index_request(std::string bucket_name,
114
+ std::string scope_name,
115
+ std::string collection_name,
116
+ create_primary_query_index_options::built options)
90
117
  {
91
- core->execute(
92
- operations::management::query_index_create_request{
93
- bucket_name,
118
+ core::operations::management::query_index_create_request request{
94
119
  "",
95
- collection_name,
120
+ "",
121
+ std::move(collection_name),
96
122
  options.index_name.value_or(""),
97
123
  {},
98
- query_ctx,
124
+ core::query_context(std::move(bucket_name), std::move(scope_name)),
99
125
  true,
100
126
  options.ignore_if_exists,
101
127
  {},
@@ -103,17 +129,104 @@ initiate_create_primary_query_index(std::shared_ptr<couchbase::core::cluster> co
103
129
  options.num_replicas,
104
130
  {},
105
131
  options.timeout,
106
- },
107
- [core, bucket_name, options = std::move(options), handler = std::move(handler)](
108
- operations::management::query_index_create_response resp) { handler(build_context(resp)); });
132
+ };
133
+ return request;
109
134
  }
110
135
 
111
136
  void
112
- initiate_create_primary_query_index(std::shared_ptr<couchbase::core::cluster> core,
113
- std::string bucket_name,
114
- couchbase::create_primary_query_index_options::built options,
115
- create_primary_query_index_handler&& handler)
137
+ query_index_manager::create_index(std::string bucket_name,
138
+ std::string index_name,
139
+ std::vector<std::string> fields,
140
+ const couchbase::create_query_index_options& options,
141
+ couchbase::create_primary_query_index_handler&& handler) const
142
+ {
143
+ auto request = build_create_index_request(std::move(bucket_name), std::move(index_name), std::move(fields), options.build());
144
+
145
+ core_->execute(std::move(request),
146
+ [handler = std::move(handler)](core::operations::management::query_index_create_response resp) mutable {
147
+ return handler(build_context(resp));
148
+ });
149
+ }
150
+
151
+ auto
152
+ query_index_manager::create_index(std::string bucket_name,
153
+ std::string index_name,
154
+ std::vector<std::string> fields,
155
+ const couchbase::create_query_index_options& options) const -> std::future<manager_error_context>
156
+ {
157
+ auto barrier = std::make_shared<std::promise<manager_error_context>>();
158
+ create_index(std::move(bucket_name), std::move(index_name), std::move(fields), options, [barrier](auto ctx) mutable {
159
+ barrier->set_value(std::move(ctx));
160
+ });
161
+ return barrier->get_future();
162
+ }
163
+
164
+ void
165
+ query_index_manager::create_primary_index(std::string bucket_name,
166
+ const create_primary_query_index_options& options,
167
+ create_query_index_handler&& handler)
168
+ {
169
+ auto request = build_create_primary_index_request(std::move(bucket_name), options.build());
170
+
171
+ core_->execute(std::move(request),
172
+ [handler = std::move(handler)](core::operations::management::query_index_create_response resp) mutable {
173
+ return handler(build_context(resp));
174
+ });
175
+ }
176
+
177
+ auto
178
+ query_index_manager::create_primary_index(std::string bucket_name, const create_primary_query_index_options& options)
179
+ -> std::future<manager_error_context>
180
+ {
181
+ auto barrier = std::make_shared<std::promise<manager_error_context>>();
182
+ create_primary_index(std::move(bucket_name), options, [barrier](auto ctx) mutable { barrier->set_value(std::move(ctx)); });
183
+ return barrier->get_future();
184
+ }
185
+
186
+ void
187
+ collection_query_index_manager::create_index(std::string index_name,
188
+ std::vector<std::string> fields,
189
+ const create_query_index_options& options,
190
+ create_query_index_handler&& handler) const
191
+ {
192
+ auto request =
193
+ build_create_index_request(bucket_name_, scope_name_, collection_name_, std::move(index_name), std::move(fields), options.build());
194
+
195
+ core_->execute(std::move(request),
196
+ [handler = std::move(handler)](core::operations::management::query_index_create_response resp) mutable {
197
+ return handler(build_context(resp));
198
+ });
199
+ }
200
+
201
+ auto
202
+ collection_query_index_manager::create_index(std::string index_name,
203
+ std::vector<std::string> fields,
204
+ const couchbase::create_query_index_options& options) const
205
+ -> std::future<manager_error_context>
206
+ {
207
+ auto barrier = std::make_shared<std::promise<manager_error_context>>();
208
+ create_index(std::move(index_name), std::move(fields), options, [barrier](auto ctx) mutable { barrier->set_value(std::move(ctx)); });
209
+ return barrier->get_future();
210
+ }
211
+
212
+ void
213
+ collection_query_index_manager::create_primary_index(const create_primary_query_index_options& options,
214
+ create_query_index_handler&& handler) const
215
+ {
216
+ auto request = build_create_primary_index_request(bucket_name_, scope_name_, collection_name_, options.build());
217
+
218
+ core_->execute(std::move(request),
219
+ [handler = std::move(handler)](core::operations::management::query_index_create_response resp) mutable {
220
+ return handler(build_context(resp));
221
+ });
222
+ }
223
+
224
+ auto
225
+ collection_query_index_manager::create_primary_index(const couchbase::create_primary_query_index_options& options)
226
+ -> std::future<manager_error_context>
116
227
  {
117
- initiate_create_primary_query_index(core, std::move(bucket_name), std::move(options), {}, "", std::move(handler));
228
+ auto barrier = std::make_shared<std::promise<manager_error_context>>();
229
+ create_primary_index(options, [barrier](auto ctx) mutable { barrier->set_value(std::move(ctx)); });
230
+ return barrier->get_future();
118
231
  }
119
- } // namespace couchbase::core::impl
232
+ } // namespace couchbase
@@ -41,7 +41,8 @@ dns_srv_tracker::dns_srv_tracker(asio::io_context& ctx, std::string address, con
41
41
  void
42
42
  dns_srv_tracker::get_srv_nodes(utils::movable_function<void(origin::node_list, std::error_code)> callback)
43
43
  {
44
- CB_LOG_TRACE("query DNS-SRV: address=\"{}\", service=\"{}\"", address_, service_);
44
+ CB_LOG_DEBUG(
45
+ "Query DNS-SRV: address=\"{}\", service=\"{}\", nameserver=\"{}:{}\"", address_, service_, config_.nameserver(), config_.port());
45
46
  dns_client_.query_srv(
46
47
  address_,
47
48
  service_,
@@ -0,0 +1,66 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020-Present 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
+ #include <couchbase/manager_error_context.hxx>
19
+ #include <utility>
20
+
21
+ #include "core/cluster.hxx"
22
+ #include "core/operations/management/bucket_drop.hxx"
23
+ #include "couchbase/bucket_manager.hxx"
24
+
25
+ namespace couchbase
26
+ {
27
+ template<typename Response>
28
+ static manager_error_context
29
+ build_context(Response& resp)
30
+ {
31
+ return manager_error_context(internal_manager_error_context{ resp.ctx.ec,
32
+ resp.ctx.last_dispatched_to,
33
+ resp.ctx.last_dispatched_from,
34
+ resp.ctx.retry_attempts,
35
+ std::move(resp.ctx.retry_reasons),
36
+ std::move(resp.ctx.client_context_id),
37
+ resp.ctx.http_status,
38
+ std::move(resp.ctx.http_body),
39
+ std::move(resp.ctx.path) });
40
+ }
41
+
42
+ static core::operations::management::bucket_drop_request
43
+ build_drop_bucket_request(std::string bucket_name, const drop_bucket_options::built& options)
44
+ {
45
+ core::operations::management::bucket_drop_request request{ std::move(bucket_name), {}, options.timeout };
46
+ return request;
47
+ }
48
+
49
+ void
50
+ bucket_manager::drop_bucket(std::string bucket_name, const drop_bucket_options& options, drop_bucket_handler&& handler) const
51
+ {
52
+ auto request = build_drop_bucket_request(std::move(bucket_name), options.build());
53
+
54
+ core_->execute(std::move(request), [handler = std::move(handler)](core::operations::management::bucket_drop_response resp) mutable {
55
+ return handler(build_context(resp));
56
+ });
57
+ }
58
+
59
+ auto
60
+ bucket_manager::drop_bucket(std::string bucket_name, const drop_bucket_options& options) const -> std::future<manager_error_context>
61
+ {
62
+ auto barrier = std::make_shared<std::promise<manager_error_context>>();
63
+ drop_bucket(std::move(bucket_name), options, [barrier](auto ctx) mutable { barrier->set_value(std::move(ctx)); });
64
+ return barrier->get_future();
65
+ }
66
+ } // namespace couchbase