devmadhuu commented on code in PR #3947:
URL: https://github.com/apache/ozone/pull/3947#discussion_r1020075201
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerManagerFacade.java:
##########
@@ -400,18 +451,200 @@ private void initializeSCMDB() {
}
public void updateReconSCMDBWithNewSnapshot() throws IOException {
- DBCheckpoint dbSnapshot = scmServiceProvider.getSCMDBSnapshot();
- if (dbSnapshot != null && dbSnapshot.getCheckpointLocation() != null) {
- LOG.info("Got new checkpoint from SCM : " +
- dbSnapshot.getCheckpointLocation());
+ if (isSyncDataFromSCMRunning.compareAndSet(false, true)) {
+ 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.");
+ }
+ } else {
+ LOG.warn("SCM DB sync is already running.");
+ }
+ }
+
+ public boolean syncSCMContainerInfoWithReconContainerInfo()
+ throws IOException {
+ if (isSyncDataFromSCMRunning.compareAndSet(false, true)) {
try {
- initializeNewRdbStore(dbSnapshot.getCheckpointLocation().toFile());
+ List<ContainerInfo> containers = containerManager.getContainers();
+ List<ContainerInfo> listOfContainers = scmServiceProvider.
+ getListOfContainers();
+ if (null != listOfContainers && listOfContainers.size() > 0) {
+ LOG.info("Got list of containers frm SCM : " +
+ listOfContainers.size());
+ listOfContainers.forEach(containerInfo -> {
+ try {
+ long containerID = containerInfo.getContainerID();
+ List<HddsProtos.SCMContainerReplicaProto> containerReplicas
+ = scmServiceProvider.getContainerReplicas(containerID);
+ boolean isContainerPresentAtRecon =
+ containers.remove(containerID);
+ if (!isContainerPresentAtRecon) {
+ try {
+ ContainerWithPipeline containerWithPipeline =
+ scmServiceProvider.getContainerWithPipeline(containerID);
+ containerManager.addNewContainer(containerWithPipeline);
+ } catch (IOException e) {
+ LOG.error("Could not get container with pipeline " +
+ "for container : {}", containerID);
+ } catch (TimeoutException e) {
+ LOG.error("Could not add new container {} in Recon " +
+ "container manager cache.", containerID);
+ }
+ }
+ synchronized (containerInfo) {
+ containerReplicas.forEach(containerReplicaProto -> {
+ final ContainerReplica replica = buildContainerReplica(
+ containerInfo, containerReplicaProto);
+ try {
+ updateContainerState(containerInfo, replica);
+ containerManager.updateContainerReplica(
+ containerInfo.containerID(), replica);
+ } catch (ContainerNotFoundException e) {
+ LOG.error("Could not update container replica as " +
+ "container {} not found.", containerID);
+ } catch (InvalidStateTransitionException e) {
+ LOG.error("Invalid state transition for container {}",
+ containerID);
+ } catch (IOException e) {
+ LOG.error("Could not update container {} state.",
+ containerID);
+ } catch (TimeoutException e) {
+ LOG.error("Timeout while updating container {} state.",
+ containerID);
+ }
+ });
+ }
+ } catch (IOException e) {
+ LOG.error("Unable to get container replicas for container : {}",
+ containerInfo.getContainerID());
+ }
+ });
+ } else {
+ LOG.debug("SCM DB sync is already running.");
+ return false;
+ }
} catch (IOException e) {
LOG.error("Unable to refresh Recon SCM DB Snapshot. ", e);
+ return false;
}
- } else {
- LOG.error("Null snapshot location got from SCM.");
}
+ return true;
+ }
+
+ private boolean updateContainerState(ContainerInfo container,
+ ContainerReplica replica)
+ throws InvalidStateTransitionException, IOException, TimeoutException {
+ final ContainerID containerId = container.containerID();
Review Comment:
We need container replica and state as container health task needs that to
process for unhealthy containers. @sumitagrawl
--
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]