Skip to content

Commit f2406b1

Browse files
committed
Merge branch 'cassandra-5.0' into trunk
2 parents ce541b6 + f8f456f commit f2406b1

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@
255255
* Add the ability to disable bulk loading of SSTables (CASSANDRA-18781)
256256
* Clean up obsolete functions and simplify cql_version handling in cqlsh (CASSANDRA-18787)
257257
Merged from 5.0:
258+
* Correctly calculate default for FailureDetector max interval (CASSANDRA-21025)
258259
* Adding missing configs in system_views.settings to be backward compatible (CASSANDRA-20863)
259260
* Heap dump should not be generated on handled exceptions (CASSANDRA-20974)
260261
* Fix range queries on early-open BTI files (CASSANDRA-20976)

src/java/org/apache/cassandra/gms/FailureDetector.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import javax.management.openmbean.TabularDataSupport;
4444
import javax.management.openmbean.TabularType;
4545

46+
import com.google.common.annotations.VisibleForTesting;
4647
import org.slf4j.Logger;
4748
import org.slf4j.LoggerFactory;
4849

@@ -444,6 +445,16 @@ public UnknownEndpointException(InetAddressAndPort ep)
444445
{
445446
super("Unknown endpoint: " + ep);
446447
}
448+
449+
/**
450+
* Only for testing. In production code, ArrivalWindow instances call getMaxInterval() during
451+
* intitialization and use the value to set the private final field MAX_INTERVAL_IN_NANO
452+
* @return the value that would be used for to populate any new ArrivalWindow instance
453+
*/
454+
@VisibleForTesting
455+
static long calculateMaxInterval()
456+
{
457+
return ArrivalWindow.getMaxInterval();
447458
}
448459
}
449460

@@ -514,9 +525,10 @@ class ArrivalWindow
514525
arrivalIntervals = new ArrayBackedBoundedStats(size);
515526
}
516527

517-
private static long getMaxInterval()
528+
@VisibleForTesting
529+
static long getMaxInterval()
518530
{
519-
long newValue = FD_MAX_INTERVAL_MS.getLong(FailureDetector.INITIAL_VALUE_NANOS);
531+
long newValue = FD_MAX_INTERVAL_MS.getLong(TimeUnit.NANOSECONDS.toMillis(FailureDetector.INITIAL_VALUE_NANOS));
520532
if (newValue != FailureDetector.INITIAL_VALUE_NANOS)
521533
logger.info("Overriding {} from {}ms to {}ms", FD_MAX_INTERVAL_MS.getKey(), FailureDetector.INITIAL_VALUE_NANOS, newValue);
522534
return TimeUnit.NANOSECONDS.convert(newValue, TimeUnit.MILLISECONDS);

test/unit/org/apache/cassandra/gms/FailureDetectorTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
import java.util.ArrayList;
2323
import java.util.List;
2424
import java.util.UUID;
25+
import java.util.concurrent.TimeUnit;
2526

2627
import org.junit.BeforeClass;
2728
import org.junit.Test;
2829

2930
import org.apache.cassandra.ServerTestUtils;
3031
import org.apache.cassandra.Util;
32+
import org.apache.cassandra.config.CassandraRelevantProperties;
3133
import org.apache.cassandra.config.DatabaseDescriptor;
3234
import org.apache.cassandra.db.commitlog.CommitLog;
3335
import org.apache.cassandra.dht.RandomPartitioner;
@@ -37,6 +39,7 @@
3739
import org.apache.cassandra.tcm.ClusterMetadata;
3840

3941
import static org.apache.cassandra.config.CassandraRelevantProperties.MAX_LOCAL_PAUSE_IN_MS;
42+
import static org.junit.Assert.assertEquals;
4043
import static org.junit.Assert.assertFalse;
4144

4245
public class FailureDetectorTest
@@ -79,4 +82,36 @@ public void testConvictAfterLeft() throws UnknownHostException
7982
FailureDetector.instance.interpret(leftHost);
8083
assertFalse("Left endpoint not convicted", FailureDetector.instance.isAlive(leftHost));
8184
}
85+
86+
@Test
87+
public void testMaxIntervalCalculation()
88+
{
89+
// Default value for ArrivalWindow.MAX_INTERVAL_IN_NANO, which is supplied by
90+
// ArrivalWindow::getMaxInterval should be 2000000000ns/2 seconds.
91+
Long initialPropertyValue = CassandraRelevantProperties.FD_MAX_INTERVAL_MS.isPresent()
92+
? CassandraRelevantProperties.FD_MAX_INTERVAL_MS.getLong()
93+
: null;
94+
try
95+
{
96+
// verify that max interval isn't being set directly using system property
97+
CassandraRelevantProperties.FD_MAX_INTERVAL_MS.reset();
98+
assertFalse(CassandraRelevantProperties.FD_MAX_INTERVAL_MS.isPresent());
99+
// in which case, max interval should default to INITIAL_VALUE_NANOS
100+
assertEquals(FailureDetector.INITIAL_VALUE_NANOS, FailureDetector.calculateMaxInterval());
101+
102+
// max interval can be overridden, but it's value should be supplied in millis
103+
long overrideMillis = TimeUnit.NANOSECONDS.toMillis(FailureDetector.INITIAL_VALUE_NANOS * 2);
104+
CassandraRelevantProperties.FD_MAX_INTERVAL_MS.setLong(overrideMillis);
105+
// max interval is a nanos value, so convert the override to get the expected value
106+
long expectedNanos = TimeUnit.NANOSECONDS.convert(overrideMillis, TimeUnit.MILLISECONDS);
107+
assertEquals(expectedNanos, FailureDetector.calculateMaxInterval());
108+
}
109+
finally
110+
{
111+
if (initialPropertyValue == null)
112+
CassandraRelevantProperties.FD_MAX_INTERVAL_MS.reset();
113+
else
114+
CassandraRelevantProperties.FD_MAX_INTERVAL_MS.setLong(initialPropertyValue);
115+
}
116+
}
82117
}

0 commit comments

Comments
 (0)