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 09:48:52 UTC

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

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



##########
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:
       The pipeline manager's job is to manage the pipeline lifecycle, and offer an interface to get, create and close pipelines. Along with this code, the background pipeline creator thread creates pipelines too. For Ratis, the code here is a really a last resort - it should not need to create pipelines normally.
   
   I think its fine that the ContainerProviders are not concerned with the PipelineProviders, and they just interface with PipelineManager.
   
   You could argue the pipeline Providers could be outside of pipeline manager and there may be value to put them into the WritableContainerProviders. However, the pipeline manager interface is established and works fine. To change it we would need to make more changes elsewhere, and I am not really sure it would gain us much.
   
   What do you think?




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