You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@uniffle.apache.org by "xianjingfeng (via GitHub)" <gi...@apache.org> on 2023/03/28 02:20:59 UTC

[GitHub] [incubator-uniffle] xianjingfeng commented on a diff in pull request #749: [#731] Make blockId layout configured by client side

xianjingfeng commented on code in PR #749:
URL: https://github.com/apache/incubator-uniffle/pull/749#discussion_r1149956456


##########
common/src/main/java/org/apache/uniffle/common/BlockIdLayoutConfig.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.uniffle.common;
+
+import java.util.Map;
+
+import org.apache.uniffle.common.config.RssClientConf;
+import org.apache.uniffle.common.config.RssConf;
+import org.apache.uniffle.common.util.Constants;
+
+public class BlockIdLayoutConfig {
+  // BlockId is long and consist of partitionId, taskAttemptId, atomicInt
+  // the length of them are ATOMIC_INT_MAX_LENGTH + PARTITION_ID_MAX_LENGTH + TASK_ATTEMPT_ID_MAX_LENGTH = 63
+  private static final int BLOCK_ID_LENGTH = 63;
+
+  /**
+   * The keys are configured in the conf of BLOCKID_LAYOUT
+   */
+  public static final String PARTITION_ID_LENGTH = "partitionIdLength";
+  public static final String TASK_ATTEMPT_ID_LENGTH = "taskAttemptIdLength";
+  public static final String SEQUENCE_ID_LENGTH = "sequenceIdLength";
+
+  private int partitionIdLength;
+  private int taskAttemptIdLength;
+  private int sequenceIdLength;
+
+  private BlockIdLayoutConfig(int partitionIdLength, int taskAttemptIdLength, int sequenceIdLength) {
+    this.partitionIdLength = partitionIdLength;
+    this.taskAttemptIdLength = taskAttemptIdLength;
+    this.sequenceIdLength = sequenceIdLength;
+  }
+
+  public int getPartitionIdLength() {
+    return partitionIdLength;
+  }
+
+  public int getTaskAttemptIdLength() {
+    return taskAttemptIdLength;
+  }
+
+  public int getSequenceIdLength() {
+    return sequenceIdLength;
+  }
+
+  @Override
+  public String toString() {
+    return "BlockIdLayoutConfig{"
+        + "partitionIdLength=" + partitionIdLength
+        + ", taskAttemptIdLength=" + taskAttemptIdLength
+        + ", sequenceIdLength=" + sequenceIdLength
+        + '}';
+  }
+
+  public static boolean validate(Map<String, String> blockIdLayoutMap) {
+    try {
+      from(blockIdLayoutMap);
+      return true;
+    } catch (Exception e) {
+      return false;
+    }
+  }
+
+  public static BlockIdLayoutConfig from(RssConf rssConf) {
+    Map<String, String> blockIdLayoutMap = rssConf.get(RssClientConf.BLOCKID_LAYOUT);
+    if (blockIdLayoutMap == null || blockIdLayoutMap.isEmpty()) {
+      return from();
+    }
+
+    return from(blockIdLayoutMap);
+  }
+
+  public static BlockIdLayoutConfig from() {
+    return new BlockIdLayoutConfig(
+        Constants.PARTITION_ID_MAX_LENGTH,
+        Constants.TASK_ATTEMPT_ID_MAX_LENGTH,
+        Constants.ATOMIC_INT_MAX_LENGTH
+    );
+  }
+
+  public static BlockIdLayoutConfig from(int partitionIdLength, int taskAttemptIdLength, int sequenceIdLength) {
+    if (partitionIdLength + taskAttemptIdLength + sequenceIdLength != BLOCK_ID_LENGTH) {

Review Comment:
   How about if one of them is 0?



-- 
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: issues-unsubscribe@uniffle.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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