Skip to content

Commit 854ccf5

Browse files
committed
Replace feature_not_available handling in update/create collection response with bucket cap check
1 parent 3a42a61 commit 854ccf5

File tree

3 files changed

+64
-11
lines changed

3 files changed

+64
-11
lines changed

core/operations/management/collection_create.cxx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
namespace couchbase::core::operations::management
2929
{
3030
std::error_code
31-
collection_create_request::encode_to(encoded_request_type& encoded, http_context& /* context */) const
31+
collection_create_request::encode_to(encoded_request_type& encoded, http_context& context) const
3232
{
3333
encoded.method = "POST";
3434
encoded.path = fmt::format("/pools/default/buckets/{}/scopes/{}/collections", bucket_name, scope_name);
@@ -42,6 +42,11 @@ collection_create_request::encode_to(encoded_request_type& encoded, http_context
4242
return couchbase::errc::common::invalid_argument;
4343
}
4444
if (history.has_value()) {
45+
auto bucket_caps = context.config.bucket_capabilities;
46+
if (bucket_caps.find(bucket_capability::non_deduped_history) == bucket_caps.end()) {
47+
return errc::common::feature_not_available;
48+
}
49+
4550
encoded.body.append(fmt::format("&history={}", history.value()));
4651
}
4752
return {};
@@ -57,9 +62,6 @@ collection_create_request::make_response(error_context::http&& ctx, const encode
5762
std::regex collection_exists("Collection with name .+ already exists");
5863
if (std::regex_search(encoded.body.data(), collection_exists)) {
5964
response.ctx.ec = errc::management::collection_exists;
60-
} else if (encoded.body.data().find("Not allowed on this version of cluster") != std::string::npos ||
61-
encoded.body.data().find("Bucket must have storage_mode=magma") != std::string::npos) {
62-
response.ctx.ec = errc::common::feature_not_available;
6365
} else {
6466
response.ctx.ec = errc::common::invalid_argument;
6567
}

core/operations/management/collection_update.cxx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
namespace couchbase::core::operations::management
2929
{
3030
std::error_code
31-
collection_update_request::encode_to(encoded_request_type& encoded, http_context& /* context */) const
31+
collection_update_request::encode_to(encoded_request_type& encoded, http_context& context) const
3232
{
3333
encoded.method = "PATCH";
3434
encoded.path = fmt::format("/pools/default/buckets/{}/scopes/{}/collections/{}", bucket_name, scope_name, collection_name);
@@ -42,6 +42,11 @@ collection_update_request::encode_to(encoded_request_type& encoded, http_context
4242
}
4343
}
4444
if (history.has_value()) {
45+
auto bucket_caps = context.config.bucket_capabilities;
46+
if (bucket_caps.find(bucket_capability::non_deduped_history) == bucket_caps.end()) {
47+
return errc::common::feature_not_available;
48+
}
49+
4550
values["history"] = history.value() ? "true" : "false";
4651
}
4752
encoded.body = utils::string_codec::v2::form_encode(values);
@@ -55,12 +60,7 @@ collection_update_request::make_response(error_context::http&& ctx, const encode
5560
if (!response.ctx.ec) {
5661
switch (encoded.status_code) {
5762
case 400: {
58-
if (encoded.body.data().find("Not allowed on this version of cluster") != std::string::npos ||
59-
encoded.body.data().find("Bucket must have storage_mode=magma") != std::string::npos) {
60-
response.ctx.ec = errc::common::feature_not_available;
61-
} else {
62-
response.ctx.ec = errc::common::invalid_argument;
63-
}
63+
response.ctx.ec = errc::common::invalid_argument;
6464
} break;
6565
case 404: {
6666
std::regex scope_not_found("Scope with name .+ is not found");

test/test_integration_management.cxx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,7 @@ TEST_CASE("integration: bucket management history", "[integration]")
987987
REQUIRE(get_resp.bucket.history_retention_bytes == 2147483648);
988988
}
989989
}
990+
990991
{
991992
couchbase::core::operations::management::bucket_drop_request req{ bucket_name };
992993
couchbase::core::operations::management::bucket_drop_request update_req{ update_bucket_name };
@@ -1539,6 +1540,56 @@ TEST_CASE("integration: collection management update collection with max expiry"
15391540
}
15401541
}
15411542

1543+
TEST_CASE("integration: collection management history retention not supported in bucket", "[integration]")
1544+
{
1545+
test::utils::integration_test_guard integration;
1546+
test::utils::open_bucket(integration.cluster, integration.ctx.bucket);
1547+
1548+
if (integration.has_bucket_capability("nonDedupedHistory")) {
1549+
SKIP("Bucket supports non deduped history");
1550+
}
1551+
1552+
auto scope_name = "_default";
1553+
auto collection_name = test::utils::uniq_id("collection");
1554+
1555+
SECTION("create collection")
1556+
{
1557+
couchbase::core::operations::management::collection_create_request req{
1558+
integration.ctx.bucket,
1559+
scope_name,
1560+
collection_name,
1561+
};
1562+
1563+
req.history = true;
1564+
1565+
auto resp = test::utils::execute(integration.cluster, req);
1566+
REQUIRE(resp.ctx.ec == couchbase::errc::common::feature_not_available);
1567+
}
1568+
1569+
SECTION("update collection")
1570+
{
1571+
auto ec = create_collection(integration.cluster, integration.ctx.bucket, scope_name, collection_name);
1572+
REQUIRE_SUCCESS(ec);
1573+
1574+
couchbase::core::operations::management::collection_update_request req{
1575+
integration.ctx.bucket,
1576+
scope_name,
1577+
collection_name,
1578+
};
1579+
1580+
req.history = true;
1581+
1582+
auto resp = test::utils::execute(integration.cluster, req);
1583+
REQUIRE(resp.ctx.ec == couchbase::errc::common::feature_not_available);
1584+
}
1585+
1586+
// Clean up the collection that was created
1587+
{
1588+
auto ec = drop_collection(integration.cluster, integration.ctx.bucket, scope_name, collection_name);
1589+
REQUIRE((!ec || ec == couchbase::errc::common::collection_not_found));
1590+
}
1591+
}
1592+
15421593
TEST_CASE("integration: collection management bucket dedup", "[integration]")
15431594
{
15441595
test::utils::integration_test_guard integration;

0 commit comments

Comments
 (0)