Skip to content

CXXCBC-376 Create and Update bucket sending unnecessary fields to server #451

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
24 changes: 18 additions & 6 deletions core/impl/get_all_buckets.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,26 @@ map_bucket_settings(const couchbase::core::management::cluster::bucket_settings&
couchbase::management::cluster::bucket_settings bucket_settings{};
bucket_settings.name = bucket.name;
bucket_settings.ram_quota_mb = bucket.ram_quota_mb;
bucket_settings.max_expiry = bucket.max_expiry;
bucket_settings.minimum_durability_level = bucket.minimum_durability_level;
bucket_settings.num_replicas = bucket.num_replicas;
bucket_settings.replica_indexes = bucket.replica_indexes;
bucket_settings.flush_enabled = bucket.flush_enabled;
bucket_settings.history_retention_collection_default = bucket.history_retention_collection_default;
bucket_settings.history_retention_bytes = bucket.history_retention_bytes;
bucket_settings.history_retention_duration = bucket.history_retention_duration;
if (bucket.max_expiry.has_value()) {
bucket_settings.max_expiry = bucket.max_expiry.value();
}
if (bucket.num_replicas.has_value()) {
bucket_settings.num_replicas = bucket.num_replicas.value();
}
if (bucket.replica_indexes.has_value()) {
bucket_settings.replica_indexes = bucket.replica_indexes.value();
}
if (bucket.flush_enabled.has_value()) {
bucket_settings.flush_enabled = bucket.flush_enabled.value();
}
if (bucket.history_retention_bytes.has_value()) {
bucket_settings.history_retention_bytes = bucket.history_retention_bytes.value();
}
if (bucket.history_retention_duration.has_value()) {
bucket_settings.history_retention_duration = bucket.history_retention_duration.value();
}
switch (bucket.conflict_resolution_type) {
case core::management::cluster::bucket_conflict_resolution::unknown:
bucket_settings.conflict_resolution_type = management::cluster::bucket_conflict_resolution::unknown;
Expand Down
24 changes: 18 additions & 6 deletions core/impl/get_bucket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,26 @@ map_bucket_settings(const couchbase::core::management::cluster::bucket_settings&
couchbase::management::cluster::bucket_settings bucket_settings{};
bucket_settings.name = bucket.name;
bucket_settings.ram_quota_mb = bucket.ram_quota_mb;
bucket_settings.max_expiry = bucket.max_expiry;
bucket_settings.minimum_durability_level = bucket.minimum_durability_level;
bucket_settings.num_replicas = bucket.num_replicas;
bucket_settings.replica_indexes = bucket.replica_indexes;
bucket_settings.flush_enabled = bucket.flush_enabled;
bucket_settings.history_retention_collection_default = bucket.history_retention_collection_default;
bucket_settings.history_retention_bytes = bucket.history_retention_bytes;
bucket_settings.history_retention_duration = bucket.history_retention_duration;
if (bucket.max_expiry.has_value()) {
bucket_settings.max_expiry = bucket.max_expiry.value();
}
if (bucket.num_replicas.has_value()) {
bucket_settings.num_replicas = bucket.num_replicas.value();
}
if (bucket.replica_indexes.has_value()) {
bucket_settings.replica_indexes = bucket.replica_indexes.value();
}
if (bucket.flush_enabled.has_value()) {
bucket_settings.flush_enabled = bucket.flush_enabled.value();
}
if (bucket.history_retention_bytes.has_value()) {
bucket_settings.history_retention_bytes = bucket.history_retention_bytes.value();
}
if (bucket.history_retention_duration.has_value()) {
bucket_settings.history_retention_duration = bucket.history_retention_duration.value();
}
switch (bucket.conflict_resolution_type) {
case core::management::cluster::bucket_conflict_resolution::unknown:
bucket_settings.conflict_resolution_type = management::cluster::bucket_conflict_resolution::unknown;
Expand Down
14 changes: 7 additions & 7 deletions core/management/bucket_settings.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ struct bucket_settings {

std::string name;
std::string uuid;
std::uint64_t ram_quota_mb{ 0 }; // If not explicitly set, defaults to 100 on create_bucket, unset on update_bucket
cluster::bucket_type bucket_type{ cluster::bucket_type::unknown };
std::uint64_t ram_quota_mb{ 100 };
std::uint32_t max_expiry{ 0 };
std::optional<std::uint32_t> max_expiry{};
bucket_compression compression_mode{ bucket_compression::unknown };
std::optional<couchbase::durability_level> minimum_durability_level{};
std::uint32_t num_replicas{ 1 };
bool replica_indexes{ false };
bool flush_enabled{ false };
std::optional<std::uint32_t> num_replicas{};
std::optional<bool> replica_indexes{};
std::optional<bool> flush_enabled{};
bucket_eviction_policy eviction_policy{ bucket_eviction_policy::unknown };
bucket_conflict_resolution conflict_resolution_type{ bucket_conflict_resolution::unknown };
std::optional<bool> history_retention_collection_default{};
std::uint32_t history_retention_bytes{ 0 };
std::uint32_t history_retention_duration{ 0 };
std::optional<std::uint32_t> history_retention_bytes;
std::optional<std::uint32_t> history_retention_duration{};

/**
* UNCOMMITTED: This API may change in the future
Expand Down
8 changes: 4 additions & 4 deletions core/management/bucket_settings_json.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ struct traits<couchbase::core::management::cluster::bucket_settings> {
result.uuid = v.at("uuid").get_string();
const static std::uint64_t megabyte = 1024LLU * 1024LLU;
result.ram_quota_mb = v.at("quota").at("rawRAM").get_unsigned() / megabyte;
result.num_replicas = v.at("replicaNumber").template as<std::uint32_t>();
result.num_replicas = v.at("replicaNumber").template as<std::optional<std::uint32_t>>();

if (auto* max_ttl = v.find("maxTTL"); max_ttl != nullptr) {
result.max_expiry = max_ttl->template as<std::uint32_t>();
result.max_expiry = max_ttl->template as<std::optional<std::uint32_t>>();
}

if (auto* history_retention_default = v.find("historyRetentionCollectionDefault"); history_retention_default != nullptr) {
result.history_retention_collection_default = history_retention_default->template as<std::optional<bool>>();
}
if (auto* history_retention_bytes = v.find("historyRetentionBytes"); history_retention_bytes != nullptr) {
result.history_retention_bytes = history_retention_bytes->template as<std::uint32_t>();
result.history_retention_bytes = history_retention_bytes->template as<std::optional<std::uint32_t>>();
}
if (auto* history_retention_duration = v.find("historyRetentionSeconds"); history_retention_duration != nullptr) {
result.history_retention_duration = history_retention_duration->template as<std::uint32_t>();
result.history_retention_duration = history_retention_duration->template as<std::optional<std::uint32_t>>();
}

if (auto& str = v.at("bucketType").get_string(); str == "couchbase" || str == "membase") {
Expand Down
34 changes: 21 additions & 13 deletions core/operations/management/bucket_create.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,35 @@ bucket_create_request::encode_to(encoded_request_type& encoded, http_context& /*
case couchbase::core::management::cluster::bucket_type::unknown:
break;
}
encoded.body.append(fmt::format("&ramQuotaMB={}", bucket.ram_quota_mb));
if (bucket.bucket_type != couchbase::core::management::cluster::bucket_type::memcached) {
encoded.body.append(fmt::format("&replicaNumber={}", bucket.num_replicas));
if (bucket.ram_quota_mb == 0) {
encoded.body.append(fmt::format("&ramQuotaMB={}", 100)); // If not explicitly set, set to prior default value of 100
} else {
encoded.body.append(fmt::format("&ramQuotaMB={}", bucket.ram_quota_mb));
}
if (bucket.max_expiry > 0) {
encoded.body.append(fmt::format("&maxTTL={}", bucket.max_expiry));

if (bucket.bucket_type != couchbase::core::management::cluster::bucket_type::memcached && bucket.num_replicas.has_value()) {
encoded.body.append(fmt::format("&replicaNumber={}", bucket.num_replicas.value()));
}
if (bucket.max_expiry.has_value()) {
encoded.body.append(fmt::format("&maxTTL={}", bucket.max_expiry.value()));
}
if (bucket.bucket_type != couchbase::core::management::cluster::bucket_type::ephemeral) {
encoded.body.append(fmt::format("&replicaIndex={}", bucket.replica_indexes ? "1" : "0"));
if (bucket.bucket_type != couchbase::core::management::cluster::bucket_type::ephemeral && bucket.replica_indexes.has_value()) {
encoded.body.append(fmt::format("&replicaIndex={}", bucket.replica_indexes.value() ? "1" : "0"));
}
if (bucket.history_retention_collection_default.has_value()) {
encoded.body.append(
fmt::format("&historyRetentionCollectionDefault={}", bucket.history_retention_collection_default.value() ? "true" : "false"));
}
if (bucket.history_retention_bytes > 0) {
encoded.body.append(fmt::format("&historyRetentionBytes={}", bucket.history_retention_bytes));
if (bucket.history_retention_bytes.has_value()) {
encoded.body.append(fmt::format("&historyRetentionBytes={}", bucket.history_retention_bytes.value()));
}
if (bucket.history_retention_duration > 0) {
encoded.body.append(fmt::format("&historyRetentionSeconds={}", bucket.history_retention_duration));
if (bucket.history_retention_duration.has_value()) {
encoded.body.append(fmt::format("&historyRetentionSeconds={}", bucket.history_retention_duration.value()));
}
encoded.body.append(fmt::format("&flushEnabled={}", bucket.flush_enabled ? "1" : "0"));
if (bucket.flush_enabled.has_value()) {
encoded.body.append(fmt::format("&flushEnabled={}", bucket.flush_enabled.value() ? "1" : "0"));
}

switch (bucket.eviction_policy) {
case couchbase::core::management::cluster::bucket_eviction_policy::full:
encoded.body.append("&evictionPolicy=fullEviction");
Expand Down Expand Up @@ -111,7 +119,7 @@ bucket_create_request::encode_to(encoded_request_type& encoded, http_context& /*
case couchbase::core::management::cluster::bucket_conflict_resolution::unknown:
break;
}
if (bucket.minimum_durability_level) {
if (bucket.minimum_durability_level.has_value()) {
switch (bucket.minimum_durability_level.value()) {
case durability_level::none:
encoded.body.append("&durabilityMinLevel=none");
Expand Down
31 changes: 21 additions & 10 deletions core/operations/management/bucket_update.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,34 @@ bucket_update_request::encode_to(encoded_request_type& encoded, http_context& /*
encoded.path = fmt::format("/pools/default/buckets/{}", bucket.name);

encoded.headers["content-type"] = "application/x-www-form-urlencoded";
encoded.body.append(fmt::format("&ramQuotaMB={}", bucket.ram_quota_mb));
encoded.body.append(fmt::format("&replicaNumber={}", bucket.num_replicas));
if (bucket.max_expiry > 0) {
encoded.body.append(fmt::format("&maxTTL={}", bucket.max_expiry));

if (bucket.ram_quota_mb > 0) {
encoded.body.append(fmt::format("&ramQuotaMB={}", bucket.ram_quota_mb));
}
if (bucket.num_replicas.has_value()) {
encoded.body.append(fmt::format("&replicaNumber={}", bucket.num_replicas.value()));
}

if (bucket.max_expiry.has_value()) {
encoded.body.append(fmt::format("&maxTTL={}", bucket.max_expiry.value()));
}
if (bucket.history_retention_collection_default.has_value()) {
encoded.body.append(
fmt::format("&historyRetentionCollectionDefault={}", bucket.history_retention_collection_default.value() ? "true" : "false"));
}
if (bucket.history_retention_bytes > 0) {
encoded.body.append(fmt::format("&historyRetentionBytes={}", bucket.history_retention_bytes));
if (bucket.history_retention_bytes.has_value()) {
encoded.body.append(fmt::format("&historyRetentionBytes={}", bucket.history_retention_bytes.value()));
}
if (bucket.history_retention_duration > 0) {
encoded.body.append(fmt::format("&historyRetentionSeconds={}", bucket.history_retention_duration));
if (bucket.history_retention_duration.has_value()) {
encoded.body.append(fmt::format("&historyRetentionSeconds={}", bucket.history_retention_duration.value()));
}
encoded.body.append(fmt::format("&replicaIndex={}", bucket.replica_indexes ? "1" : "0"));
encoded.body.append(fmt::format("&flushEnabled={}", bucket.flush_enabled ? "1" : "0"));
if (bucket.replica_indexes.has_value()) {
encoded.body.append(fmt::format("&replicaIndex={}", bucket.replica_indexes.value() ? "1" : "0"));
}
if (bucket.flush_enabled.has_value()) {
encoded.body.append(fmt::format("&flushEnabled={}", bucket.flush_enabled.value() ? "1" : "0"));
}

switch (bucket.eviction_policy) {
case couchbase::core::management::cluster::bucket_eviction_policy::full:
encoded.body.append("&evictionPolicy=fullEviction");
Expand Down
14 changes: 7 additions & 7 deletions couchbase/management/bucket_settings.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ struct bucket_settings {

std::string name;
cluster::bucket_type bucket_type{ cluster::bucket_type::unknown };
std::uint64_t ram_quota_mb{ 100 };
std::uint32_t max_expiry{ 0 };
std::uint64_t ram_quota_mb{ 0 };
std::optional<std::uint32_t> max_expiry{};
bucket_compression compression_mode{ bucket_compression::unknown };
std::optional<couchbase::durability_level> minimum_durability_level{};
std::uint32_t num_replicas{ 1 };
bool replica_indexes{ false };
bool flush_enabled{ false };
std::optional<std::uint32_t> num_replicas{};
std::optional<bool> replica_indexes{};
std::optional<bool> flush_enabled{};
bucket_eviction_policy eviction_policy{ bucket_eviction_policy::unknown };
bucket_conflict_resolution conflict_resolution_type{ bucket_conflict_resolution::unknown };
std::optional<bool> history_retention_collection_default{};
std::uint32_t history_retention_bytes{ 0 };
std::uint32_t history_retention_duration{ 0 };
std::optional<std::uint32_t> history_retention_bytes;
std::optional<std::uint32_t> history_retention_duration{};

/**
* UNCOMMITTED: This API may change in the future
Expand Down