Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions engine/src/main/java/com/arcadedb/GlobalConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -2557,6 +2557,13 @@ Maximum time in milliseconds a follower waits for a leader to be (re)elected bef
up with a SEVERE alert) instead of restarting forever (issue #5291).""",
Integer.class, 10),

HA_JVM_PAUSE_CLOSE_THRESHOLD_MS("arcadedb.ha.jvmPauseCloseThresholdMs", SCOPE.SERVER,
"""
JVM-pause length in milliseconds above which Ratis closes this node's Raft division (Ratis default: \
60000). 0 or a negative value disables the close: a long pause still steps a leader down, and ArcadeDB's \
health monitor decides whether the node needs recovery. Set a positive value to restore the Ratis behavior.""",
Long.class, 0L),

HA_STOP_SERVER_ON_REPLICATION_FAILURE("arcadedb.ha.stopServerOnReplicationFailure", SCOPE.SERVER,
"""
After a phase-2 local commit fails on the leader while followers have applied the entry, step-down \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2284,10 +2284,19 @@ private void restartRatis(final boolean formatStorage) {
LogManager.instance().log(this, Level.FINE, "Error closing old client: %s", t, t.getMessage());
}
try {
if (oldServer != null)
if (oldServer != null) {
oldServer.close();
// Issue #8898: a close that returns with the server not CLOSED means a second server is about to start
// beside one that may still answer the leader. This does not see a close that Ratis already performed
// itself (close() is then a no-op that reports CLOSED), nor a gRPC shutdown that close() swallowed.
final LifeCycle.State afterClose = oldServer.getLifeCycleState();
if (afterClose != LifeCycle.State.CLOSED)
LogManager.instance().log(this, Level.WARNING,
"Old Ratis server is %s after close(); restart proceeds anyway",
afterClose);
}
} catch (final Throwable t) {
LogManager.instance().log(this, Level.FINE, "Error closing old server: %s", t, t.getMessage());
LogManager.instance().log(this, Level.WARNING, "Error closing old Ratis server before restart: %s", t, t.getMessage());
}

try {
Expand Down Expand Up @@ -2341,7 +2350,7 @@ private void restartRatis(final boolean formatStorage) {
offerTimeout, grpcMessageSizeMax, maxQueuedBytes, this::refreshRaftClient);

restartFailureCount = 0;
HALog.log(this, HALog.BASIC, "Ratis recovered successfully");
LogManager.instance().log(this, Level.INFO, "Ratis restarted in place (%s storage)", formatStorage ? "reformatted" : "recovered");
} catch (final Throwable t) {
restartFailureCount++;
LogManager.instance().log(this, Level.SEVERE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
*/
class RaftPropertiesBuilder {

/**
* Close threshold used when {@code arcadedb.ha.jvmPauseCloseThresholdMs} disables the Ratis JVM-pause close (issue
* #8898). TimeDuration has no "disabled" value, so out of reach is ten years.
*/
static final TimeDuration JVM_PAUSE_CLOSE_DISABLED = TimeDuration.valueOf(3650, TimeUnit.DAYS);

private RaftPropertiesBuilder() {
}

Expand Down Expand Up @@ -316,6 +322,12 @@ static RaftProperties build(final ContextConfiguration configuration) {
replicate.""",
appendBuffer.getSize(), grpcMessageSizeMax);

// Issue #8898: Ratis closes the whole division on a long JVM pause, and the in-place restart that followed did
// not recover the follower. 0 (default) puts that close out of reach; a leader still steps down on a pause.
final long jvmPauseCloseMs = configuration.getValueAsLong(GlobalConfiguration.HA_JVM_PAUSE_CLOSE_THRESHOLD_MS);
RaftServerConfigKeys.setCloseThreshold(properties,
jvmPauseCloseMs > 0 ? TimeDuration.valueOf(jvmPauseCloseMs, TimeUnit.MILLISECONDS) : JVM_PAUSE_CLOSE_DISABLED);

// Leader lease: consistent reads without round-trip
RaftServerConfigKeys.Read.setLeaderLeaseEnabled(properties, true);
RaftServerConfigKeys.Read.setLeaderLeaseTimeoutRatio(properties, 0.9);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,34 @@ void aValidWindowIsLeftAlone() {
final RaftProperties props = RaftPropertiesBuilder.build(config);
assertThat(RaftServerConfigKeys.Rpc.timeoutMax(props).toLong(TimeUnit.MILLISECONDS)).isEqualTo(5000L);
}

/**
* Issue #8898: Ratis's own JVM-pause monitor closes the whole division when a pause exceeds
* {@code raft.server.close.threshold} (60s by default), behind ArcadeDB's back, and the in-place restart that
* follows never recovers the follower. By default ArcadeDB therefore keeps that close out of reach and leaves
* long-pause recovery to its own monitors.
*/
@Test
void jvmPauseCloseThresholdIsOutOfReachByDefault() {
final RaftProperties props = RaftPropertiesBuilder.build(new ContextConfiguration());
assertThat(RaftServerConfigKeys.closeThreshold(props)).isEqualTo(RaftPropertiesBuilder.JVM_PAUSE_CLOSE_DISABLED);
}

@Test
void zeroOrNegativeJvmPauseCloseThresholdDisablesTheClose() {
for (final long value : new long[] { 0L, -1L }) {
final ContextConfiguration config = new ContextConfiguration();
config.setValue(GlobalConfiguration.HA_JVM_PAUSE_CLOSE_THRESHOLD_MS, value);
final RaftProperties props = RaftPropertiesBuilder.build(config);
assertThat(RaftServerConfigKeys.closeThreshold(props)).isEqualTo(RaftPropertiesBuilder.JVM_PAUSE_CLOSE_DISABLED);
}
}

@Test
void jvmPauseCloseThresholdCanBeRestoredToACustomValue() {
final ContextConfiguration config = new ContextConfiguration();
config.setValue(GlobalConfiguration.HA_JVM_PAUSE_CLOSE_THRESHOLD_MS, 90_000L);
final RaftProperties props = RaftPropertiesBuilder.build(config);
assertThat(RaftServerConfigKeys.closeThreshold(props).toLong(TimeUnit.MILLISECONDS)).isEqualTo(90_000L);
}
}