Skip to content

Commit 4104cc3

Browse files
authored
Configure collection properties: add support for replicationFactor + writeConcern (#193)
* add replicationFactor + writeConcern * fix formatting * add graph properties
1 parent 52d5c1b commit 4104cc3

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

arango/collection.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,33 @@ def response_handler(resp: Response) -> Json:
301301
return self._execute(request, response_handler)
302302

303303
def configure(
304-
self, sync: Optional[bool] = None, schema: Optional[Json] = None
304+
self,
305+
sync: Optional[bool] = None,
306+
schema: Optional[Json] = None,
307+
replication_factor: Optional[int] = None,
308+
write_concern: Optional[int] = None,
305309
) -> Result[Json]:
306310
"""Configure collection properties.
307311
308312
:param sync: Block until operations are synchronized to disk.
309313
:type sync: bool | None
310314
:param schema: document schema for validation of objects.
311315
:type schema: dict
316+
:param replication_factor: Number of copies of each shard on different
317+
servers in a cluster. Allowed values are 1 (only one copy is kept
318+
and no synchronous replication), and n (n-1 replicas are kept and
319+
any two copies are replicated across servers synchronously, meaning
320+
every write to the master is copied to all slaves before operation
321+
is reported successful).
322+
:type replication_factor: int
323+
:param write_concern: Write concern for the collection. Determines how
324+
many copies of each shard are required to be in sync on different
325+
DBServers. If there are less than these many copies in the cluster
326+
a shard will refuse to write. Writes to shards with enough
327+
up-to-date copies will succeed at the same time. The value of this
328+
parameter cannot be larger than that of **replication_factor**.
329+
Default value is 1. Used for clusters only.
330+
:type write_concern: int
312331
:return: New collection properties.
313332
:rtype: dict
314333
:raise arango.exceptions.CollectionConfigureError: If operation fails.
@@ -318,6 +337,10 @@ def configure(
318337
data["waitForSync"] = sync
319338
if schema is not None:
320339
data["schema"] = schema
340+
if replication_factor is not None:
341+
data["replicationFactor"] = replication_factor
342+
if write_concern is not None:
343+
data["writeConcern"] = write_concern
321344

322345
request = Request(
323346
method="put",

arango/database.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,8 +1165,11 @@ def create_graph(
11651165
edge_definitions: Optional[Sequence[Json]] = None,
11661166
orphan_collections: Optional[Sequence[str]] = None,
11671167
smart: Optional[bool] = None,
1168+
disjoint: Optional[bool] = None,
11681169
smart_field: Optional[str] = None,
11691170
shard_count: Optional[int] = None,
1171+
replication_factor: Optional[int] = None,
1172+
write_concern: Optional[int] = None,
11701173
) -> Result[Graph]:
11711174
"""Create a new graph.
11721175
@@ -1184,6 +1187,10 @@ def create_graph(
11841187
**smart_field** below). Applies only to enterprise version of
11851188
ArangoDB.
11861189
:type smart: bool | None
1190+
:param disjoint: If set to True, create a disjoint SmartGraph instead
1191+
of a regular SmartGraph. Applies only to enterprise version of
1192+
ArangoDB.
1193+
:type disjoint: bool | None
11871194
:param smart_field: Document field used to shard the vertices of the
11881195
graph. To use this, parameter **smart** must be set to True and
11891196
every vertex in the graph must have the smart field. Applies only
@@ -1195,6 +1202,21 @@ def create_graph(
11951202
cannot be modified later once set. Applies only to enterprise
11961203
version of ArangoDB.
11971204
:type shard_count: int | None
1205+
:param replication_factor: Number of copies of each shard on different
1206+
servers in a cluster. Allowed values are 1 (only one copy is kept
1207+
and no synchronous replication), and n (n-1 replicas are kept and
1208+
any two copies are replicated across servers synchronously, meaning
1209+
every write to the master is copied to all slaves before operation
1210+
is reported successful).
1211+
:type replication_factor: int
1212+
:param write_concern: Write concern for the collection. Determines how
1213+
many copies of each shard are required to be in sync on different
1214+
DBServers. If there are less than these many copies in the cluster
1215+
a shard will refuse to write. Writes to shards with enough
1216+
up-to-date copies will succeed at the same time. The value of this
1217+
parameter cannot be larger than that of **replication_factor**.
1218+
Default value is 1. Used for clusters only.
1219+
:type write_concern: int
11981220
:return: Graph API wrapper.
11991221
:rtype: arango.graph.Graph
12001222
:raise arango.exceptions.GraphCreateError: If create fails.
@@ -1223,10 +1245,16 @@ def create_graph(
12231245
data["orphanCollections"] = orphan_collections
12241246
if smart is not None: # pragma: no cover
12251247
data["isSmart"] = smart
1248+
if disjoint is not None: # pragma: no cover
1249+
data["isDisjoint"] = disjoint
12261250
if smart_field is not None: # pragma: no cover
12271251
data["options"]["smartGraphAttribute"] = smart_field
12281252
if shard_count is not None: # pragma: no cover
12291253
data["options"]["numberOfShards"] = shard_count
1254+
if replication_factor is not None: # pragma: no cover
1255+
data["options"]["replicationFactor"] = replication_factor
1256+
if write_concern is not None: # pragma: no cover
1257+
data["options"]["writeConcern"] = write_concern
12301258

12311259
request = Request(method="post", endpoint="/_api/gharial", data=data)
12321260

0 commit comments

Comments
 (0)