You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@uniffle.apache.org by GitBox <gi...@apache.org> on 2022/10/09 03:12:51 UTC

[GitHub] [incubator-uniffle] jerqi commented on a diff in pull request #210: [Improvement] Add hdfs path health check to AppBalanceSelectStorageStrategy

jerqi commented on code in PR #210:
URL: https://github.com/apache/incubator-uniffle/pull/210#discussion_r990724501


##########
coordinator/src/main/java/org/apache/uniffle/coordinator/AbstractSelectStorageStrategy.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.coordinator;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.commons.lang3.RandomUtils;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+import org.apache.uniffle.common.RemoteStorageInfo;
+import org.apache.uniffle.common.exception.RssException;
+
+import static org.apache.uniffle.coordinator.LowestIOSampleCostSelectStorageStrategy.RankValue;
+
+/**
+ * This is a simple implementation class, which provides some methods to check whether the path is normal
+ */
+public abstract class AbstractSelectStorageStrategy implements SelectStorageStrategy {
+  /**
+   * store remote path -> application count for assignment strategy
+   */
+  protected final Map<String, LowestIOSampleCostSelectStorageStrategy.RankValue> remoteStoragePathRankValue;
+  protected final int fileSize;
+
+  public AbstractSelectStorageStrategy(
+      Map<String, LowestIOSampleCostSelectStorageStrategy.RankValue> remoteStoragePathRankValue,
+      CoordinatorConf conf) {
+    this.remoteStoragePathRankValue = remoteStoragePathRankValue;
+    fileSize = conf.getInteger(CoordinatorConf.COORDINATOR_REMOTE_STORAGE_SCHEDULE_FILE_SIZE);
+  }
+
+  public void readAndWriteHdfsStorage(FileSystem fs, Path testPath,
+      String uri, RankValue rankValue) throws IOException {
+    byte[] data = RandomUtils.nextBytes(fileSize);
+    try (FSDataOutputStream fos = fs.create(testPath)) {
+      fos.write(data);
+      fos.flush();
+    }
+    byte[] readData = new byte[fileSize];
+    int readBytes;
+    try (FSDataInputStream fis = fs.open(testPath)) {
+      int hasReadBytes = 0;
+      do {
+        readBytes = fis.read(readData);
+        if (hasReadBytes < fileSize) {
+          for (int i = 0; i < readBytes; i++) {
+            if (data[hasReadBytes + i] != readData[i]) {
+              remoteStoragePathRankValue.put(uri, new RankValue(Long.MAX_VALUE, rankValue.getAppNum().get()));
+              throw new RssException("The content of reading and writing is inconsistent.");
+            }
+          }
+        }
+        hasReadBytes += readBytes;
+      } while (readBytes != -1);
+    }
+  }
+
+  @Override

Review Comment:
   If we don't implement the method `detectStorage` and `pickStorage`, we can remove them in the abstract class.



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