Skip to content

Optimize glob iterator - #73518

Merged
thevar1able merged 11 commits into
masterfrom
fix-glob-iterator
Jan 20, 2025
Merged

thevar1able merged 11 commits into
masterfrom
fix-glob-iterator

Conversation

@thevar1able

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Performance Improvement

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

Don't list blob storage keys if we only have curly brackets expansion in table function. Closes #73333

CI Settings (Only check the boxes if you know what you are doing):

  • Allow: All Required Checks
  • Allow: Stateless tests
  • Allow: Stateful tests
  • Allow: Integration Tests
  • Allow: Performance tests
  • Allow: All Builds
  • Allow: batch 1, 2 for multi-batch jobs
  • Allow: batch 3, 4, 5, 6 for multi-batch jobs

  • Exclude: Style check
  • Exclude: Fast test
  • Exclude: All with ASAN
  • Exclude: All with TSAN, MSAN, UBSAN, Coverage
  • Exclude: All with aarch64, release, debug

  • Run only fuzzers related jobs (libFuzzer fuzzers, AST fuzzers, etc.)
  • Exclude: AST fuzzers

  • Do not test
  • Woolen Wolfdog
  • Upload binaries for special builds
  • Disable merge-commit
  • Disable CI cache

@thevar1able
thevar1able marked this pull request as draft December 18, 2024 09:55
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-performance Pull request with some performance improvements label Dec 18, 2024
@robot-ch-test-poll

robot-ch-test-poll commented Dec 18, 2024 •

Copy link
Copy Markdown
Contributor

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

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

Check nameDescriptionStatus
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. Integration 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❌ failure
Successful checks
Check nameDescriptionStatus
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
Docs checkBuilds and tests the documentation✅ 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
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
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✅ 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

@kssenii kssenii self-assigned this Dec 18, 2024
@thevar1able
thevar1able requested a review from kssenii December 18, 2024 15:27
@thevar1able
thevar1able marked this pull request as ready for review December 18, 2024 15:39

@zvonand zvonand left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do you limit number of expandable globs to 1?

@kssenii kssenii removed their assignment Dec 19, 2024
@divanik divanik self-assigned this Dec 20, 2024
Comment thread src/Common/parseGlobs.cpp Resolved
local_context, is_archive ? nullptr : read_keys, query_settings.list_object_keys_size,
query_settings.throw_on_zero_files_match, file_progress_callback);
auto path = configuration->getPath();
if (containsOnlyEnumGlobs(path))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why?
We can expand enum globs regardless of whether there are other globs. It is OK to expand e.g. prefix{1,2,3}/file*.csv

@zvonand zvonand Dec 30, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, I think it is even OK to expand stuff like prefix{1?,2?,3?}/file*.csv. This is still better than having shorter prefix and matching it against regex

@divanik

divanik commented Jan 13, 2025

Copy link
Copy Markdown
Contributor

The code LGTM to me. Please, correct the failed tests

@thevar1able

thevar1able commented Jan 13, 2025 •

Copy link
Copy Markdown
Member Author

@divanik thanks for looking into it.

I thought at first to fix the test, but it seems that behavior with skipping missing files set in globs is rather desirable. I'll fall back to optimizing just the single glob instead, we can think about multiple globs later.

@zvonand

zvonand commented Jan 13, 2025 •

Copy link
Copy Markdown
Contributor

I'll fall back to optimizing just the single glob instead, we can think about multiple globs later.

But this is a pretty narrow case. It is only good for enumerating files (e.g. directory/file{1,2,3}.csv), but will not work for directories in many cases; it is pretty often that you specify a set of directories where you want all files or a specific set of files to be read, e.g. location/{dir1,dir2,dir3}/data*.csv, this really looks like an obvious and valid use case.
Listing unneeded directories may create huge slowdowns that can be avoided.

Or maybe you mean something different by "optimizing just the single glob"?

@thevar1able

thevar1able commented Jan 13, 2025 •

Copy link
Copy Markdown
Member Author

@zvonand

But this is a pretty narrow case

This is causing an actual issue and is the reason I got here, so "pretty narrow" is quite relative.

The reason I'm thinking about unwinding just one glob is that with a path like location/{dir1,dir2,dir3}/something/{file1,file2,file3}.csv current implementation will ignore missing location/dir2/file1.csv for example. If we unwrap all the enum globs, all paths are expected and missing file error will be thrown. I think that enum globs should be strict, and current behavior is simply invalid, but I'm not sure how to safely transition from one to another.

Also it seems that test_storage_hdfs was dropped, so let's just rerun tests and see where it fails now.

