amaliujia commented on a change in pull request #1785:
URL: https://github.com/apache/ozone/pull/1785#discussion_r556237370



##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineStateManagerV2Impl.java
##########
@@ -242,14 +242,35 @@ public void updatePipelineState(
       throws IOException {
     lock.writeLock().lock();
     try {
+      PipelineID pipelineID = PipelineID.getFromProtobuf(pipelineIDProto);
+      Pipeline.PipelineState state = getPipeline(pipelineID)
+                                       .getPipelineState();
       pipelineStateMap.updatePipelineState(
           PipelineID.getFromProtobuf(pipelineIDProto),
           Pipeline.PipelineState.fromProtobuf(newState));
+      updatePipelineStateInDb(pipelineID, state);
     } finally {
       lock.writeLock().unlock();
     }
   }
 
+  private void updatePipelineStateInDb(PipelineID pipelineId,
+                                       Pipeline.PipelineState state)
+    throws IOException {
+    // null check is here to prevent the case where SCM store
+    // is closed but the staleNode handlers/pipleine creations
+    // still try to access it.
+    if (pipelineStore != null) {
+      try {
+        pipelineStore.put(pipelineId, getPipeline(pipelineId));
+      } catch (IOException ex) {
+        LOG.info("Pipeline {} state update failed", pipelineId);
+        // revert back to old state in memory
+        updatePipelineState(pipelineId, state);

Review comment:
       I am thinking that we can move this revert to the `try catch finally` 
block in `updatePipelineState`. So that in `updatePipelineState` the logic will 
more readable, e.g. update DB, and catch any exception and revert in memory 
state changes that has done beforehands.




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