Skip to content

CXXCBC-119 Subdoc exists should return a true/false value rather than error #444

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
8 changes: 8 additions & 0 deletions core/impl/lookup_in_all_replicas.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ initiate_lookup_in_all_replicas_operation(std::shared_ptr<cluster> core,
lookup_in_entry.value = field.value;
lookup_in_entry.exists = field.exists;
lookup_in_entry.original_index = field.original_index;
lookup_in_entry.ec = field.ec;
if (field.opcode == protocol::subdoc_opcode::exists && field.ec == errc::key_value::path_not_found) {
lookup_in_entry.ec.clear();
}
entries.emplace_back(lookup_in_entry);
}
ctx->result_.emplace_back(lookup_in_replica_result{ resp.cas, entries, resp.deleted, true /* replica */ });
Expand Down Expand Up @@ -155,6 +159,10 @@ initiate_lookup_in_all_replicas_operation(std::shared_ptr<cluster> core,
lookup_in_entry.value = field.value;
lookup_in_entry.exists = field.exists;
lookup_in_entry.original_index = field.original_index;
lookup_in_entry.ec = field.ec;
if (field.opcode == protocol::subdoc_opcode::exists && field.ec == errc::key_value::path_not_found) {
lookup_in_entry.ec.clear();
}
entries.emplace_back(lookup_in_entry);
}
ctx->result_.emplace_back(lookup_in_replica_result{ resp.cas, entries, resp.deleted, false /* active */ });
Expand Down
9 changes: 9 additions & 0 deletions core/impl/lookup_in_any_replica.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ initiate_lookup_in_any_replica_operation(std::shared_ptr<cluster> core,
entry.original_index = field.original_index;
entry.exists = field.exists;
entry.value = field.value;
entry.ec = field.ec;
if (field.opcode == protocol::subdoc_opcode::exists &&
field.ec == errc::key_value::path_not_found) {
entry.ec.clear();
}
entries.emplace_back(entry);
}
return local_handler(std::move(resp.ctx),
Expand Down Expand Up @@ -156,6 +161,10 @@ initiate_lookup_in_any_replica_operation(std::shared_ptr<cluster> core,
entry.original_index = field.original_index;
entry.exists = field.exists;
entry.value = field.value;
entry.ec = field.ec;
if (field.opcode == protocol::subdoc_opcode::exists && field.ec == errc::key_value::path_not_found) {
entry.ec.clear();
}
entries.emplace_back(entry);
}
return local_handler(std::move(resp.ctx),
Expand Down
3 changes: 3 additions & 0 deletions core/operations/document_lookup_in.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ lookup_in_request::make_response(key_value_error_context&& ctx, const encoded_re
fields[i].status = res_entry.status;
fields[i].ec =
protocol::map_status_code(protocol::client_opcode::subdoc_multi_mutation, static_cast<std::uint16_t>(res_entry.status));
if (fields[i].opcode == protocol::subdoc_opcode::exists && fields[i].ec == errc::key_value::path_not_found) {
fields[i].ec.clear();
}
if (!fields[i].ec && !ctx.ec()) {
ec = fields[i].ec;
}
Expand Down
8 changes: 8 additions & 0 deletions core/operations/document_lookup_in_all_replicas.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ struct lookup_in_all_replicas_request {
lookup_in_entry.exists = field.exists;
lookup_in_entry.original_index = field.original_index;
lookup_in_entry.opcode = field.opcode;
if (lookup_in_entry.opcode == protocol::subdoc_opcode::exists &&
lookup_in_entry.ec == errc::key_value::path_not_found) {
lookup_in_entry.ec.clear();
}
top_entry.fields.emplace_back(lookup_in_entry);
}
ctx->result_.emplace_back(lookup_in_all_replicas_response::entry{ top_entry });
Expand Down Expand Up @@ -169,6 +173,10 @@ struct lookup_in_all_replicas_request {
lookup_in_entry.exists = field.exists;
lookup_in_entry.original_index = field.original_index;
lookup_in_entry.opcode = field.opcode;
if (lookup_in_entry.opcode == protocol::subdoc_opcode::exists &&
lookup_in_entry.ec == errc::key_value::path_not_found) {
lookup_in_entry.ec.clear();
}
top_entry.fields.emplace_back(lookup_in_entry);
}
ctx->result_.emplace_back(lookup_in_all_replicas_response::entry{ top_entry });
Expand Down
8 changes: 8 additions & 0 deletions core/operations/document_lookup_in_any_replica.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ struct lookup_in_any_replica_request {
lookup_in_entry.exists = field.exists;
lookup_in_entry.original_index = field.original_index;
lookup_in_entry.opcode = field.opcode;
if (lookup_in_entry.opcode == protocol::subdoc_opcode::exists &&
lookup_in_entry.ec == errc::key_value::path_not_found) {
lookup_in_entry.ec.clear();
}
res.fields.emplace_back(lookup_in_entry);
}
return local_handler(res);
Expand Down Expand Up @@ -173,6 +177,10 @@ struct lookup_in_any_replica_request {
lookup_in_entry.exists = field.exists;
lookup_in_entry.original_index = field.original_index;
lookup_in_entry.opcode = field.opcode;
if (lookup_in_entry.opcode == protocol::subdoc_opcode::exists &&
lookup_in_entry.ec == errc::key_value::path_not_found) {
lookup_in_entry.ec.clear();
}
res.fields.emplace_back(lookup_in_entry);
}
return local_handler(res);
Expand Down
40 changes: 37 additions & 3 deletions test/test_integration_subdoc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ TEST_CASE("integration: subdoc get & exists", "[integration]")
id,
couchbase::lookup_in_specs::exists("non-exist"),
couchbase::key_value_status_code::subdoc_path_not_found,
couchbase::errc::key_value::path_not_found);
std::error_code{});
}

