devmadhuu commented on code in PR #8917:
URL: https://github.com/apache/ozone/pull/8917#discussion_r2265835056
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ReconDBProvider.java:
##########
@@ -115,4 +128,25 @@ public void close() throws Exception {
dbStore = null;
}
}
+
+ public void replaceStagedDb(ReconDBProvider stagedReconDBProvider) throws
Exception {
+ File dbPath = dbStore.getDbLocation();
+ File stagedDbPath = stagedReconDBProvider.getDbStore().getDbLocation();
+ File backupPath = new File(dbPath.getAbsolutePath() + ".backup");
+ stagedReconDBProvider.close();
+ try {
+ FileUtils.deleteDirectory(backupPath);
+ FileUtils.moveDirectory(dbPath, backupPath);
Review Comment:
Similar cleanup is needed for new backup also which was taken for production
DB after successful swap.
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ReconDBProvider.java:
##########
@@ -115,4 +128,25 @@ public void close() throws Exception {
dbStore = null;
}
}
+
+ public void replaceStagedDb(ReconDBProvider stagedReconDBProvider) throws
Exception {
+ File dbPath = dbStore.getDbLocation();
+ File stagedDbPath = stagedReconDBProvider.getDbStore().getDbLocation();
+ File backupPath = new File(dbPath.getAbsolutePath() + ".backup");
+ stagedReconDBProvider.close();
+ try {
+ FileUtils.deleteDirectory(backupPath);
Review Comment:
`deleteQuietly` should be better option here.
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ReconDBProvider.java:
##########
@@ -115,4 +128,25 @@ public void close() throws Exception {
dbStore = null;
}
}
+
+ public void replaceStagedDb(ReconDBProvider stagedReconDBProvider) throws
Exception {
+ File dbPath = dbStore.getDbLocation();
+ File stagedDbPath = stagedReconDBProvider.getDbStore().getDbLocation();
+ File backupPath = new File(dbPath.getAbsolutePath() + ".backup");
+ stagedReconDBProvider.close();
+ try {
+ FileUtils.deleteDirectory(backupPath);
+ FileUtils.moveDirectory(dbPath, backupPath);
+ close();
+ FileUtils.moveDirectory(stagedDbPath, backupPath);
Review Comment:
Pls check if this is by mistake. here you are moving staged db to backup
instead of to main production db path.
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ReconDBProvider.java:
##########
@@ -115,4 +128,25 @@ public void close() throws Exception {
dbStore = null;
}
}
+
+ public void replaceStagedDb(ReconDBProvider stagedReconDBProvider) throws
Exception {
+ File dbPath = dbStore.getDbLocation();
+ File stagedDbPath = stagedReconDBProvider.getDbStore().getDbLocation();
+ File backupPath = new File(dbPath.getAbsolutePath() + ".backup");
+ stagedReconDBProvider.close();
+ try {
+ FileUtils.deleteDirectory(backupPath);
+ FileUtils.moveDirectory(dbPath, backupPath);
+ close();
Review Comment:
Shouldn't we close first and then move ?
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ReconDBProvider.java:
##########
@@ -115,4 +128,25 @@ public void close() throws Exception {
dbStore = null;
}
}
+
+ public void replaceStagedDb(ReconDBProvider stagedReconDBProvider) throws
Exception {
+ File dbPath = dbStore.getDbLocation();
+ File stagedDbPath = stagedReconDBProvider.getDbStore().getDbLocation();
+ File backupPath = new File(dbPath.getAbsolutePath() + ".backup");
+ stagedReconDBProvider.close();
+ try {
+ FileUtils.deleteDirectory(backupPath);
+ FileUtils.moveDirectory(dbPath, backupPath);
+ close();
+ FileUtils.moveDirectory(stagedDbPath, backupPath);
Review Comment:
Also use`Files.move(stagingDir, prodDB, StandardCopyOption.ATOMIC_MOVE,
StandardCopyOption.REPLACE_EXISTING);`
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ReconDBProvider.java:
##########
@@ -115,4 +128,25 @@ public void close() throws Exception {
dbStore = null;
}
}
+
+ public void replaceStagedDb(ReconDBProvider stagedReconDBProvider) throws
Exception {
+ File dbPath = dbStore.getDbLocation();
+ File stagedDbPath = stagedReconDBProvider.getDbStore().getDbLocation();
+ File backupPath = new File(dbPath.getAbsolutePath() + ".backup");
+ stagedReconDBProvider.close();
+ try {
+ FileUtils.deleteDirectory(backupPath);
+ FileUtils.moveDirectory(dbPath, backupPath);
+ close();
+ FileUtils.moveDirectory(stagedDbPath, backupPath);
+ dbStore = initializeDBStore(configuration, dbPath.getName());
+ } catch (Exception e) {
+ if (dbStore == null) {
Review Comment:
Pls revisit this logic because `dbStore` may not always be null even when
some exception due to movement of any dir, so restoring back the main
production db from backup could be an issue here.
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ReconDBProvider.java:
##########
@@ -115,4 +128,25 @@ public void close() throws Exception {
dbStore = null;
}
}
+
+ public void replaceStagedDb(ReconDBProvider stagedReconDBProvider) throws
Exception {
+ File dbPath = dbStore.getDbLocation();
+ File stagedDbPath = stagedReconDBProvider.getDbStore().getDbLocation();
+ File backupPath = new File(dbPath.getAbsolutePath() + ".backup");
+ stagedReconDBProvider.close();
+ try {
+ FileUtils.deleteDirectory(backupPath);
+ FileUtils.moveDirectory(dbPath, backupPath);
+ close();
+ FileUtils.moveDirectory(stagedDbPath, backupPath);
+ dbStore = initializeDBStore(configuration, dbPath.getName());
+ } catch (Exception e) {
Review Comment:
This exception also should be used to record the lastRun reprocess of task
as failure to reflect correct status and metrics.
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ReconDBProvider.java:
##########
@@ -115,4 +128,25 @@ public void close() throws Exception {
dbStore = null;
}
}
+
+ public void replaceStagedDb(ReconDBProvider stagedReconDBProvider) throws
Exception {
Review Comment:
Before doing below operations, pls keep track of STAGING states because in a
live cluster, we don't know what could be various reasons which can just block
these operations, so later those states can be used in metrics.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]