bshashikant commented on a change in pull request #1725:
URL: https://github.com/apache/ozone/pull/1725#discussion_r559326758
##########
File path:
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMStateMachine.java
##########
@@ -26,27 +26,55 @@
import java.util.concurrent.CompletableFuture;
import com.google.protobuf.InvalidProtocolBufferException;
+import org.apache.hadoop.hdds.scm.exceptions.SCMException;
+import org.apache.hadoop.util.Time;
import org.apache.ratis.protocol.Message;
+import org.apache.ratis.server.protocol.TermIndex;
+import org.apache.ratis.statemachine.SnapshotInfo;
import org.apache.ratis.statemachine.TransactionContext;
import org.apache.ratis.statemachine.impl.BaseStateMachine;
import org.apache.hadoop.hdds.protocol.proto.SCMRatisProtocol.RequestType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static
org.apache.hadoop.hdds.scm.exceptions.SCMException.ResultCodes.SCM_NOT_INITIALIZED;
/**
* TODO.
*/
public class SCMStateMachine extends BaseStateMachine {
+ private static final Logger LOG =
+ LoggerFactory.getLogger(BaseStateMachine.class);
private final Map<RequestType, Object> handlers;
+ private final SCMDBTransactionBuffer transactionBuffer;
- public SCMStateMachine() {
+ public SCMStateMachine(SCMDBTransactionBuffer buffer) throws SCMException {
this.handlers = new EnumMap<>(RequestType.class);
+ this.transactionBuffer = buffer;
+ SCMTransactionInfo latestTrxInfo = buffer.getLatestTrxInfo();
+ if (!latestTrxInfo.isInitialized()) {
+ if (!updateLastAppliedTermIndex(latestTrxInfo.getTerm(),
+ latestTrxInfo.getTransactionIndex())) {
+ throw new SCMException(
+ String.format("Failed to update LastAppliedTermIndex " +
+ "in StateMachine to term:{} index:{}",
+ latestTrxInfo.getTerm(), latestTrxInfo.getTransactionIndex()
+ ), SCM_NOT_INITIALIZED);
+ }
+ }
}
public void registerHandler(RequestType type, Object handler) {
handlers.put(type, handler);
}
+ @Override
+ public SnapshotInfo getLatestSnapshot() {
+ return transactionBuffer.getLatestSnapshot();
+ }
+
@Override
public CompletableFuture<Message> applyTransaction(
Review comment:
Can we rename applyTransaction to applyTansactionSerial as this is a
serialized operation anyways?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]