Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

feat(snapshot) Compress table files after taking the snapshot #29

Merged
merged 15 commits into from
Mar 15, 2021

Conversation

fpacifici
Copy link
Contributor

Built on top of #28.

In certain cases, it is convenient to zip the table files after writing the snapshot and before using to ingest it somewhere else.
The main use case is when we need to ingest some tables contained in the snapshot via HTTP without the need of any pre-processing (we can do this with clickhouse for some tables like groupedmessages).
When that happens, ingeting a gzip file is a lot cheaper than a decompressed one. The difference in the ingestion time is more than enough to justify the time spent to gzip the file.

This allows the snapshot configuration to define whether a table has to be compressed or not.
The same snapshot can contain compressed and uncompressed table files.
In this current version compression happens for each table before closing the transaction. The transaction is not locking anything though, so this should not be a problem. We could optimize it by closing the transaction first if needed.

@fpacifici fpacifici requested a review from a team March 14, 2021 23:37
Comment on lines +104 to +112
if table.zip:
logger.debug("Zipping file file for %s", table.table)
with self.__storage.get_table_file(
table.table, dump_format, FileMode.READ
) as uncompressed_file:
with self.__storage.get_table_file(
table.table, dump_format, FileMode.WRITE, zip=True
) as compressed_file:
shutil.copyfileobj(uncompressed_file, compressed_file)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried both writing directly on the gzip file and writing in an uncompressed file and compress it afterwards.
The second won easily in terms of time taken.

@fpacifici fpacifici changed the base branch from feat/support_formatting to master March 15, 2021 22:25
@fpacifici fpacifici merged commit 68a90fb into master Mar 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants