Repository navigation
feat(app): prefer shared MergeTree settings #3570
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@hyperdx/app': patch | ||
| '@hyperdx/common-utils': patch | ||
| --- | ||
|
|
||
| feat: on ClickHouse Cloud, read `system.shared_merge_tree_settings` when detecting `_block_number` and `_block_offset` columns, falling back to `system.merge_tree_settings` per key |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2242,28 +2242,44 @@ export class Metadata { | |
| } | ||
|
|
||
| /** | ||
| * Reads and caches system.merge_tree_settings per connection. Returns | ||
| * undefined on failure so the next call retries. | ||
| * Reads and caches MergeTree settings per connection; on Cloud, | ||
| * system.shared_merge_tree_settings overrides system.merge_tree_settings per | ||
| * key. Returns undefined on failure so the next call retries. | ||
| */ | ||
| async getMergeTreeSettings({ | ||
| connectionId, | ||
| }: { | ||
| connectionId: string; | ||
| }): Promise<Map<string, string> | undefined> { | ||
| const readSettings = (query: string) => | ||
| this.clickhouseClient | ||
| .query<'JSON'>({ | ||
| connectionId, | ||
| query, | ||
| query_params: undefined, | ||
| clickhouse_settings: this.getClickHouseSettings(), | ||
| }) | ||
| .then(res => res.json<{ name: string; value: string }>()) | ||
| .then(json => json.data); | ||
|
|
||
| return this.cache.getOrFetch( | ||
| `${connectionId}.mergeTreeSettings`, | ||
| async () => { | ||
| try { | ||
| const json = await this.clickhouseClient | ||
| .query<'JSON'>({ | ||
| connectionId, | ||
| query: 'SELECT name, value FROM system.merge_tree_settings', | ||
| query_params: undefined, | ||
| clickhouse_settings: this.getClickHouseSettings(), | ||
| }) | ||
| .then(res => res.json<{ name: string; value: string }>()); | ||
|
|
||
| return new Map(json.data.map(row => [row.name, row.value])); | ||
| // OSS has no shared_merge_tree_settings; querying it fails. | ||
| const isCloud = await this.isClickHouseCloud({ connectionId }); | ||
| const [mergeTreeRows, sharedMergeTreeRows] = await Promise.all([ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 major — A failed shared-table read throws away the merge_tree_settings result too Both queries run in one Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond |
||
| readSettings('SELECT name, value FROM system.merge_tree_settings'), | ||
| isCloud | ||
| ? readSettings( | ||
| 'SELECT name, value FROM system.shared_merge_tree_settings', | ||
| ) | ||
| : [], | ||
| ]); | ||
|
|
||
| // Later rows win. | ||
| const rows = [...mergeTreeRows, ...sharedMergeTreeRows]; | ||
| return new Map(rows.map(row => [row.name, row.value])); | ||
| } catch (e) { | ||
| console.warn('Error fetching MergeTree settings:', e); | ||
| return undefined; | ||
|
|
||
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.
🟠 major — A failed Cloud check permanently caches settings that ignore the shared table
If the Cloud check fails once (a timeout or network blip),
isClickHouseCloud(metadata.ts:2146-2173) doesn't cache the failure but returnsfalse.getMergeTreeSettingsthen builds a map frommerge_tree_settingsalone.MetadataCache.setstores it with no TTL (metadata.ts:304-330), so a Cloud connection keeps missing the shared-table values for the life of the session. That is exactly the bug this PR is meant to fix. Fix: if detection fails, don't cache this result either. For example, add a method that returnsboolean | undefined, and returnundefinedfromgetMergeTreeSettingswhen the result isundefined.Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond