diff options
author | Valerij Fredriksen <freva@users.noreply.github.com> | 2020-12-02 16:24:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-02 16:24:48 +0100 |
commit | 44c06eb7569533a53a49b7aa703d9a0d84746fb1 (patch) | |
tree | 528285a1ead6540a5f18a9ed778feb1f2feaa34f | |
parent | e0ff48f98757a80ce516518f86a7d013f7e18aa1 (diff) | |
parent | 6e95457b48804e5bf8da03721336cab8e23d7eff (diff) |
Merge pull request #15606 from vespa-engine/bratseth/more-questdb-robustness
Start over if we cannot alter the db
-rw-r--r-- | node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/QuestMetricsDb.java | 34 |
1 files changed, 23 insertions, 11 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 0b3775a683f..8e90294b4a5 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 @@ -174,7 +174,7 @@ public class QuestMetricsDb extends AbstractComponent implements MetricsDb { * * @param e the exception indicating corruption */ - private void repair(CairoException e) { + private void repair(Exception e) { log.log(Level.WARNING, "QuestDb seems corrupted, wiping data and starting over", e); IOUtils.recursiveDeleteDir(new File(dataDir)); initializeDb(); @@ -182,22 +182,34 @@ public class QuestMetricsDb extends AbstractComponent implements MetricsDb { private void ensureExists(String table) { SqlExecutionContext context = newContext(); + if (0 == engine.getStatus(context.getCairoSecurityContext(), new Path(), table)) { // table exists + ensureUpdated(table, context); + } else { + create(table, context); + } + } + + private void ensureUpdated(String table, SqlExecutionContext context) { try (SqlCompiler compiler = new SqlCompiler(engine)) { if (0 == engine.getStatus(context.getCairoSecurityContext(), new Path(), table)) { ensureColumnExists("inService", "boolean", table, compiler, context); // TODO: Remove after December 2020 ensureColumnExists("stable", "boolean", table, compiler, context); // TODO: Remove after December 2020 } - else { - compiler.compile("create table " + table + - " (hostname string, at timestamp, cpu_util float, mem_total_util float, disk_util float," + - " application_generation long, inService boolean, stable boolean)" + - " timestamp(at)" + - "PARTITION BY DAY;", - context); - // We should do this if we get a version where selecting on strings work embedded, see below - // compiler.compile("alter table " + tableName + " alter column hostname add index", context); - } + } catch (SqlException e) { + repair(e); + } + } + private void create(String table, SqlExecutionContext context) { + try (SqlCompiler compiler = new SqlCompiler(engine)) { + compiler.compile("create table " + table + + " (hostname string, at timestamp, cpu_util float, mem_total_util float, disk_util float," + + " application_generation long, inService boolean, stable boolean)" + + " timestamp(at)" + + "PARTITION BY DAY;", + context); + // We should do this if we get a version where selecting on strings work embedded, see below + // compiler.compile("alter table " + tableName + " alter column hostname add index", context); } catch (SqlException e) { throw new IllegalStateException("Could not create Quest db table '" + table + "'", e); |