From 860a24bb85a474e88264bf84082339f677fa12f1 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Mon, 9 Nov 2020 13:36:05 +0100 Subject: Don't remove all partitions: Not currently supported --- .../com/yahoo/vespa/hosted/provision/autoscale/QuestMetricsDb.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 070bf98bf87..2cb80a04e33 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 @@ -114,18 +114,23 @@ public class QuestMetricsDb implements MetricsDb { // Since we remove full days at once we need to keep at least the scaling window + 1 day Instant oldestToKeep = clock.instant().minus(Autoscaler.maxScalingWindow().plus(Duration.ofDays(1))); SqlExecutionContext context = newContext(); + int partitionsFound = 0; try (SqlCompiler compiler = new SqlCompiler(engine)) { File tableRoot = new File(dataDir, tableName); List removeList = new ArrayList<>(); for (String dirEntry : tableRoot.list()) { File partitionDir = new File(tableRoot, dirEntry); if ( ! partitionDir.isDirectory()) continue; + + partitionsFound++; DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneId.of("UTC")); Instant partitionDay = Instant.from(formatter.parse(dirEntry + "T00:00:00")); if (partitionDay.isBefore(oldestToKeep)) removeList.add(dirEntry); + } - if ( ! removeList.isEmpty()) + // Remove unless all partitions are old: Removing all partitions "will be supported in the future" + if ( removeList.size() < partitionsFound && ! removeList.isEmpty()) compiler.compile("alter table " + tableName + " drop partition " + removeList.stream().map(dir -> "'" + dir + "'").collect(Collectors.joining(",")), context); -- cgit v1.2.3