-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix large partitions in the metrics v2 table for the sidecar
Introduce a new metrics table to reduce disk usage and partition sizes
- Loading branch information
1 parent
05e5f32
commit 7774e4e
Showing
6 changed files
with
172 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/server/src/main/java/io/cassandrareaper/storage/cassandra/Migration024.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2020-2020 The Last Pickle Ltd | ||
* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.cassandrareaper.storage.cassandra; | ||
|
||
|
||
import com.datastax.driver.core.Session; | ||
import com.datastax.driver.core.VersionNumber; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public final class Migration024 { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(Migration024.class); | ||
private static final String METRICS_V3_TABLE = "node_metrics_v3"; | ||
|
||
private Migration024() { | ||
} | ||
|
||
/** | ||
* Apply TWCS for metrics tables if the Cassandra version allows it. | ||
*/ | ||
public static void migrate(Session session, String keyspace) { | ||
|
||
VersionNumber lowestNodeVersion = session.getCluster().getMetadata().getAllHosts() | ||
.stream() | ||
.map(host -> host.getCassandraVersion()) | ||
.min(VersionNumber::compareTo) | ||
.get(); | ||
|
||
if ((VersionNumber.parse("3.0.8").compareTo(lowestNodeVersion) <= 0 | ||
&& VersionNumber.parse("3.0.99").compareTo(lowestNodeVersion) >= 0) | ||
|| VersionNumber.parse("3.8").compareTo(lowestNodeVersion) <= 0) { | ||
try { | ||
if (!isUsingTwcs(session, keyspace)) { | ||
LOG.info("Altering {} to use TWCS...", METRICS_V3_TABLE); | ||
session.execute( | ||
"ALTER TABLE " + METRICS_V3_TABLE + " WITH compaction = {'class': 'TimeWindowCompactionStrategy', " | ||
+ "'unchecked_tombstone_compaction': 'true', " | ||
+ "'compaction_window_size': '10', " | ||
+ "'compaction_window_unit': 'MINUTES'}"); | ||
|
||
LOG.info("{} was successfully altered to use TWCS.", METRICS_V3_TABLE); | ||
|
||
} | ||
} catch (RuntimeException e) { | ||
LOG.error("Failed altering metrics tables to TWCS", e); | ||
} | ||
} | ||
|
||
} | ||
|
||
private static boolean isUsingTwcs(Session session, String keyspace) { | ||
return session | ||
.getCluster() | ||
.getMetadata() | ||
.getKeyspace(keyspace) | ||
.getTable(METRICS_V3_TABLE) | ||
.getOptions() | ||
.getCompaction() | ||
.get("class") | ||
.contains("TimeWindowCompactionStrategy"); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/server/src/main/resources/db/cassandra/024_node_metrics_v3_partitioning.cql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
-- | ||
-- Copyright 2020-2020 The Last Pickle Ltd | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
-- | ||
-- Upgrade to handle diagnostic event subscriptions | ||
|
||
DROP TABLE IF EXISTS node_metrics_v2; | ||
|
||
CREATE TABLE IF NOT EXISTS node_metrics_v3 ( | ||
cluster text, | ||
metric_domain text, | ||
metric_type text, | ||
time_bucket text, | ||
host text, | ||
ts timestamp, | ||
metric_scope text, | ||
metric_name text, | ||
metric_attribute text, | ||
value double, | ||
PRIMARY KEY ((cluster, metric_domain, metric_type, time_bucket, host), ts, metric_scope, metric_name, metric_attribute) | ||
) WITH CLUSTERING ORDER BY (ts DESC, metric_scope ASC, metric_name ASC, metric_attribute ASC) | ||
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4', 'unchecked_tombstone_compaction': 'true'} | ||
AND default_time_to_live = 3600 | ||
AND gc_grace_seconds = 300; |