Skip to content

Commit

Permalink
Use {{DB}} in all queries
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Mangani <[email protected]>
  • Loading branch information
lmangani authored Oct 22, 2023
1 parent a855ba5 commit 366a36d
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions lib/db/maintain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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)
Expand Down

0 comments on commit 366a36d

Please sign in to comment.