From faef66150c5928c6abce08ff2d2a6b4dccd1926c Mon Sep 17 00:00:00 2001 From: max Date: Tue, 1 Feb 2022 17:40:26 +0100 Subject: [PATCH 1/3] add replicationFactor + writeConcern --- arango/collection.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/arango/collection.py b/arango/collection.py index 1d53b06e..6fdc556b 100644 --- a/arango/collection.py +++ b/arango/collection.py @@ -301,7 +301,11 @@ def response_handler(resp: Response) -> Json: return self._execute(request, response_handler) def configure( - self, sync: Optional[bool] = None, schema: Optional[Json] = None + self, + sync: Optional[bool] = None, + schema: Optional[Json] = None, + replication_factor: Optional[int] = None, + write_concern: Optional[int] = None ) -> Result[Json]: """Configure collection properties. @@ -309,6 +313,21 @@ def configure( :type sync: bool | None :param schema: document schema for validation of objects. :type schema: dict + :param replication_factor: Number of copies of each shard on different + servers in a cluster. Allowed values are 1 (only one copy is kept + and no synchronous replication), and n (n-1 replicas are kept and + any two copies are replicated across servers synchronously, meaning + every write to the master is copied to all slaves before operation + is reported successful). + :type replication_factor: int + :param write_concern: Write concern for the collection. Determines how + many copies of each shard are required to be in sync on different + DBServers. If there are less than these many copies in the cluster + a shard will refuse to write. Writes to shards with enough + up-to-date copies will succeed at the same time. The value of this + parameter cannot be larger than that of **replication_factor**. + Default value is 1. Used for clusters only. + :type write_concern: int :return: New collection properties. :rtype: dict :raise arango.exceptions.CollectionConfigureError: If operation fails. @@ -318,6 +337,10 @@ def configure( data["waitForSync"] = sync if schema is not None: data["schema"] = schema + if replication_factor is not None: + data["replicationFactor"] = replication_factor + if write_concern is not None: + data["writeConcern"] = write_concern request = Request( method="put", From bcfa3975654d0dcdf045b810c488d10c993828d2 Mon Sep 17 00:00:00 2001 From: max Date: Tue, 1 Feb 2022 17:50:18 +0100 Subject: [PATCH 2/3] fix formatting --- arango/collection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arango/collection.py b/arango/collection.py index 6fdc556b..4fd848fa 100644 --- a/arango/collection.py +++ b/arango/collection.py @@ -305,7 +305,7 @@ def configure( sync: Optional[bool] = None, schema: Optional[Json] = None, replication_factor: Optional[int] = None, - write_concern: Optional[int] = None + write_concern: Optional[int] = None, ) -> Result[Json]: """Configure collection properties. From d9d9edd17c4bd9898fe8fe9571f46791422cd79d Mon Sep 17 00:00:00 2001 From: max Date: Tue, 1 Feb 2022 18:18:55 +0100 Subject: [PATCH 3/3] add graph properties --- arango/database.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/arango/database.py b/arango/database.py index 5b009fb7..ea9ac058 100644 --- a/arango/database.py +++ b/arango/database.py @@ -1165,8 +1165,11 @@ def create_graph( edge_definitions: Optional[Sequence[Json]] = None, orphan_collections: Optional[Sequence[str]] = None, smart: Optional[bool] = None, + disjoint: Optional[bool] = None, smart_field: Optional[str] = None, shard_count: Optional[int] = None, + replication_factor: Optional[int] = None, + write_concern: Optional[int] = None, ) -> Result[Graph]: """Create a new graph. @@ -1184,6 +1187,10 @@ def create_graph( **smart_field** below). Applies only to enterprise version of ArangoDB. :type smart: bool | None + :param disjoint: If set to True, create a disjoint SmartGraph instead + of a regular SmartGraph. Applies only to enterprise version of + ArangoDB. + :type disjoint: bool | None :param smart_field: Document field used to shard the vertices of the graph. To use this, parameter **smart** must be set to True and every vertex in the graph must have the smart field. Applies only @@ -1195,6 +1202,21 @@ def create_graph( cannot be modified later once set. Applies only to enterprise version of ArangoDB. :type shard_count: int | None + :param replication_factor: Number of copies of each shard on different + servers in a cluster. Allowed values are 1 (only one copy is kept + and no synchronous replication), and n (n-1 replicas are kept and + any two copies are replicated across servers synchronously, meaning + every write to the master is copied to all slaves before operation + is reported successful). + :type replication_factor: int + :param write_concern: Write concern for the collection. Determines how + many copies of each shard are required to be in sync on different + DBServers. If there are less than these many copies in the cluster + a shard will refuse to write. Writes to shards with enough + up-to-date copies will succeed at the same time. The value of this + parameter cannot be larger than that of **replication_factor**. + Default value is 1. Used for clusters only. + :type write_concern: int :return: Graph API wrapper. :rtype: arango.graph.Graph :raise arango.exceptions.GraphCreateError: If create fails. @@ -1223,10 +1245,16 @@ def create_graph( data["orphanCollections"] = orphan_collections if smart is not None: # pragma: no cover data["isSmart"] = smart + if disjoint is not None: # pragma: no cover + data["isDisjoint"] = disjoint if smart_field is not None: # pragma: no cover data["options"]["smartGraphAttribute"] = smart_field if shard_count is not None: # pragma: no cover data["options"]["numberOfShards"] = shard_count + if replication_factor is not None: # pragma: no cover + data["options"]["replicationFactor"] = replication_factor + if write_concern is not None: # pragma: no cover + data["options"]["writeConcern"] = write_concern request = Request(method="post", endpoint="/_api/gharial", data=data)