aswinshakil commented on a change in pull request #2942:
URL: https://github.com/apache/ozone/pull/2942#discussion_r778370164
##########
File path:
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerManagerFacade.java
##########
@@ -307,6 +327,109 @@ private void initializePipelinesFromScm() {
}
}
+ private void initializeSCMDB() {
+ try {
+ long scmContainersCount = scmServiceProvider.getSCMContainersCount();
+ long reconContainerCount = containerManager.getContainers().size();
+ long threshold = ozoneConfiguration.getInt(
+ ReconServerConfigKeys.OZONE_RECON_SCM_CONTAINER_THRESHOLD,
+ ReconServerConfigKeys.OZONE_RECON_SCM_CONTAINER_THRESHOLD_DEFAULT);
+
+ if(Math.abs(scmContainersCount - reconContainerCount) > threshold) {
+ updateReconSCMDBWithNewSnapshot();
+ LOG.info("Update Recon DB with SCM DB");
+ } else {
+ initializePipelinesFromScm();
+ }
+ } catch (IOException e) {
+ LOG.error("Exception encountered while getting SCM DB.");
+ }
+ }
+
+ public void updateReconSCMDBWithNewSnapshot() throws IOException {
+ DBCheckpoint dbSnapshot = scmServiceProvider.getSCMDBSnapshot();
+ if (dbSnapshot != null && dbSnapshot.getCheckpointLocation() != null) {
+ LOG.info("Got new checkpoint from SCM : " +
+ dbSnapshot.getCheckpointLocation());
+ try {
+ initializeNewRdbStore(dbSnapshot.getCheckpointLocation().toFile());
+ } catch (IOException e) {
+ LOG.error("Unable to refresh Recon SCM DB Snapshot. ", e);
+ }
+ } else {
+ LOG.error("Null snapshot location got from SCM.");
+ }
+ }
+
+ private void deleteOldSCMDB() throws IOException {
+ if (dbStore != null) {
+ File oldDBLocation = dbStore.getDbLocation();
+ if (oldDBLocation.exists()) {
+ LOG.info("Cleaning up old SCM snapshot db at {}.",
+ oldDBLocation.getAbsolutePath());
+ FileUtils.deleteDirectory(oldDBLocation);
+ }
+ }
+ }
+
+ private void initializeNewRdbStore(File dbFile) throws IOException {
+ try {
+ DBStore newStore = createDBAndAddSCMTablesAndCodecs(
+ dbFile, new ReconSCMDBDefinition());
+ Table<UUID, DatanodeDetails> nodeTable =
+ ReconSCMDBDefinition.NODES.getTable(dbStore);
+ Table<UUID, DatanodeDetails> newNodeTable =
+ ReconSCMDBDefinition.NODES.getTable(newStore);
+ TableIterator<UUID, ? extends KeyValue<UUID,
+ DatanodeDetails>> iterator = nodeTable.iterator();
+ while (iterator.hasNext()) {
+ KeyValue<UUID, DatanodeDetails> keyValue = iterator.next();
+ newNodeTable.put(keyValue.getKey(), keyValue.getValue());
+ }
+ deleteOldSCMDB();
Review comment:
`deleteOldSCMDB()` is added here because in the next step we set the new
DB to the `dbStore`. If we keep it as the last step we won't have the reference
to the old DB.
--
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]