@divanik

divanik commented Jan 13, 2025

Copy link
Copy Markdown
Contributor

Oh, I see the problem. Current semantics is: take all files which name corresponds to regex. Even with single enumeration glob we can meet non-existent files. Is it ok for us to throw the error in this case?

@zvonand

zvonand commented Jan 13, 2025 •

Copy link
Copy Markdown
Contributor

If we unwrap all the enum globs, all paths are expected and missing file error will be thrown. I think that enum globs should be strict, and current behavior is simply invalid.

Well, maybe it is and maybe it isn't -- actually a difficult question :)

But this is the behavior that currently exists, and it has been here for a long time (due to how the globs were handled initially). This would be a very breaking change.

We can throw exception in case there were no globs at all or if there was a glob but no files found after all the processing.

Maybe introduce some setting like strict_enumeration_globs or something that will be disabled by default? IDK if this is needed though

@zvonand

zvonand commented Jan 13, 2025 •

Copy link
Copy Markdown
Contributor

take all files which name corresponds to regex

Yes, and I think it is more intuitive, isn't it?

The same thing about range globs, which I think are even more natural to behave like a regex:
dir{1..100} -- what if there are lots of directories, but one (dir55) is missing? Or maybe there are only dirs with odd numbers? (yes, sounds pretty synthetic, but still) There is no good way to use a glob then

@divanik

divanik commented Jan 13, 2025

Copy link
Copy Markdown
Contributor
  1. You can always set ignore_non_existent_file = true in this chunk of code to comply with the current behavior.

  2. Also I'd like to restrict number of unrolled files by the setting max_enum_unfold and fallback to blob listing (maybe with extended prefix) in case of having more than max_enum_unfold values

@zvonand

zvonand commented Jan 13, 2025 •

Copy link
Copy Markdown
Contributor

to comply with the current behavior

Yes, but it will still be breaking. You never needed to set this setting, but after upgrade you have to, and this may not be obvious actually.

Also, by enabling this setting exception will not be thrown even if no files were found at all, which is a different case. And there will not be a way to differentiate it.

Also I'd like to restrict number of unrolled files by the setting max_enum_unfold and fallback to blob listing

Yes, sounds very reasonable

@divanik

divanik commented Jan 13, 2025 •

Copy link
Copy Markdown
Contributor

Yes, but it will still be breaking. You never needed to set this setting, but after upgrade you have to, and this may not be obvious actually.

I mean hardcoding true here. Also it makes sense to add throw_on_zero_match to comply KeysIterator's behavior with a GlobIterator's one in case nothing is matched.

@thevar1able

Copy link
Copy Markdown
Member Author

Let's stop on strict expansion if just one enum glob is present. Further optimizations may be done in separate PRs.

cc @alexey-milovidov

@divanik

divanik commented Jan 20, 2025

Copy link
Copy Markdown
Contributor

Let's stop on strict expansion if just one enum glob is present. Further optimizations may be done in separate PRs.

What do you mean by strict expansion? To fail if some of the files is not present?

@thevar1able

Copy link
Copy Markdown
Member Author

@divanik Right.

@thevar1able
thevar1able added this pull request to the merge queue Jan 20, 2025
Merged via the queue into master with commit b61243d Jan 20, 2025
@thevar1able
thevar1able deleted the fix-glob-iterator branch January 20, 2025 14:57
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jan 20, 2025
alexey-milovidov pushed a commit that referenced this pull request Aug 5, 2026
All 22 failures in `Integration tests (amd_asan_ubsan, flaky)` reduce
to three causes:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113396&sha=1c45aad21479ffccd7c9e5099a0aab2667981054&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20flaky%29

1. pyhdfs 0.4.0 (the runner image has it now; the tests were written
   against 0.3.1) no longer defaults `user_name` to the local user, so
   WebHDFS requests ran as `nobody` and every write to `/` failed with
   `HdfsAccessControlException`. Pass `user_name="root"` at every
   `HdfsClient` construction site.

2. `PartitionManager._add_rule` was renamed to `add_rule` while the
   tests were gone; `test_url_reconnect` used the old name.

3. Since #73518 an enum glob (single brackets expansion, e.g.
   `{1..5}` or `{1,2,3,4,5}`) expands into concrete paths without
   listing, and every expanded path must exist. Reference only the
   files the test actually creates, matching the
   `test_s3_enum_glob_should_not_list` adaptation in the same PR.

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize s3[Cluster]('s3://bucket/prefix/{a.json,b.json}') S3 list request count

7 participants