-
Notifications
You must be signed in to change notification settings - Fork 7
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
CHINA-280: Set 1 hour request timeout for S3 during restore #154
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b43ddb8
CHINA-280: Set 1 hour request timeout for S3 during restore
ianton-ru 92cb452
Fix build
ianton-ru b86afee
Update ch_backup/clickhouse/disks.py
ianton-ru ba078cd
Add timeout to /tmp/clickhouse-disks-config.xml too
ianton-ru e17cd4e
Fix requirements.txt
ianton-ru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
requests>2.19 | ||
requests>2.19,<2.32 | ||
boto3<1.19 | ||
botocore<1.22 | ||
psutil | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
""" | ||
Unit tests disks module. | ||
""" | ||
|
||
import unittest | ||
|
||
import xmltodict | ||
from tests.unit.utils import assert_equal, parametrize | ||
|
||
from ch_backup.backup_context import BackupContext | ||
from ch_backup.clickhouse.config import ClickhouseConfig | ||
from ch_backup.clickhouse.disks import ClickHouseTemporaryDisks | ||
from ch_backup.config import DEFAULT_CONFIG, Config | ||
|
||
write_result = "" | ||
|
||
|
||
@parametrize( | ||
{ | ||
"id": "No timeout", | ||
"args": { | ||
"clickhouse_config": """ | ||
<clickhouse> | ||
<storage_configuration> | ||
<disks> | ||
<object_storage> | ||
<type>s3</type> | ||
<endpoint>https://s3.eu-central-1.amazonaws.com/double-cloud-storage-chc0001/cloud_storage/chc0001/s1/</endpoint> | ||
<access_key_id>AKIAACCESSKEY</access_key_id> | ||
<secret_access_key>SecretAccesskey</secret_access_key> | ||
</object_storage> | ||
</disks> | ||
</storage_configuration> | ||
</clickhouse> | ||
""", | ||
"disk_name": "object_storage", | ||
"source": { | ||
"endpoint": "s3.us-west-1.amazonaws.com", | ||
"bucket": "double-cloud-storage-chc0002", | ||
"path": "cloud_storage/chc0002/s2/", | ||
}, | ||
"temp_config": """ | ||
<clickhouse> | ||
<storage_configuration> | ||
<disks> | ||
<object_storage_source> | ||
<type>s3</type> | ||
<endpoint>https://s3.us-west-1.amazonaws.com/double-cloud-storage-chc0002/cloud_storage/chc0002/s2/</endpoint> | ||
<access_key_id>AKIAACCESSKEY</access_key_id> | ||
<secret_access_key>SecretAccesskey</secret_access_key> | ||
<request_timeout_ms>3600000</request_timeout_ms> | ||
</object_storage_source> | ||
<object_storage> | ||
<request_timeout_ms replace="replace">3600000</request_timeout_ms> | ||
</object_storage> | ||
</disks> | ||
</storage_configuration> | ||
</clickhouse> | ||
""", | ||
}, | ||
}, | ||
{ | ||
"id": "Small timeout", | ||
"args": { | ||
"clickhouse_config": """ | ||
<clickhouse> | ||
<storage_configuration> | ||
<disks> | ||
<object_storage> | ||
<type>s3</type> | ||
<endpoint>https://s3.eu-central-1.amazonaws.com/double-cloud-storage-chc0001/cloud_storage/chc0001/s1/</endpoint> | ||
<access_key_id>AKIAACCESSKEY</access_key_id> | ||
<secret_access_key>SecretAccesskey</secret_access_key> | ||
<request_timeout_ms>30000</request_timeout_ms> | ||
</object_storage> | ||
</disks> | ||
</storage_configuration> | ||
</clickhouse> | ||
""", | ||
"disk_name": "object_storage", | ||
"source": { | ||
"endpoint": "s3.us-west-1.amazonaws.com", | ||
"bucket": "double-cloud-storage-chc0002", | ||
"path": "cloud_storage/chc0002/s2/", | ||
}, | ||
"temp_config": """ | ||
<clickhouse> | ||
<storage_configuration> | ||
<disks> | ||
<object_storage_source> | ||
<type>s3</type> | ||
<endpoint>https://s3.us-west-1.amazonaws.com/double-cloud-storage-chc0002/cloud_storage/chc0002/s2/</endpoint> | ||
<access_key_id>AKIAACCESSKEY</access_key_id> | ||
<secret_access_key>SecretAccesskey</secret_access_key> | ||
<request_timeout_ms>3600000</request_timeout_ms> | ||
</object_storage_source> | ||
<object_storage> | ||
<request_timeout_ms replace="replace">3600000</request_timeout_ms> | ||
</object_storage> | ||
</disks> | ||
</storage_configuration> | ||
</clickhouse> | ||
""", | ||
}, | ||
}, | ||
{ | ||
"id": "Large timeout", | ||
"args": { | ||
"clickhouse_config": """ | ||
<clickhouse> | ||
<storage_configuration> | ||
<disks> | ||
<object_storage> | ||
<type>s3</type> | ||
<endpoint>https://s3.eu-central-1.amazonaws.com/double-cloud-storage-chc0001/cloud_storage/chc0001/s1/</endpoint> | ||
<access_key_id>AKIAACCESSKEY</access_key_id> | ||
<secret_access_key>SecretAccesskey</secret_access_key> | ||
<request_timeout_ms>7200000</request_timeout_ms> | ||
</object_storage> | ||
</disks> | ||
</storage_configuration> | ||
</clickhouse> | ||
""", | ||
"disk_name": "object_storage", | ||
"source": { | ||
"endpoint": "s3.us-west-1.amazonaws.com", | ||
"bucket": "double-cloud-storage-chc0002", | ||
"path": "cloud_storage/chc0002/s2/", | ||
}, | ||
"temp_config": """ | ||
<clickhouse> | ||
<storage_configuration> | ||
<disks> | ||
<object_storage_source> | ||
<type>s3</type> | ||
<endpoint>https://s3.us-west-1.amazonaws.com/double-cloud-storage-chc0002/cloud_storage/chc0002/s2/</endpoint> | ||
<access_key_id>AKIAACCESSKEY</access_key_id> | ||
<secret_access_key>SecretAccesskey</secret_access_key> | ||
<request_timeout_ms>7200000</request_timeout_ms> | ||
</object_storage_source> | ||
</disks> | ||
</storage_configuration> | ||
</clickhouse> | ||
""", | ||
}, | ||
}, | ||
) | ||
def test_temporary_disk(clickhouse_config, disk_name, source, temp_config): | ||
context = BackupContext(DEFAULT_CONFIG) # type: ignore[arg-type] | ||
context.ch_ctl = unittest.mock.MagicMock() | ||
context.backup_layout = unittest.mock.MagicMock() | ||
context.backup_meta = unittest.mock.MagicMock() | ||
with unittest.mock.patch( | ||
"builtins.open", | ||
new=unittest.mock.mock_open(read_data=clickhouse_config), | ||
create=True, | ||
): | ||
with unittest.mock.patch("yaml.load", return_value=""): | ||
context.ch_config = ClickhouseConfig(Config("foo")) | ||
context.ch_config.load() | ||
with unittest.mock.patch("builtins.open", new=unittest.mock.mock_open()) as m: | ||
disk = ClickHouseTemporaryDisks( | ||
context.ch_ctl, | ||
context.backup_layout, | ||
context.config_root, | ||
context.backup_meta, | ||
source["bucket"], | ||
source["path"], | ||
source["endpoint"], | ||
context.ch_config, | ||
) | ||
|
||
# pylint: disable=global-statement | ||
global write_result | ||
write_result = "" | ||
m().write = write_collector | ||
|
||
# pylint: disable=protected-access | ||
disk._create_temporary_disk( | ||
context.backup_meta, | ||
disk_name, | ||
source["bucket"], | ||
source["path"], | ||
source["endpoint"], | ||
) | ||
m.assert_called_with( | ||
f"/etc/clickhouse-server/config.d/cloud_storage_tmp_disk_{disk_name}_source.xml", | ||
"w", | ||
encoding="utf-8", | ||
) | ||
|
||
expected_content = xmltodict.parse(temp_config) | ||
actual_content = xmltodict.parse(write_result) | ||
assert_equal(actual_content, expected_content) | ||
|
||
|
||
def write_collector(x): | ||
# pylint: disable=global-statement | ||
global write_result | ||
write_result += x.decode("utf-8") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the motivation of replacing
request_timeout_ms
forclickhouse-server
config? AFAIK there is only one long-running operation(CopyObject
) and is it done using withclickhouse-disk
. Maybe make sense to keeprequest_timeout_ms
only forclickhouse-disks
config?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency.
If source disk is not used in clickhouse-server, better remove additional config for server at all.