Skip to content

Commit 8ff842c

Browse files
committed
added support for minReplicationFactor
1 parent a384df6 commit 8ff842c

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Added support for the following attributes on collection level:
1111

1212
- distributeShardsLike
1313
- smartJoinAttribute (only effective in ArangoDB enterprise edition)
14+
- minReplicationFactor
1415

1516
Removed unused `$_action` member in class `AqlUserFunction`, also
1617
removed its `__toString()` method.

lib/ArangoDBClient/Collection.php

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ class Collection
9090
*/
9191
private $_replicationFactor;
9292

93+
/**
94+
* The minimum replicationFactor value for writes to be successful
95+
*
96+
* @var mixed - minimum replicationFactor value
97+
*/
98+
private $_minReplicationFactor;
99+
93100
/**
94101
* The shardingStrategy value (might be NULL for new collections)
95102
*
@@ -185,6 +192,11 @@ class Collection
185192
*/
186193
const ENTRY_REPLICATION_FACTOR = 'replicationFactor';
187194

195+
/**
196+
* Collection 'minReplicationFactor' index
197+
*/
198+
const ENTRY_MIN_REPLICATION_FACTOR = 'minReplicationFactor';
199+
188200
/**
189201
* Collection 'shardingStrategy' index
190202
*/
@@ -304,6 +316,7 @@ public function __clone()
304316
$this->_distributeShardsLike = null;
305317
$this->_numberOfShards = null;
306318
$this->_replicationFactor = null;
319+
$this->_minReplicationFactor = null;
307320
$this->_shardingStrategy = null;
308321
$this->_shardKeys = null;
309322
$this->_smartJoinAttribute = null;
@@ -374,6 +387,10 @@ public function getAll()
374387
$result[self::ENTRY_REPLICATION_FACTOR] = $this->_replicationFactor;
375388
}
376389

390+
if (null !== $this->_minReplicationFactor) {
391+
$result[self::ENTRY_MIN_REPLICATION_FACTOR] = $this->_minReplicationFactor;
392+
}
393+
377394
if (null !== $this->_shardingStrategy) {
378395
$result[self::ENTRY_SHARDING_STRATEGY] = $this->_shardingStrategy;
379396
}
@@ -470,6 +487,11 @@ public function set($key, $value)
470487
return;
471488
}
472489

490+
if ($key === self::ENTRY_MIN_REPLICATION_FACTOR) {
491+
$this->setMinReplicationFactor($value);
492+
return;
493+
}
494+
473495
if ($key === self::ENTRY_SHARDING_STRATEGY) {
474496
$this->setShardingStrategy($value);
475497
return;
@@ -807,7 +829,7 @@ public function getNumberOfShards()
807829
/**
808830
* Set the replicationFactor value
809831
*
810-
* @param int $value - replicationFactor value
832+
* @param mixed $value - replicationFactor value (either a number, or "satellite")
811833
*
812834
* @return void
813835
*/
@@ -828,7 +850,30 @@ public function getReplicationFactor()
828850
}
829851

830852
/**
831-
* Set the shardingStragy value
853+
* Set the minReplicationFactor value
854+
*
855+
* @param int $value - minReplicationFactor value
856+
*
857+
* @return void
858+
*/
859+
public function setMinReplicationFactor($value)
860+
{
861+
assert(null === $value || is_numeric($value));
862+
$this->_minReplicationFactor = $value;
863+
}
864+
865+
/**
866+
* Get the minReplicationFactor value (if already known)
867+
*
868+
* @return mixed - minReplicationFactor value
869+
*/
870+
public function getMinReplicationFactor()
871+
{
872+
return $this->_minReplicationFactor;
873+
}
874+
875+
/**
876+
* Set the shardingStrategy value
832877
*
833878
* @param string $value - shardingStrategy value
834879
*

lib/ArangoDBClient/CollectionHandler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ class CollectionHandler extends Handler
238238
* <li>'distributeShardsLike' - name of prototype collection for identical sharding.</li>
239239
* <li>'numberOfShards' - number of shards for the collection.</li>
240240
* <li>'replicationFactor' - number of replicas to keep (default: 1).</li>
241+
* <li>'minReplicationFactor' - minimum number of replicas to be successful when writing (default: 1).</li>
241242
* <li>'shardKeys' - array of shard key attributes.</li>
242243
* <li>'shardingStrategy' - sharding strategy to use in cluster.</li>
243244
* <li>'smartJoinAttribute' - attribute name for smart joins (if not shard key).</li>
@@ -295,6 +296,10 @@ public function create($collection, array $options = [])
295296
$params[Collection::ENTRY_REPLICATION_FACTOR] = $collection->getReplicationFactor();
296297
}
297298

299+
if ($collection->getMinReplicationFactor() !== null) {
300+
$params[Collection::ENTRY_MIN_REPLICATION_FACTOR] = $collection->getMinReplicationFactor();
301+
}
302+
298303
if ($collection->getShardingStrategy() !== null) {
299304
$params[Collection::ENTRY_SHARDING_STRATEGY] = $collection->getShardingStrategy();
300305
}

tests/CollectionBasicTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ public function testCreateCollectionWithReplicationFactor1()
314314
}
315315

316316
$collection->setName($name);
317+
$collection->setMinReplicationFactor(1);
317318
$collection->setReplicationFactor(1);
318319

319320
$response = $collectionHandler->create($collection);
@@ -322,6 +323,7 @@ public function testCreateCollectionWithReplicationFactor1()
322323
$properties = $resultingCollection->getAll();
323324

324325
static::assertEquals(1, $properties[Collection::ENTRY_REPLICATION_FACTOR]);
326+
static::assertEquals(1, $properties[Collection::ENTRY_MIN_REPLICATION_FACTOR]);
325327
}
326328

327329

@@ -349,6 +351,7 @@ public function testCreateCollectionWithReplicationFactor2()
349351
}
350352

351353
$collection->setName($name);
354+
$collection->setMinReplicationFactor(2);
352355
$collection->setReplicationFactor(2);
353356

354357
$response = $collectionHandler->create($collection);
@@ -357,6 +360,7 @@ public function testCreateCollectionWithReplicationFactor2()
357360
$properties = $resultingCollection->getAll();
358361

359362
static::assertEquals(2, $properties[Collection::ENTRY_REPLICATION_FACTOR]);
363+
static::assertEquals(2, $properties[Collection::ENTRY_MIN_REPLICATION_FACTOR]);
360364
}
361365

362366
/**
@@ -397,6 +401,7 @@ public function testCreateCollectionWithReplicationFactorSatellite()
397401
$properties = $resultingCollection->getAll();
398402

399403
static::assertEquals("satellite", $properties[Collection::ENTRY_REPLICATION_FACTOR]);
404+
static::assertEquals(0, $properties[Collection::ENTRY_MIN_REPLICATION_FACTOR]);
400405
}
401406

402407

0 commit comments

Comments
 (0)