Skip to content

Commit 205e88f

Browse files
authored
CXXCBC-367 & CXXCBC-370 support bucket settings for bucket no dedup feature & collection management (#446)
1 parent f976f36 commit 205e88f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1490
-49
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ set(couchbase_cxx_client_FILES
170170
core/operations/management/cluster_developer_preview_enable.cxx
171171
core/operations/management/collection_create.cxx
172172
core/operations/management/collection_drop.cxx
173+
core/operations/management/collection_update.cxx
173174
core/operations/management/collections_manifest_get.cxx
174175
core/operations/management/error_utils.cxx
175176
core/operations/management/eventing_deploy_function.cxx
@@ -271,7 +272,9 @@ set(couchbase_cxx_client_FILES
271272
core/impl/configuration_profiles_registry.cxx
272273
core/impl/conjunction_query.cxx
273274
core/impl/create_bucket.cxx
275+
core/impl/create_collection.cxx
274276
core/impl/create_query_index.cxx
277+
core/impl/create_scope.cxx
275278
core/impl/date_range.cxx
276279
core/impl/date_range_facet.cxx
277280
core/impl/date_range_facet_result.cxx
@@ -280,7 +283,9 @@ set(couchbase_cxx_client_FILES
280283
core/impl/disjunction_query.cxx
281284
core/impl/dns_srv_tracker.cxx
282285
core/impl/drop_bucket.cxx
286+
core/impl/drop_collection.cxx
283287
core/impl/drop_query_index.cxx
288+
core/impl/drop_scope.cxx
284289
core/impl/exists.cxx
285290
core/impl/expiry.cxx
286291
core/impl/fail_fast_retry_strategy.cxx
@@ -293,6 +298,7 @@ set(couchbase_cxx_client_FILES
293298
core/impl/get_all_buckets.cxx
294299
core/impl/get_all_query_indexes.cxx
295300
core/impl/get_all_replicas.cxx
301+
core/impl/get_all_scopes.cxx
296302
core/impl/get_and_lock.cxx
297303
core/impl/get_and_touch.cxx
298304
core/impl/get_any_replica.cxx
@@ -380,6 +386,7 @@ set(couchbase_cxx_client_FILES
380386
core/impl/transaction_op_error_category.cxx
381387
core/impl/unlock.cxx
382388
core/impl/update_bucket.cxx
389+
core/impl/update_collection.cxx
383390
core/impl/upsert.cxx
384391
core/impl/view_error_category.cxx
385392
core/impl/watch_query_indexes.cxx

core/impl/create_bucket.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ map_bucket_settings(const couchbase::management::cluster::bucket_settings& bucke
5959
bucket_settings.num_replicas = bucket.num_replicas;
6060
bucket_settings.replica_indexes = bucket.replica_indexes;
6161
bucket_settings.flush_enabled = bucket.flush_enabled;
62+
bucket_settings.history_retention_collection_default = bucket.history_retention_collection_default;
63+
bucket_settings.history_retention_bytes = bucket.history_retention_bytes;
64+
bucket_settings.history_retention_duration = bucket.history_retention_duration;
6265
switch (bucket.conflict_resolution_type) {
6366
case management::cluster::bucket_conflict_resolution::unknown:
6467
bucket_settings.conflict_resolution_type = core::management::cluster::bucket_conflict_resolution::unknown;

core/impl/create_collection.cxx

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
20+
#include "core/cluster.hxx"
21+
#include "core/operations/management/collection_create.hxx"
22+
#include "couchbase/collection_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::collection_create_request
42+
build_collection_create_request(std::string bucket_name,
43+
std::string scope_name,
44+
std::string collection_name,
45+
const create_collection_settings& settings,
46+
const create_collection_options::built& options)
47+
{
48+
core::operations::management::collection_create_request request{
49+
std::move(bucket_name), std::move(scope_name), std::move(collection_name), settings.max_expiry, settings.history, {},
50+
options.timeout
51+
};
52+
return request;
53+
}
54+
55+
void
56+
collection_manager::create_collection(std::string scope_name,
57+
std::string collection_name,
58+
const couchbase::create_collection_settings& settings,
59+
const couchbase::create_collection_options& options,
60+
couchbase::create_collection_handler&& handler) const
61+
{
62+
auto request =
63+
build_collection_create_request(bucket_name_, std::move(scope_name), std::move(collection_name), settings, options.build());
64+
65+
core_->execute(std::move(request),
66+
[handler = std::move(handler)](core::operations::management::collection_create_response resp) mutable {
67+
return handler(build_context(resp));
68+
});
69+
}
70+
71+
auto
72+
collection_manager::create_collection(std::string scope_name,
73+
std::string collection_name,
74+
const couchbase::create_collection_settings& settings,
75+
const couchbase::create_collection_options& options) const -> std::future<manager_error_context>
76+
{
77+
auto barrier = std::make_shared<std::promise<manager_error_context>>();
78+
create_collection(std::move(scope_name), std::move(collection_name), settings, options, [barrier](auto ctx) mutable {
79+
barrier->set_value(std::move(ctx));
80+
});
81+
return barrier->get_future();
82+
}
83+
} // namespace couchbase

core/impl/create_scope.cxx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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/scope_create.hxx"
23+
#include "couchbase/collection_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::scope_create_request
43+
build_scope_create_request(std::string bucket_name, std::string scope_name, const create_scope_options::built& options)
44+
{
45+
core::operations::management::scope_create_request request{ std::move(bucket_name), std::move(scope_name), {}, options.timeout };
46+
return request;
47+
}
48+
49+
void
50+
collection_manager::create_scope(std::string scope_name,
51+
const couchbase::create_scope_options& options,
52+
couchbase::create_scope_handler&& handler) const
53+
{
54+
auto request = build_scope_create_request(bucket_name_, std::move(scope_name), options.build());
55+
56+
core_->execute(std::move(request), [handler = std::move(handler)](core::operations::management::scope_create_response resp) mutable {
57+
return handler(build_context(resp));
58+
});
59+
}
60+
61+
auto
62+
collection_manager::create_scope(std::string scope_name, const couchbase::create_scope_options& options) const
63+
-> std::future<manager_error_context>
64+
{
65+
auto barrier = std::make_shared<std::promise<manager_error_context>>();
66+
create_scope(std::move(scope_name), options, [barrier](auto ctx) mutable { barrier->set_value(std::move(ctx)); });
67+
return barrier->get_future();
68+
}
69+
} // namespace couchbase

core/impl/drop_collection.cxx

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
20+
#include "core/cluster.hxx"
21+
#include "core/operations/management/collection_drop.hxx"
22+
#include "couchbase/collection_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::collection_drop_request
42+
build_collection_drop_request(std::string bucket_name,
43+
std::string scope_name,
44+
std::string collection_name,
45+
const drop_collection_options::built& options)
46+
{
47+
core::operations::management::collection_drop_request request{
48+
std::move(bucket_name), std::move(scope_name), std::move(collection_name), {}, options.timeout
49+
};
50+
return request;
51+
}
52+
53+
void
54+
collection_manager::drop_collection(std::string scope_name,
55+
std::string collection_name,
56+
const couchbase::drop_collection_options& options,
57+
couchbase::drop_collection_handler&& handler) const
58+
{
59+
auto request = build_collection_drop_request(bucket_name_, std::move(scope_name), std::move(collection_name), options.build());
60+
61+
core_->execute(std::move(request), [handler = std::move(handler)](core::operations::management::collection_drop_response resp) mutable {
62+
return handler(build_context(resp));
63+
});
64+
}
65+
66+
auto
67+
collection_manager::drop_collection(std::string scope_name,
68+
std::string collection_name,
69+
const couchbase::drop_collection_options& options) const -> std::future<manager_error_context>
70+
{
71+
auto barrier = std::make_shared<std::promise<manager_error_context>>();
72+
drop_collection(
73+
std::move(scope_name), std::move(collection_name), options, [barrier](auto ctx) mutable { barrier->set_value(std::move(ctx)); });
74+
return barrier->get_future();
75+
}
76+
} // namespace couchbase

core/impl/drop_scope.cxx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
20+
#include "core/cluster.hxx"
21+
#include "core/operations/management/scope_drop.hxx"
22+
#include "couchbase/collection_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::scope_drop_request
42+
build_drop_scope_request(std::string bucket_name, std::string scope_name, const drop_scope_options::built& options)
43+
{
44+
core::operations::management::scope_drop_request request{ std::move(bucket_name), std::move(scope_name), {}, options.timeout };
45+
return request;
46+
}
47+
48+
void
49+
collection_manager::drop_scope(std::string scope_name,
50+
const couchbase::drop_scope_options& options,
51+
couchbase::drop_scope_handler&& handler) const
52+
{
53+
auto request = build_drop_scope_request(bucket_name_, std::move(scope_name), options.build());
54+
55+
core_->execute(std::move(request), [handler = std::move(handler)](core::operations::management::scope_drop_response resp) mutable {
56+
return handler(build_context(resp));
57+
});
58+
}
59+
60+
auto
61+
collection_manager::drop_scope(std::string scope_name, const couchbase::drop_scope_options& options) const
62+
-> std::future<manager_error_context>
63+
{
64+
auto barrier = std::make_shared<std::promise<manager_error_context>>();
65+
drop_scope(std::move(scope_name), options, [barrier](auto ctx) mutable { barrier->set_value(std::move(ctx)); });
66+
return barrier->get_future();
67+
}
68+
} // namespace couchbase

core/impl/get_all_buckets.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ map_bucket_settings(const couchbase::core::management::cluster::bucket_settings&
5757
bucket_settings.num_replicas = bucket.num_replicas;
5858
bucket_settings.replica_indexes = bucket.replica_indexes;
5959
bucket_settings.flush_enabled = bucket.flush_enabled;
60+
bucket_settings.history_retention_collection_default = bucket.history_retention_collection_default;
61+
bucket_settings.history_retention_bytes = bucket.history_retention_bytes;
62+
bucket_settings.history_retention_duration = bucket.history_retention_duration;
6063
switch (bucket.conflict_resolution_type) {
6164
case core::management::cluster::bucket_conflict_resolution::unknown:
6265
bucket_settings.conflict_resolution_type = management::cluster::bucket_conflict_resolution::unknown;

0 commit comments

Comments
 (0)