Merge "Update all columns in metrics on an update to refresh TTL" into stable/rocky
This commit is contained in:
commit
81abadf4ea
@ -64,6 +64,7 @@ public class CassandraCluster {
|
|||||||
+ "set value = ?, value_meta = ?, region = ?, tenant_id = ?, metric_name = ?, dimensions = ? "
|
+ "set value = ?, value_meta = ?, region = ?, tenant_id = ?, metric_name = ?, dimensions = ? "
|
||||||
+ "where metric_id = ? and time_stamp = ?";
|
+ "where metric_id = ? and time_stamp = ?";
|
||||||
|
|
||||||
|
// TODO: Remove update statements, TTL issues
|
||||||
private static final String MEASUREMENT_UPDATE_CQL = "update monasca.measurements USING TTL ? "
|
private static final String MEASUREMENT_UPDATE_CQL = "update monasca.measurements USING TTL ? "
|
||||||
+ "set value = ?, value_meta = ? " + "where metric_id = ? and time_stamp = ?";
|
+ "set value = ?, value_meta = ? " + "where metric_id = ? and time_stamp = ?";
|
||||||
|
|
||||||
@ -71,10 +72,6 @@ public class CassandraCluster {
|
|||||||
+ "set metric_id = ?, created_at = ?, updated_at = ? "
|
+ "set metric_id = ?, created_at = ?, updated_at = ? "
|
||||||
+ "where region = ? and tenant_id = ? and metric_name = ? and dimensions = ? and dimension_names = ?";
|
+ "where region = ? and tenant_id = ? and metric_name = ? and dimensions = ? and dimension_names = ?";
|
||||||
|
|
||||||
private static final String METRICS_UPDATE_CQL = "update monasca.metrics USING TTL ? "
|
|
||||||
+ "set updated_at = ? "
|
|
||||||
+ "where region = ? and tenant_id = ? and metric_name = ? and dimensions = ? and dimension_names = ?";
|
|
||||||
|
|
||||||
private static final String DIMENSION_INSERT_CQL = "insert into monasca.dimensions "
|
private static final String DIMENSION_INSERT_CQL = "insert into monasca.dimensions "
|
||||||
+ "(region, tenant_id, name, value) values (?, ?, ?, ?)";
|
+ "(region, tenant_id, name, value) values (?, ?, ?, ?)";
|
||||||
|
|
||||||
@ -115,7 +112,6 @@ public class CassandraCluster {
|
|||||||
private PreparedStatement measurementInsertStmt;
|
private PreparedStatement measurementInsertStmt;
|
||||||
private PreparedStatement measurementUpdateStmt;
|
private PreparedStatement measurementUpdateStmt;
|
||||||
private PreparedStatement metricInsertStmt;
|
private PreparedStatement metricInsertStmt;
|
||||||
private PreparedStatement metricUpdateStmt;
|
|
||||||
private PreparedStatement dimensionStmt;
|
private PreparedStatement dimensionStmt;
|
||||||
private PreparedStatement dimensionMetricStmt;
|
private PreparedStatement dimensionMetricStmt;
|
||||||
private PreparedStatement metricDimensionStmt;
|
private PreparedStatement metricDimensionStmt;
|
||||||
@ -182,9 +178,9 @@ public class CassandraCluster {
|
|||||||
metricsSession = cluster.connect(dbConfig.getKeySpace());
|
metricsSession = cluster.connect(dbConfig.getKeySpace());
|
||||||
|
|
||||||
measurementInsertStmt = metricsSession.prepare(MEASUREMENT_INSERT_CQL).setIdempotent(true);
|
measurementInsertStmt = metricsSession.prepare(MEASUREMENT_INSERT_CQL).setIdempotent(true);
|
||||||
|
// TODO: Remove update statements, TTL issues
|
||||||
measurementUpdateStmt = metricsSession.prepare(MEASUREMENT_UPDATE_CQL).setIdempotent(true);
|
measurementUpdateStmt = metricsSession.prepare(MEASUREMENT_UPDATE_CQL).setIdempotent(true);
|
||||||
metricInsertStmt = metricsSession.prepare(METRICS_INSERT_CQL).setIdempotent(true);
|
metricInsertStmt = metricsSession.prepare(METRICS_INSERT_CQL).setIdempotent(true);
|
||||||
metricUpdateStmt = metricsSession.prepare(METRICS_UPDATE_CQL).setIdempotent(true);
|
|
||||||
dimensionStmt = metricsSession.prepare(DIMENSION_INSERT_CQL).setIdempotent(true);
|
dimensionStmt = metricsSession.prepare(DIMENSION_INSERT_CQL).setIdempotent(true);
|
||||||
dimensionMetricStmt = metricsSession.prepare(DIMENSION_METRIC_INSERT_CQL).setIdempotent(true);
|
dimensionMetricStmt = metricsSession.prepare(DIMENSION_METRIC_INSERT_CQL).setIdempotent(true);
|
||||||
metricDimensionStmt = metricsSession.prepare(METRIC_DIMENSION_INSERT_CQL).setIdempotent(true);
|
metricDimensionStmt = metricsSession.prepare(METRIC_DIMENSION_INSERT_CQL).setIdempotent(true);
|
||||||
@ -232,6 +228,7 @@ public class CassandraCluster {
|
|||||||
return measurementInsertStmt;
|
return measurementInsertStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove update statements, TTL issues
|
||||||
public PreparedStatement getMeasurementUpdateStmt() {
|
public PreparedStatement getMeasurementUpdateStmt() {
|
||||||
return measurementUpdateStmt;
|
return measurementUpdateStmt;
|
||||||
}
|
}
|
||||||
@ -240,10 +237,6 @@ public class CassandraCluster {
|
|||||||
return metricInsertStmt;
|
return metricInsertStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreparedStatement getMetricUpdateStmt() {
|
|
||||||
return metricUpdateStmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreparedStatement getDimensionStmt() {
|
public PreparedStatement getDimensionStmt() {
|
||||||
return dimensionStmt;
|
return dimensionStmt;
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,9 @@ public class CassandraMetricRepo extends CassandraRepo implements Repo<MetricEnv
|
|||||||
metric.getValue(), metric.getValueMeta(), region, tenantId, metricName, dimensions, id));
|
metric.getValue(), metric.getValueMeta(), region, tenantId, metricName, dimensions, id));
|
||||||
} else {
|
} else {
|
||||||
metricCacheHitMeter.mark();
|
metricCacheHitMeter.mark();
|
||||||
batches.addMetricQuery(cluster.getMetricUpdateStmt().bind(retention,
|
// MUST update all relevant columns to ensure TTL consistency in a row
|
||||||
|
batches.addMetricQuery(cluster.getMetricInsertStmt().bind(retention,
|
||||||
|
defIdShaHash.getSha1HashByteBuffer(), new Timestamp(metric.getTimestamp()),
|
||||||
new Timestamp(metric.getTimestamp()), region, tenantId, metricName,
|
new Timestamp(metric.getTimestamp()), region, tenantId, metricName,
|
||||||
getDimensionList(dimensions), new ArrayList<>(dimensions.keySet())));
|
getDimensionList(dimensions), new ArrayList<>(dimensions.keySet())));
|
||||||
batches.addMeasurementQuery(buildMeasurementUpdateQuery(defIdShaHash, metric.getTimestamp(),
|
batches.addMeasurementQuery(buildMeasurementUpdateQuery(defIdShaHash, metric.getTimestamp(),
|
||||||
|
Loading…
Reference in New Issue
Block a user