From e6c5da9ce9e702649cee5652eaebbcfe802b6815 Mon Sep 17 00:00:00 2001 From: inespot <34454302+inespot@users.noreply.github.com> Date: Tue, 12 Nov 2024 17:14:17 -0500 Subject: [PATCH] Phi threshold can be set via nodetool (#579) Co-authored-by: ines potier --- .../metrics/FailureDetectorMetrics.java | 28 ++++++++++--- .../nodetool/GetPhiConvictThreshold.java | 31 +++++++++++++++ .../nodetool/SetPhiConvictThreshold.java | 39 +++++++++++++++++++ .../cassandra/config/DatabaseDescriptor.java | 4 +- .../org/apache/cassandra/tools/NodeProbe.java | 10 +++++ .../org/apache/cassandra/tools/NodeTool.java | 2 + 6 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 src/java/com/palantir/cassandra/tools/nodetool/GetPhiConvictThreshold.java create mode 100644 src/java/com/palantir/cassandra/tools/nodetool/SetPhiConvictThreshold.java diff --git a/src/java/com/palantir/cassandra/metrics/FailureDetectorMetrics.java b/src/java/com/palantir/cassandra/metrics/FailureDetectorMetrics.java index f2a1c7dc7a..a006592c26 100644 --- a/src/java/com/palantir/cassandra/metrics/FailureDetectorMetrics.java +++ b/src/java/com/palantir/cassandra/metrics/FailureDetectorMetrics.java @@ -19,18 +19,28 @@ package com.palantir.cassandra.metrics; import java.net.InetAddress; +import java.util.Optional; import java.util.function.Supplier; import com.google.common.net.InetAddresses; import com.codahale.metrics.Gauge; import com.codahale.metrics.Snapshot; +import com.sun.istack.internal.NotNull; +import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.db.Directories; import org.apache.cassandra.metrics.CassandraMetricsRegistry; import static org.apache.cassandra.metrics.CassandraMetricsRegistry.Metrics; public class FailureDetectorMetrics { + private static final String groupName = FailureDetectorMetrics.class.getPackage().getName(); + static + { + Metrics.register(createMetricName("FailureDetectorPhiThreshold"), (Gauge) DatabaseDescriptor::getPhiConvictThreshold); + } + public static void register( InetAddress ep, Gauge phiSupplier, Gauge lastIntervalSupplier, Supplier snapshotSupplier) { @@ -46,17 +56,25 @@ public static void unregister(InetAddress ep) Metrics.remove(createMetricName(ep, "FailureDetectorArrivalIntervals")); } - private static CassandraMetricsRegistry.MetricName createMetricName(InetAddress ep, String name) + private static CassandraMetricsRegistry.MetricName createMetricName(String name) + { + return new CassandraMetricsRegistry.MetricName(groupName, "FailureDetector", name, mBeanName("", name)); + } + + private static CassandraMetricsRegistry.MetricName createMetricName(@NotNull InetAddress ep, String name) { String endpoint = InetAddresses.toAddrString(ep); - String groupName = FailureDetectorMetrics.class.getPackage().getName(); + return new CassandraMetricsRegistry.MetricName(groupName, "FailureDetector", name, endpoint, mBeanName(endpoint, name)); + } + private static String mBeanName(String endpoint, String name) + { StringBuilder mbeanName = new StringBuilder(); mbeanName.append(groupName).append(":"); mbeanName.append("type=FailureDetector"); - mbeanName.append(",endpoint=").append(endpoint); + if(!endpoint.isEmpty()) + mbeanName.append(",endpoint=").append(endpoint); mbeanName.append(",name=").append(name); - - return new CassandraMetricsRegistry.MetricName(groupName, "FailureDetector", name, endpoint, mbeanName.toString()); + return mbeanName.toString(); } } diff --git a/src/java/com/palantir/cassandra/tools/nodetool/GetPhiConvictThreshold.java b/src/java/com/palantir/cassandra/tools/nodetool/GetPhiConvictThreshold.java new file mode 100644 index 0000000000..0a1c4680ae --- /dev/null +++ b/src/java/com/palantir/cassandra/tools/nodetool/GetPhiConvictThreshold.java @@ -0,0 +1,31 @@ +/* + * (c) Copyright 2024 Palantir Technologies Inc. All rights reserved. + * + * 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 com.palantir.cassandra.tools.nodetool; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool; + +import io.airlift.command.Command; + +@Command(name = "getphiconvictthreshold", description = "Get failure detector phi threshold value") +public class GetPhiConvictThreshold extends NodeTool.NodeToolCmd +{ + @Override + protected void execute(NodeProbe probe) { + System.out.println("Phi convict threshold: " + probe.getPhiConvictThreshold()); + } +} diff --git a/src/java/com/palantir/cassandra/tools/nodetool/SetPhiConvictThreshold.java b/src/java/com/palantir/cassandra/tools/nodetool/SetPhiConvictThreshold.java new file mode 100644 index 0000000000..144d921bc1 --- /dev/null +++ b/src/java/com/palantir/cassandra/tools/nodetool/SetPhiConvictThreshold.java @@ -0,0 +1,39 @@ +/* + * (c) Copyright 2024 Palantir Technologies Inc. All rights reserved. + * + * 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 com.palantir.cassandra.tools.nodetool; + +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool; + +import io.airlift.command.Arguments; +import io.airlift.command.Command; + +@Command(name = "setphiconvictthreshold", description = "Set failure detector phi threshold") +public class SetPhiConvictThreshold extends NodeTool.NodeToolCmd +{ + @Arguments( + title = "phi_convict_treshold", + usage = "", + description = "Phi value", + required = true) + private Double threshold = null; + + @Override + protected void execute(NodeProbe probe) { + probe.setPhiConvictThreshold(threshold); + } +} diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java index c5ba9b0827..88877457dc 100644 --- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java +++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java @@ -413,9 +413,9 @@ else if (conf.disk_access_mode == Config.DiskAccessMode.mmap_index_only) } /* phi convict threshold for FailureDetector */ - if (conf.phi_convict_threshold < 5 || conf.phi_convict_threshold > 16) + if (conf.phi_convict_threshold < 5) { - throw new ConfigurationException("phi_convict_threshold must be between 5 and 16", false); + throw new ConfigurationException("phi_convict_threshold must be greater than 5"); } /* Thread per pool */ diff --git a/src/java/org/apache/cassandra/tools/NodeProbe.java b/src/java/org/apache/cassandra/tools/NodeProbe.java index 739bde3404..e1db44dc33 100644 --- a/src/java/org/apache/cassandra/tools/NodeProbe.java +++ b/src/java/org/apache/cassandra/tools/NodeProbe.java @@ -1011,6 +1011,16 @@ public int getInterDCStreamThroughput() return ssProxy.getInterDCStreamThroughputMbPerSec(); } + public void setPhiConvictThreshold(double value) + { + fdProxy.setPhiConvictThreshold(value); + } + + public double getPhiConvictThreshold() + { + return fdProxy.getPhiConvictThreshold(); + } + public void setRowCountFailureThreshold(int value) { ssProxy.setRowCountFailureThreshold(value); diff --git a/src/java/org/apache/cassandra/tools/NodeTool.java b/src/java/org/apache/cassandra/tools/NodeTool.java index 7411fed6ec..0bbeb1b49f 100644 --- a/src/java/org/apache/cassandra/tools/NodeTool.java +++ b/src/java/org/apache/cassandra/tools/NodeTool.java @@ -99,10 +99,12 @@ public int execute(String... args) GetTraceProbability.class, GetInterDCStreamThroughput.class, GetReadThresholds.class, + GetPhiConvictThreshold.class, SetRowCountFailureThreshold.class, SetRowCountWarnThreshold.class, SetTombstoneFailureThreshold.class, SetTombstoneWarnThreshold.class, + SetPhiConvictThreshold.class, GetEndpoints.class, GetSSTables.class, GossipInfo.class,