Skip to content

Commit bdeb36d

Browse files
committed
PCBC-796: add storage backend option for bucket manager
Change-Id: If31dcaecd77b1f6aa4143a93389c848dd4c51d82 Reviewed-on: https://review.couchbase.org/c/php-couchbase/+/167049 Tested-by: Build Bot <[email protected]> Reviewed-by: Sergey Avseyev <[email protected]>
1 parent 45cab54 commit bdeb36d

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

api/couchbase.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,13 @@ interface EvictionPolicy
14041404
public const NOT_RECENTLY_USED = "nruEviction";
14051405
}
14061406

1407+
1408+
interface StorageBackend
1409+
{
1410+
public const COUCHSTORE = "couchstore";
1411+
public const MAGMA = "magma";
1412+
}
1413+
14071414
class BucketSettings
14081415
{
14091416
public function name(): string {}
@@ -1420,6 +1427,8 @@ public function bucketType(): string {}
14201427

14211428
public function evictionPolicy(): string {}
14221429

1430+
public function storageBackend(): string {}
1431+
14231432
public function maxTtl(): int {}
14241433

14251434
public function compressionMode(): string {}
@@ -1449,6 +1458,16 @@ public function setBucketType(string $type): BucketSettings {}
14491458
*/
14501459
public function setEvictionPolicy(string $policy): BucketSettings {}
14511460

1461+
/**
1462+
* Configures storage backend for the bucket.
1463+
*
1464+
* @param string $policy storage backend. Use constants COUCHSTORE, MAGMA.
1465+
*
1466+
* @see \StorageBackend::COUCHSTORE
1467+
* @see \StorageBackend::MAGMA
1468+
*/
1469+
public function setStorageBackend(string $policy): BucketSettings {}
1470+
14521471
public function setMaxTtl(int $ttlSeconds): BucketSettings {}
14531472

14541473
public function setCompressionMode(string $mode): BucketSettings {}

src/couchbase/managers/bucket_manager.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ static void httpcb_getBucket(void *ctx, zval *return_value, zval *response)
4949
if (mval && Z_TYPE_P(mval) == IS_STRING) {
5050
pcbc_update_property(pcbc_bucket_settings_ce, return_value, ("eviction_policy"), mval);
5151
}
52+
mval = zend_symtable_str_find(marr, ZEND_STRL("storageBackend"));
53+
if (mval && Z_TYPE_P(mval) == IS_STRING) {
54+
pcbc_update_property(pcbc_bucket_settings_ce, return_value, ("storage_backend"), mval);
55+
}
5256
mval = zend_symtable_str_find(marr, ZEND_STRL("maxTTL"));
5357
if (mval && Z_TYPE_P(mval) == IS_LONG) {
5458
pcbc_update_property(pcbc_bucket_settings_ce, return_value, ("max_ttl"), mval);
@@ -206,6 +210,10 @@ PHP_METHOD(BucketManager, createBucket)
206210
if (Z_TYPE_P(prop) == IS_STRING) {
207211
add_assoc_zval(&payload, "compressionMode", prop);
208212
}
213+
prop = pcbc_read_property(pcbc_bucket_settings_ce, settings, ("storage_backend"), 0, &ret);
214+
if (Z_TYPE_P(prop) == IS_STRING) {
215+
add_assoc_zval(&payload, "storageBackend", prop);
216+
}
209217
prop = pcbc_read_property(pcbc_bucket_settings_ce, settings, ("minimal_durability_level"), 0, &ret);
210218
if (Z_TYPE_P(prop) == IS_LONG) {
211219
switch (Z_LVAL_P(prop)) {
@@ -457,6 +465,9 @@ zend_function_entry bucket_settings_methods[] = {
457465
zend_class_entry *pcbc_eviction_policy_ce;
458466
static const zend_function_entry pcbc_eviction_policy_methods[] = {PHP_FE_END};
459467

468+
zend_class_entry *pcbc_storage_backend_ce;
469+
static const zend_function_entry pcbc_storage_backend_methods[] = {PHP_FE_END};
470+
460471
PHP_MINIT_FUNCTION(BucketManager)
461472
{
462473
zend_class_entry ce;
@@ -476,6 +487,7 @@ PHP_MINIT_FUNCTION(BucketManager)
476487
zend_declare_property_null(pcbc_bucket_settings_ce, ZEND_STRL("eviction_policy"), ZEND_ACC_PRIVATE);
477488
zend_declare_property_null(pcbc_bucket_settings_ce, ZEND_STRL("max_ttl"), ZEND_ACC_PRIVATE);
478489
zend_declare_property_null(pcbc_bucket_settings_ce, ZEND_STRL("compression_mode"), ZEND_ACC_PRIVATE);
490+
zend_declare_property_null(pcbc_bucket_settings_ce, ZEND_STRL("storage_backend"), ZEND_ACC_PRIVATE);
479491
zend_declare_property_null(pcbc_bucket_settings_ce, ZEND_STRL("minimal_durability_level"), ZEND_ACC_PRIVATE);
480492

481493
INIT_NS_CLASS_ENTRY(ce, "Couchbase", "EvictionPolicy", pcbc_eviction_policy_methods);
@@ -485,6 +497,11 @@ PHP_MINIT_FUNCTION(BucketManager)
485497
zend_declare_class_constant_stringl(pcbc_eviction_policy_ce, ZEND_STRL("NO_EVICTION"), ZEND_STRL("noEviction"));
486498
zend_declare_class_constant_stringl(pcbc_eviction_policy_ce, ZEND_STRL("NOT_RECENTLY_USED"),
487499
ZEND_STRL("nruEviction"));
500+
501+
INIT_NS_CLASS_ENTRY(ce, "Couchbase", "StorageBackend", pcbc_storage_backend_methods);
502+
pcbc_storage_backend_ce = zend_register_internal_interface(&ce);
503+
zend_declare_class_constant_stringl(pcbc_storage_backend_ce, ZEND_STRL("COUCHSTORE"), ZEND_STRL("couchstore"));
504+
zend_declare_class_constant_stringl(pcbc_storage_backend_ce, ZEND_STRL("MAGMA"), ZEND_STRL("magma"));
488505
return SUCCESS;
489506
}
490507

@@ -642,6 +659,28 @@ PHP_METHOD(BucketSettings, setEvictionPolicy)
642659
RETURN_ZVAL(getThis(), 1, 0);
643660
}
644661

662+
PHP_METHOD(BucketSettings, storageBackend)
663+
{
664+
if (zend_parse_parameters_none_throw() == FAILURE) {
665+
RETURN_NULL();
666+
}
667+
668+
zval *prop, rv;
669+
prop = pcbc_read_property(pcbc_bucket_settings_ce, getThis(), ("storage_backend"), 0, &rv);
670+
ZVAL_COPY(return_value, prop);
671+
}
672+
673+
PHP_METHOD(BucketSettings, setStorageBackend)
674+
{
675+
zend_string *val;
676+
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "S", &val) == FAILURE) {
677+
RETURN_NULL();
678+
}
679+
680+
pcbc_update_property_str(pcbc_bucket_settings_ce, getThis(), ("storage_backend"), val);
681+
RETURN_ZVAL(getThis(), 1, 0);
682+
}
683+
645684
PHP_METHOD(BucketSettings, maxTtl)
646685
{
647686
if (zend_parse_parameters_none_throw() == FAILURE) {

0 commit comments

Comments
 (0)