SECTION("non existent doc")
Expand Down Expand Up @@ -1153,7 +1153,7 @@ TEST_CASE("integration: subdoc all replica reads", "[integration]")
id,
couchbase::lookup_in_specs::exists("non-exist"),
couchbase::key_value_status_code::subdoc_path_not_found,
couchbase::errc::key_value::path_not_found);
std::error_code{});
}

SECTION("non existent doc")
Expand Down Expand Up @@ -1295,6 +1295,19 @@ TEST_CASE("integration: subdoc all replica reads", "[integration]")
REQUIRE(ctx.ec() == couchbase::errc::key_value::document_not_found);
REQUIRE(result.empty());
}

SECTION("non existent path exists")
{
auto specs = couchbase::lookup_in_specs{
couchbase::lookup_in_specs::exists("non-exists"),
};
auto [ctx, result] = collection.lookup_in_all_replicas(key, specs).get();
REQUIRE_SUCCESS(ctx.ec());
for (auto& res : result) {
REQUIRE(!res.cas().empty());
REQUIRE(!res.exists(0));
}
}
}
}

Expand Down Expand Up @@ -1376,7 +1389,7 @@ TEST_CASE("integration: subdoc any replica reads", "[integration]")
id,
couchbase::lookup_in_specs::exists("non-exist"),
couchbase::key_value_status_code::subdoc_path_not_found,
couchbase::errc::key_value::path_not_found);
std::error_code{});
}

SECTION("non existent doc")
Expand Down Expand Up @@ -1540,6 +1553,16 @@ TEST_CASE("integration: subdoc any replica reads", "[integration]")
REQUIRE(ctx.ec() == couchbase::errc::common::invalid_argument);
REQUIRE(result.cas().empty());
}

SECTION("non existent path exists")
{
auto specs = couchbase::lookup_in_specs{
couchbase::lookup_in_specs::exists("non-exists"),
};
auto [ctx, result] = collection.lookup_in_any_replica(key, specs).get();
REQUIRE_SUCCESS(ctx.ec());
REQUIRE(!result.exists(0));
}
}
}

Expand Down Expand Up @@ -1627,4 +1650,15 @@ TEST_CASE("integration: public API lookup in per-spec errors", "[integration]")
}
REQUIRE_SUCCESS(ec);
}

SECTION("non existent path exists")
{
auto specs = couchbase::lookup_in_specs{
couchbase::lookup_in_specs::exists("dictkey2"),
};
auto [ctx, result] = collection.lookup_in(key, specs).get();

REQUIRE_SUCCESS(ctx.ec());
REQUIRE(!result.exists(0));
}
}