Skip to content

Commit

Permalink
Phi threshold can be set via nodetool (#579)
Browse files Browse the repository at this point in the history
Co-authored-by: ines potier <[email protected]>
  • Loading branch information
inespot and ines potier authored Nov 12, 2024
1 parent 6fdd4a7 commit e6c5da9
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Double>) DatabaseDescriptor::getPhiConvictThreshold);
}

public static void register(
InetAddress ep, Gauge<Double> phiSupplier, Gauge<Long> lastIntervalSupplier, Supplier<Snapshot> snapshotSupplier)
{
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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 = "<value>",
description = "Phi value",
required = true)
private Double threshold = null;

@Override
protected void execute(NodeProbe probe) {
probe.setPhiConvictThreshold(threshold);
}
}
4 changes: 2 additions & 2 deletions src/java/org/apache/cassandra/config/DatabaseDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
10 changes: 10 additions & 0 deletions src/java/org/apache/cassandra/tools/NodeProbe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/java/org/apache/cassandra/tools/NodeTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e6c5da9

Please sign in to comment.