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

OVH/openstack stability enhancements #196

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
42 changes: 24 additions & 18 deletions rohmu/object_storage/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,26 +368,27 @@ def iter_key(
args["ContinuationToken"] = continuation_token
self.stats.operation(StorageOperation.iter_key)
response = self.get_client().list_objects_v2(**args)
status_code = response.get("ResponseMetadata", {}).get("HTTPStatusCode")
if status_code:
self.stats.increase(metric="rohmu.s3.iter_key_response", tags={"status_code": str(status_code)})

for item in response.get("Contents", []):
if with_metadata:
try:
if response.get("KeyCount") != 0:
for item in response["Contents"]:
if with_metadata:
metadata = {k.lower(): v for k, v in self._metadata_for_key(item["Key"]).items()}
except FileNotFoundFromStorageError:
continue
else:
metadata = None
name = self.format_key_from_backend(item["Key"])
yield IterKeyItem(
type=KEY_TYPE_OBJECT,
value={
"last_modified": item["LastModified"],
"md5": item["ETag"].strip('"'),
"metadata": metadata,
"name": name,
"size": item["Size"],
},
)
else:
metadata = None
name = self.format_key_from_backend(item["Key"])
yield IterKeyItem(
type=KEY_TYPE_OBJECT,
value={
"last_modified": item["LastModified"],
"md5": item["ETag"].strip('"'),
"metadata": metadata,
"name": name,
"size": item["Size"],
},
)

for common_prefix in response.get("CommonPrefixes", []):
yield IterKeyItem(
Expand All @@ -405,17 +406,22 @@ def _get_object_stream(self, key: str, byte_range: Optional[tuple[int, int]]) ->
kwargs: dict[str, Any] = {}
if byte_range:
kwargs["Range"] = f"bytes={byte_range[0]}-{byte_range[1]}"
status_code: int | None = None
try:
# Actual usage is accounted for in
# _read_object_to_fileobj, although that omits the initial
# get_object call if it fails.
response = self.get_client().get_object(Bucket=self.bucket_name, Key=path, **kwargs)
status_code = response.get("ResponseMetadata", {}).get("HTTPStatusCode")
except botocore.exceptions.ClientError as ex:
status_code = ex.response.get("ResponseMetadata", {}).get("HTTPStatusCode")
if status_code == 404:
raise FileNotFoundFromStorageError(path)
else:
raise StorageError(f"Fetching the remote object {path} failed") from ex
finally:
if status_code:
self.stats.increase(metric="rohmu.s3.get_object_stream_response", tags={"status_code": str(status_code)})
return response["Body"], response["ContentLength"], response["Metadata"]

def _read_object_to_fileobj(
Expand Down
Loading