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

Make local object storage work consistently with s3 object storage, fix problem with append, make it configurable as independent storage #48791

Merged
merged 28 commits into from May 4, 2023

Conversation

kssenii
Copy link
Member

@kssenii kssenii commented Apr 14, 2023

Changelog category (leave one):

  • Backward Incompatible Change

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

Make local object storage work consistently with s3 object storage, fix problem with append (closes #48465), make it configurable as independent storage. The change is backward incompatible because cache on top of local object storage is not incompatible to previous versions.

@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-improvement Pull request with some product improvements label Apr 14, 2023
@kssenii kssenii force-pushed the better-local-object-storage branch from 9934483 to 9374666 Compare April 15, 2023 11:53
@kssenii kssenii marked this pull request as draft April 16, 2023 19:07
@kssenii kssenii marked this pull request as ready for review April 20, 2023 10:34
@@ -1,14 +0,0 @@
cached_azure
Copy link
Member Author

@kssenii kssenii Apr 21, 2023

Choose a reason for hiding this comment

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

removed this test because it is impossible to make it not flaky with custom nested (cached) disk configuration which I used in test tests/queries/0_stateless/02714_local_object_storage.sql

CurrentThread::isInitialized() && CurrentThread::get().getQueryContext() ? std::string(CurrentThread::getQueryId()) : "",
file_size.value(),
/* allow_seeks */true,
/* use_external_buffer */false);
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed this code because it is not needed when local object storage works the same way as s3 object storage (and in this PR is starts to), as cache is added on the different layer.

@@ -54,53 +51,6 @@ std::mutex DiskLocal::reservation_mutex;

using DiskLocalPtr = std::shared_ptr<DiskLocal>;

