Skip to content
Closed
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
4 changes: 4 additions & 0 deletions hadoop-hdds/server-scm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public class SCMStateMachine extends BaseStateMachine {
// would never be reached. Set only while not yet ready; -1 means uncaptured.
private volatile long leaderCommitIndexOnStart = -1L;

// Whether a Ratis leader has been observed at any point since this SCM process started.
// Never reset: it distinguishes an SCM that has not yet joined a working quorum from one
// that is merely between leaders. See SCMSecurityProtocolServer#isLeaderlessPrimaryScmSigner.
private volatile boolean leaderEverKnown;

public SCMStateMachine(final StorageContainerManager scm,
SCMHADBTransactionBuffer buffer) {
this.scm = scm;
Expand All @@ -119,6 +124,14 @@ public SCMStateMachine() {
this.metrics = null;
}

/**
* @return true iff a Ratis leader has been observed since this SCM process started. False means
* this SCM has never been part of a working quorum, not merely that it is between leaders.
*/
public boolean isLeaderEverKnown() {
return leaderEverKnown;
}

private void addRatisEvent(String message) {
if (metrics != null) {
metrics.addRatisEvent(message);
Expand Down Expand Up @@ -284,6 +297,8 @@ public CompletableFuture<TermIndex> notifyInstallSnapshotFromLeader(
@Override
public void notifyLeaderChanged(RaftGroupMemberId groupMemberId,
RaftPeerId newLeaderId) {
// A leader exists regardless of whether this state machine is initialized yet.
leaderEverKnown = true;
if (!isInitialized) {
return;
}
Expand Down Expand Up @@ -374,6 +389,9 @@ public long takeSnapshot() throws IOException {
@Override
public void notifyTermIndexUpdated(long term, long index) {

// Committed entries can only come from a leader.
leaderEverKnown = true;

// We need to call updateLastApplied here because now in ratis when a
// node becomes leader, it is checking stateMachineIndex >=
// placeHolderIndex (when a node becomes leader, it writes a conf entry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@
import org.apache.hadoop.hdds.protocol.proto.SCMSecurityProtocolProtos.SCMSecurityRequest;
import org.apache.hadoop.hdds.protocol.proto.SCMSecurityProtocolProtos.SCMSecurityResponse;
import org.apache.hadoop.hdds.protocol.proto.SCMSecurityProtocolProtos.Status;
import org.apache.hadoop.hdds.protocol.proto.SCMSecurityProtocolProtos.Type;
import org.apache.hadoop.hdds.protocolPB.SCMSecurityProtocolPB;
import org.apache.hadoop.hdds.scm.ha.RatisUtil;
import org.apache.hadoop.hdds.scm.server.SCMSecurityProtocolServer;
import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
import org.apache.hadoop.hdds.security.exception.SCMSecurityException;
import org.apache.hadoop.hdds.server.OzoneProtocolMessageDispatcher;
import org.apache.hadoop.hdds.utils.ProtocolMessageMetrics;
import org.apache.ratis.protocol.exceptions.NotLeaderException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -79,9 +82,22 @@ public SCMSecurityProtocolServerSideTranslatorPB(SCMSecurityProtocol impl,
public SCMSecurityResponse submitRequest(RpcController controller,
SCMSecurityRequest request) throws ServiceException {
if (!scm.checkLeader()) {
RatisUtil.checkRatisException(
scm.getScmHAManager().getRatisServer().triggerNotLeaderException(),
scm.getSecurityProtocolRpcPort(), scm.getScmId(), scm.getHostname(), ROLE_TYPE);
NotLeaderException nle =
scm.getScmHAManager().getRatisServer().triggerNotLeaderException();
boolean isRenew = request.getCmdType() == Type.GetSCMCertificate
&& request.getGetSCMCertificateRequest().getRenew();
boolean isLeaderlessScmCertBypass =
request.getCmdType() == Type.GetSCMCertificate && !isRenew
&& SCMSecurityProtocolServer.isLeaderlessPrimaryScmSigner(scm, nle, isRenew,
request.getGetSCMCertificateRequest().getScmDetails().getScmNodeId());
if (isLeaderlessScmCertBypass) {
LOG.warn("Bypassing leadership check for leaderless primary SCM certificate signing " +
"request from SCM node {}",
request.getGetSCMCertificateRequest().getScmDetails().getScmNodeId());
} else {
RatisUtil.checkRatisException(nle,
scm.getSecurityProtocolRpcPort(), scm.getScmId(), scm.getHostname(), ROLE_TYPE);
}
}
return dispatcher.processRequest(request, this::processRequest,
request.getCmdType(), request.getTraceID());
Expand Down
Loading
Loading