You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/06/04 06:07:36 UTC

[GitHub] [ozone] umamaheswararao commented on a change in pull request #2300: HDDS-5292. Introduce the WritableContainerInterface to SCM

umamaheswararao commented on a change in pull request #2300:
URL: https://github.com/apache/ozone/pull/2300#discussion_r645309536



##########
File path: hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/WritableRatisContainerProvider.java
##########
@@ -0,0 +1,158 @@
+/**
+ * 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>http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * <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 org.apache.hadoop.hdds.client.ReplicationConfig;
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.hdds.scm.PipelineChoosePolicy;
+import org.apache.hadoop.hdds.scm.PipelineRequestInformation;
+import org.apache.hadoop.hdds.scm.container.ContainerInfo;
+import org.apache.hadoop.hdds.scm.container.ContainerManagerV2;
+import org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList;
+import org.apache.hadoop.hdds.scm.exceptions.SCMException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Class to obtain a writable container for Ratis and Standalone pipelines.
+ */
+public class WritableRatisContainerProvider
+    implements WritableContainerProvider<ReplicationConfig> {
+
+  private static final Logger LOG = LoggerFactory
+      .getLogger(WritableRatisContainerProvider.class);
+
+  private final ConfigurationSource conf;
+  private final PipelineManager pipelineManager;
+  private final PipelineChoosePolicy pipelineChoosePolicy;
+  private final ContainerManagerV2 containerManager;
+
+  public WritableRatisContainerProvider(ConfigurationSource conf,
+      PipelineManager pipelineManager,
+      ContainerManagerV2 containerManager,
+      PipelineChoosePolicy pipelineChoosePolicy) {
+    this.conf = conf;
+    this.pipelineManager = pipelineManager;
+    this.containerManager = containerManager;
+    this.pipelineChoosePolicy = pipelineChoosePolicy;
+  }
+
+
+  @Override
+  public ContainerInfo getContainer(final long size,
+      ReplicationConfig repConfig, String owner, ExcludeList excludeList)
+      throws IOException {
+    /*
+      Here is the high level logic.
+
+      1. We try to find pipelines in open state.
+
+      2. If there are no pipelines in OPEN state, then we try to create one.
+
+      3. We allocate a block from the available containers in the selected
+      pipeline.
+
+      TODO : #CLUTIL Support random picking of two containers from the list.
+      So we can use different kind of policies.
+    */
+
+    ContainerInfo containerInfo;
+
+    //TODO we need to continue the refactor to use repConfig everywhere
+    //in downstream managers.
+
+    while (true) {
+      List<Pipeline> availablePipelines =
+          pipelineManager
+              .getPipelines(repConfig, Pipeline.PipelineState.OPEN,
+                  excludeList.getDatanodes(), excludeList.getPipelineIds());
+      Pipeline pipeline = null;
+      if (availablePipelines.size() == 0 && !excludeList.isEmpty()) {
+        // if no pipelines can be found, try finding pipeline without
+        // exclusion
+        availablePipelines = pipelineManager
+            .getPipelines(repConfig, Pipeline.PipelineState.OPEN);
+      }
+      if (availablePipelines.size() == 0) {
+        try {
+          // TODO: #CLUTIL Remove creation logic when all replication types and
+          // factors are handled by pipeline creator
+          pipeline = pipelineManager.createPipeline(repConfig);

Review comment:
       IIUC, we will still have to use PipelineManager to check replication type and pick the pipelineProvider even in EC case right? So, this WritableContainerPRovider will not use the pipeline providers directly. Ctors will be pretty much same but choosing policy(last args in ctor) can change. Is it a good idea to bring pipeline providers here instead of keeping inside pipelineManager? once created we may have to let pipeline manager know and cache. I am not very strong on this, but thinking about the point that these WritabeCOntainerProvider will not actually use pipeline providers directly. 

##########
File path: hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/WritableContainerProvider.java
##########
@@ -0,0 +1,36 @@
+/**
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 org.apache.hadoop.hdds.client.ReplicationConfig;
+import org.apache.hadoop.hdds.scm.container.ContainerInfo;
+import org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList;
+
+import java.io.IOException;
+
+/**
+ * Interface used by the WritableContainerFactory to obtain a writable container
+ * from the providers.
+ */
+public interface WritableContainerProvider<T extends ReplicationConfig> {
+

Review comment:
       It would be good to explain the idea and expectation/scope of this interface in javadoc.

##########
File path: hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/BlockManagerImpl.java
##########
@@ -174,95 +176,19 @@ public AllocatedBlock allocateBlock(final long size,
           INVALID_BLOCK_SIZE);
     }
 
-    /*
-      Here is the high level logic.
-
-      1. We try to find pipelines in open state.
-
-      2. If there are no pipelines in OPEN state, then we try to create one.
-
-      3. We allocate a block from the available containers in the selected
-      pipeline.
-
-      TODO : #CLUTIL Support random picking of two containers from the list.
-      So we can use different kind of policies.
-    */
-
-    ContainerInfo containerInfo;
-
-    //TODO we need to continue the refactor to use ReplicationConfig everywhere
-    //in downstream managers.
-
-    while (true) {
-      List<Pipeline> availablePipelines =
-          pipelineManager
-              .getPipelines(replicationConfig, Pipeline.PipelineState.OPEN,
-                  excludeList.getDatanodes(), excludeList.getPipelineIds());
-      Pipeline pipeline = null;
-      if (availablePipelines.size() == 0 && !excludeList.isEmpty()) {
-        // if no pipelines can be found, try finding pipeline without
-        // exclusion
-        availablePipelines = pipelineManager
-            .getPipelines(replicationConfig, Pipeline.PipelineState.OPEN);
-      }
-      if (availablePipelines.size() == 0) {
-        try {
-          // TODO: #CLUTIL Remove creation logic when all replication types and
-          // factors are handled by pipeline creator
-          pipeline = pipelineManager.createPipeline(replicationConfig);
-
-          // wait until pipeline is ready
-          pipelineManager.waitPipelineReady(pipeline.getId(), 0);
-        } catch (SCMException se) {
-          LOG.warn("Pipeline creation failed for replicationConfig {} " +
-              "Datanodes may be used up.", replicationConfig, se);
-          break;
-        } catch (IOException e) {
-          LOG.warn("Pipeline creation failed for replicationConfig: {}. "
-              + "Retrying get pipelines call once.", replicationConfig, e);
-          availablePipelines = pipelineManager
-              .getPipelines(replicationConfig, Pipeline.PipelineState.OPEN,
-                  excludeList.getDatanodes(), excludeList.getPipelineIds());
-          if (availablePipelines.size() == 0 && !excludeList.isEmpty()) {
-            // if no pipelines can be found, try finding pipeline without
-            // exclusion
-            availablePipelines = pipelineManager
-                .getPipelines(replicationConfig, Pipeline.PipelineState.OPEN);
-          }
-          if (availablePipelines.size() == 0) {
-            LOG.info(
-                "Could not find available pipeline of replicationConfig: {} "
-                    + "even after retrying",
-                replicationConfig);
-            break;
-          }
-        }
-      }
-
-      if (null == pipeline) {
-        PipelineRequestInformation pri =
-            PipelineRequestInformation.Builder.getBuilder()
-                .setSize(size)
-                .build();
-        pipeline = pipelineChoosePolicy.choosePipeline(
-            availablePipelines, pri);
-      }
-
-      // look for OPEN containers that match the criteria.
-      containerInfo = containerManager.getMatchingContainer(size, owner,
-          pipeline, excludeList.getContainerIds());
-
-      if (containerInfo != null) {
-        return newBlock(containerInfo);
-      }
+    ContainerInfo containerInfo = writableContainerFactory.getContainer(
+        size, replicationConfig, owner, excludeList);
+
+    if (containerInfo != null) {
+      return newBlock(containerInfo);
+    } else {
+      // we have tried all strategies we know and but somehow we are not able

Review comment:
       you can just remove this else condition and leave the old code below?




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org