bshashikant commented on a change in pull request #1953:
URL: https://github.com/apache/ozone/pull/1953#discussion_r583508539
##########
File path:
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMStateMachine.java
##########
@@ -179,25 +193,79 @@ public long takeSnapshot() throws IOException {
long startTime = Time.monotonicNow();
TermIndex lastTermIndex = getLastAppliedTermIndex();
long lastAppliedIndex = lastTermIndex.getIndex();
- TransactionInfo lastAppliedTrxInfo =
- TransactionInfo.fromTermIndex(lastTermIndex);
- if (transactionBuffer.getLatestTrxInfo()
- .compareTo(lastAppliedTrxInfo) < 0) {
+ if (isInitialized.get()) {
+ TransactionInfo lastAppliedTrxInfo =
+ TransactionInfo.fromTermIndex(lastTermIndex);
+ if (transactionBuffer.getLatestTrxInfo().compareTo(lastAppliedTrxInfo)
+ < 0) {
+ transactionBuffer.updateLatestTrxInfo(
+ TransactionInfo.builder().setCurrentTerm(lastTermIndex.getTerm())
+ .setTransactionIndex(lastTermIndex.getIndex()).build());
+ transactionBuffer.setLatestSnapshot(
+ transactionBuffer.getLatestTrxInfo().toSnapshotInfo());
+ } else {
+ lastAppliedIndex =
+ transactionBuffer.getLatestTrxInfo().getTransactionIndex();
+ }
+
+ transactionBuffer.flush();
+ LOG.info("Current Snapshot Index {}, takeSnapshot took {} ms",
+ lastAppliedIndex, Time.monotonicNow() - startTime);
+ }
+ super.takeSnapshot();
+ return lastAppliedIndex;
+ }
+
+ @Override
+ public void initialize(
+ RaftServer server, RaftGroupId id, RaftStorage raftStorage)
+ throws IOException {
+ super.initialize(server, id, raftStorage);
+ storage.init(raftStorage);
+ loadSnapshot(storage.getLatestSnapshot());
+ }
+
+ private long loadSnapshot(SingleFileSnapshotInfo snapshot)
+ throws IOException {
+ if (snapshot == null) {
Review comment:
for the latest snapshot, getLatestSnapshot is already overriden in
SCMStateMachine.
----------------------------------------------------------------
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]