Skip to content
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

[DE-542] Adding support for shards retrieval #274

Merged
merged 5 commits into from
Aug 21, 2023
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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
main
-----

* [DE-542] Added `shards()` method to `Collection`

7.6.0
----
-----

* [DE-562] Index Cache Refilling by @apetenchea in https://github.com/ArangoDB-Community/python-arango/pull/259

Expand Down
29 changes: 29 additions & 0 deletions arango/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
CollectionRenameError,
CollectionResponsibleShardError,
CollectionRevisionError,
CollectionShardsError,
CollectionStatisticsError,
CollectionTruncateError,
CollectionUnloadError,
Expand Down Expand Up @@ -300,6 +301,31 @@ def response_handler(resp: Response) -> Json:

return self._execute(request, response_handler)

def shards(self, details: bool = False) -> Result[Json]:
"""Return collection shards and properties.

Available only in a cluster setup.

:param details: Include responsible servers for each shard.
:type details: bool
:return: Collection shards and properties.
:rtype: dict
:raise arango.exceptions.CollectionShardsError: If retrieval fails.
"""
request = Request(
method="get",
endpoint=f"/_api/collection/{self.name}/shards",
params={"details": details},
read=self.name,
)

def response_handler(resp: Response) -> Json:
if resp.is_success:
return format_collection(resp.body)
raise CollectionShardsError(resp, request)

return self._execute(request, response_handler)

def configure(
self,
sync: Optional[bool] = None,
Expand Down Expand Up @@ -330,6 +356,9 @@ def configure(
Default value is 1. Used for clusters only.
:type write_concern: int
:return: New collection properties.
:param computed_values: Define expressions on the collection level that
run on inserts, modifications, or both.
:type computed_values: dict | None
:rtype: dict
:raise arango.exceptions.CollectionConfigureError: If operation fails.
"""
Expand Down
4 changes: 4 additions & 0 deletions arango/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ class CollectionConfigureError(ArangoServerError):
"""Failed to configure collection properties."""


class CollectionShardsError(ArangoServerError):
"""Failed to retrieve collection shards."""


class CollectionStatisticsError(ArangoServerError):
"""Failed to retrieve collection statistics."""

Expand Down
2 changes: 1 addition & 1 deletion arango/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def normalize_headers(
if driver_flags is not None:
for flag in driver_flags:
flags = flags + flag + ";"
driver_version = "7.5.8"
driver_version = "7.6.0"
driver_header = "python-arango/" + driver_version + " (" + flags + ")"
normalized_headers: Headers = {
"charset": "utf-8",
Expand Down
4 changes: 2 additions & 2 deletions tester.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ if [[ "$tests" != "all" && "$tests" != "community" && "$tests" != "enterprise" ]
exit 1
fi

# 3.11.1
# 3.11.2
# 3.10.9
# 3.9.9
# 3.9.11
version="${3:-3.11.1}"

if [[ -n "$4" && "$4" != "notest" ]]; then
Expand Down
7 changes: 7 additions & 0 deletions tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ def test_collection_management(db, bad_db, cluster):
)
assert db.has_collection(col_name) is True

if cluster:
for details in (False, True):
shards = col.shards(details=details)
assert shards["name"] == col_name
assert shards["system"] is False
assert len(shards["shards"]) == 2

properties = col.properties()
assert "key_options" in properties
assert properties["schema"] == schema
Expand Down
23 changes: 12 additions & 11 deletions tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_database_attributes(db, username):
assert isinstance(db.wal, WAL)


def test_database_misc_methods(sys_db, db, bad_db):
def test_database_misc_methods(sys_db, db, bad_db, cluster):
# Test get properties
properties = db.properties()
assert "id" in properties
Expand Down Expand Up @@ -202,10 +202,6 @@ def test_database_misc_methods(sys_db, db, bad_db):
# Test get log levels
assert isinstance(sys_db.log_levels(), dict)

# Test get log levels (with server_id)
server_id = sys_db.replication.server_id()
assert isinstance(sys_db.log_levels(server_id), dict)

# Test get log levels with bad database
with assert_raises(ServerLogLevelError) as err:
bad_db.log_levels()
Expand All @@ -219,12 +215,17 @@ def test_database_misc_methods(sys_db, db, bad_db):
for key, value in sys_db.log_levels().items():
assert result[key] == value

# Test set log levels (with server_id)
result = sys_db.set_log_levels(server_id, **new_levels)
for key, value in new_levels.items():
assert result[key] == value
for key, value in sys_db.log_levels(server_id).items():
assert result[key] == value
if cluster:
# Test get log levels (with server_id)
server_id = sys_db.cluster.server_id()
assert isinstance(sys_db.log_levels(server_id), dict)

# Test set log levels (with server_id)
result = sys_db.set_log_levels(server_id, **new_levels)
for key, value in new_levels.items():
assert result[key] == value
for key, value in sys_db.log_levels(server_id).items():
assert result[key] == value

# Test set log levels with bad database
with assert_raises(ServerLogLevelSetError):
Expand Down
Loading