From 366a36d55b4ee72bc7e71483370717f075223325 Mon Sep 17 00:00:00 2001 From: Lorenzo Mangani Date: Sun, 22 Oct 2023 17:32:22 +0200 Subject: [PATCH] Use {{DB}} in all queries Signed-off-by: Lorenzo Mangani --- lib/db/maintain/index.js | 42 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/db/maintain/index.js b/lib/db/maintain/index.js index f1689154..5fb58d4a 100644 --- a/lib/db/maintain/index.js +++ b/lib/db/maintain/index.js @@ -51,7 +51,7 @@ const upgradeSingle = async (db, key, scripts) => { 'ENGINE={{ReplacingMergeTree}}(ver) ORDER BY k', true) } } - let ver = await client.rawRequest(`SELECT max(ver) as ver FROM ver WHERE k = ${key} FORMAT JSON`, + let ver = await client.rawRequest(`SELECT max(ver) as ver FROM {{DB}}.ver WHERE k = ${key} FORMAT JSON`, null, db) ver = ver.data.data && ver.data.data[0] && ver.data.data[0].ver ? ver.data.data[0].ver : 0 for (let i = parseInt(ver); i < scripts.length; ++i) { @@ -83,8 +83,8 @@ const upgradeRequest = async (db, request, useDefaultDB, updateVer) => { console.log(request) await client.rawRequest(request, null, useDefaultDB ? db : undefined) if (updateVer) { - console.log(`INSERT INTO ver (k, ver) VALUES (${updateVer.key}, ${updateVer.to})`) - await client.rawRequest(`INSERT INTO ver (k, ver) VALUES (${updateVer.key}, ${updateVer.to})`, null, db) + console.log(`INSERT INTO {{DB}}.ver (k, ver) VALUES (${updateVer.key}, ${updateVer.to})`) + await client.rawRequest(`INSERT INTO {{DB}}.ver (k, ver) VALUES (${updateVer.key}, ${updateVer.to})`, null, db) } } @@ -105,53 +105,53 @@ module.exports.rotate = async (opts) => { return upgradeRequest(db.db, req, true) } if (db.samples_days + '' !== settings.v3_samples_days) { - const alterTable = 'ALTER TABLE samples_v3 {{{OnCluster}}} MODIFY SETTING ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600, index_granularity = 8192' - const rotateTable = `ALTER TABLE samples_v3 {{{OnCluster}}} MODIFY TTL toDateTime(timestamp_ns / 1000000000) + INTERVAL ${db.samples_days} DAY` + const alterTable = 'ALTER TABLE {{DB}}.samples_v3 {{{OnCluster}}} MODIFY SETTING ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600, index_granularity = 8192' + const rotateTable = `ALTER TABLE {{DB}}.samples_v3 {{{OnCluster}}} MODIFY TTL toDateTime(timestamp_ns / 1000000000) + INTERVAL ${db.samples_days} DAY` await _update(alterTable, null, db.db) await _update(rotateTable, null, db.db) await client.addSetting('rotate', 'v3_samples_days', db.samples_days + '', db.db) } if (db.time_series_days + '' !== settings.v3_time_series_days) { - const alterTable = 'ALTER TABLE time_series {{{OnCluster}}} MODIFY SETTING ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600, index_granularity = 8192' - const rotateTable = `ALTER TABLE time_series {{{OnCluster}}} MODIFY TTL "date" + INTERVAL ${db.time_series_days} DAY` + const alterTable = 'ALTER TABLE {{DB}}.time_series {{{OnCluster}}} MODIFY SETTING ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600, index_granularity = 8192' + const rotateTable = `ALTER TABLE {{DB}}.time_series {{{OnCluster}}} MODIFY TTL "date" + INTERVAL ${db.time_series_days} DAY` await _update(alterTable, null, db.db) await _update(rotateTable, null, db.db) - const alterView = 'ALTER TABLE time_series_gin {{{OnCluster}}} MODIFY SETTING ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600, index_granularity = 8192' - const rotateView = `ALTER TABLE time_series_gin {{{OnCluster}}} MODIFY TTL "date" + INTERVAL ${db.time_series_days} DAY` + const alterView = 'ALTER TABLE {{DB}}.time_series_gin {{{OnCluster}}} MODIFY SETTING ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600, index_granularity = 8192' + const rotateView = `ALTER TABLE {{DB}}.time_series_gin {{{OnCluster}}} MODIFY TTL "date" + INTERVAL ${db.time_series_days} DAY` await _update(alterView, null, db.db) await _update(rotateView, null, db.db) await client.addSetting('rotate', 'v3_time_series_days', db.time_series_days + '', db.db) } if (db.storage_policy && db.storage_policy !== settings.v3_storage_policy) { logger.debug(`Altering storage policy: ${db.storage_policy}`) - const alterTs = `ALTER TABLE time_series {{{OnCluster}}} MODIFY SETTING storage_policy='${db.storage_policy}'` - const alterTsVw = `ALTER TABLE time_series_gin {{{OnCluster}}} MODIFY SETTING storage_policy='${db.storage_policy}'` - const alterSm = `ALTER TABLE samples_v3 {{{OnCluster}}} MODIFY SETTING storage_policy='${db.storage_policy}'` + const alterTs = `ALTER TABLE {{DB}}.time_series {{{OnCluster}}} MODIFY SETTING storage_policy='${db.storage_policy}'` + const alterTsVw = `ALTER TABLE {{DB}}.time_series_gin {{{OnCluster}}} MODIFY SETTING storage_policy='${db.storage_policy}'` + const alterSm = `ALTER TABLE {{DB}}.samples_v3 {{{OnCluster}}} MODIFY SETTING storage_policy='${db.storage_policy}'` await _update(alterTs, null, db.db) await _update(alterTsVw, null, db.db) await _update(alterSm, null, db.db) await client.addSetting('rotate', 'v3_storage_policy', db.storage_policy, db.db) } if (db.samples_days + '' !== settings.v1_traces_days) { - let alterTable = 'ALTER TABLE tempo_traces {{{OnCluster}}} MODIFY SETTING ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600, index_granularity = 8192' - let rotateTable = `ALTER TABLE tempo_traces {{{OnCluster}}} MODIFY TTL toDateTime(timestamp_ns / 1000000000) + INTERVAL ${db.samples_days} DAY` + let alterTable = 'ALTER TABLE {{DB}}.tempo_traces {{{OnCluster}}} MODIFY SETTING ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600, index_granularity = 8192' + let rotateTable = `ALTER TABLE {{DB}}.tempo_traces {{{OnCluster}}} MODIFY TTL toDateTime(timestamp_ns / 1000000000) + INTERVAL ${db.samples_days} DAY` await _update(alterTable, null, db.db) await _update(rotateTable, null, db.db) - alterTable = 'ALTER TABLE tempo_traces_attrs_gin {{{OnCluster}}} MODIFY SETTING ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600, index_granularity = 8192' - rotateTable = `ALTER TABLE tempo_traces_attrs_gin {{{OnCluster}}} MODIFY TTL date + INTERVAL ${db.samples_days} DAY` + alterTable = 'ALTER TABLE {{DB}}.tempo_traces_attrs_gin {{{OnCluster}}} MODIFY SETTING ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600, index_granularity = 8192' + rotateTable = `ALTER TABLE {{DB}}.tempo_traces_attrs_gin {{{OnCluster}}} MODIFY TTL date + INTERVAL ${db.samples_days} DAY` await _update(alterTable, null, db.db) await _update(rotateTable, null, db.db) - alterTable = 'ALTER TABLE tempo_traces_kv {{{OnCluster}}} MODIFY SETTING ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600, index_granularity = 8192' - rotateTable = `ALTER TABLE tempo_traces_kv {{{OnCluster}}} MODIFY TTL date + INTERVAL ${db.samples_days} DAY` + alterTable = 'ALTER TABLE {{DB}}.tempo_traces_kv {{{OnCluster}}} MODIFY SETTING ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600, index_granularity = 8192' + rotateTable = `ALTER TABLE {{DB}}.tempo_traces_kv {{{OnCluster}}} MODIFY TTL date + INTERVAL ${db.samples_days} DAY` await _update(alterTable, null, db.db) await _update(rotateTable, null, db.db) await client.addSetting('rotate', 'v1_traces_days', db.samples_days + '', db.db) } if (db.storage_policy && db.storage_policy !== settings.v1_traces_storage_policy) { logger.debug(`Altering storage policy: ${db.storage_policy}`) - const alterTs = `ALTER TABLE tempo_traces MODIFY SETTING storage_policy='${db.storage_policy}'` - const alterTsVw = `ALTER TABLE tempo_traces_attrs_gin MODIFY SETTING storage_policy='${db.storage_policy}'` - const alterSm = `ALTER TABLE tempo_traces_kv MODIFY SETTING storage_policy='${db.storage_policy}'` + const alterTs = `ALTER TABLE {{DB}}.tempo_traces MODIFY SETTING storage_policy='${db.storage_policy}'` + const alterTsVw = `ALTER TABLE {{DB}}.tempo_traces_attrs_gin MODIFY SETTING storage_policy='${db.storage_policy}'` + const alterSm = `ALTER TABLE {{DB}}.tempo_traces_kv MODIFY SETTING storage_policy='${db.storage_policy}'` await _update(alterTs, null, db.db) await _update(alterTsVw, null, db.db) await _update(alterSm, null, db.db)