Skip to content

RCBC-510: Add BucketSettings#num_vbuckets #174

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
merged 2 commits into from
Apr 2, 2025
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
2 changes: 1 addition & 1 deletion ext/couchbase
26 changes: 26 additions & 0 deletions ext/rcb_buckets.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ cb_generate_bucket_settings(VALUE bucket,
}
}

if (VALUE num_vbuckets = rb_hash_aref(bucket, rb_id2sym(rb_intern("num_vbuckets")));
!NIL_P(num_vbuckets)) {
if (TYPE(num_vbuckets) == T_FIXNUM) {
entry.num_vbuckets = FIX2UINT(num_vbuckets);
} else {
throw ruby_exception(
rb_eArgError,
rb_sprintf("num vbuckets must be an Integer, given %+" PRIsVALUE, num_vbuckets));
}
}

if (is_create) {
if (VALUE conflict_resolution_type =
rb_hash_aref(bucket, rb_id2sym(rb_intern("conflict_resolution_type")));
Expand Down Expand Up @@ -506,6 +517,18 @@ cb_extract_bucket_settings(const core::management::cluster::bucket_settings& ent
break;
}
}
switch (entry.storage_backend) {
case core::management::cluster::bucket_storage_backend::couchstore:
rb_hash_aset(
bucket, rb_id2sym(rb_intern("storage_backend")), rb_id2sym(rb_intern("couchstore")));
break;
case core::management::cluster::bucket_storage_backend::magma:
rb_hash_aset(bucket, rb_id2sym(rb_intern("storage_backend")), rb_id2sym(rb_intern("magma")));
break;
case core::management::cluster::bucket_storage_backend::unknown:
rb_hash_aset(bucket, rb_id2sym(rb_intern("storage_backend")), Qnil);
break;
}
if (entry.history_retention_collection_default.has_value()) {
rb_hash_aset(bucket,
rb_id2sym(rb_intern("history_retention_collection_default")),
Expand All @@ -518,6 +541,9 @@ cb_extract_bucket_settings(const core::management::cluster::bucket_settings& ent
rb_hash_aset(
bucket, rb_id2sym(rb_intern("history_retention_duration")), ULONG2NUM(val.value()));
}
if (const auto& val = entry.num_vbuckets; val.has_value()) {
rb_hash_aset(bucket, rb_id2sym(rb_intern("num_vbuckets")), USHORT2NUM(val.value()));
}

VALUE capabilities = rb_ary_new_capa(static_cast<long>(entry.capabilities.size()));
for (const auto& capa : entry.capabilities) {
Expand Down
10 changes: 8 additions & 2 deletions lib/couchbase/management/bucket_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ def initialize(backend)
def create_bucket(settings, options = Options::Bucket::CreateBucket.new)
@backend.bucket_create(
{

name: settings.name,
flush_enabled: settings.flush_enabled,
ram_quota_mb: settings.ram_quota_mb,
Expand All @@ -222,6 +221,7 @@ def create_bucket(settings, options = Options::Bucket::CreateBucket.new)
history_retention_collection_default: settings.history_retention_collection_default,
history_retention_duration: settings.history_retention_duration,
history_retention_bytes: settings.history_retention_bytes,
num_vbuckets: settings.num_vbuckets,
}, options.to_backend
)
end
Expand Down Expand Up @@ -252,6 +252,7 @@ def update_bucket(settings, options = Options::Bucket::UpdateBucket.new)
history_retention_collection_default: settings.history_retention_collection_default,
history_retention_bytes: settings.history_retention_bytes,
history_retention_duration: settings.history_retention_duration,
num_vbuckets: settings.num_vbuckets,
}, options.to_backend
)
end
Expand Down Expand Up @@ -342,9 +343,11 @@ def extract_bucket_settings(entry)
bucket.minimum_durability_level = entry[:minimum_durability_level]
bucket.compression_mode = entry[:compression_mode]
bucket.instance_variable_set(:@healthy, entry[:nodes].all? { |node| node[:status] == "healthy" })
bucket.storage_backend = entry[:storage_backend]
bucket.history_retention_collection_default = entry[:history_retention_collection_default]
bucket.history_retention_bytes = entry[:history_retention_bytes]
bucket.history_retention_duration = entry[:history_retention_duration]
bucket.num_vbuckets = entry[:num_vbuckets]
end
end
end
Expand Down Expand Up @@ -405,7 +408,7 @@ class BucketSettings
# @return [nil, :none, :majority, :majority_and_persist_to_active, :persist_to_majority] the minimum durability level
attr_accessor :minimum_durability_level

# @return [Boolean, nil] whether to enable history retention on collections by default
# @return [Boolean, nil] whether to enable history retention on collections by default
attr_accessor :history_retention_collection_default

# @return [Integer, nil] the maximum size, in bytes, of the change history that is written to disk for all
Expand All @@ -416,6 +419,9 @@ class BucketSettings
# collections in this bucket
attr_accessor :history_retention_duration

# @return [Integer, nil] the number of vBuckets the bucket should have. If not set, the server default will be used
attr_accessor :num_vbuckets

# @api private
# @return [Boolean] false if status of the bucket is not healthy
def healthy?
Expand Down
Loading