-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CXXCBC-275 Update how we handle query_context. (#369)
* 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
1 parent
4a46b7c
commit 37b593f
Showing
49 changed files
with
2,865 additions
and
552 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.