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

Backup/Restore for KeeperMap tables #56460

Merged
merged 17 commits into from Nov 18, 2023
Merged

Conversation

antonio2368
Copy link
Member

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Add support for backing up and restoring tables using KeeperMap engine.

cc @vitlibar there are tests missing and some polishing is left but created a draft PR so you can take a look while I'm still working on it

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

@robot-ch-test-poll robot-ch-test-poll added the pr-improvement Pull request with some product improvements label Nov 8, 2023
@robot-ch-test-poll
Copy link
Contributor

robot-ch-test-poll commented Nov 8, 2023

This is an automated comment for commit 9bcedf3 with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Successful checks
Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker image for serversThe check to build and optionally push the mentioned image to docker hub✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integrational tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Mergeable CheckChecks if all other necessary checks are successful✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
Push to DockerhubThe check for building and pushing the CI related docker images to docker hub✅ success
SQLTestThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
SQLancerFuzzing tests that detect logical bugs with SQLancer tool✅ success
SqllogicRun clickhouse on the sqllogic test set against sqlite and checks that all statements are passed✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style CheckRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success
Check nameDescriptionStatus
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR⏳ pending
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc❌ failure

@vitlibar vitlibar self-assigned this Nov 8, 2023
@antonio2368 antonio2368 marked this pull request as ready for review November 10, 2023 09:30
@@ -452,13 +452,15 @@ void BackupImpl::readBackupMetadata()
size_of_entries = 0;

const auto * contents = config_root->getNodeByPath("contents");
std::vector<std::pair<String /*source*/, String /*target*/>> reference_files;
Copy link
Member

Choose a reason for hiding this comment

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

This line is not necessary anymore.

src/Backups/BackupImpl.h Outdated Show resolved Hide resolved
if (!deduplicate_files)
{
for (const auto & reference : info.reference_sources)
writer->copyFile(reference, info.data_file_name, info.size - info.base_size);
Copy link
Member

Choose a reason for hiding this comment

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

I like this approach. And it can be faster too because instead of copying the same file again to another destination you just copy it inside a backup.

target_info->reference_sources.push_back(reference.file_name);
reference.size = target_info->size;
total_size_of_files += reference.size;
reference.checksum = target_info->checksum;
Copy link
Member

Choose a reason for hiding this comment

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

encrypted_by_disk should be copied too:

reference.encrypted_by_disk = target_info->encrypted_by_disk;

if (info.reference_target.empty())
{
file_name_to_info.emplace(info.file_name, &info);
total_size_of_files += info.size;
Copy link
Member

@vitlibar vitlibar Nov 16, 2023

Choose a reason for hiding this comment

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

We can use this copy-inside-backup approach for other copies too if we insert here something like:

SizeAndChecksum size_and_checksum{info.size, info.checksum};
auto [it, inserted] = data_file_index_by_checksum.emplace(size_and_checksum, i);
if (inserted)
{
    info.data_file_name = info.file_name;
    info.data_file_index = i;
}
else
{
    /// specify that info must not be written in the usual way ...
    info.data_file_name.clear();
    info.data_file_index = -1;

    /// ... because target_info will be copied to its place instead
    auto & target_info = it->second;
    target_info->reference_sources.push_back(info.file_name);
}

Copy link
Member Author

Choose a reason for hiding this comment

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

so we are okay with using size and checksum in plain backups as unique id?

Copy link
Member

@vitlibar vitlibar Nov 17, 2023

Choose a reason for hiding this comment

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

A plain backup means every file is stored in its place: there can files of the same contents; empty files are stored too; and references to the base backup are not used. So a plain backup is about how it must look on Disk or S3 when it's completed. It's not about how we should write it - we can write it any way we like if the result is the same. I mean there is no difference in the result whether we

copy SRC TO DEST[0], DEST[1], ... DEST[N]

or

copy SRC TO DEST[0], then
copy DEST[0] to DEST[1], ... DEST[N]

Copy link
Member Author

Choose a reason for hiding this comment

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

but there is a difference if we use size and checksum
if files from different backup entries match in size and checksum this will produce a different result

Copy link
Member

@vitlibar vitlibar Nov 17, 2023

Choose a reason for hiding this comment

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

if files from different backup entries match in size and checksum this will produce a different result

I didn't quite understand. Do you mean that two files of the same size but different by contents can have the same checksum?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean chances are almost nonexistent for a collision to happen, especially with 128bits we use for checksum but just asking if we are okay with that.

Copy link
Member

@vitlibar vitlibar Nov 17, 2023

Choose a reason for hiding this comment

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

The formula is (https://en.wikipedia.org/wiki/Birthday_attack)

p(n, H) = 1-exp(-n^2 / 2 / H)

So if we used 128-bit hashes without size, for a backup with 1000000 files we would have the probability like 10^-27 that two hashes match. With sizes the probability must be even smaller.

Copy link
Member

Choose a reason for hiding this comment

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

Though that optimization is not very crucial anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

let me do this in a different PR so we are not blocking backups of KeeperMap and then we can discuss if we are okay with the solution.

@antonio2368 antonio2368 merged commit 274f2c7 into master Nov 18, 2023
349 of 353 checks passed
@antonio2368 antonio2368 deleted the keeper-map-backup-restore branch November 18, 2023 18:27
LOG_TRACE(log, "Copying file inside backup from {} to {} ", source, destination);
copyS3File(
client,
client,
Copy link
Member

@rschu1ze rschu1ze Nov 19, 2023

Choose a reason for hiding this comment

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

Broke my local build:

/home/ubuntu/repo/ClickHouse/src/Backups/BackupIO_S3.cpp:255:5: error: no matching function for call to 'copyS3File'
  255 |     copyS3File(
      |     ^~~~~~~~~~
/home/ubuntu/repo/ClickHouse/src/IO/S3/copyS3File.h:31:6: note: candidate function not viable: no known conversion from 'std::shared_ptr<S3::Client>' to 'const String' (aka 'const basic_string<char, char_traits<char>, allocator<char>>') for 2nd argument
   33 | void copyS3File(
      |      ^
   34 |     const std::shared_ptr<const S3::Client> & s3_client,
   35 |     const String & src_bucket,
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
[10301/12493] Building CXX object src/CMakeFiles/dbms.dir/Functions/CastOverloadResolver.cpp.o
ninja: build stopped: subcommand failed.

Fix: #56974

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually it's this PR #56314 which modifies copyS3File
It didn't have the latest master so it didn't catch the new code that calls copyS3File

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants