Skip to content

Commit

Permalink
CXXCBC-365: handle >16 specs in lookup_in_any_replica (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-Woz committed Aug 17, 2023
1 parent b6148c1 commit c6be14e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/impl/lookup_in_any_replica.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ initiate_lookup_in_any_replica_operation(std::shared_ptr<cluster> core,
if (!config.supports_subdoc_read_replica()) {
ec = errc::common::feature_not_available;
}
if (r->specs().size() > 16) {
ec = errc::common::invalid_argument;
}
if (ec) {
std::optional<std::string> first_error_path{};
std::optional<std::size_t> first_error_index{};
Expand Down
3 changes: 3 additions & 0 deletions core/operations/document_lookup_in_any_replica.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ struct lookup_in_any_replica_request {
if (!config.supports_subdoc_read_replica()) {
ec = errc::common::feature_not_available;
}
if (specs.size() > 16) {
ec = errc::common::invalid_argument;
}

if (ec) {
std::optional<std::string> first_error_path{};
Expand Down
27 changes: 27 additions & 0 deletions test/test_integration_subdoc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,21 @@ TEST_CASE("integration: subdoc any replica reads", "[integration]")
couchbase::errc::key_value::path_mismatch);
}

SECTION("too many specs")
{
couchbase::core::operations::lookup_in_any_replica_request req{ id };
auto specs = couchbase::lookup_in_specs{};

for (int i = 0; i < 17; i++) {
specs.push_back(couchbase::lookup_in_specs::get("dictkey"));
}
req.specs = specs.specs();

auto resp = test::utils::execute(integration.cluster, req);
REQUIRE(resp.ctx.ec() == couchbase::errc::common::invalid_argument);
REQUIRE(resp.fields.empty());
}

SECTION("public API")
{
auto collection = couchbase::cluster(integration.cluster).bucket(integration.ctx.bucket).scope("_default").collection("_default");
Expand All @@ -1513,5 +1528,17 @@ TEST_CASE("integration: subdoc any replica reads", "[integration]")
REQUIRE(ctx.ec() == couchbase::errc::key_value::document_irretrievable);
REQUIRE(result.cas().empty());
}

SECTION("too many specs")
{
auto specs = couchbase::lookup_in_specs{};

for (int i = 0; i < 17; i++) {
specs.push_back(couchbase::lookup_in_specs::get("dictkey"));
}
auto [ctx, result] = collection.lookup_in_any_replica(key, specs).get();
REQUIRE(ctx.ec() == couchbase::errc::common::invalid_argument);
REQUIRE(result.cas().empty());
}
}
}

0 comments on commit c6be14e

Please sign in to comment.