Skip to content
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
20 changes: 12 additions & 8 deletions barman/clients/cloud_walarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,6 @@ def upload_wal(self, wal_path, override_tags=None):
"""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easier to review with "hide whitespaces"

# Extract the WAL file
wal_name = self.retrieve_wal_name(wal_path)
# Use the correct file object for the upload (simple|gzip|bz2)
file_object = self.retrieve_file_obj(wal_path)
# Correctly format the destination path
destination = os.path.join(
self.cloud_interface.path,
Expand All @@ -319,11 +317,14 @@ def upload_wal(self, wal_path, override_tags=None):
wal_name,
)

# Put the file in the correct bucket.
# The put method will handle automatically multipart upload
self.cloud_interface.upload_fileobj(
fileobj=file_object, key=destination, override_tags=override_tags
)
# Use the correct file object for the upload (simple|gzip|bz2)
file_object = self.retrieve_file_obj(wal_path)
with closing(file_object):
# Put the file in the correct bucket.
# The put method will handle automatically multipart upload
self.cloud_interface.upload_fileobj(
fileobj=file_object, key=destination, override_tags=override_tags
)

def retrieve_file_obj(self, wal_path):
"""
Expand All @@ -339,6 +340,8 @@ def retrieve_file_obj(self, wal_path):
This could change in the future because the WAL files dimension could
be more than 16MB on some postgres install.

NOTE: caller is responsible for closing the returned file object.

TODO: Evaluate using tempfile if the WAL is bigger than 16MB

:param str wal_path:
Expand All @@ -350,7 +353,8 @@ def retrieve_file_obj(self, wal_path):
if not self.compression:
return wal_file

return compress(wal_file, self.compression, self.compression_level)
with closing(wal_file):
return compress(wal_file, self.compression, self.compression_level)

def retrieve_wal_name(self, wal_path):
"""
Expand Down