Skip to content

Commit bf82cdb

Browse files
committed
RCBC-510: Add BucketSettings#num_vbuckets
1 parent caf2d9f commit bf82cdb

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

ext/couchbase

ext/rcb_buckets.cxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,17 @@ cb_generate_bucket_settings(VALUE bucket,
232232
}
233233
}
234234

235+
if (VALUE num_vbuckets = rb_hash_aref(bucket, rb_id2sym(rb_intern("num_vbuckets")));
236+
!NIL_P(num_vbuckets)) {
237+
if (TYPE(num_vbuckets) == T_FIXNUM) {
238+
entry.num_vbuckets = FIX2UINT(num_vbuckets);
239+
} else {
240+
throw ruby_exception(
241+
rb_eArgError,
242+
rb_sprintf("num vbuckets must be an Integer, given %+" PRIsVALUE, num_vbuckets));
243+
}
244+
}
245+
235246
if (is_create) {
236247
if (VALUE conflict_resolution_type =
237248
rb_hash_aref(bucket, rb_id2sym(rb_intern("conflict_resolution_type")));
@@ -530,6 +541,9 @@ cb_extract_bucket_settings(const core::management::cluster::bucket_settings& ent
530541
rb_hash_aset(
531542
bucket, rb_id2sym(rb_intern("history_retention_duration")), ULONG2NUM(val.value()));
532543
}
544+
if (const auto& val = entry.num_vbuckets; val.has_value()) {
545+
rb_hash_aset(bucket, rb_id2sym(rb_intern("num_vbuckets")), USHORT2NUM(val.value()));
546+
}
533547

534548
VALUE capabilities = rb_ary_new_capa(static_cast<long>(entry.capabilities.size()));
535549
for (const auto& capa : entry.capabilities) {

lib/couchbase/management/bucket_manager.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def create_bucket(settings, options = Options::Bucket::CreateBucket.new)
221221
history_retention_collection_default: settings.history_retention_collection_default,
222222
history_retention_duration: settings.history_retention_duration,
223223
history_retention_bytes: settings.history_retention_bytes,
224+
num_vbuckets: settings.num_vbuckets,
224225
}, options.to_backend
225226
)
226227
end
@@ -251,6 +252,7 @@ def update_bucket(settings, options = Options::Bucket::UpdateBucket.new)
251252
history_retention_collection_default: settings.history_retention_collection_default,
252253
history_retention_bytes: settings.history_retention_bytes,
253254
history_retention_duration: settings.history_retention_duration,
255+
num_vbuckets: settings.num_vbuckets,
254256
}, options.to_backend
255257
)
256258
end
@@ -345,6 +347,7 @@ def extract_bucket_settings(entry)
345347
bucket.history_retention_collection_default = entry[:history_retention_collection_default]
346348
bucket.history_retention_bytes = entry[:history_retention_bytes]
347349
bucket.history_retention_duration = entry[:history_retention_duration]
350+
bucket.num_vbuckets = entry[:num_vbuckets]
348351
end
349352
end
350353
end
@@ -405,7 +408,7 @@ class BucketSettings
405408
# @return [nil, :none, :majority, :majority_and_persist_to_active, :persist_to_majority] the minimum durability level
406409
attr_accessor :minimum_durability_level
407410

408-
# @return [Boolean, nil] whether to enable history retention on collections by default
411+
# @return [Boolean, nil] whether to enable history retention on collections by default
409412
attr_accessor :history_retention_collection_default
410413

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

422+
# @return [Integer, nil] the number of vBuckets the bucket should have. If not set, the server default will be used
423+
attr_accessor :num_vbuckets
424+
419425
# @api private
420426
# @return [Boolean] false if status of the bucket is not healthy
421427
def healthy?

0 commit comments

Comments
 (0)