Skip to content

Configure collection properties: add support for replicationFactor + writeConcern #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion arango/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,33 @@ 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.

:param sync: Block until operations are synchronized to disk.
: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.
Expand All @@ -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",
Expand Down
28 changes: 28 additions & 0 deletions arango/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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)

Expand Down