summaryrefslogtreecommitdiffstats
path: root/node-repository
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2021-06-22 19:38:23 +0200
committerJon Bratseth <bratseth@gmail.com>2021-06-25 17:24:05 +0200
commiteecb3386a78b99dafc63d05b0ebd5a29ffa28161 (patch)
tree87d4995085dbd7d7e6e2fc98c28ca62c286a69e2 /node-repository
parent4f18bc8a12eebfff2854536f562f6941b2cd3254 (diff)
Serialize writes to each table
Diffstat (limited to 'node-repository')
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/QuestMetricsDb.java57
1 files changed, 31 insertions, 26 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 4726993e298..80ebd878237 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
@@ -105,22 +105,24 @@ public class QuestMetricsDb extends AbstractComponent implements MetricsDb {
}
private void addNodeMetrics(Collection<Pair<String, NodeMetricSnapshot>> snapshots, TableWriter writer) {
- for (var snapshot : snapshots) {
- Optional<Long> atMillis = nodeTable.adjustOrDiscard(snapshot.getSecond().at());
- if (atMillis.isEmpty()) return;
- TableWriter.Row row = writer.newRow(atMillis.get() * 1000); // in microseconds
- row.putStr(0, snapshot.getFirst());
- // (1 is timestamp)
- row.putFloat(2, (float)snapshot.getSecond().load().cpu());
- row.putFloat(3, (float)snapshot.getSecond().load().memory());
- row.putFloat(4, (float)snapshot.getSecond().load().disk());
- row.putLong(5, snapshot.getSecond().generation());
- row.putBool(6, snapshot.getSecond().inService());
- row.putBool(7, snapshot.getSecond().stable());
- row.putFloat(8, (float)snapshot.getSecond().queryRate());
- row.append();
+ synchronized (nodeTable.writeLock) {
+ for (var snapshot : snapshots) {
+ Optional<Long> atMillis = nodeTable.adjustOrDiscard(snapshot.getSecond().at());
+ if (atMillis.isEmpty()) return;
+ TableWriter.Row row = writer.newRow(atMillis.get() * 1000); // in microseconds
+ row.putStr(0, snapshot.getFirst());
+ // (1 is timestamp)
+ row.putFloat(2, (float) snapshot.getSecond().load().cpu());
+ row.putFloat(3, (float) snapshot.getSecond().load().memory());
+ row.putFloat(4, (float) snapshot.getSecond().load().disk());
+ row.putLong(5, snapshot.getSecond().generation());
+ row.putBool(6, snapshot.getSecond().inService());
+ row.putBool(7, snapshot.getSecond().stable());
+ row.putFloat(8, (float) snapshot.getSecond().queryRate());
+ row.append();
+ }
+ writer.commit();
}
- writer.commit();
}
@Override
@@ -140,18 +142,20 @@ public class QuestMetricsDb extends AbstractComponent implements MetricsDb {
}
private void addClusterMetrics(ApplicationId applicationId, Map<ClusterSpec.Id, ClusterMetricSnapshot> snapshots, TableWriter writer) {
- for (var snapshot : snapshots.entrySet()) {
- Optional<Long> atMillis = clusterTable.adjustOrDiscard(snapshot.getValue().at());
- if (atMillis.isEmpty()) return;
- TableWriter.Row row = writer.newRow(atMillis.get() * 1000); // in microseconds
- row.putStr(0, applicationId.serializedForm());
- row.putStr(1, snapshot.getKey().value());
- // (2 is timestamp)
- row.putFloat(3, (float)snapshot.getValue().queryRate());
- row.putFloat(4, (float)snapshot.getValue().writeRate());
- row.append();
+ synchronized (clusterTable.writeLock) {
+ for (var snapshot : snapshots.entrySet()) {
+ Optional<Long> atMillis = clusterTable.adjustOrDiscard(snapshot.getValue().at());
+ if (atMillis.isEmpty()) return;
+ TableWriter.Row row = writer.newRow(atMillis.get() * 1000); // in microseconds
+ row.putStr(0, applicationId.serializedForm());
+ row.putStr(1, snapshot.getKey().value());
+ // (2 is timestamp)
+ row.putFloat(3, (float) snapshot.getValue().queryRate());
+ row.putFloat(4, (float) snapshot.getValue().writeRate());
+ row.append();
+ }
+ writer.commit();
}
- writer.commit();
}
@Override
@@ -330,6 +334,7 @@ public class QuestMetricsDb extends AbstractComponent implements MetricsDb {
/** A questDb table */
private class Table {
+ private final Object writeLock = new Object();
private final String name;
private final Clock clock;
private final File dir;