static void loadDiskLocalConfig(const String & 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.

this code is just moved to a separate file, see src/Disks/loadLocalDiskConfig.cpp

@devcrafter devcrafter self-assigned this Apr 21, 2023
@kssenii kssenii requested a review from devcrafter April 28, 2023 10:26
@robot-clickhouse-ci-1
Copy link
Contributor

robot-clickhouse-ci-1 commented May 1, 2023

This is an automated comment for commit 35f437a with description of existing statuses. It's updated for the latest CI running
The full report is available here
The overall status of the commit is 🔴 failure

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
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🟢 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
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
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc🔴 failure
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors🔴 failure
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

@kssenii kssenii requested review from devcrafter and removed request for devcrafter May 2, 2023 12:29
@@ -367,7 +367,13 @@ class IDisk : public Space
/// Actually it's a part of IDiskRemote implementation but we have so
/// complex hierarchy of disks (with decorators), so we cannot even
/// dynamic_cast some pointer to IDisk to pointer to IDiskRemote.
virtual MetadataStoragePtr getMetadataStorage() = 0;
virtual MetadataStoragePtr getMetadataStorage()
Copy link
Member

Choose a reason for hiding this comment

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

Why we have implementation now?

Copy link
Member Author

Choose a reason for hiding this comment

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

because no need to require implementation of this method from all disks, only from DiskObjectStorage, so it is ok to throw NOT_IMPLEMENTED here.

@@ -59,7 +59,7 @@ ReadSettings CachedObjectStorage::patchSettings(const ReadSettings & read_settin
if (!canUseReadThroughCache())
modified_settings.read_from_filesystem_cache_if_exists_otherwise_bypass_cache = true;

return IObjectStorage::patchSettings(modified_settings);
return object_storage->patchSettings(modified_settings);
Copy link
Member

Choose a reason for hiding this comment

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

So it was a bug before this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really, it did not affect anything, when readObjects is passed to inner object storage (s3) it will apply it's own patch settings for its read.

@@ -18,31 +18,14 @@ struct StoredObject

uint64_t bytes_size = 0;

std::string getPathKeyForCache() const;

const std::string & getMappedPath() const;
Copy link
Member

Choose a reason for hiding this comment

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

Why we have getter for mapped path and don't have getter for absolute path? Maybe it should be const?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why we have getter for mapped path and don't have getter for absolute path?

fixed

Maybe it should be const

copy assignment operator does not work then

fs::copy(from, to, fs::copy_options::recursive | fs::copy_options::overwrite_existing);
auto in = readObject(object_from);
auto out = writeObject(object_to, WriteMode::Rewrite);
copyData(*in, *out);
Copy link
Member

Choose a reason for hiding this comment

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

Why we need to read/write? Why we cannot copy blob from object_from to object_to?

Copy link
Member Author

Choose a reason for hiding this comment

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

because the point is to not use std::filesystem::copy (for #42337)

LOG_TEST(log, "Write object: {}", path);
return std::make_unique<WriteBufferFromFile>(path, buf_size, flags);
if (mode != WriteMode::Rewrite)
throw Exception(ErrorCodes::BAD_ARGUMENTS, "LocalObjectStorage doesn't support append to files");
Copy link
Member

Choose a reason for hiding this comment

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

It can be really surprizing

Copy link
Member Author

Choose a reason for hiding this comment

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

same as in S3ObjectStorage, they are consistent now.

@@ -47,30 +50,39 @@ std::unique_ptr<ReadBufferFromFileBase> LocalObjectStorage::readObjects( /// NOL
std::optional<size_t> read_hint,
std::optional<size_t> file_size) const
{
if (objects.size() != 1)
Copy link
Member

Choose a reason for hiding this comment

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

We should still have this check since we banned append in write?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, append is not banned, it is now implemented same as in s3, which means that here objects.size() != 1 in case append was made.

@@ -7,9 +7,6 @@
#include <Common/logger_useful.h>
#include <Common/setThreadName.h>
#include <Core/ServerUUID.h>
#include <Disks/ObjectStorages/MetadataStorageFromDisk.h>
#include <Disks/ObjectStorages/FakeMetadataStorageFromDisk.h>
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can remove whole FakeMetadataStorageFromDisk now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed!

@@ -660,7 +660,6 @@ class IColumn;
M(Bool, enable_filesystem_cache_on_write_operations, false, "Write into cache on write operations. To actually work this setting requires be added to disk config too", 0) \
M(Bool, enable_filesystem_cache_log, false, "Allows to record the filesystem caching log for each query", 0) \
M(Bool, read_from_filesystem_cache_if_exists_otherwise_bypass_cache, false, "Allow to use the filesystem cache in passive mode - benefit from the existing cache entries, but don't put more entries into the cache. If you set this setting for heavy ad-hoc queries and leave it disabled for short real-time queries, this will allows to avoid cache threshing by too heavy queries and to improve the overall system efficiency.", 0) \
M(Bool, enable_filesystem_cache_on_lower_level, true, "If read buffer supports caching inside threadpool, allow it to do it, otherwise cache outside ot threadpool. Do not use this setting, it is needed for testing", 0) \
Copy link
Member

Choose a reason for hiding this comment

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

Like it.

@@ -35,6 +36,8 @@ inline String toString(DataSourceType data_source_type)
return "web";
case DataSourceType::AzureBlobStorage:
return "azure_blob_storage";
case DataSourceType::LocalBlobStorage:
Copy link
Member

Choose a reason for hiding this comment

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

Looks like now it's impossible to create cache on top of <type>local</type>. Not a popular feature, but need to mention in changelog.

std::string generateBlobNameForPath(const std::string & path) override { return path; }

std::string getUniqueId(const std::string & path) const override;
std::string generateBlobNameForPath(const std::string & path) override;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this function can be 100% the same for all object storages?

Copy link
Member Author

@kssenii kssenii May 3, 2023

Choose a reason for hiding this comment

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

For local no, because it will require to create subdirectories.

@kssenii kssenii force-pushed the better-local-object-storage branch from 343d44f to 35f437a Compare May 3, 2023 12:37
@alesapin
Copy link
Member

alesapin commented May 4, 2023

Need to address stress test failure, rest is LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-improvement Pull request with some product improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LocalObjectStorage corrupts data
6 participants