Repository navigation
Conversation
…probe Add `object_storage_cluster_local_read_max_files` and `object_storage_cluster_local_read_probe_ms`. When enabled, the initiator lists the object storage files for a `*Cluster` query for up to the time budget. If the listing finishes within the budget and yields at most the file limit, the query is read locally. Otherwise the query keeps the cluster path. The default of `0` keeps the existing behavior. Co-authored-by: Cursor <cursoragent@cursor.com>
The `object_storage_cluster_local_read_max_files` probe listed files and then discarded them, so the local read or the cluster task distributor listed the same files again. Keep the probe iterator and the objects it already returned on the query info, and replay them in `ReadFromObjectStorageStep` and in `getTaskIteratorExtension`. Placeholder metadata from `skip_object_metadata` is dropped for local reads so they fetch the real size. Queries that read `_tags` still list again, because the probe does not request tags. Co-authored-by: Cursor <cursoragent@cursor.com>
Keep the local-or-cluster decision on `ObjectStorageClusterReadProbe` instead of a second flag on `SelectQueryInfo`. A finished listing is represented by a null iterator, so the separate exhausted flag is gone. `createObjectIteratorForRead` always sets `tasks_go_to_other_replicas` and emits profile events, so those parameters are removed. Placeholder metadata from `skip_object_metadata` is no longer cleared for local reads, because the read already treats an unfetched object as an unknown size. Co-authored-by: Cursor <cursoragent@cursor.com>
…e children A `Merge` passes one `SelectQueryInfo` to every child, so a single probe slot let the first child's local-read decision apply to later children. The probe is now keyed by the cluster storage, and `05429_object_storage_cluster_local_read_merge` checks a small child read locally next to a large child that stays on the cluster. Co-authored-by: Cursor <cursoragent@cursor.com>
The probe now counts the same tasks the cluster would run, so with `bucket` split granularity each bucket counts, not each file. The setting `object_storage_cluster_local_read_max_files` is renamed to `object_storage_cluster_local_read_max_tasks`. Co-authored-by: Cursor <cursoragent@cursor.com>
…probe The probe drops a finished iterator, so a local read lost the `_data_lake_snapshot_version` that the cluster read reports. The probe now stores the snapshot version before it releases the iterator, and the replay iterator returns it. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5021b15138
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| auto object = iterator->next(0); | ||
| if (!object) | ||
| { | ||
| probe->read_locally = true; |
There was a problem hiding this comment.
Enforce the probe deadline across iterator calls
When iterator->next(0) starts just before the deadline but a slow object-store listing or bucket split returns nullptr after it, this branch marks the probe local without checking elapsed time again. Consequently object_storage_cluster_local_read_probe_ms neither bounds planning latency nor preserves the documented rule that a listing finishing outside the budget stays distributed; use a deadline-aware/cancellable iterator operation and verify the deadline before accepting exhaustion as a local-read decision.
Useful? React with 👍 / 👎.
…cluster-local-read-probe
…cluster-local-read-probe
PR 2808 — confirmed issues1. Local read drops every file listed without object metadataSeverity: High
The local scan reuses those objects. A cluster read of the same path does not hit this. The worker rebuilds An exact path with no glob is unaffected: that Steps to reproduce:
2. The probe time budget does not cover the listing callSeverity: Medium
Steps to reproduce:
|
PR 2808: both issues reproducedBoth issues from the audit comment reproduce on the PR build.
Issue 1: a local read drops every file listed without object metadataTwo non-empty files: SELECT _path, _size, x
FROM s3(s3, filename = 'pr2808/local_read_*.tsv', format = 'TSV', structure = 'x UInt32')
ORDER BY _path;
-- warehouse/pr2808/local_read_a.tsv 2 1
-- warehouse/pr2808/local_read_b.tsv 2 2All queries below use these settings: SETTINGS object_storage_cluster = 'default_cluster',
object_storage_cluster_local_read_max_tasks = 10,
object_storage_cluster_local_read_probe_ms = 5000The bug. The query succeeds and returns no data: -- One-key brace expansion
SELECT count(), sum(x) FROM s3(s3, filename = 'pr2808/local_read_{a}.tsv', format = 'TSV', structure = 'x UInt32');
-- 0 0 expected: 1 1
-- Two-key brace expansion
SELECT count(), sum(x) FROM s3(s3, filename = 'pr2808/local_read_{a,b}.tsv', format = 'TSV', structure = 'x UInt32');
-- 0 0 expected: 2 3
-- Glob whose keys come from the _path filter
SELECT count(), sum(x) FROM s3(s3, filename = 'pr2808/local_read_*.tsv', format = 'TSV', structure = 'x UInt32')
WHERE _path = 'warehouse/pr2808/local_read_a.tsv';
-- 0 0 expected: 1 1Controls. Each of these returns the right data: -- The same brace read with the setting off, so it runs on the cluster
SELECT count(), sum(x) FROM s3(s3, filename = 'pr2808/local_read_{a,b}.tsv', ...)
SETTINGS object_storage_cluster_local_read_max_tasks = 0;
-- 2 3
-- An exact path, read locally
SELECT count(), sum(x) FROM s3(s3, filename = 'pr2808/local_read_a.tsv', ...);
-- 1 1
-- A plain glob, read locally
SELECT count(), sum(x) FROM s3(s3, filename = 'pr2808/local_read_*.tsv', ...);
-- 2 3
-- The failing brace read with the empty-file skip turned off
SELECT count(), sum(x) FROM s3(s3, filename = 'pr2808/local_read_{a,b}.tsv', ...)
SETTINGS s3_skip_empty_files = 0;
-- 2 3Which queries read locally. SELECT log_comment, ProfileEvents['Shards'] > 0 AS distributed, result_rows
FROM system.query_log WHERE type = 'QueryFinish' AND log_comment LIKE 'pr2808\_%';
-- pr2808_brace_one_local 0 1
-- pr2808_brace_two_local 0 1
-- pr2808_glob_filter_local 0 1
-- pr2808_brace_cluster 1 1
-- pr2808_exact_local 0 1
-- pr2808_glob_local 0 1
-- pr2808_brace_local_noskip 0 1Conclusion. Rows are lost only when two things combine:
Turning off Issue 2: the probe time budget does not cover the listing callToxiproxy adds 3 s of latency to every S3 response. -- Probe on, with a 1 ms budget
EXPLAIN SELECT count() FROM s3(s3_proxy, filename = 'pr2808/local_read_*.tsv', format = 'TSV', structure = 'x UInt32')
SETTINGS object_storage_cluster = 'default_cluster',
object_storage_cluster_local_read_max_tasks = 10,
object_storage_cluster_local_read_probe_ms = 1;
-- planning: 7147 ms, 2 ListObjects batches
-- trace: Local-read probe for _table_function.s3 saw 1 task(s) (limit 10), read_locally=false,
-- reason=probe time budget exceeded
-- Control: the setting off
EXPLAIN SELECT count() FROM s3(s3_proxy, filename = 'pr2808/local_read_*.tsv', format = 'TSV', structure = 'x UInt32')
SETTINGS object_storage_cluster = 'default_cluster',
object_storage_cluster_local_read_max_tasks = 0;
-- planning: 3624 ms, 1 ListObjects batch (resolving a sample path; this happens without the PR too)Conclusion. The probe added 3523 ms to planning, one full Impact. The full
The cluster read reuses the probe's iterator, so the listing time moves from execution into planning; it is not added on top. The bug blocks planning, which includes |
… read The cluster local-read probe lists with `skip_object_metadata = true` and the local read reuses those objects. For a brace expansion and for keys taken from a `_path` filter the listing is a `KeysIterator`, which returns a placeholder `ObjectMetadata` with `is_fetched = false`, `size_bytes = 0` and `is_size_known = true`. `StorageObjectStorageSource` fetched metadata only when it was missing, so the placeholder was accepted and, with `s3_skip_empty_files` (the default), such files were skipped as empty. The query succeeded and returned no rows. Fetch the metadata also when it is a placeholder (`is_fetched = false`). Review comment: #2808 (comment) Related: #2808 Co-authored-by: Cursor <cursoragent@cursor.com>
…alya-26.8/object-storage-cluster-local-read-probe
05484 is already taken on the base branch. Co-authored-by: Cursor <cursoragent@cursor.com>
The S3 object names and log comments still used the old 05484 prefix. Co-authored-by: Cursor <cursoragent@cursor.com>
…s budget `isSmallEnoughForLocalRead` checked `object_storage_cluster_local_read_probe_ms` only before each `next` call. A `next` that started inside the budget but returned `nullptr` after it was still taken for a small listing, contrary to the documented rule that the query stays on the cluster when the task list does not end inside the budget. Check the deadline once more after the last `next`. A finished iterator is no longer attached to the probe on that path either: all its tasks are already in the probe. A `next` call that has already started cannot be interrupted, so planning can still exceed the budget by one listing call. Document it in `object_storage_cluster_local_read_probe_ms`. Review comment: #2808 (comment) Related: #2808 Co-authored-by: Cursor <cursoragent@cursor.com>
The local-read probe added a sixth parameter to the virtual `IStorageCluster::getTaskIteratorExtension`. The whole-query dispatch unit-test mocks still overrode the five-parameter form, so `unit_tests_dbms` failed to compile after the merge of `antalya-26.8`. Co-authored-by: Cursor <cursoragent@cursor.com>
…e files than without it The probe lists with the filter known at planning time, before the optimizer pushes filters into the read. The test compares the files sent to the swarm nodes with `object_storage_cluster_local_read_max_tasks` set to 0 and to 1 for a plain `_path` filter, a filter of the outer query and a `_path` set taken from a subquery. Co-authored-by: Cursor <cursoragent@cursor.com>
… settings history `object_storage_cluster_local_read_max_tasks` and `object_storage_cluster_local_read_probe_ms` sat in the `26.6.8.20003.altinityantalya` block, a release line that does not contain them. The settings history check requires a new setting under the current version block, so they move to `26.8.39.20001.altinityantalya`. Co-authored-by: Cursor <cursoragent@cursor.com>
…r `DESCRIBE` and `EXPLAIN` The probe lists objects while planning. `DESCRIBE (SELECT ...)`, `EXPLAIN PLAN` and `EXPLAIN PIPELINE` read no data, but they reached `getQueryProcessingStage` and ran the listing, so with `s3_throw_on_zero_files_match` (or an unreachable storage) they failed where they did not before the probe existed. `DESCRIBE` now builds its header in analyze mode, which does not ask the storage for the processing stage. For `EXPLAIN` the planner sets `object_storage_cluster_local_read_max_tasks` to 0 for the query, so the explained plan is the one of the cluster read. Co-authored-by: Cursor <cursoragent@cursor.com>
…EXPLAIN ANALYZE` The previous commit made `DESCRIBE` only analyze the query. In that mode the planner does not check `SELECT` on the tables of nested subqueries, so a user with a grant on some columns could learn the types of the other columns: `DESCRIBE (SELECT * FROM (SELECT secret FROM t))` returned `secret String`. `DESCRIBE` plans the query in full again and marks it with the new `SelectQueryOptions::plan_only` flag. The planner uses the flag to skip the local-read probe. `EXPLAIN` without `ANALYZE` sets the same flag, so it keeps showing the plan of the cluster read. The flag is new because `is_explain` also changes how the legacy analyzer handles global subqueries. `EXPLAIN ANALYZE` executes the query, so it does not set the flag and runs the probe, as the query does. Tests: `05818_object_storage_cluster_local_read_describe_nested_access`, `05819_object_storage_cluster_local_read_explain_analyze_probes`. Co-authored-by: Cursor <cursoragent@cursor.com>
When `object_storage_cluster_local_read_max_tasks` reuses the probe listing, the listed objects are placeholders: their metadata is not fetched and their size is reported as zero. Two problems followed from this: - Progress: the local read reported zero bytes for each file, so `total_bytes_to_read` was wrong. The new resolver in `ReadFromObjectStorageStep::createIterator` fetches the metadata of each placeholder once and reports its real size through `FileProgress`. - Missing files: with `s3_ignore_file_doesnt_exist = 1`, a file deleted after listing made the reader end its stream early, so the objects after it were silently dropped. The same query without the probe returned all the remaining rows. `StorageObjectStorageSource::createReader` now skips such a file with `continue`. The metadata fetch moved into `StorageObjectStorageSource::fetchObjectMetadataIfNeeded`, shared by the reader and the resolver. `ObjectIteratorWithPrefetchedObjects` applies the resolver outside its mutex, because it may read from the object storage. Adds the test `05820_object_storage_cluster_local_read_ignore_missing_file`. Co-authored-by: Cursor <cursoragent@cursor.com>
A cluster local read after the `object_storage_cluster_local_read_max_tasks` probe reports each placeholder's real size to the progress callback. With `cluster_table_function_split_granularity = 'bucket'` this reported nothing for a file listed without metadata, so `total_bytes_to_read` stayed zero: - `ObjectIteratorSplitByBuckets` fetches the metadata of the original object through `createReadBuffer` and then clones it for every bucket. The clones are no longer placeholders, so the metadata resolver in `ReadFromObjectStorageStep` skipped them. - With `s3_validate_etag_on_read = 0` the clones stay placeholders. Reporting each of them would count the file once per bucket. `ObjectIteratorSplitByBuckets` now reports the size once per file that the listing skipped the metadata of. The resolver reports a bucket placeholder only the first time it sees its file. Files listed with metadata are still reported by the listing. Co-authored-by: Cursor <cursoragent@cursor.com>
With `cluster_table_function_split_granularity = 'bucket'`, `ObjectIteratorSplitByBuckets` asks `FormatFactory::getSplitter` for a splitter of the format. Only `Parquet` registers one, and `getSplitter` called the empty creator for any other format, so a query over `TSV` failed with `std::bad_function_call`. The iterator also had no branch for a format without a splitter, so it would have dropped the file. `getSplitter` now returns null when the format has no splitter, and the iterator passes such a file through as a single task. Adds the test `05821_object_storage_cluster_local_read_bucket_unsplittable_format`. Co-authored-by: Cursor <cursoragent@cursor.com>
…doesnt_exist` With `cluster_table_function_split_granularity = 'bucket'`, `ObjectIteratorSplitByBuckets` opens each file to read its row groups. For a file listed without metadata, `createReadBuffer` fetches the metadata and fails when the file does not exist, so `s3_ignore_file_doesnt_exist = 1` was not honored: the query failed with `S3_ERROR`, both for the distributed read and for the local read after the `object_storage_cluster_local_read_max_tasks` probe. When missing files are ignored, `ObjectIteratorSplitByBuckets` now fetches the metadata first and skips a file that does not exist. The setting is passed from the storage configuration. Without the setting nothing changes. Adds the test `05822_object_storage_cluster_local_read_bucket_ignore_missing_file`. Co-authored-by: Cursor <cursoragent@cursor.com>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Select plain or swarm mode for cluster query
Documentation entry for user-facing changes
We have a
object_storage_clusterfeature to make distributed query to table on object storage.But small query can be executed faster locally, directly on initiator.
This feature allow to select local or distributed way based on expected query size.
It does not give 100% accuracy, it's a some kind of heuristic.
Distributed query is split on tasks for remote nodes.
Now we start to do in on early stage. If we get only few tasks, not greater than
object_storage_cluster_local_read_max_tasksand spend not more thanobject_storage_cluster_local_read_probe_msmilliseconds, we execute query locally. In other case, execute on cluster.CI/CD Options
Exclude tests:
Regression jobs to run: