diff options
author | Harald Musum <musum@yahooinc.com> | 2022-01-31 23:35:59 +0100 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2022-01-31 23:35:59 +0100 |
commit | b6c4fe447f44f18323260a32dd163a4eebd64db9 (patch) | |
tree | b9f2a0b924526bbdbf82f94f3d0c6251bb6eb941 | |
parent | 0d0d920353d5129dacfec542fa63d6d5c6ddb87d (diff) |
Add method for issuing a query and waiting for it to be executed
Needs to be done for some queries (e.g. 'alter table) from Questdb
version 6.1.3 and later.
-rw-r--r-- | node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/QuestMetricsDb.java | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/QuestMetricsDb.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/QuestMetricsDb.java index 08a9e373085..7b5d64fbd5a 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/QuestMetricsDb.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/QuestMetricsDb.java @@ -341,6 +341,14 @@ public class QuestMetricsDb extends AbstractComponent implements MetricsDb { } } + /** + * Issues and wait for 'alter table' SQL statement to be executed against the QuestDb engine. + * Needs to be done for some queries, e.g. 'alter table' queries, see https://github.com/questdb/questdb/issues/1846 + */ + private void issueAndWait(String sql, SqlExecutionContext context) throws SqlException { + issue(sql, context).execute(null).await(); + } + private SqlExecutionContext newContext() { return new SqlExecutionContextImpl(engine(), 1); } @@ -374,7 +382,7 @@ public class QuestMetricsDb extends AbstractComponent implements MetricsDb { void gc() { synchronized (writeLock) { try { - issue("alter table " + name + " drop partition where at < dateadd('d', -4, now());", newContext()); + issueAndWait("alter table " + name + " drop partition where at < dateadd('d', -4, now());", newContext()); } catch (SqlException e) { log.log(Level.WARNING, "Failed to gc old metrics data in " + dir + " table " + name, e); @@ -396,7 +404,7 @@ public class QuestMetricsDb extends AbstractComponent implements MetricsDb { void ensureColumnExists(String column, String columnType) throws SqlException { if (columnNames().contains(column)) return; - issue("alter table " + name + " add column " + column + " " + columnType, newContext()); + issueAndWait("alter table " + name + " add column " + column + " " + columnType, newContext()); } private Optional<Long> adjustOrDiscard(Instant at) { |