Skip to content

Commit

Permalink
CXXCBC-275 Update how we handle query_context. (#369)
Browse files Browse the repository at this point in the history
* CXXCBC-275 Update how we handle query_context.

And, completely flesh out the query index managers.

Co-authored-by: Sergey Avseyev <[email protected]>
  • Loading branch information
davidkelly and avsej authored Feb 17, 2023
1 parent 4a46b7c commit 37b593f
Show file tree
Hide file tree
Showing 49 changed files with 2,865 additions and 552 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,14 @@ set(couchbase_cxx_client_FILES
core/impl/append.cxx
core/impl/best_effort_retry_strategy.cxx
core/impl/build_deferred_query_indexes.cxx
core/impl/collection_query_index_manager.cxx
core/impl/cluster.cxx
core/impl/common_error_category.cxx
core/impl/configuration_profiles_registry.cxx
core/impl/create_query_index.cxx
core/impl/decrement.cxx
core/impl/dns_srv_tracker.cxx
core/impl/drop_query_index.cxx
core/impl/exists.cxx
core/impl/expiry.cxx
core/impl/fail_fast_retry_strategy.cxx
Expand All @@ -272,6 +275,7 @@ set(couchbase_cxx_client_FILES
core/impl/get_all_replicas.cxx
core/impl/get_and_lock.cxx
core/impl/get_and_touch.cxx
core/impl/get_all_query_indexes.cxx
core/impl/get_any_replica.cxx
core/impl/get_replica.cxx
core/impl/increment.cxx
Expand All @@ -293,6 +297,7 @@ set(couchbase_cxx_client_FILES
core/impl/search_error_category.cxx
core/impl/streaming_json_lexter_error_category.cxx
core/impl/unlock.cxx
core/impl/watch_query_indexes.cxx
core/impl/subdoc/array_add_unique.cxx
core/impl/subdoc/array_append.cxx
core/impl/subdoc/array_insert.cxx
Expand Down
23 changes: 17 additions & 6 deletions core/impl/build_deferred_query_indexes.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,24 @@ build_context(Response& resp)
std::move(resp.ctx.http_body),
std::move(resp.ctx.path) };
}

void
initiate_build_deferred_indexes(std::shared_ptr<couchbase::core::cluster> core,
std::string bucket_name,
build_query_index_options::built options,
query_context query_ctx,
std::string collection_name,
build_deferred_query_indexes_handler&& handler)
{
core->execute(
operations::management::query_index_get_all_deferred_request{
bucket_name,
options.scope_name.value_or(""),
options.collection_name.value_or(""),
"",
collection_name,
query_ctx,
{},
options.timeout,
},
[core, bucket_name, options = std::move(options), handler = std::move(handler)](
[core, bucket_name, collection_name, options = std::move(options), query_ctx, handler = std::move(handler)](
operations::management::query_index_get_all_deferred_response resp1) mutable {
auto list_resp = std::move(resp1);
if (list_resp.ctx.ec) {
Expand All @@ -66,8 +68,9 @@ initiate_build_deferred_indexes(std::shared_ptr<couchbase::core::cluster> core,
core->execute(
operations::management::query_index_build_request{
std::move(bucket_name),
options.scope_name.value_or(""),
options.collection_name.value_or(""),
"",
collection_name,
query_ctx,
std::move(list_resp.index_names),
{},
options.timeout,
Expand All @@ -78,4 +81,12 @@ initiate_build_deferred_indexes(std::shared_ptr<couchbase::core::cluster> core,
});
});
}
void
initiate_build_deferred_indexes(std::shared_ptr<couchbase::core::cluster> core,
std::string bucket_name,
build_query_index_options::built options,
build_deferred_query_indexes_handler&& handler)
{
return initiate_build_deferred_indexes(core, std::move(bucket_name), options, {}, "", std::move(handler));
}
} // namespace couchbase::core::impl
93 changes: 93 additions & 0 deletions core/impl/collection_query_index_manager.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* -*- 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 <core/query_context.hxx>
#include <couchbase/collection_query_index_manager.hxx>

namespace couchbase
{

void
collection_query_index_manager::get_all_indexes(const get_all_query_indexes_options& options, get_all_indexes_handler&& handler) const
{
return core::impl::initiate_get_all_query_indexes(core_,
"",
options.build(),
core::query_context(bucket_name_, scope_name_),
collection_name_,
std::forward<get_all_indexes_handler>(handler));
}

void
collection_query_index_manager::create_index(std::string index_name,
std::vector<std::string> fields,
const create_query_index_options& options,
create_query_index_handler&& handler) const
{
return core::impl::initiate_create_query_index(core_,
"",
std::move(index_name),
std::move(fields),
options.build(),
{ bucket_name_, scope_name_ },
collection_name_,
std::forward<create_query_index_handler>(handler));
}

void
collection_query_index_manager::create_primary_index(const create_primary_query_index_options& options,
create_query_index_handler&& handler) const
{
return core::impl::initiate_create_primary_query_index(
core_, "", options.build(), { bucket_name_, scope_name_ }, collection_name_, std::move(handler));
}

void
collection_query_index_manager::drop_primary_index(const drop_primary_query_index_options& options,
drop_query_index_handler&& handler) const
{
return core::impl::initiate_drop_primary_query_index(
core_, "", options.build(), { bucket_name_, scope_name_ }, collection_name_, std::move(handler));
}
void
collection_query_index_manager::drop_index(std::string index_name,
const drop_query_index_options& options,
drop_query_index_handler&& handler) const
{
return core::impl::initiate_drop_query_index(
core_, "", std::move(index_name), options.build(), { bucket_name_, scope_name_ }, collection_name_, std::move(handler));
}
void
collection_query_index_manager::build_deferred_indexes(const build_query_index_options& options,
build_deferred_query_indexes_handler&& handler) const
{
return core::impl::initiate_build_deferred_indexes(core_,
"",
options.build(),
{ bucket_name_, scope_name_ },
collection_name_,
std::forward<build_deferred_query_indexes_handler>(handler));
}
void
collection_query_index_manager::watch_indexes(std::vector<std::string> index_names,
const watch_query_indexes_options& options,
watch_query_indexes_handler&& handler) const
{
return core::impl::initiate_watch_query_indexes(
core_, "", std::move(index_names), options.build(), { bucket_name_, scope_name_ }, collection_name_, std::move(handler));
}
} // namespace couchbase
119 changes: 119 additions & 0 deletions core/impl/create_query_index.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/* -*- 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/error_codes.hxx>
#include <couchbase/query_index_manager.hxx>

#include "core/cluster.hxx"
#include "core/operations/management/query_index_create.hxx"

namespace couchbase::core::impl
{
template<typename Response>
static manager_error_context
build_context(Response& resp)
{
return { 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) };
}

void
initiate_create_query_index(std::shared_ptr<couchbase::core::cluster> core,
std::string bucket_name,
std::string index_name,
std::vector<std::string> fields,
couchbase::create_query_index_options::built options,
query_context query_ctx,
std::string collection_name,
create_query_index_handler&& handler)
{
core->execute(
operations::management::query_index_create_request{
bucket_name,
"",
collection_name,
index_name,
fields,
query_ctx,
false,
options.ignore_if_exists,
options.condition,
options.deferred,
options.num_replicas,
{},
options.timeout,
},
[core, bucket_name, options = std::move(options), handler = std::move(handler)](
operations::management::query_index_create_response resp) { handler(build_context(resp)); });
}

void
initiate_create_query_index(std::shared_ptr<couchbase::core::cluster> core,
std::string bucket_name,
std::string index_name,
std::vector<std::string> fields,
couchbase::create_query_index_options::built options,
create_query_index_handler&& handler)
{
initiate_create_query_index(
core, std::move(bucket_name), std::move(index_name), std::move(fields), options, {}, "", std::move(handler));
}

void
initiate_create_primary_query_index(std::shared_ptr<couchbase::core::cluster> core,
std::string bucket_name,
couchbase::create_primary_query_index_options::built options,
query_context query_ctx,
std::string collection_name,
create_primary_query_index_handler&& handler)
{
core->execute(
operations::management::query_index_create_request{
bucket_name,
"",
collection_name,
options.index_name.value_or(""),
{},
query_ctx,
true,
options.ignore_if_exists,
{},
options.deferred,
options.num_replicas,
{},
options.timeout,
},
[core, bucket_name, options = std::move(options), handler = std::move(handler)](
operations::management::query_index_create_response resp) { handler(build_context(resp)); });
}

void
initiate_create_primary_query_index(std::shared_ptr<couchbase::core::cluster> core,
std::string bucket_name,
couchbase::create_primary_query_index_options::built options,
create_primary_query_index_handler&& handler)
{
initiate_create_primary_query_index(core, std::move(bucket_name), std::move(options), {}, "", std::move(handler));
}
} // namespace couchbase::core::impl
Loading

0 comments on commit 37b593f

Please sign in to comment.