bharatviswa504 commented on a change in pull request #986:
URL: https://github.com/apache/hadoop-ozone/pull/986#discussion_r437016807



##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OMRatisSnapshotInfo.java
##########
@@ -49,81 +39,15 @@
   private volatile long term = 0;
   private volatile long snapshotIndex = -1;
 
-  private final File ratisSnapshotFile;
-
-  public OMRatisSnapshotInfo(File ratisDir) throws IOException {

Review comment:
       This is needed during returning getLatestSnapshot in OMStateMachine.

##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
##########
@@ -3073,9 +3092,8 @@ public TermIndex installSnapshot(String leaderId) {
     // Restart (unpause) the state machine and update its last applied index
     // to the installed checkpoint's snapshot index.
     try {
-      reloadOMState(checkpointSnapshotIndex, checkpointSnapshotTermIndex);
-      omRatisServer.getOmStateMachine().unpause(checkpointSnapshotIndex,
-          checkpointSnapshotTermIndex);
+      reloadOMState(leaderIndex, leaderTerm);
+      omRatisServer.getOmStateMachine().unpause(leaderIndex, leaderTerm);

Review comment:
       Yes, this is an existing issue 
   I think you have opened a jira to address this issue
   https://issues.apache.org/jira/browse/HDDS-3741

##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
##########
@@ -3027,30 +3017,59 @@ public TermIndex installSnapshot(String leaderId) {
     DBCheckpoint omDBcheckpoint = getDBCheckpointFromLeader(leaderId);
     Path newDBlocation = omDBcheckpoint.getCheckpointLocation();
 
-    // Check if current ratis log index is smaller than the downloaded
-    // snapshot index. If yes, proceed by stopping the ratis server so that
-    // the OM state can be re-initialized. If no, then do not proceed with
-    // installSnapshot.
     long lastAppliedIndex = omRatisServer.getLastAppliedTermIndex().getIndex();
-    long checkpointSnapshotIndex = omDBcheckpoint.getRatisSnapshotIndex();
-    long checkpointSnapshotTermIndex =
-        omDBcheckpoint.getRatisSnapshotTerm();
-    if (checkpointSnapshotIndex <= lastAppliedIndex) {
-      LOG.error("Failed to install checkpoint from OM leader: {}. The last " +
-          "applied index: {} is greater than or equal to the checkpoint's " +
-          "snapshot index: {}. Deleting the downloaded checkpoint {}", 
leaderId,
-          lastAppliedIndex, checkpointSnapshotIndex,
-          newDBlocation);
-      try {
-        FileUtils.deleteFully(newDBlocation);
-      } catch (IOException e) {
-        LOG.error("Failed to fully delete the downloaded DB checkpoint {} " +
-            "from OM leader {}.", newDBlocation,
-            leaderId, e);
+
+    // Check if current ratis log index is smaller than the downloaded
+    // checkpoint transaction index. If yes, proceed by stopping the ratis
+    // server so that the OM state can be re-initialized. If no, then do not
+    // proceed with installSnapshot.
+
+    OMTransactionInfo omTransactionInfo = null;
+    try {
+      // Set new DB location as DB path
+      OzoneConfiguration tempConfig = getConfiguration();
+
+      Path dbDir = newDBlocation.getParent();
+      if (dbDir != null) {
+        tempConfig.set(OZONE_OM_DB_DIRS, dbDir.toString());
+      } else {
+        LOG.error("Incorrect DB location path {} received from checkpoint.",
+            newDBlocation);
+        return null;
+      }
+
+      OMMetadataManager tempMetadataMgr =
+          new OmMetadataManagerImpl(configuration);
+
+      omTransactionInfo =
+          OMTransactionInfo.readTransactionInfo(tempMetadataMgr);
+      tempMetadataMgr.stop();
+
+      if (omTransactionInfo.getTransactionIndex() <= lastAppliedIndex) {
+        LOG.error("Failed to install checkpoint from OM leader: {}. The last " 
+
+                "applied index: {} is greater than or equal to the " +
+                "checkpoint's applied index: {}. Deleting the downloaded " +
+                "checkpoint {}", leaderId, lastAppliedIndex,
+            omTransactionInfo.getTransactionIndex(), newDBlocation);
+        try {
+          FileUtils.deleteFully(newDBlocation);
+        } catch (IOException e) {
+          LOG.error("Failed to fully delete the downloaded DB checkpoint {} " +
+                  "from OM leader {}.", newDBlocation,
+              leaderId, e);
+          return null;
+        }
       }
+    } catch (Exception ex) {
+      LOG.error("Failed during checking downloaded leader transaction index " +

Review comment:
       Done

##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
##########
@@ -3027,30 +3017,59 @@ public TermIndex installSnapshot(String leaderId) {
     DBCheckpoint omDBcheckpoint = getDBCheckpointFromLeader(leaderId);
     Path newDBlocation = omDBcheckpoint.getCheckpointLocation();
 
-    // Check if current ratis log index is smaller than the downloaded
-    // snapshot index. If yes, proceed by stopping the ratis server so that
-    // the OM state can be re-initialized. If no, then do not proceed with
-    // installSnapshot.
     long lastAppliedIndex = omRatisServer.getLastAppliedTermIndex().getIndex();
-    long checkpointSnapshotIndex = omDBcheckpoint.getRatisSnapshotIndex();
-    long checkpointSnapshotTermIndex =
-        omDBcheckpoint.getRatisSnapshotTerm();
-    if (checkpointSnapshotIndex <= lastAppliedIndex) {
-      LOG.error("Failed to install checkpoint from OM leader: {}. The last " +
-          "applied index: {} is greater than or equal to the checkpoint's " +
-          "snapshot index: {}. Deleting the downloaded checkpoint {}", 
leaderId,
-          lastAppliedIndex, checkpointSnapshotIndex,
-          newDBlocation);
-      try {
-        FileUtils.deleteFully(newDBlocation);
-      } catch (IOException e) {
-        LOG.error("Failed to fully delete the downloaded DB checkpoint {} " +
-            "from OM leader {}.", newDBlocation,
-            leaderId, e);
+
+    // Check if current ratis log index is smaller than the downloaded
+    // checkpoint transaction index. If yes, proceed by stopping the ratis
+    // server so that the OM state can be re-initialized. If no, then do not
+    // proceed with installSnapshot.
+
+    OMTransactionInfo omTransactionInfo = null;
+    try {
+      // Set new DB location as DB path
+      OzoneConfiguration tempConfig = getConfiguration();
+
+      Path dbDir = newDBlocation.getParent();
+      if (dbDir != null) {
+        tempConfig.set(OZONE_OM_DB_DIRS, dbDir.toString());
+      } else {
+        LOG.error("Incorrect DB location path {} received from checkpoint.",
+            newDBlocation);
+        return null;
+      }
+
+      OMMetadataManager tempMetadataMgr =
+          new OmMetadataManagerImpl(configuration);

Review comment:
       This is to make code simple, as anyway when using direct rocksdb also we 
need to open DB and read from the table. OMMetadataManager usage will be 
cleaner, and simpler to do.
   As anyway, even if we open DB directly it opens all column families.

##########
File path: 
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOzoneManagerSnapshotProvider.java
##########
@@ -111,23 +113,43 @@ public void testDownloadCheckpoint() throws Exception {
         .getFailoverProxyProvider(objectStore.getClientProxy())
         .getCurrentProxyOMNodeId();
 
-    OzoneManager ozoneManager = cluster.getOzoneManager(leaderOMNodeId);
+    OzoneManager leaderOM = cluster.getOzoneManager(leaderOMNodeId);
 
     // Get a follower OM
-    String followerNodeId = ozoneManager.getPeerNodes().get(0).getOMNodeId();
+    String followerNodeId = leaderOM.getPeerNodes().get(0).getOMNodeId();
     OzoneManager followerOM = cluster.getOzoneManager(followerNodeId);
 
     // Download latest checkpoint from leader OM to follower OM
     DBCheckpoint omSnapshot = followerOM.getOmSnapshotProvider()
         .getOzoneManagerDBSnapshot(leaderOMNodeId);
 
-    long leaderSnapshotIndex = ozoneManager.getRatisSnapshotIndex();
-    long downloadedSnapshotIndex = omSnapshot.getRatisSnapshotIndex();
+    long leaderSnapshotIndex =
+        OMTransactionInfo.readTransactionInfo(leaderOM.getMetadataManager())
+            .getTransactionIndex();

Review comment:
       Yes. done

##########
File path: 
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/OMConfigKeys.java
##########
@@ -133,13 +133,6 @@ private OMConfigKeys() {
       "ozone.om.ratis.log.purge.gap";
   public static final int OZONE_OM_RATIS_LOG_PURGE_GAP_DEFAULT = 1000000;
 
-  // OM Snapshot configurations
-  public static final String OZONE_OM_RATIS_SNAPSHOT_AUTO_TRIGGER_THRESHOLD_KEY
-      = "ozone.om.ratis.snapshot.auto.trigger.threshold";

Review comment:
       Yes. agreed done.

##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerStateMachine.java
##########
@@ -139,6 +139,10 @@ public void initialize(RaftServer server, RaftGroupId id,
 
   @Override
   public SnapshotInfo getLatestSnapshot() {
+    TermIndex lastAppliedIndex = getLastAppliedTermIndex();

Review comment:
       This is already taken care during start and reload. We are setting the 
snapshotInfo from DB values. So, I think this should be fine here.

##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
##########
@@ -3027,30 +3017,59 @@ public TermIndex installSnapshot(String leaderId) {
     DBCheckpoint omDBcheckpoint = getDBCheckpointFromLeader(leaderId);
     Path newDBlocation = omDBcheckpoint.getCheckpointLocation();
 
-    // Check if current ratis log index is smaller than the downloaded
-    // snapshot index. If yes, proceed by stopping the ratis server so that
-    // the OM state can be re-initialized. If no, then do not proceed with
-    // installSnapshot.
     long lastAppliedIndex = omRatisServer.getLastAppliedTermIndex().getIndex();
-    long checkpointSnapshotIndex = omDBcheckpoint.getRatisSnapshotIndex();
-    long checkpointSnapshotTermIndex =
-        omDBcheckpoint.getRatisSnapshotTerm();
-    if (checkpointSnapshotIndex <= lastAppliedIndex) {
-      LOG.error("Failed to install checkpoint from OM leader: {}. The last " +
-          "applied index: {} is greater than or equal to the checkpoint's " +
-          "snapshot index: {}. Deleting the downloaded checkpoint {}", 
leaderId,
-          lastAppliedIndex, checkpointSnapshotIndex,
-          newDBlocation);
-      try {
-        FileUtils.deleteFully(newDBlocation);
-      } catch (IOException e) {
-        LOG.error("Failed to fully delete the downloaded DB checkpoint {} " +
-            "from OM leader {}.", newDBlocation,
-            leaderId, e);
+
+    // Check if current ratis log index is smaller than the downloaded
+    // checkpoint transaction index. If yes, proceed by stopping the ratis
+    // server so that the OM state can be re-initialized. If no, then do not
+    // proceed with installSnapshot.
+
+    OMTransactionInfo omTransactionInfo = null;
+    try {
+      // Set new DB location as DB path
+      OzoneConfiguration tempConfig = getConfiguration();
+
+      Path dbDir = newDBlocation.getParent();
+      if (dbDir != null) {
+        tempConfig.set(OZONE_OM_DB_DIRS, dbDir.toString());
+      } else {
+        LOG.error("Incorrect DB location path {} received from checkpoint.",
+            newDBlocation);
+        return null;
+      }
+
+      OMMetadataManager tempMetadataMgr =
+          new OmMetadataManagerImpl(configuration);
+
+      omTransactionInfo =
+          OMTransactionInfo.readTransactionInfo(tempMetadataMgr);
+      tempMetadataMgr.stop();
+

Review comment:
       Done

##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/OzoneManagerSnapshotProvider.java
##########
@@ -112,16 +112,16 @@ public OzoneManagerSnapshotProvider(ConfigurationSource 
conf,
    */
   public DBCheckpoint getOzoneManagerDBSnapshot(String leaderOMNodeID)
       throws IOException {
-    String snapshotFileName = OM_SNAPSHOT_DB + "_" + 
System.currentTimeMillis();
-    File targetFile = new File(omSnapshotDir, snapshotFileName + ".tar.gz");
+    String snapshotTime = Long.toString(System.currentTimeMillis());
+    String snapshotFileName = Paths.get(omSnapshotDir.getAbsolutePath(),
+        snapshotTime, OM_DB_NAME).toFile().getAbsolutePath();
+    File targetFile = new File(snapshotFileName + ".tar.gz");

Review comment:
       Yes so that we can use OMMetadataManager code

##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerStateMachine.java
##########
@@ -515,13 +515,29 @@ private synchronized void 
computeAndUpdateLastAppliedIndex(
     }
   }
 
-  public void updateLastAppliedIndexWithSnaphsotIndex() {
+  public void updateLastAppliedIndexWithSnaphsotIndex() throws IOException {
     // This is done, as we have a check in Ratis for not throwing
     // LeaderNotReadyException, it checks stateMachineIndex >= raftLog
     // nextIndex (placeHolderIndex).
-    setLastAppliedTermIndex(TermIndex.newTermIndex(snapshotInfo.getTerm(),
-        snapshotInfo.getIndex()));
-    LOG.info("LastAppliedIndex set from SnapShotInfo {}",
+
+    OMTransactionInfo omTransactionInfo =
+        OMTransactionInfo.readTransactionInfo(
+            ozoneManager.getMetadataManager());
+
+    if (omTransactionInfo != null) {
+      setLastAppliedTermIndex(TermIndex.newTermIndex(
+          omTransactionInfo.getCurrentTerm(),
+          omTransactionInfo.getTransactionIndex()));
+      snapshotInfo.updateTermIndex(omTransactionInfo.getCurrentTerm(),
+          omTransactionInfo.getTransactionIndex());
+    } else {
+      // On a newly setup OM,it will not have any transaction info in DB,
+      // use default values.
+      setLastAppliedTermIndex(TermIndex.newTermIndex(snapshotInfo.getTerm(),
+          snapshotInfo.getIndex()));
+    }
+
+    LOG.info("LastAppliedIndex is set from TransactionInfo from OM DB is {}",

Review comment:
       Done

##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerStateMachine.java
##########
@@ -515,13 +515,29 @@ private synchronized void 
computeAndUpdateLastAppliedIndex(
     }
   }
 
-  public void updateLastAppliedIndexWithSnaphsotIndex() {
+  public void updateLastAppliedIndexWithSnaphsotIndex() throws IOException {
     // This is done, as we have a check in Ratis for not throwing
     // LeaderNotReadyException, it checks stateMachineIndex >= raftLog
     // nextIndex (placeHolderIndex).
-    setLastAppliedTermIndex(TermIndex.newTermIndex(snapshotInfo.getTerm(),
-        snapshotInfo.getIndex()));
-    LOG.info("LastAppliedIndex set from SnapShotInfo {}",
+
+    OMTransactionInfo omTransactionInfo =
+        OMTransactionInfo.readTransactionInfo(
+            ozoneManager.getMetadataManager());
+
+    if (omTransactionInfo != null) {
+      setLastAppliedTermIndex(TermIndex.newTermIndex(
+          omTransactionInfo.getCurrentTerm(),
+          omTransactionInfo.getTransactionIndex()));
+      snapshotInfo.updateTermIndex(omTransactionInfo.getCurrentTerm(),
+          omTransactionInfo.getTransactionIndex());
+    } else {
+      // On a newly setup OM,it will not have any transaction info in DB,
+      // use default values.
+      setLastAppliedTermIndex(TermIndex.newTermIndex(snapshotInfo.getTerm(),

Review comment:
       Done

##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerStateMachine.java
##########
@@ -338,20 +341,17 @@ public void unpause(long newLastAppliedSnaphsotIndex,
   }
 
   /**
-   * Take OM Ratis snapshot. Write the snapshot index to file. Snapshot index
-   * is the log index corresponding to the last applied transaction on the OM
-   * State Machine.
+   * Take OM Ratis snapshot is a dummy operation as when double buffer
+   * flushes the lastAppliedIndex is flushed to DB and that is used as
+   * snapshot index.
    *
    * @return the last applied index on the state machine which has been
    * stored in the snapshot file.
    */
   @Override
   public long takeSnapshot() throws IOException {
-    LOG.info("Saving Ratis snapshot on the OM.");
-    if (ozoneManager != null) {
-      return ozoneManager.saveRatisSnapshot().getIndex();
-    }
-    return 0;
+    LOG.info("Current Snapshot Index {}", getLastAppliedTermIndex());
+    return getLastAppliedTermIndex().getIndex();

Review comment:
       Good catch. Done

##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
##########
@@ -3027,30 +3017,59 @@ public TermIndex installSnapshot(String leaderId) {
     DBCheckpoint omDBcheckpoint = getDBCheckpointFromLeader(leaderId);
     Path newDBlocation = omDBcheckpoint.getCheckpointLocation();
 
-    // Check if current ratis log index is smaller than the downloaded
-    // snapshot index. If yes, proceed by stopping the ratis server so that
-    // the OM state can be re-initialized. If no, then do not proceed with
-    // installSnapshot.
     long lastAppliedIndex = omRatisServer.getLastAppliedTermIndex().getIndex();
-    long checkpointSnapshotIndex = omDBcheckpoint.getRatisSnapshotIndex();
-    long checkpointSnapshotTermIndex =
-        omDBcheckpoint.getRatisSnapshotTerm();
-    if (checkpointSnapshotIndex <= lastAppliedIndex) {
-      LOG.error("Failed to install checkpoint from OM leader: {}. The last " +
-          "applied index: {} is greater than or equal to the checkpoint's " +
-          "snapshot index: {}. Deleting the downloaded checkpoint {}", 
leaderId,
-          lastAppliedIndex, checkpointSnapshotIndex,
-          newDBlocation);
-      try {
-        FileUtils.deleteFully(newDBlocation);
-      } catch (IOException e) {
-        LOG.error("Failed to fully delete the downloaded DB checkpoint {} " +
-            "from OM leader {}.", newDBlocation,
-            leaderId, e);
+
+    // Check if current ratis log index is smaller than the downloaded
+    // checkpoint transaction index. If yes, proceed by stopping the ratis
+    // server so that the OM state can be re-initialized. If no, then do not
+    // proceed with installSnapshot.
+
+    OMTransactionInfo omTransactionInfo = null;
+    try {
+      // Set new DB location as DB path
+      OzoneConfiguration tempConfig = getConfiguration();
+
+      Path dbDir = newDBlocation.getParent();
+      if (dbDir != null) {
+        tempConfig.set(OZONE_OM_DB_DIRS, dbDir.toString());
+      } else {
+        LOG.error("Incorrect DB location path {} received from checkpoint.",
+            newDBlocation);
+        return null;
+      }
+
+      OMMetadataManager tempMetadataMgr =
+          new OmMetadataManagerImpl(configuration);

Review comment:
       With skip Initialization of tables which is heavy part during 
initalization is skipped. And made this as internal config by not adding to 
ozone-default.xml

##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/OzoneManagerSnapshotProvider.java
##########
@@ -112,16 +112,16 @@ public OzoneManagerSnapshotProvider(ConfigurationSource 
conf,
    */
   public DBCheckpoint getOzoneManagerDBSnapshot(String leaderOMNodeID)
       throws IOException {
-    String snapshotFileName = OM_SNAPSHOT_DB + "_" + 
System.currentTimeMillis();
-    File targetFile = new File(omSnapshotDir, snapshotFileName + ".tar.gz");
+    String snapshotTime = Long.toString(System.currentTimeMillis());
+    String snapshotFileName = Paths.get(omSnapshotDir.getAbsolutePath(),
+        snapshotTime, OM_DB_NAME).toFile().getAbsolutePath();
+    File targetFile = new File(snapshotFileName + ".tar.gz");

Review comment:
       Yes so that we can reuse OMMetadataManager code.
   <OM_Ratis_Dir>/<<time>>/om.db

##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
##########
@@ -3027,30 +3017,59 @@ public TermIndex installSnapshot(String leaderId) {
     DBCheckpoint omDBcheckpoint = getDBCheckpointFromLeader(leaderId);
     Path newDBlocation = omDBcheckpoint.getCheckpointLocation();
 
-    // Check if current ratis log index is smaller than the downloaded
-    // snapshot index. If yes, proceed by stopping the ratis server so that
-    // the OM state can be re-initialized. If no, then do not proceed with
-    // installSnapshot.
     long lastAppliedIndex = omRatisServer.getLastAppliedTermIndex().getIndex();
-    long checkpointSnapshotIndex = omDBcheckpoint.getRatisSnapshotIndex();
-    long checkpointSnapshotTermIndex =
-        omDBcheckpoint.getRatisSnapshotTerm();
-    if (checkpointSnapshotIndex <= lastAppliedIndex) {
-      LOG.error("Failed to install checkpoint from OM leader: {}. The last " +
-          "applied index: {} is greater than or equal to the checkpoint's " +
-          "snapshot index: {}. Deleting the downloaded checkpoint {}", 
leaderId,
-          lastAppliedIndex, checkpointSnapshotIndex,
-          newDBlocation);
-      try {
-        FileUtils.deleteFully(newDBlocation);
-      } catch (IOException e) {
-        LOG.error("Failed to fully delete the downloaded DB checkpoint {} " +
-            "from OM leader {}.", newDBlocation,
-            leaderId, e);
+
+    // Check if current ratis log index is smaller than the downloaded
+    // checkpoint transaction index. If yes, proceed by stopping the ratis
+    // server so that the OM state can be re-initialized. If no, then do not
+    // proceed with installSnapshot.
+
+    OMTransactionInfo omTransactionInfo = null;
+    try {
+      // Set new DB location as DB path
+      OzoneConfiguration tempConfig = getConfiguration();
+
+      Path dbDir = newDBlocation.getParent();
+      if (dbDir != null) {
+        tempConfig.set(OZONE_OM_DB_DIRS, dbDir.toString());
+      } else {
+        LOG.error("Incorrect DB location path {} received from checkpoint.",
+            newDBlocation);
+        return null;
+      }
+
+      OMMetadataManager tempMetadataMgr =
+          new OmMetadataManagerImpl(configuration);

Review comment:
       Added a config to use internally to skip initialization of tables. Rest 
most of the part is required for opening DB. This is done to make it simple and 
avoid less refactor.

##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/OzoneManagerSnapshotProvider.java
##########
@@ -112,16 +112,16 @@ public OzoneManagerSnapshotProvider(ConfigurationSource 
conf,
    */
   public DBCheckpoint getOzoneManagerDBSnapshot(String leaderOMNodeID)
       throws IOException {
-    String snapshotFileName = OM_SNAPSHOT_DB + "_" + 
System.currentTimeMillis();
-    File targetFile = new File(omSnapshotDir, snapshotFileName + ".tar.gz");
+    String snapshotTime = Long.toString(System.currentTimeMillis());
+    String snapshotFileName = Paths.get(omSnapshotDir.getAbsolutePath(),
+        snapshotTime, OM_DB_NAME).toFile().getAbsolutePath();
+    File targetFile = new File(snapshotFileName + ".tar.gz");

Review comment:
       Yes so that we can reuse OMMetadataManager code.
   <OM_Ratis_Dir>/<time>/om.db

##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
##########
@@ -3027,30 +3017,59 @@ public TermIndex installSnapshot(String leaderId) {
     DBCheckpoint omDBcheckpoint = getDBCheckpointFromLeader(leaderId);
     Path newDBlocation = omDBcheckpoint.getCheckpointLocation();
 
-    // Check if current ratis log index is smaller than the downloaded
-    // snapshot index. If yes, proceed by stopping the ratis server so that
-    // the OM state can be re-initialized. If no, then do not proceed with
-    // installSnapshot.
     long lastAppliedIndex = omRatisServer.getLastAppliedTermIndex().getIndex();
-    long checkpointSnapshotIndex = omDBcheckpoint.getRatisSnapshotIndex();
-    long checkpointSnapshotTermIndex =
-        omDBcheckpoint.getRatisSnapshotTerm();
-    if (checkpointSnapshotIndex <= lastAppliedIndex) {
-      LOG.error("Failed to install checkpoint from OM leader: {}. The last " +
-          "applied index: {} is greater than or equal to the checkpoint's " +
-          "snapshot index: {}. Deleting the downloaded checkpoint {}", 
leaderId,
-          lastAppliedIndex, checkpointSnapshotIndex,
-          newDBlocation);
-      try {
-        FileUtils.deleteFully(newDBlocation);
-      } catch (IOException e) {
-        LOG.error("Failed to fully delete the downloaded DB checkpoint {} " +
-            "from OM leader {}.", newDBlocation,
-            leaderId, e);
+
+    // Check if current ratis log index is smaller than the downloaded
+    // checkpoint transaction index. If yes, proceed by stopping the ratis
+    // server so that the OM state can be re-initialized. If no, then do not
+    // proceed with installSnapshot.
+
+    OMTransactionInfo omTransactionInfo = null;
+    try {
+      // Set new DB location as DB path
+      OzoneConfiguration tempConfig = getConfiguration();
+
+      Path dbDir = newDBlocation.getParent();
+      if (dbDir != null) {
+        tempConfig.set(OZONE_OM_DB_DIRS, dbDir.toString());
+      } else {
+        LOG.error("Incorrect DB location path {} received from checkpoint.",
+            newDBlocation);
+        return null;
+      }
+
+      OMMetadataManager tempMetadataMgr =
+          new OmMetadataManagerImpl(configuration);

Review comment:
       The most expensive this is initialization of tables, and also for loadDB 
we cannot just pass path, it also requires configuration object.  So, to make 
it simple added an internal configuration.
   
   ```
   DBStoreBuilder dbStoreBuilder = DBStoreBuilder.newBuilder(configuration,
             rocksDBConfiguration).setName(OM_DB_NAME)
             .setPath(Paths.get(metaDir.getPath()));
   
         this.store = addOMTablesAndCodecs(dbStoreBuilder).build();
   ```




----------------------------------------------------------------
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]

Reply via email to