Skip to content

CXXCBC-367 & CXXCBC-370 support bucket settings for bucket no dedup feature & collection management #446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ set(couchbase_cxx_client_FILES
core/operations/management/cluster_developer_preview_enable.cxx
core/operations/management/collection_create.cxx
core/operations/management/collection_drop.cxx
core/operations/management/collection_update.cxx
core/operations/management/collections_manifest_get.cxx
core/operations/management/error_utils.cxx
core/operations/management/eventing_deploy_function.cxx
Expand Down Expand Up @@ -271,7 +272,9 @@ set(couchbase_cxx_client_FILES
core/impl/configuration_profiles_registry.cxx
core/impl/conjunction_query.cxx
core/impl/create_bucket.cxx
core/impl/create_collection.cxx
core/impl/create_query_index.cxx
core/impl/create_scope.cxx
core/impl/date_range.cxx
core/impl/date_range_facet.cxx
core/impl/date_range_facet_result.cxx
Expand All @@ -280,7 +283,9 @@ set(couchbase_cxx_client_FILES
core/impl/disjunction_query.cxx
core/impl/dns_srv_tracker.cxx
core/impl/drop_bucket.cxx
core/impl/drop_collection.cxx
core/impl/drop_query_index.cxx
core/impl/drop_scope.cxx
core/impl/exists.cxx
core/impl/expiry.cxx
core/impl/fail_fast_retry_strategy.cxx
Expand All @@ -293,6 +298,7 @@ set(couchbase_cxx_client_FILES
core/impl/get_all_buckets.cxx
core/impl/get_all_query_indexes.cxx
core/impl/get_all_replicas.cxx
core/impl/get_all_scopes.cxx
core/impl/get_and_lock.cxx
core/impl/get_and_touch.cxx
core/impl/get_any_replica.cxx
Expand Down Expand Up @@ -380,6 +386,7 @@ set(couchbase_cxx_client_FILES
core/impl/transaction_op_error_category.cxx
core/impl/unlock.cxx
core/impl/update_bucket.cxx
core/impl/update_collection.cxx
core/impl/upsert.cxx
core/impl/view_error_category.cxx
core/impl/watch_query_indexes.cxx
Expand Down
3 changes: 3 additions & 0 deletions core/impl/create_bucket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ map_bucket_settings(const couchbase::management::cluster::bucket_settings& bucke
bucket_settings.num_replicas = bucket.num_replicas;
bucket_settings.replica_indexes = bucket.replica_indexes;
bucket_settings.flush_enabled = bucket.flush_enabled;
bucket_settings.history_retention_collection_default = bucket.history_retention_collection_default;
bucket_settings.history_retention_bytes = bucket.history_retention_bytes;
bucket_settings.history_retention_duration = bucket.history_retention_duration;
switch (bucket.conflict_resolution_type) {
case management::cluster::bucket_conflict_resolution::unknown:
bucket_settings.conflict_resolution_type = core::management::cluster::bucket_conflict_resolution::unknown;
Expand Down
83 changes: 83 additions & 0 deletions core/impl/create_collection.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 2020-Present Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <couchbase/manager_error_context.hxx>

#include "core/cluster.hxx"
#include "core/operations/management/collection_create.hxx"
#include "couchbase/collection_manager.hxx"

namespace couchbase
{
template<typename Response>
static manager_error_context
build_context(Response& resp)
{
return manager_error_context(internal_manager_error_context{ resp.ctx.ec,
resp.ctx.last_dispatched_to,
resp.ctx.last_dispatched_from,
resp.ctx.retry_attempts,
std::move(resp.ctx.retry_reasons),
std::move(resp.ctx.client_context_id),
resp.ctx.http_status,
std::move(resp.ctx.http_body),
std::move(resp.ctx.path) });
}

static core::operations::management::collection_create_request
build_collection_create_request(std::string bucket_name,
std::string scope_name,
std::string collection_name,
const create_collection_settings& settings,
const create_collection_options::built& options)
{
core::operations::management::collection_create_request request{
std::move(bucket_name), std::move(scope_name), std::move(collection_name), settings.max_expiry, settings.history, {},
options.timeout
};
return request;
}

void
collection_manager::create_collection(std::string scope_name,
std::string collection_name,
const couchbase::create_collection_settings& settings,
const couchbase::create_collection_options& options,
couchbase::create_collection_handler&& handler) const
{
auto request =
build_collection_create_request(bucket_name_, std::move(scope_name), std::move(collection_name), settings, options.build());

core_->execute(std::move(request),
[handler = std::move(handler)](core::operations::management::collection_create_response resp) mutable {
return handler(build_context(resp));
});
}

auto
collection_manager::create_collection(std::string scope_name,
std::string collection_name,
const couchbase::create_collection_settings& settings,
const couchbase::create_collection_options& options) const -> std::future<manager_error_context>
{
auto barrier = std::make_shared<std::promise<manager_error_context>>();
create_collection(std::move(scope_name), std::move(collection_name), settings, options, [barrier](auto ctx) mutable {
barrier->set_value(std::move(ctx));
});
return barrier->get_future();
}
} // namespace couchbase
69 changes: 69 additions & 0 deletions core/impl/create_scope.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 2020-Present Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <couchbase/manager_error_context.hxx>
#include <utility>

#include "core/cluster.hxx"
#include "core/operations/management/scope_create.hxx"
#include "couchbase/collection_manager.hxx"

namespace couchbase
{
template<typename Response>
static manager_error_context
build_context(Response& resp)
{
return manager_error_context(internal_manager_error_context{ resp.ctx.ec,
resp.ctx.last_dispatched_to,
resp.ctx.last_dispatched_from,
resp.ctx.retry_attempts,
std::move(resp.ctx.retry_reasons),
std::move(resp.ctx.client_context_id),
resp.ctx.http_status,
std::move(resp.ctx.http_body),
std::move(resp.ctx.path) });
}

static core::operations::management::scope_create_request
build_scope_create_request(std::string bucket_name, std::string scope_name, const create_scope_options::built& options)
{
core::operations::management::scope_create_request request{ std::move(bucket_name), std::move(scope_name), {}, options.timeout };
return request;
}

void
collection_manager::create_scope(std::string scope_name,
const couchbase::create_scope_options& options,
couchbase::create_scope_handler&& handler) const
{
auto request = build_scope_create_request(bucket_name_, std::move(scope_name), options.build());

core_->execute(std::move(request), [handler = std::move(handler)](core::operations::management::scope_create_response resp) mutable {
return handler(build_context(resp));
});
}

auto
collection_manager::create_scope(std::string scope_name, const couchbase::create_scope_options& options) const
-> std::future<manager_error_context>
{
auto barrier = std::make_shared<std::promise<manager_error_context>>();
create_scope(std::move(scope_name), options, [barrier](auto ctx) mutable { barrier->set_value(std::move(ctx)); });
return barrier->get_future();
}
} // namespace couchbase
76 changes: 76 additions & 0 deletions core/impl/drop_collection.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 2020-Present Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <couchbase/manager_error_context.hxx>

#include "core/cluster.hxx"
#include "core/operations/management/collection_drop.hxx"
#include "couchbase/collection_manager.hxx"

namespace couchbase
{
template<typename Response>
static manager_error_context
build_context(Response& resp)
{
return manager_error_context(internal_manager_error_context{ resp.ctx.ec,
resp.ctx.last_dispatched_to,
resp.ctx.last_dispatched_from,
resp.ctx.retry_attempts,
std::move(resp.ctx.retry_reasons),
std::move(resp.ctx.client_context_id),
resp.ctx.http_status,
std::move(resp.ctx.http_body),
std::move(resp.ctx.path) });
}

static core::operations::management::collection_drop_request
build_collection_drop_request(std::string bucket_name,
std::string scope_name,
std::string collection_name,
const drop_collection_options::built& options)
{
core::operations::management::collection_drop_request request{
std::move(bucket_name), std::move(scope_name), std::move(collection_name), {}, options.timeout
};
return request;
}

void
collection_manager::drop_collection(std::string scope_name,
std::string collection_name,
const couchbase::drop_collection_options& options,
couchbase::drop_collection_handler&& handler) const
{
auto request = build_collection_drop_request(bucket_name_, std::move(scope_name), std::move(collection_name), options.build());

core_->execute(std::move(request), [handler = std::move(handler)](core::operations::management::collection_drop_response resp) mutable {
return handler(build_context(resp));
});
}

auto
collection_manager::drop_collection(std::string scope_name,
std::string collection_name,
const couchbase::drop_collection_options& options) const -> std::future<manager_error_context>
{
auto barrier = std::make_shared<std::promise<manager_error_context>>();
drop_collection(
std::move(scope_name), std::move(collection_name), options, [barrier](auto ctx) mutable { barrier->set_value(std::move(ctx)); });
return barrier->get_future();
}
} // namespace couchbase
68 changes: 68 additions & 0 deletions core/impl/drop_scope.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 2020-Present Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <couchbase/manager_error_context.hxx>

#include "core/cluster.hxx"
#include "core/operations/management/scope_drop.hxx"
#include "couchbase/collection_manager.hxx"

namespace couchbase
{
template<typename Response>
static manager_error_context
build_context(Response& resp)
{
return manager_error_context(internal_manager_error_context{ resp.ctx.ec,
resp.ctx.last_dispatched_to,
resp.ctx.last_dispatched_from,
resp.ctx.retry_attempts,
std::move(resp.ctx.retry_reasons),
std::move(resp.ctx.client_context_id),
resp.ctx.http_status,
std::move(resp.ctx.http_body),
std::move(resp.ctx.path) });
}

static core::operations::management::scope_drop_request
build_drop_scope_request(std::string bucket_name, std::string scope_name, const drop_scope_options::built& options)
{
core::operations::management::scope_drop_request request{ std::move(bucket_name), std::move(scope_name), {}, options.timeout };
return request;
}

void
collection_manager::drop_scope(std::string scope_name,
const couchbase::drop_scope_options& options,
couchbase::drop_scope_handler&& handler) const
{
auto request = build_drop_scope_request(bucket_name_, std::move(scope_name), options.build());

core_->execute(std::move(request), [handler = std::move(handler)](core::operations::management::scope_drop_response resp) mutable {
return handler(build_context(resp));
});
}

auto
collection_manager::drop_scope(std::string scope_name, const couchbase::drop_scope_options& options) const
-> std::future<manager_error_context>
{
auto barrier = std::make_shared<std::promise<manager_error_context>>();
drop_scope(std::move(scope_name), options, [barrier](auto ctx) mutable { barrier->set_value(std::move(ctx)); });
return barrier->get_future();
}
} // namespace couchbase
3 changes: 3 additions & 0 deletions core/impl/get_all_buckets.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ map_bucket_settings(const couchbase::core::management::cluster::bucket_settings&
bucket_settings.num_replicas = bucket.num_replicas;
bucket_settings.replica_indexes = bucket.replica_indexes;
bucket_settings.flush_enabled = bucket.flush_enabled;
bucket_settings.history_retention_collection_default = bucket.history_retention_collection_default;
bucket_settings.history_retention_bytes = bucket.history_retention_bytes;
bucket_settings.history_retention_duration = bucket.history_retention_duration;
switch (bucket.conflict_resolution_type) {
case core::management::cluster::bucket_conflict_resolution::unknown:
bucket_settings.conflict_resolution_type = management::cluster::bucket_conflict_resolution::unknown;
Expand Down
Loading