Skip to content

Commit 5c463fb

Browse files
committed
PYCBC-1667: Update Bucket & Storage Support in SDKs
Motivation ========== The server is adding support for creating Magma buckets with 128 vBuckets. We are adding a numVBuckets parameter to bucket_settings to allow configuring the number of vbuckets. Changes ======= Add numVBuckets to BucketSettings Results ======= All relevant FIT tests pass Change-Id: Ibbfec1baec8e0ff6067c6236e419671c0159d5c6 Reviewed-on: https://review.couchbase.org/c/couchbase-python-client/+/226147 Tested-by: Build Bot <build@couchbase.com> Reviewed-by: Jared Casey <jared.casey@couchbase.com>
1 parent db9e015 commit 5c463fb

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

couchbase/management/logic/buckets_logic.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ class BucketSettings(dict):
411411
BidirectionalTransform("history_retention_duration",
412412
ParamTransform("historyRetentionDuration", TimeDeltaToSeconds(int)),
413413
ParamTransform("historyRetentionDuration", SecondsToTimeDelta(timedelta))),
414+
BidirectionalTransform("num_vbuckets",
415+
ParamTransform("numVBuckets", Identity(int)),
416+
ParamTransform("numVBuckets", Identity(int))),
414417
])
415418

416419
@overload
@@ -429,7 +432,8 @@ def __init__(self,
429432
storage_backend=None, # type: StorageBackend
430433
history_retention_collection_default=None, # type: Optional[bool]
431434
history_retention_bytes=None, # type: int
432-
history_retention_duration=None # type: timedelta
435+
history_retention_duration=None, # type: timedelta
436+
num_vbuckets=None # type: int
433437
):
434438
# type: (...) -> None
435439
"""BucketSettings provides a means of mapping bucket settings into an object.
@@ -540,6 +544,13 @@ def history_retention_duration(self) -> Optional[timedelta]:
540544
"""
541545
return self.get('history_retention_duration')
542546

547+
@property
548+
def num_vbuckets(self) -> Optional[int]:
549+
"""
550+
The number of vBuckets in this bucket
551+
"""
552+
return self.get('num_vbuckets')
553+
543554
def transform_to_dest(self) -> Dict[str, Any]:
544555
kwargs = {**self}
545556
# needed?
@@ -577,7 +588,8 @@ def __init__(self, # nosec
577588
storage_backend=None, # type: StorageBackend
578589
history_retention_collection_default=None, # type: Optional[bool]
579590
history_retention_bytes=None, # type: int
580-
history_retention_duration=None # type: timedelta
591+
history_retention_duration=None, # type: timedelta
592+
num_vbuckets=None # type: int
581593
):
582594
"""
583595
Bucket creation settings.
@@ -600,6 +612,7 @@ def __init__(self, # nosec
600612
written to disk for all collections in this bucket
601613
:param history_retention_duration: specifies the maximum duration to be covered by the change history that
602614
is written to disk for all collections in this bucket
615+
:param num_vbuckets: specifies the number of vBuckets in the bucket.
603616
604617
.. note::
605618
History retention settings are only supported for Magma buckets, the server will ignore retention settings

src/management/bucket_management.cxx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,16 @@ build_bucket_settings(couchbase::core::management::cluster::bucket_settings sett
295295
Py_DECREF(pyObj_tmp);
296296
}
297297

298+
if (settings.num_vbuckets.has_value()) {
299+
pyObj_tmp = PyLong_FromUnsignedLong(settings.num_vbuckets.value());
300+
if (-1 == PyDict_SetItemString(pyObj_bucket_settings, "numVBuckets", pyObj_tmp)) {
301+
Py_DECREF(pyObj_bucket_settings);
302+
Py_XDECREF(pyObj_tmp);
303+
return nullptr;
304+
}
305+
Py_DECREF(pyObj_tmp);
306+
}
307+
298308
return pyObj_bucket_settings;
299309
}
300310

@@ -721,6 +731,11 @@ get_bucket_settings(PyObject* settings)
721731
static_cast<uint32_t>(PyLong_AsUnsignedLong(pyObj_history_retention_duration));
722732
}
723733

734+
PyObject* pyObj_num_vbuckets = PyDict_GetItemString(settings, "numVBuckets");
735+
if (pyObj_num_vbuckets != nullptr) {
736+
bucket_settings.num_vbuckets = static_cast<uint16_t>(PyLong_AsUnsignedLong(pyObj_num_vbuckets));
737+
}
738+
724739
return bucket_settings;
725740
}
726741

0 commit comments

Comments
 (0)