Source:
public TermIndex installSnapshot(String leaderId) { if (omSnapshotProvider == null) { LOG.error("OM Snapshot Provider is not configured as there are no peer " + "nodes."); return null; } DBCheckpoint omDBcheckpoint; try { omDBcheckpoint = omSnapshotProvider.getOzoneManagerDBSnapshot(leaderId); } catch (IOException e) { LOG.error("Failed to download checkpoint from OM leader {}", leaderId, e); return null; } long lastAppliedIndex = omRatisServer.getStateMachineLastAppliedIndex(); long checkpointSnapshotIndex = omDBcheckpoint.getRatisSnapshotIndex(); 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: {}", leaderId, lastAppliedIndex, checkpointSnapshotIndex); return null; } omRatisServer.stop(); omDoubleBuffer.stop(); File dbFile = metadataManager.getStore().getDbLocation(); String dbBackupFileName = OzoneConsts.OM_DB_BACKUP_PREFIX + lastAppliedIndex + "_" + System.currentTimeMillis(); File dbBackupFile = new File(dbFile.getParentFile(), dbBackupFileName); try { Files.move(dbFile.toPath(), dbBackupFile.toPath()); } catch (IOException e) { LOG.error("Failed to create a backup of the current DB. Aborting " + "snapshot installation.", e); return null; } Path checkpointPath = omDBcheckpoint.getCheckpointLocation(); try { Files.move(checkpointPath, dbFile.toPath()); } catch (IOException e) { LOG.error("Failed to move downloaded DB checkpoint to metadata " + "directory {}",checkpointPath, dbFile.toPath(), e); return null; } try { reloadOMState(); } catch (IOException e) { LOG.error("Failed to reload OM state with new DB checkpoint.", e); return null; } TermIndex newTermIndex = TermIndex.newTermIndex(0, checkpointSnapshotIndex); return newTermIndex; }

Target:
public TermIndex installSnapshot(String leaderId) { if (omSnapshotProvider == null) { LOG.error("OM Snapshot Provider is not configured as there are no peer " + "nodes."); return null; } DBCheckpoint omDBcheckpoint = getDBCheckpointFromLeader(leaderId); Path newDBlocation = omDBcheckpoint.getCheckpointLocation(); long lastAppliedIndex = omRatisServer.getStateMachineLastAppliedIndex(); long checkpointSnapshotIndex = omDBcheckpoint.getRatisSnapshotIndex(); 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); } return null; } omRatisServer.getOmStateMachine().pause(); File dbBackup; try { dbBackup = replaceOMDBWithCheckpoint(lastAppliedIndex, newDBlocation); } catch (Exception e) { LOG.error("OM DB checkpoint replacement with new downloaded checkpoint " + "failed.", e); return null; } try { reloadOMState(checkpointSnapshotIndex); omRatisServer.getOmStateMachine().unpause(checkpointSnapshotIndex); } catch (IOException e) { LOG.error("Failed to reload OM state with new DB checkpoint.", e); return null; } try { FileUtils.deleteFully(dbBackup); } catch (IOException e) { LOG.error("Failed to delete the backup of the original DB {}", dbBackup); } TermIndex newTermIndex = TermIndex.newTermIndex(0, checkpointSnapshotIndex); return newTermIndex; }