Skip to content

Commit

Permalink
Remove error on non existent subdoc exists (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-Woz committed Aug 18, 2023
1 parent 43cf66a commit f976f36
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 3 deletions.
8 changes: 8 additions & 0 deletions core/impl/lookup_in_all_replicas.cxx
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
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
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
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
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
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));
}
}

0 comments on commit f976f36

Please sign in to comment.