timmylicheng commented on a change in pull request #980:
URL: https://github.com/apache/hadoop-ozone/pull/980#discussion_r433026330



##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineStateManagerV2Impl.java
##########
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * <p>http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * <p>Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+
+package org.apache.hadoop.hdds.scm.pipeline;
+
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hdds.protocol.DatanodeDetails;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.protocol.proto.SCMRatisProtocol;
+import org.apache.hadoop.hdds.scm.container.ContainerID;
+import org.apache.hadoop.hdds.scm.ha.SCMHAInvocationHandler;
+import org.apache.hadoop.hdds.scm.ha.SCMRatisServer;
+import org.apache.hadoop.hdds.scm.node.NodeManager;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.lang.reflect.Proxy;
+import java.util.Collection;
+import java.util.List;
+import java.util.NavigableSet;
+
+/**
+ * Implementation of pipeline state manager.
+ * PipelineStateMap class holds the data structures related to pipeline and its
+ * state. All the read and write operations in PipelineStateMap are protected
+ * by a read write lock.
+ */
+public class PipelineStateManagerV2Impl implements PipelineStateManagerV2 {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(PipelineStateManager.class);
+
+  private final PipelineStateMap pipelineStateMap;
+  private final NodeManager nodeManager;
+  private Table<PipelineID, Pipeline> pipelineStore;
+
+  public PipelineStateManagerV2Impl(Table<PipelineID, Pipeline> pipelineStore,
+                                    NodeManager nodeManager) {
+    this.pipelineStateMap = new PipelineStateMap();
+    this.nodeManager = nodeManager;
+    this.pipelineStore = pipelineStore;
+  }
+
+  @Override
+  public void initialize() throws IOException {
+    if (pipelineStore == null || nodeManager == null) {
+      throw new IOException("PipelineStore cannot be null");
+    }
+    if (pipelineStore.isEmpty()) {
+      LOG.info("No pipeline exists in current db");
+      return;
+    }
+    TableIterator<PipelineID, ? extends Table.KeyValue<PipelineID, Pipeline>>
+        iterator = pipelineStore.iterator();
+    while (iterator.hasNext()) {
+      Pipeline pipeline = iterator.next().getValue();
+      addPipeline(pipeline.getProtobufMessage());
+    }
+  }
+
+  @Override
+  public void addPipeline(HddsProtos.Pipeline pipelineProto)
+      throws IOException {
+    Pipeline pipeline = Pipeline.getFromProtobuf(pipelineProto);
+    if (pipelineStore != null) {
+      pipelineStore.put(pipeline.getId(), pipeline);
+    }
+    pipelineStateMap.addPipeline(pipeline);
+    if (nodeManager != null) {
+      nodeManager.addPipeline(pipeline);
+    }

Review comment:
       Update.




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