advancedxy commented on code in PR #396: URL: https://github.com/apache/incubator-uniffle/pull/396#discussion_r1045677704
########## integration-test/common/src/test/java/org/apache/uniffle/test/ShuffleServerConcurrentWriteOfHdfsTest.java: ########## @@ -0,0 +1,148 @@ +/* + * 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.test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.stream.IntStream; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.Path; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.roaringbitmap.longlong.Roaring64NavigableMap; + +import org.apache.uniffle.client.impl.ShuffleReadClientImpl; +import org.apache.uniffle.client.request.RssFinishShuffleRequest; +import org.apache.uniffle.client.request.RssRegisterShuffleRequest; +import org.apache.uniffle.client.request.RssSendCommitRequest; +import org.apache.uniffle.client.request.RssSendShuffleDataRequest; +import org.apache.uniffle.client.util.DefaultIdHelper; +import org.apache.uniffle.common.PartitionRange; +import org.apache.uniffle.common.ShuffleBlockInfo; +import org.apache.uniffle.common.ShuffleServerInfo; +import org.apache.uniffle.coordinator.CoordinatorConf; +import org.apache.uniffle.server.ShuffleServerConf; +import org.apache.uniffle.storage.util.StorageType; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ShuffleServerConcurrentWriteOfHdfsTest extends ShuffleServerWithHdfsTest { + private static final int MAX_CONCURRENCY = 3; + + @BeforeAll + private static void setupServers() throws Exception { + CoordinatorConf coordinatorConf = getCoordinatorConf(); + createCoordinatorServer(coordinatorConf); + ShuffleServerConf shuffleServerConf = getShuffleServerConf(); + shuffleServerConf.setString(ShuffleServerConf.RSS_STORAGE_TYPE, StorageType.HDFS.name()); + shuffleServerConf.setInteger(ShuffleServerConf.SERVER_MAX_CONCURRENCY_OF_ONE_PARTITION, MAX_CONCURRENCY); + shuffleServerConf.setBoolean(shuffleServerConf.SINGLE_BUFFER_FLUSH_ENABLED, true); + shuffleServerConf.setString("rss.server.single.buffer.flush.threshold", "1m"); + createShuffleServer(shuffleServerConf); + startServers(); + } + + @Test + public void testConcurrentWrite2Hdfs() throws Exception { + String appId = "testConcurrentWrite2Hdfs"; + String dataBasePath = HDFS_URI + "rss/test"; Review Comment: I'm not sure, but it seems we never cleanup this base path? ########## integration-test/common/src/test/java/org/apache/uniffle/test/ShuffleServerConcurrentWriteOfHdfsTest.java: ########## @@ -0,0 +1,148 @@ +/* + * 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.test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.stream.IntStream; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.Path; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.roaringbitmap.longlong.Roaring64NavigableMap; + +import org.apache.uniffle.client.impl.ShuffleReadClientImpl; +import org.apache.uniffle.client.request.RssFinishShuffleRequest; +import org.apache.uniffle.client.request.RssRegisterShuffleRequest; +import org.apache.uniffle.client.request.RssSendCommitRequest; +import org.apache.uniffle.client.request.RssSendShuffleDataRequest; +import org.apache.uniffle.client.util.DefaultIdHelper; +import org.apache.uniffle.common.PartitionRange; +import org.apache.uniffle.common.ShuffleBlockInfo; +import org.apache.uniffle.common.ShuffleServerInfo; +import org.apache.uniffle.coordinator.CoordinatorConf; +import org.apache.uniffle.server.ShuffleServerConf; +import org.apache.uniffle.storage.util.StorageType; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ShuffleServerConcurrentWriteOfHdfsTest extends ShuffleServerWithHdfsTest { + private static final int MAX_CONCURRENCY = 3; + + @BeforeAll + private static void setupServers() throws Exception { + CoordinatorConf coordinatorConf = getCoordinatorConf(); + createCoordinatorServer(coordinatorConf); + ShuffleServerConf shuffleServerConf = getShuffleServerConf(); + shuffleServerConf.setString(ShuffleServerConf.RSS_STORAGE_TYPE, StorageType.HDFS.name()); + shuffleServerConf.setInteger(ShuffleServerConf.SERVER_MAX_CONCURRENCY_OF_ONE_PARTITION, MAX_CONCURRENCY); + shuffleServerConf.setBoolean(shuffleServerConf.SINGLE_BUFFER_FLUSH_ENABLED, true); + shuffleServerConf.setString("rss.server.single.buffer.flush.threshold", "1m"); + createShuffleServer(shuffleServerConf); + startServers(); + } + + @Test + public void testConcurrentWrite2Hdfs() throws Exception { + String appId = "testConcurrentWrite2Hdfs"; + String dataBasePath = HDFS_URI + "rss/test"; + RssRegisterShuffleRequest rrsr = new RssRegisterShuffleRequest( + appId, + 0, + Lists.newArrayList(new PartitionRange(0, 1)), + dataBasePath + ); + shuffleServerClient.registerShuffle(rrsr); + + List<Roaring64NavigableMap> bitmaps = new ArrayList<>(); + Map<Long, byte[]> expectedDatas = new HashMap<>(); + IntStream.range(0, 20).forEach(x -> { + Roaring64NavigableMap bitmap = Roaring64NavigableMap.bitmapOf(); + bitmaps.add(bitmap); + + Map<Long, byte[]> expectedData = Maps.newHashMap(); + + List<ShuffleBlockInfo> blocks = createShuffleBlockList( + 0, + 0, + 0, + 1, + 1024 * 1025, + bitmap, + expectedData, + mockSSI + ); + expectedDatas.putAll(expectedData); + + Map<Integer, List<ShuffleBlockInfo>> partitionToBlocks = Maps.newHashMap(); + partitionToBlocks.put(0, blocks); + Map<Integer, Map<Integer, List<ShuffleBlockInfo>>> shuffleToBlocks = Maps.newHashMap(); + shuffleToBlocks.put(0, partitionToBlocks); + RssSendShuffleDataRequest rssdr = new RssSendShuffleDataRequest(appId, 3, 1000, shuffleToBlocks); + shuffleServerClient.sendShuffleData(rssdr); + }); + + RssSendCommitRequest rscr = new RssSendCommitRequest(appId, 0); + shuffleServerClient.sendCommit(rscr); + + RssFinishShuffleRequest rfsr = new RssFinishShuffleRequest(appId, 0); + shuffleServerClient.finishShuffle(rfsr); + + // Check the concurrent hdfs file creation + FileStatus[] fileStatuses = fs.listStatus(new Path(dataBasePath + "/" + appId + "/0/0-1")); + long actual = Arrays.stream(fileStatuses).filter(x -> x.getPath().getName().endsWith(".data")).count(); Review Comment: ".data" -> `org.apache.uniffle.common.util.Constants.SHUFFLE_DATA_FILE_SUFFIX` ########## server/src/main/java/org/apache/uniffle/server/ShuffleServerConf.java: ########## @@ -314,6 +314,13 @@ public class ShuffleServerConf extends RssBaseConf { .defaultValue(3600 * 1000L) .withDescription("the interval of leak shuffle data check"); + public static final ConfigOption<Integer> SERVER_MAX_CONCURRENCY_OF_ONE_PARTITION = ConfigOptions + .key("rss.server.max.concurrency.of.single-one-partition") Review Comment: how about this: `rss.server.max.concurrency.of.single.partition.writer`? ########## integration-test/common/src/test/java/org/apache/uniffle/test/ShuffleServerConcurrentWriteOfHdfsTest.java: ########## @@ -0,0 +1,148 @@ +/* + * 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.test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.stream.IntStream; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.Path; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.roaringbitmap.longlong.Roaring64NavigableMap; + +import org.apache.uniffle.client.impl.ShuffleReadClientImpl; +import org.apache.uniffle.client.request.RssFinishShuffleRequest; +import org.apache.uniffle.client.request.RssRegisterShuffleRequest; +import org.apache.uniffle.client.request.RssSendCommitRequest; +import org.apache.uniffle.client.request.RssSendShuffleDataRequest; +import org.apache.uniffle.client.util.DefaultIdHelper; +import org.apache.uniffle.common.PartitionRange; +import org.apache.uniffle.common.ShuffleBlockInfo; +import org.apache.uniffle.common.ShuffleServerInfo; +import org.apache.uniffle.coordinator.CoordinatorConf; +import org.apache.uniffle.server.ShuffleServerConf; +import org.apache.uniffle.storage.util.StorageType; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ShuffleServerConcurrentWriteOfHdfsTest extends ShuffleServerWithHdfsTest { + private static final int MAX_CONCURRENCY = 3; + + @BeforeAll + private static void setupServers() throws Exception { + CoordinatorConf coordinatorConf = getCoordinatorConf(); + createCoordinatorServer(coordinatorConf); + ShuffleServerConf shuffleServerConf = getShuffleServerConf(); + shuffleServerConf.setString(ShuffleServerConf.RSS_STORAGE_TYPE, StorageType.HDFS.name()); + shuffleServerConf.setInteger(ShuffleServerConf.SERVER_MAX_CONCURRENCY_OF_ONE_PARTITION, MAX_CONCURRENCY); + shuffleServerConf.setBoolean(shuffleServerConf.SINGLE_BUFFER_FLUSH_ENABLED, true); + shuffleServerConf.setString("rss.server.single.buffer.flush.threshold", "1m"); + createShuffleServer(shuffleServerConf); + startServers(); + } + + @Test + public void testConcurrentWrite2Hdfs() throws Exception { + String appId = "testConcurrentWrite2Hdfs"; + String dataBasePath = HDFS_URI + "rss/test"; + RssRegisterShuffleRequest rrsr = new RssRegisterShuffleRequest( + appId, + 0, + Lists.newArrayList(new PartitionRange(0, 1)), + dataBasePath + ); + shuffleServerClient.registerShuffle(rrsr); + + List<Roaring64NavigableMap> bitmaps = new ArrayList<>(); + Map<Long, byte[]> expectedDatas = new HashMap<>(); Review Comment: -> `expectedData`. Data is already the plural of datum. ########## integration-test/common/src/test/java/org/apache/uniffle/test/ShuffleServerConcurrentWriteOfHdfsTest.java: ########## @@ -0,0 +1,148 @@ +/* + * 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.test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.stream.IntStream; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.Path; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.roaringbitmap.longlong.Roaring64NavigableMap; + +import org.apache.uniffle.client.impl.ShuffleReadClientImpl; +import org.apache.uniffle.client.request.RssFinishShuffleRequest; +import org.apache.uniffle.client.request.RssRegisterShuffleRequest; +import org.apache.uniffle.client.request.RssSendCommitRequest; +import org.apache.uniffle.client.request.RssSendShuffleDataRequest; +import org.apache.uniffle.client.util.DefaultIdHelper; +import org.apache.uniffle.common.PartitionRange; +import org.apache.uniffle.common.ShuffleBlockInfo; +import org.apache.uniffle.common.ShuffleServerInfo; +import org.apache.uniffle.coordinator.CoordinatorConf; +import org.apache.uniffle.server.ShuffleServerConf; +import org.apache.uniffle.storage.util.StorageType; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ShuffleServerConcurrentWriteOfHdfsTest extends ShuffleServerWithHdfsTest { + private static final int MAX_CONCURRENCY = 3; + + @BeforeAll + private static void setupServers() throws Exception { + CoordinatorConf coordinatorConf = getCoordinatorConf(); + createCoordinatorServer(coordinatorConf); + ShuffleServerConf shuffleServerConf = getShuffleServerConf(); + shuffleServerConf.setString(ShuffleServerConf.RSS_STORAGE_TYPE, StorageType.HDFS.name()); + shuffleServerConf.setInteger(ShuffleServerConf.SERVER_MAX_CONCURRENCY_OF_ONE_PARTITION, MAX_CONCURRENCY); + shuffleServerConf.setBoolean(shuffleServerConf.SINGLE_BUFFER_FLUSH_ENABLED, true); + shuffleServerConf.setString("rss.server.single.buffer.flush.threshold", "1m"); Review Comment: this should be `ShuffleServerConf.SINGLE_BUFFER_FLUSH_THRESHOLD`? ########## storage/src/main/java/org/apache/uniffle/storage/common/HdfsStorage.java: ########## @@ -99,15 +99,16 @@ public void updateWriteMetrics(StorageWriteMetrics metrics) { ShuffleWriteHandler newWriteHandler(CreateShuffleWriteHandlerRequest request) { try { String user = request.getUser(); - return new HdfsShuffleWriteHandler( + return new PooledHdfsShuffleWriteHandler( Review Comment: Let's just use HdfsShuffleWriteHandler when `request.getMaxFileNumber` = 1? The rational is to reduce unnecessary overhead and also keep the original logic intact. ########## integration-test/common/src/test/java/org/apache/uniffle/test/ShuffleServerWithHdfsTest.java: ########## @@ -51,10 +51,10 @@ public class ShuffleServerWithHdfsTest extends ShuffleReadWriteBase { - private ShuffleServerGrpcClient shuffleServerClient; + protected ShuffleServerGrpcClient shuffleServerClient; @BeforeAll - public static void setupServers() throws Exception { + private static void setupServers() throws Exception { Review Comment: Per junit's doc: https://junit.org/junit5/docs/5.0.0/api/org/junit/jupiter/api/BeforeAll.html I'm not sure it's best practice to declare this `setupServers` as private. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
