Skip to content

Commit 262c681

Browse files
committed
Update bucket settings to be compatible with dp9 and not set defaults for optional fields
1 parent ab1b94d commit 262c681

File tree

3 files changed

+26
-34
lines changed

3 files changed

+26
-34
lines changed

ext/couchbase.cxx

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4370,18 +4370,20 @@ cb_Backend_document_query(VALUE self, VALUE statement, VALUE options)
43704370
static void
43714371
cb_generate_bucket_settings(VALUE bucket, couchbase::core::management::cluster::bucket_settings& entry, bool is_create)
43724372
{
4373-
if (VALUE bucket_type = rb_hash_aref(bucket, rb_id2sym(rb_intern("bucket_type"))); TYPE(bucket_type) == T_SYMBOL) {
4374-
if (bucket_type == rb_id2sym(rb_intern("couchbase")) || bucket_type == rb_id2sym(rb_intern("membase"))) {
4375-
entry.bucket_type = couchbase::core::management::cluster::bucket_type::couchbase;
4376-
} else if (bucket_type == rb_id2sym(rb_intern("memcached"))) {
4377-
entry.bucket_type = couchbase::core::management::cluster::bucket_type::memcached;
4378-
} else if (bucket_type == rb_id2sym(rb_intern("ephemeral"))) {
4379-
entry.bucket_type = couchbase::core::management::cluster::bucket_type::ephemeral;
4373+
if (VALUE bucket_type = rb_hash_aref(bucket, rb_id2sym(rb_intern("bucket_type"))); !NIL_P(bucket_type)) {
4374+
if (TYPE(bucket_type) == T_SYMBOL) {
4375+
if (bucket_type == rb_id2sym(rb_intern("couchbase")) || bucket_type == rb_id2sym(rb_intern("membase"))) {
4376+
entry.bucket_type = couchbase::core::management::cluster::bucket_type::couchbase;
4377+
} else if (bucket_type == rb_id2sym(rb_intern("memcached"))) {
4378+
entry.bucket_type = couchbase::core::management::cluster::bucket_type::memcached;
4379+
} else if (bucket_type == rb_id2sym(rb_intern("ephemeral"))) {
4380+
entry.bucket_type = couchbase::core::management::cluster::bucket_type::ephemeral;
4381+
} else {
4382+
throw ruby_exception(rb_eArgError, rb_sprintf("unknown bucket type, given %+" PRIsVALUE, bucket_type));
4383+
}
43804384
} else {
4381-
throw ruby_exception(rb_eArgError, rb_sprintf("unknown bucket type, given %+" PRIsVALUE, bucket_type));
4385+
throw ruby_exception(rb_eArgError, rb_sprintf("bucket type must be a Symbol, given %+" PRIsVALUE, bucket_type));
43824386
}
4383-
} else {
4384-
throw ruby_exception(rb_eArgError, rb_sprintf("bucket type must be a Symbol, given %+" PRIsVALUE, bucket_type));
43854387
}
43864388

43874389
if (VALUE name = rb_hash_aref(bucket, rb_id2sym(rb_intern("name"))); TYPE(name) == T_STRING) {
@@ -4390,10 +4392,12 @@ cb_generate_bucket_settings(VALUE bucket, couchbase::core::management::cluster::
43904392
throw ruby_exception(rb_eArgError, rb_sprintf("bucket name must be a String, given %+" PRIsVALUE, name));
43914393
}
43924394

4393-
if (VALUE quota = rb_hash_aref(bucket, rb_id2sym(rb_intern("ram_quota_mb"))); TYPE(quota) == T_FIXNUM) {
4394-
entry.ram_quota_mb = FIX2ULONG(quota);
4395-
} else {
4396-
throw ruby_exception(rb_eArgError, rb_sprintf("bucket RAM quota must be an Integer, given %+" PRIsVALUE, quota));
4395+
if (VALUE quota = rb_hash_aref(bucket, rb_id2sym(rb_intern("ram_quota_mb"))); !NIL_P(quota)) {
4396+
if (TYPE(quota) == T_FIXNUM) {
4397+
entry.ram_quota_mb = FIX2ULONG(quota);
4398+
} else {
4399+
throw ruby_exception(rb_eArgError, rb_sprintf("bucket RAM quota must be an Integer, given %+" PRIsVALUE, quota));
4400+
}
43974401
}
43984402

43994403
if (VALUE expiry = rb_hash_aref(bucket, rb_id2sym(rb_intern("max_expiry"))); !NIL_P(expiry)) {
@@ -4699,8 +4703,12 @@ cb_extract_bucket_settings(const couchbase::core::management::cluster::bucket_se
46994703
if (const auto &val = entry.num_replicas; val.has_value()) {
47004704
rb_hash_aset(bucket, rb_id2sym(rb_intern("num_replicas")), ULONG2NUM(val.value()));
47014705
}
4702-
rb_hash_aset(bucket, rb_id2sym(rb_intern("replica_indexes")), entry.replica_indexes ? Qtrue : Qfalse);
4703-
rb_hash_aset(bucket, rb_id2sym(rb_intern("flush_enabled")), entry.flush_enabled ? Qtrue : Qfalse);
4706+
if (const auto &val = entry.replica_indexes; val.has_value()) {
4707+
rb_hash_aset(bucket, rb_id2sym(rb_intern("replica_indexes")), val.value() ? Qtrue : Qfalse);
4708+
}
4709+
if (const auto &val = entry.flush_enabled; val.has_value()) {
4710+
rb_hash_aset(bucket, rb_id2sym(rb_intern("flush_enabled")), val.value() ? Qtrue : Qfalse);
4711+
}
47044712
switch (entry.eviction_policy) {
47054713
case couchbase::core::management::cluster::bucket_eviction_policy::full:
47064714
rb_hash_aset(bucket, rb_id2sym(rb_intern("eviction_policy")), rb_id2sym(rb_intern("full")));

lib/couchbase/management/bucket_manager.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -436,22 +436,6 @@ def ejection_policy=(val)
436436

437437
# @yieldparam [BucketSettings] self
438438
def initialize
439-
@bucket_type = :couchbase
440-
@name = nil
441-
@minimum_durability_level = nil
442-
@healthy = true
443-
@flush_enabled = false
444-
@ram_quota_mb = 100
445-
@num_replicas = 1
446-
@replica_indexes = false
447-
@max_expiry = 0
448-
@compression_mode = :passive
449-
@conflict_resolution_type = :sequence_number
450-
@eviction_policy = :value_only
451-
@storage_backend = nil
452-
@history_retention_collection_default = nil
453-
@history_retention_bytes = nil
454-
@history_retention_duration = nil
455439
yield self if block_given?
456440
end
457441
end

test/bucket_manager_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ def test_update_bucket_history_retention_unsupported
124124
res = @bucket_manager.get_bucket(bucket_name)
125125

126126
assert_nil res.history_retention_collection_default
127-
assert_equal 0, res.history_retention_bytes
128-
assert_equal 0, res.history_retention_duration
127+
assert_nil res.history_retention_bytes
128+
assert_nil res.history_retention_duration
129129

130130
assert_raises(Error::InvalidArgument) do
131131
@bucket_manager.update_bucket(

0 commit comments

Comments
 (0)