From 5dd5d49e10f21a0d56af5a940da710973d5ff79b Mon Sep 17 00:00:00 2001 From: Junfan Zhang Date: Thu, 27 Apr 2023 14:22:18 +0800 Subject: [PATCH 1/9] [#845] feat(storage): Introduce capacity based storage chooser strategy --- .../uniffle/common/util/ClassUtils.java | 27 ++++++++++++ .../uniffle/server/ShuffleServerConf.java | 7 +++ .../server/storage/LocalStorageManager.java | 35 +++++++++------ .../storage/LocalStorageManagerTest.java | 44 +++++++++++++++++++ .../uniffle/storage/common/LocalStorage.java | 6 +++ 5 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 common/src/main/java/org/apache/uniffle/common/util/ClassUtils.java diff --git a/common/src/main/java/org/apache/uniffle/common/util/ClassUtils.java b/common/src/main/java/org/apache/uniffle/common/util/ClassUtils.java new file mode 100644 index 0000000000..d2845bf33e --- /dev/null +++ b/common/src/main/java/org/apache/uniffle/common/util/ClassUtils.java @@ -0,0 +1,27 @@ +package org.apache.uniffle.common.util; + +import java.lang.reflect.Constructor; +import java.util.stream.Stream; + +import org.apache.commons.lang3.tuple.Pair; + +import org.apache.uniffle.common.exception.RssException; + +public class ClassUtils { + + public static T instantiate(Class clazz, Pair, Object>... typeAndVals) + throws RssException { + try { + if (typeAndVals == null || typeAndVals.length == 0) { + return clazz.newInstance(); + } + Class[] types = Stream.of(typeAndVals).map(x -> x.getLeft()).toArray(Class[]::new); + Constructor constructor = clazz.getConstructor(types); + return constructor.newInstance( + Stream.of(typeAndVals).map(x -> x.getRight()).toArray(Object[]::new) + ); + } catch (Exception e) { + throw new RssException(e); + } + } +} diff --git a/server/src/main/java/org/apache/uniffle/server/ShuffleServerConf.java b/server/src/main/java/org/apache/uniffle/server/ShuffleServerConf.java index 5ee38ad35a..3506aaacbc 100644 --- a/server/src/main/java/org/apache/uniffle/server/ShuffleServerConf.java +++ b/server/src/main/java/org/apache/uniffle/server/ShuffleServerConf.java @@ -295,6 +295,13 @@ public class ShuffleServerConf extends RssBaseConf { .defaultValue(0L) .withDescription("For multistorage, fail times exceed the number, will switch storage"); + public static final ConfigOption LOCAL_STORAGE_CHOOSER_CLASS = ConfigOptions + .key("rss.server.localstorage.storage.chooser.class") + .stringType() + .defaultValue("org.apache.uniffle.server.storage.local.HashBasedStorageChooser") + .withDescription("For localstorage, the storage chooser for per-partition. " + + "Default value is the hash-based disk selector."); + public static final ConfigOption> TAGS = ConfigOptions .key("rss.server.tags") .stringType() diff --git a/server/src/main/java/org/apache/uniffle/server/storage/LocalStorageManager.java b/server/src/main/java/org/apache/uniffle/server/storage/LocalStorageManager.java index c1bb63b7b1..62d4df5967 100644 --- a/server/src/main/java/org/apache/uniffle/server/storage/LocalStorageManager.java +++ b/server/src/main/java/org/apache/uniffle/server/storage/LocalStorageManager.java @@ -50,6 +50,7 @@ import org.apache.uniffle.common.storage.StorageInfo; import org.apache.uniffle.common.storage.StorageMedia; import org.apache.uniffle.common.storage.StorageStatus; +import org.apache.uniffle.common.util.ClassUtils; import org.apache.uniffle.common.util.JavaUtils; import org.apache.uniffle.common.util.RssUtils; import org.apache.uniffle.common.util.ThreadUtils; @@ -62,6 +63,7 @@ import org.apache.uniffle.server.event.AppPurgeEvent; import org.apache.uniffle.server.event.PurgeEvent; import org.apache.uniffle.server.event.ShufflePurgeEvent; +import org.apache.uniffle.server.storage.local.StorageChooser; import org.apache.uniffle.storage.common.LocalStorage; import org.apache.uniffle.storage.common.Storage; import org.apache.uniffle.storage.common.StorageMediaProvider; @@ -71,6 +73,7 @@ import org.apache.uniffle.storage.util.ShuffleStorageUtils; import org.apache.uniffle.storage.util.StorageType; +import static org.apache.uniffle.server.ShuffleServerConf.LOCAL_STORAGE_CHOOSER_CLASS; import static org.apache.uniffle.server.ShuffleServerConf.LOCAL_STORAGE_INITIALIZE_MAX_FAIL_NUMBER; public class LocalStorageManager extends SingleStorageManager { @@ -84,6 +87,8 @@ public class LocalStorageManager extends SingleStorageManager { private final Map partitionsOfStorage; private final List typeProviders = Lists.newArrayList(); + private final StorageChooser storageChooser; + @VisibleForTesting LocalStorageManager(ShuffleServerConf conf) { super(conf); @@ -155,6 +160,17 @@ public class LocalStorageManager extends SingleStorageManager { StringUtils.join(localStorages.stream().map(LocalStorage::getBasePath).collect(Collectors.toList())) ); this.checker = new LocalStorageChecker(conf, localStorages); + this.storageChooser = initStorageChooser(conf); + } + + private StorageChooser initStorageChooser(ShuffleServerConf conf) { + try { + String className = conf.get(LOCAL_STORAGE_CHOOSER_CLASS); + Class> clz = (Class>) Class.forName(className); + return ClassUtils.instantiate(clz); + } catch (Exception e) { + throw new RssException(e); + } } private StorageMedia getStorageTypeForBasePath(String basePath) { @@ -184,19 +200,8 @@ public Storage selectStorage(ShuffleDataFlushEvent event) { return storage; } } - - List candidates = localStorages - .stream() - .filter(x -> x.canWrite() && !x.isCorrupted()) - .collect(Collectors.toList()); - final LocalStorage selectedStorage = candidates.get( - ShuffleStorageUtils.getStorageIndex( - candidates.size(), - appId, - shuffleId, - partitionId - ) - ); + final LocalStorage selectedStorage = + storageChooser.pick(event, localStorages.stream().toArray(LocalStorage[]::new)); return partitionsOfStorage.compute( UnionKey.buildKey(appId, shuffleId, partitionId), (key, localStorage) -> { @@ -355,4 +360,8 @@ public Map getStorageInfo() { public List getStorages() { return localStorages; } + + public StorageChooser getStorageChooser() { + return storageChooser; + } } diff --git a/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java b/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java index 43c8f06402..71db0686b9 100644 --- a/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java +++ b/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java @@ -40,6 +40,7 @@ import org.apache.uniffle.server.ShuffleDataReadEvent; import org.apache.uniffle.server.ShuffleServerConf; import org.apache.uniffle.server.ShuffleServerMetrics; +import org.apache.uniffle.server.storage.local.CapacityBasedStorageChooser; import org.apache.uniffle.storage.common.LocalStorage; import org.apache.uniffle.storage.common.Storage; import org.apache.uniffle.storage.util.StorageType; @@ -107,6 +108,49 @@ public void testStorageSelectionWhenReachingHighWatermark() { assertNotEquals(storage1, storage2); } + + @Test + public void testPluggableStorageSelection() { + String[] storagePaths = {"/tmp/rss-data1", "/tmp/rss-data2", "/tmp/rss-data3"}; + + ShuffleServerConf conf = new ShuffleServerConf(); + conf.set(ShuffleServerConf.RSS_STORAGE_BASE_PATH, Arrays.asList(storagePaths)); + conf.setLong(ShuffleServerConf.DISK_CAPACITY, 1024L); + conf.setString(ShuffleServerConf.RSS_STORAGE_TYPE, org.apache.uniffle.storage.util.StorageType.LOCALFILE.name()); + conf.setString( + ShuffleServerConf.LOCAL_STORAGE_CHOOSER_CLASS, + "org.apache.uniffle.server.storage.local.CapacityBasedStorageChooser" + ); + LocalStorageManager localStorageManager = new LocalStorageManager(conf); + + List storages = localStorageManager.getStorages(); + assertNotNull(storages); + + LocalStorage s1 = storages.get(0); + LocalStorage s2 = storages.get(1); + LocalStorage s3 = storages.get(2); + + String appId = "testPluggableStorageSelection"; + + // case1 + s1.setDiskSize(300); + s2.setDiskSize(200); + s3.setDiskSize(500); + ShuffleDataFlushEvent event1 = toDataFlushEvent(appId, 1, 1); + Storage storage = localStorageManager.selectStorage(event1); + assertEquals(s2, storage); + + // case2 + s2.markCorrupted(); + storage = localStorageManager.selectStorage(event1); + assertEquals(s1, storage); + + // case3 + s1.markCorrupted(); + storage = localStorageManager.selectStorage(event1); + assertEquals(s3, storage); + } + @Test public void testStorageSelection() { String[] storagePaths = {"/tmp/rss-data1", "/tmp/rss-data2", "/tmp/rss-data3"}; diff --git a/storage/src/main/java/org/apache/uniffle/storage/common/LocalStorage.java b/storage/src/main/java/org/apache/uniffle/storage/common/LocalStorage.java index b5ca09e82b..c3dbf5b137 100644 --- a/storage/src/main/java/org/apache/uniffle/storage/common/LocalStorage.java +++ b/storage/src/main/java/org/apache/uniffle/storage/common/LocalStorage.java @@ -198,6 +198,12 @@ public void updateUploadedShuffle(String shuffleKey, long size, List pa metaData.addUploadedShufflePartitionList(shuffleKey, partitions); } + // only for tests + @VisibleForTesting + public void setDiskSize(long size) { + metaData.getDiskSize().set(size); + } + public long getDiskSize() { return metaData.getDiskSize().longValue(); } From b1d3afe9ffaf714ff66e7283dadfabbaaabda018 Mon Sep 17 00:00:00 2001 From: Junfan Zhang Date: Thu, 27 Apr 2023 14:28:41 +0800 Subject: [PATCH 2/9] add doc --- docs/server_guide.md | 1 + .../main/java/org/apache/uniffle/server/ShuffleServerConf.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/server_guide.md b/docs/server_guide.md index 48143a228d..84866311cb 100644 --- a/docs/server_guide.md +++ b/docs/server_guide.md @@ -91,6 +91,7 @@ This document will introduce how to deploy Uniffle shuffle servers. | rss.server.max.concurrency.of.single.partition.writer | 1 | The max concurrency of single partition writer, the data partition file number is equal to this value. Default value is 1. This config could improve the writing speed, especially for huge partition. | | rss.metrics.reporter.class | - | The class of metrics reporter. | |rss.server.multistorage.manager.selector.class | org.apache.uniffle.server.storage.multi.DefaultStorageManagerSelector | The manager selector strategy for `MEMORY_LOCALFILE_HDFS`. Default value is `DefaultStorageManagerSelector`, and another `HugePartitionSensitiveStorageManagerSelector` will flush only huge partition's data to cold storage. | +|rss.server.localstorage.storage.chooser.class|org.apache.uniffle.server.storage.local.HashBasedStorageChooser|For localstorage, the storage chooser is for per-partition. Default value is the hash-based disk selector.| ### Advanced Configurations |Property Name|Default| Description | diff --git a/server/src/main/java/org/apache/uniffle/server/ShuffleServerConf.java b/server/src/main/java/org/apache/uniffle/server/ShuffleServerConf.java index 3506aaacbc..0bd3350b45 100644 --- a/server/src/main/java/org/apache/uniffle/server/ShuffleServerConf.java +++ b/server/src/main/java/org/apache/uniffle/server/ShuffleServerConf.java @@ -299,7 +299,7 @@ public class ShuffleServerConf extends RssBaseConf { .key("rss.server.localstorage.storage.chooser.class") .stringType() .defaultValue("org.apache.uniffle.server.storage.local.HashBasedStorageChooser") - .withDescription("For localstorage, the storage chooser for per-partition. " + .withDescription("For localstorage, the storage chooser is for per-partition. " + "Default value is the hash-based disk selector."); public static final ConfigOption> TAGS = ConfigOptions From 33eea6aa4707a9423614b2e3967133ae0c0359d2 Mon Sep 17 00:00:00 2001 From: Junfan Zhang Date: Thu, 27 Apr 2023 14:36:31 +0800 Subject: [PATCH 3/9] fox --- .../apache/uniffle/server/storage/LocalStorageManagerTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java b/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java index 71db0686b9..b411d65988 100644 --- a/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java +++ b/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java @@ -40,7 +40,6 @@ import org.apache.uniffle.server.ShuffleDataReadEvent; import org.apache.uniffle.server.ShuffleServerConf; import org.apache.uniffle.server.ShuffleServerMetrics; -import org.apache.uniffle.server.storage.local.CapacityBasedStorageChooser; import org.apache.uniffle.storage.common.LocalStorage; import org.apache.uniffle.storage.common.Storage; import org.apache.uniffle.storage.util.StorageType; @@ -130,12 +129,12 @@ public void testPluggableStorageSelection() { LocalStorage s2 = storages.get(1); LocalStorage s3 = storages.get(2); - String appId = "testPluggableStorageSelection"; // case1 s1.setDiskSize(300); s2.setDiskSize(200); s3.setDiskSize(500); + String appId = "testPluggableStorageSelection"; ShuffleDataFlushEvent event1 = toDataFlushEvent(appId, 1, 1); Storage storage = localStorageManager.selectStorage(event1); assertEquals(s2, storage); From 599f6765405cf2d3e7706b23df5ee0fcf3b33356 Mon Sep 17 00:00:00 2001 From: Junfan Zhang Date: Thu, 27 Apr 2023 14:41:05 +0800 Subject: [PATCH 4/9] fox --- .gitignore | 1 - .../local/CapacityBasedStorageChooser.java | 48 +++++++++++++ .../local/HashBasedStorageChooser.java | 53 ++++++++++++++ .../server/storage/local/StorageChooser.java | 27 +++++++ .../CapacityBasedStorageChooserTest.java | 72 +++++++++++++++++++ 5 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 server/src/main/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooser.java create mode 100644 server/src/main/java/org/apache/uniffle/server/storage/local/HashBasedStorageChooser.java create mode 100644 server/src/main/java/org/apache/uniffle/server/storage/local/StorageChooser.java create mode 100644 server/src/test/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooserTest.java diff --git a/.gitignore b/.gitignore index b6901d7ce7..6e995a2ee8 100644 --- a/.gitignore +++ b/.gitignore @@ -28,7 +28,6 @@ deploy/kubernetes/docker/hadoopconfig/* *.dll *.so *.dylib -local vendor VERSION testbin/* diff --git a/server/src/main/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooser.java b/server/src/main/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooser.java new file mode 100644 index 0000000000..e88300f64d --- /dev/null +++ b/server/src/main/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooser.java @@ -0,0 +1,48 @@ +/* + * 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.server.storage.local; + +import java.math.BigDecimal; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.uniffle.server.ShuffleDataFlushEvent; +import org.apache.uniffle.storage.common.LocalStorage; + +public class CapacityBasedStorageChooser implements StorageChooser { + + @Override + public LocalStorage pick(ShuffleDataFlushEvent event, LocalStorage... storages) { + final List candidates = Arrays.stream(storages) + .filter(x -> x.canWrite() && !x.isCorrupted()) + .collect(Collectors.toList()); + + if (candidates.size() == 0) { + return null; + } + + candidates.sort((s1, s2) -> { + BigDecimal s1UsedRatio = BigDecimal.valueOf(s1.getDiskSize()).divide(BigDecimal.valueOf(s1.getCapacity())); + BigDecimal s2UsedRatio = BigDecimal.valueOf(s2.getDiskSize()).divide(BigDecimal.valueOf(s2.getCapacity())); + return s1UsedRatio.compareTo(s2UsedRatio); + }); + + return candidates.get(0); + } +} diff --git a/server/src/main/java/org/apache/uniffle/server/storage/local/HashBasedStorageChooser.java b/server/src/main/java/org/apache/uniffle/server/storage/local/HashBasedStorageChooser.java new file mode 100644 index 0000000000..7c4c07cccf --- /dev/null +++ b/server/src/main/java/org/apache/uniffle/server/storage/local/HashBasedStorageChooser.java @@ -0,0 +1,53 @@ +/* + * 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.server.storage.local; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.uniffle.server.ShuffleDataFlushEvent; +import org.apache.uniffle.storage.common.LocalStorage; +import org.apache.uniffle.storage.util.ShuffleStorageUtils; + +public class HashBasedStorageChooser implements StorageChooser { + + @Override + public LocalStorage pick(ShuffleDataFlushEvent event, LocalStorage... storages) { + List candidates = Arrays.stream(storages) + .filter(x -> x.canWrite() && !x.isCorrupted()) + .collect(Collectors.toList()); + + if (candidates.size() == 0) { + return null; + } + + String appId = event.getAppId(); + int shuffleId = event.getShuffleId(); + int partitionId = event.getStartPartition(); + final LocalStorage selectedStorage = candidates.get( + ShuffleStorageUtils.getStorageIndex( + candidates.size(), + appId, + shuffleId, + partitionId + ) + ); + return selectedStorage; + } +} diff --git a/server/src/main/java/org/apache/uniffle/server/storage/local/StorageChooser.java b/server/src/main/java/org/apache/uniffle/server/storage/local/StorageChooser.java new file mode 100644 index 0000000000..84744ce59b --- /dev/null +++ b/server/src/main/java/org/apache/uniffle/server/storage/local/StorageChooser.java @@ -0,0 +1,27 @@ +/* + * 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.server.storage.local; + +import org.apache.uniffle.server.ShuffleDataFlushEvent; +import org.apache.uniffle.storage.common.Storage; + +public interface StorageChooser { + + T pick(ShuffleDataFlushEvent event, T... candidates); + +} diff --git a/server/src/test/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooserTest.java b/server/src/test/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooserTest.java new file mode 100644 index 0000000000..2326bcccd1 --- /dev/null +++ b/server/src/test/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooserTest.java @@ -0,0 +1,72 @@ +/* + * 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.server.storage.local; + +import java.util.Collections; + +import org.junit.jupiter.api.Test; + +import org.apache.uniffle.server.ShuffleDataFlushEvent; +import org.apache.uniffle.storage.common.LocalStorage; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class CapacityBasedStorageChooserTest { + + @Test + public void test() { + ShuffleDataFlushEvent event = new ShuffleDataFlushEvent( + 1, + "1", + 1, + 1, + 1, + 1, + Collections.emptyList(), + null, + null + ); + + // case1 + LocalStorage s1 = mock(LocalStorage.class); + when(s1.canWrite()).thenReturn(true); + when(s1.isCorrupted()).thenReturn(false); + when(s1.getDiskSize()).thenReturn(50L); + when(s1.getCapacity()).thenReturn(200L); + + LocalStorage s2 = mock(LocalStorage.class); + when(s2.canWrite()).thenReturn(true); + when(s2.isCorrupted()).thenReturn(false); + when(s2.getDiskSize()).thenReturn(10L); + when(s2.getCapacity()).thenReturn(200L); + + CapacityBasedStorageChooser storageChooser = new CapacityBasedStorageChooser(); + assertEquals(s2, storageChooser.pick(event, s1, s2)); + + // case2 + when(s2.canWrite()).thenReturn(false); + assertEquals(s1, storageChooser.pick(event, s1, s2)); + + // case3 + when(s1.isCorrupted()).thenReturn(true); + assertNull(storageChooser.pick(event, s1, s2)); + } +} From 8ff6e6c95b52e2ebaf74f1e31d1ba0ede86a66be Mon Sep 17 00:00:00 2001 From: Junfan Zhang Date: Thu, 27 Apr 2023 14:41:33 +0800 Subject: [PATCH 5/9] fix --- .../apache/uniffle/common/util/ClassUtils.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/common/src/main/java/org/apache/uniffle/common/util/ClassUtils.java b/common/src/main/java/org/apache/uniffle/common/util/ClassUtils.java index d2845bf33e..e765bde026 100644 --- a/common/src/main/java/org/apache/uniffle/common/util/ClassUtils.java +++ b/common/src/main/java/org/apache/uniffle/common/util/ClassUtils.java @@ -1,3 +1,20 @@ +/* + * 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.util; import java.lang.reflect.Constructor; From 270e5d6d1e34226b4f39511f47a84f7f4cca399b Mon Sep 17 00:00:00 2001 From: Junfan Zhang Date: Thu, 27 Apr 2023 14:51:07 +0800 Subject: [PATCH 6/9] fix --- .../CapacityBasedStorageChooserTest.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/server/src/test/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooserTest.java b/server/src/test/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooserTest.java index 2326bcccd1..c03a54dab5 100644 --- a/server/src/test/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooserTest.java +++ b/server/src/test/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooserTest.java @@ -33,18 +33,6 @@ public class CapacityBasedStorageChooserTest { @Test public void test() { - ShuffleDataFlushEvent event = new ShuffleDataFlushEvent( - 1, - "1", - 1, - 1, - 1, - 1, - Collections.emptyList(), - null, - null - ); - // case1 LocalStorage s1 = mock(LocalStorage.class); when(s1.canWrite()).thenReturn(true); @@ -58,6 +46,17 @@ public void test() { when(s2.getDiskSize()).thenReturn(10L); when(s2.getCapacity()).thenReturn(200L); + ShuffleDataFlushEvent event = new ShuffleDataFlushEvent( + 1, + "1", + 1, + 1, + 1, + 1, + Collections.emptyList(), + null, + null + ); CapacityBasedStorageChooser storageChooser = new CapacityBasedStorageChooser(); assertEquals(s2, storageChooser.pick(event, s1, s2)); From 108d0d63b35a427d4aac39c586aa6712c1e8167e Mon Sep 17 00:00:00 2001 From: Junfan Zhang Date: Thu, 27 Apr 2023 14:59:58 +0800 Subject: [PATCH 7/9] fix --- .../src/main/java/org/apache/uniffle/common/util/ClassUtils.java | 1 + 1 file changed, 1 insertion(+) diff --git a/common/src/main/java/org/apache/uniffle/common/util/ClassUtils.java b/common/src/main/java/org/apache/uniffle/common/util/ClassUtils.java index e765bde026..a9429d0098 100644 --- a/common/src/main/java/org/apache/uniffle/common/util/ClassUtils.java +++ b/common/src/main/java/org/apache/uniffle/common/util/ClassUtils.java @@ -26,6 +26,7 @@ public class ClassUtils { + @SuppressWarnings("unchecked") public static T instantiate(Class clazz, Pair, Object>... typeAndVals) throws RssException { try { From 048646c2c4620397dbfc08b283ff316c2a66dfa9 Mon Sep 17 00:00:00 2001 From: Junfan Zhang Date: Thu, 4 May 2023 14:22:31 +0800 Subject: [PATCH 8/9] optimize --- .../uniffle/common/util/ClassUtils.java | 2 +- docs/server_guide.md | 2 +- .../uniffle/server/ShuffleServerConf.java | 8 +++---- .../server/storage/LocalStorageManager.java | 21 ++++++++----------- ... AvailableSpaceStorageChoosingPolicy.java} | 4 ++-- ...er.java => HashStorageChoosingPolicy.java} | 4 ++-- ...hooser.java => StorageChoosingPolicy.java} | 4 ++-- .../storage/LocalStorageManagerTest.java | 4 ++-- ...ilableSpaceStorageChoosingPolicyTest.java} | 10 ++++----- 9 files changed, 28 insertions(+), 31 deletions(-) rename server/src/main/java/org/apache/uniffle/server/storage/local/{CapacityBasedStorageChooser.java => AvailableSpaceStorageChoosingPolicy.java} (89%) rename server/src/main/java/org/apache/uniffle/server/storage/local/{HashBasedStorageChooser.java => HashStorageChoosingPolicy.java} (90%) rename server/src/main/java/org/apache/uniffle/server/storage/local/{StorageChooser.java => StorageChoosingPolicy.java} (88%) rename server/src/test/java/org/apache/uniffle/server/storage/local/{CapacityBasedStorageChooserTest.java => AvailableSpaceStorageChoosingPolicyTest.java} (86%) diff --git a/common/src/main/java/org/apache/uniffle/common/util/ClassUtils.java b/common/src/main/java/org/apache/uniffle/common/util/ClassUtils.java index a9429d0098..5b7ebae231 100644 --- a/common/src/main/java/org/apache/uniffle/common/util/ClassUtils.java +++ b/common/src/main/java/org/apache/uniffle/common/util/ClassUtils.java @@ -31,7 +31,7 @@ public static T instantiate(Class clazz, Pair, Object>... typeAn throws RssException { try { if (typeAndVals == null || typeAndVals.length == 0) { - return clazz.newInstance(); + return clazz.getConstructor().newInstance(); } Class[] types = Stream.of(typeAndVals).map(x -> x.getLeft()).toArray(Class[]::new); Constructor constructor = clazz.getConstructor(types); diff --git a/docs/server_guide.md b/docs/server_guide.md index 84866311cb..022148bb44 100644 --- a/docs/server_guide.md +++ b/docs/server_guide.md @@ -91,7 +91,7 @@ This document will introduce how to deploy Uniffle shuffle servers. | rss.server.max.concurrency.of.single.partition.writer | 1 | The max concurrency of single partition writer, the data partition file number is equal to this value. Default value is 1. This config could improve the writing speed, especially for huge partition. | | rss.metrics.reporter.class | - | The class of metrics reporter. | |rss.server.multistorage.manager.selector.class | org.apache.uniffle.server.storage.multi.DefaultStorageManagerSelector | The manager selector strategy for `MEMORY_LOCALFILE_HDFS`. Default value is `DefaultStorageManagerSelector`, and another `HugePartitionSensitiveStorageManagerSelector` will flush only huge partition's data to cold storage. | -|rss.server.localstorage.storage.chooser.class|org.apache.uniffle.server.storage.local.HashBasedStorageChooser|For localstorage, the storage chooser is for per-partition. Default value is the hash-based disk selector.| +|rss.server.localstorage.storage.choosing.policy.class|org.apache.uniffle.server.storage.local.HashStorageChoosingPolicy|For localstorage, the storage choosing policy is for per-partition. Default value is the hash-based disk selector.| ### Advanced Configurations |Property Name|Default| Description | diff --git a/server/src/main/java/org/apache/uniffle/server/ShuffleServerConf.java b/server/src/main/java/org/apache/uniffle/server/ShuffleServerConf.java index 0bd3350b45..77ac28247e 100644 --- a/server/src/main/java/org/apache/uniffle/server/ShuffleServerConf.java +++ b/server/src/main/java/org/apache/uniffle/server/ShuffleServerConf.java @@ -295,11 +295,11 @@ public class ShuffleServerConf extends RssBaseConf { .defaultValue(0L) .withDescription("For multistorage, fail times exceed the number, will switch storage"); - public static final ConfigOption LOCAL_STORAGE_CHOOSER_CLASS = ConfigOptions - .key("rss.server.localstorage.storage.chooser.class") + public static final ConfigOption LOCAL_STORAGE_CHOOSING_POLICY = ConfigOptions + .key("rss.server.localstorage.storage.choosing.policy.class") .stringType() - .defaultValue("org.apache.uniffle.server.storage.local.HashBasedStorageChooser") - .withDescription("For localstorage, the storage chooser is for per-partition. " + .defaultValue("org.apache.uniffle.server.storage.local.HashStorageChoosingPolicy") + .withDescription("For localstorage, the storage choosing policy is for per-partition. " + "Default value is the hash-based disk selector."); public static final ConfigOption> TAGS = ConfigOptions diff --git a/server/src/main/java/org/apache/uniffle/server/storage/LocalStorageManager.java b/server/src/main/java/org/apache/uniffle/server/storage/LocalStorageManager.java index 62d4df5967..2bb358e453 100644 --- a/server/src/main/java/org/apache/uniffle/server/storage/LocalStorageManager.java +++ b/server/src/main/java/org/apache/uniffle/server/storage/LocalStorageManager.java @@ -63,7 +63,7 @@ import org.apache.uniffle.server.event.AppPurgeEvent; import org.apache.uniffle.server.event.PurgeEvent; import org.apache.uniffle.server.event.ShufflePurgeEvent; -import org.apache.uniffle.server.storage.local.StorageChooser; +import org.apache.uniffle.server.storage.local.StorageChoosingPolicy; import org.apache.uniffle.storage.common.LocalStorage; import org.apache.uniffle.storage.common.Storage; import org.apache.uniffle.storage.common.StorageMediaProvider; @@ -73,7 +73,7 @@ import org.apache.uniffle.storage.util.ShuffleStorageUtils; import org.apache.uniffle.storage.util.StorageType; -import static org.apache.uniffle.server.ShuffleServerConf.LOCAL_STORAGE_CHOOSER_CLASS; +import static org.apache.uniffle.server.ShuffleServerConf.LOCAL_STORAGE_CHOOSING_POLICY; import static org.apache.uniffle.server.ShuffleServerConf.LOCAL_STORAGE_INITIALIZE_MAX_FAIL_NUMBER; public class LocalStorageManager extends SingleStorageManager { @@ -87,7 +87,7 @@ public class LocalStorageManager extends SingleStorageManager { private final Map partitionsOfStorage; private final List typeProviders = Lists.newArrayList(); - private final StorageChooser storageChooser; + private final StorageChoosingPolicy storageChoosingPolicy; @VisibleForTesting LocalStorageManager(ShuffleServerConf conf) { @@ -160,13 +160,14 @@ public class LocalStorageManager extends SingleStorageManager { StringUtils.join(localStorages.stream().map(LocalStorage::getBasePath).collect(Collectors.toList())) ); this.checker = new LocalStorageChecker(conf, localStorages); - this.storageChooser = initStorageChooser(conf); + this.storageChoosingPolicy = initStorageChoosingPolicy(conf); } - private StorageChooser initStorageChooser(ShuffleServerConf conf) { + private StorageChoosingPolicy initStorageChoosingPolicy(ShuffleServerConf conf) { try { - String className = conf.get(LOCAL_STORAGE_CHOOSER_CLASS); - Class> clz = (Class>) Class.forName(className); + String className = conf.get(LOCAL_STORAGE_CHOOSING_POLICY); + Class> clz = + (Class>) Class.forName(className); return ClassUtils.instantiate(clz); } catch (Exception e) { throw new RssException(e); @@ -201,7 +202,7 @@ public Storage selectStorage(ShuffleDataFlushEvent event) { } } final LocalStorage selectedStorage = - storageChooser.pick(event, localStorages.stream().toArray(LocalStorage[]::new)); + storageChoosingPolicy.choose(event, localStorages.stream().toArray(LocalStorage[]::new)); return partitionsOfStorage.compute( UnionKey.buildKey(appId, shuffleId, partitionId), (key, localStorage) -> { @@ -360,8 +361,4 @@ public Map getStorageInfo() { public List getStorages() { return localStorages; } - - public StorageChooser getStorageChooser() { - return storageChooser; - } } diff --git a/server/src/main/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooser.java b/server/src/main/java/org/apache/uniffle/server/storage/local/AvailableSpaceStorageChoosingPolicy.java similarity index 89% rename from server/src/main/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooser.java rename to server/src/main/java/org/apache/uniffle/server/storage/local/AvailableSpaceStorageChoosingPolicy.java index e88300f64d..43215bc29e 100644 --- a/server/src/main/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooser.java +++ b/server/src/main/java/org/apache/uniffle/server/storage/local/AvailableSpaceStorageChoosingPolicy.java @@ -25,10 +25,10 @@ import org.apache.uniffle.server.ShuffleDataFlushEvent; import org.apache.uniffle.storage.common.LocalStorage; -public class CapacityBasedStorageChooser implements StorageChooser { +public class AvailableSpaceStorageChoosingPolicy implements StorageChoosingPolicy { @Override - public LocalStorage pick(ShuffleDataFlushEvent event, LocalStorage... storages) { + public LocalStorage choose(final ShuffleDataFlushEvent event, final LocalStorage... storages) { final List candidates = Arrays.stream(storages) .filter(x -> x.canWrite() && !x.isCorrupted()) .collect(Collectors.toList()); diff --git a/server/src/main/java/org/apache/uniffle/server/storage/local/HashBasedStorageChooser.java b/server/src/main/java/org/apache/uniffle/server/storage/local/HashStorageChoosingPolicy.java similarity index 90% rename from server/src/main/java/org/apache/uniffle/server/storage/local/HashBasedStorageChooser.java rename to server/src/main/java/org/apache/uniffle/server/storage/local/HashStorageChoosingPolicy.java index 7c4c07cccf..c506261c69 100644 --- a/server/src/main/java/org/apache/uniffle/server/storage/local/HashBasedStorageChooser.java +++ b/server/src/main/java/org/apache/uniffle/server/storage/local/HashStorageChoosingPolicy.java @@ -25,10 +25,10 @@ import org.apache.uniffle.storage.common.LocalStorage; import org.apache.uniffle.storage.util.ShuffleStorageUtils; -public class HashBasedStorageChooser implements StorageChooser { +public class HashStorageChoosingPolicy implements StorageChoosingPolicy { @Override - public LocalStorage pick(ShuffleDataFlushEvent event, LocalStorage... storages) { + public LocalStorage choose(final ShuffleDataFlushEvent event, final LocalStorage... storages) { List candidates = Arrays.stream(storages) .filter(x -> x.canWrite() && !x.isCorrupted()) .collect(Collectors.toList()); diff --git a/server/src/main/java/org/apache/uniffle/server/storage/local/StorageChooser.java b/server/src/main/java/org/apache/uniffle/server/storage/local/StorageChoosingPolicy.java similarity index 88% rename from server/src/main/java/org/apache/uniffle/server/storage/local/StorageChooser.java rename to server/src/main/java/org/apache/uniffle/server/storage/local/StorageChoosingPolicy.java index 84744ce59b..18542f39b7 100644 --- a/server/src/main/java/org/apache/uniffle/server/storage/local/StorageChooser.java +++ b/server/src/main/java/org/apache/uniffle/server/storage/local/StorageChoosingPolicy.java @@ -20,8 +20,8 @@ import org.apache.uniffle.server.ShuffleDataFlushEvent; import org.apache.uniffle.storage.common.Storage; -public interface StorageChooser { +public interface StorageChoosingPolicy { - T pick(ShuffleDataFlushEvent event, T... candidates); + T choose(final ShuffleDataFlushEvent event, final T... candidates); } diff --git a/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java b/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java index b411d65988..20e6e9c30d 100644 --- a/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java +++ b/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java @@ -117,8 +117,8 @@ public void testPluggableStorageSelection() { conf.setLong(ShuffleServerConf.DISK_CAPACITY, 1024L); conf.setString(ShuffleServerConf.RSS_STORAGE_TYPE, org.apache.uniffle.storage.util.StorageType.LOCALFILE.name()); conf.setString( - ShuffleServerConf.LOCAL_STORAGE_CHOOSER_CLASS, - "org.apache.uniffle.server.storage.local.CapacityBasedStorageChooser" + ShuffleServerConf.LOCAL_STORAGE_CHOOSING_POLICY, + "org.apache.uniffle.server.storage.local.AvailableSpaceStorageChoosingPolicy" ); LocalStorageManager localStorageManager = new LocalStorageManager(conf); diff --git a/server/src/test/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooserTest.java b/server/src/test/java/org/apache/uniffle/server/storage/local/AvailableSpaceStorageChoosingPolicyTest.java similarity index 86% rename from server/src/test/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooserTest.java rename to server/src/test/java/org/apache/uniffle/server/storage/local/AvailableSpaceStorageChoosingPolicyTest.java index c03a54dab5..df5945df7c 100644 --- a/server/src/test/java/org/apache/uniffle/server/storage/local/CapacityBasedStorageChooserTest.java +++ b/server/src/test/java/org/apache/uniffle/server/storage/local/AvailableSpaceStorageChoosingPolicyTest.java @@ -29,7 +29,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class CapacityBasedStorageChooserTest { +public class AvailableSpaceStorageChoosingPolicyTest { @Test public void test() { @@ -57,15 +57,15 @@ public void test() { null, null ); - CapacityBasedStorageChooser storageChooser = new CapacityBasedStorageChooser(); - assertEquals(s2, storageChooser.pick(event, s1, s2)); + AvailableSpaceStorageChoosingPolicy storageChooser = new AvailableSpaceStorageChoosingPolicy(); + assertEquals(s2, storageChooser.choose(event, s1, s2)); // case2 when(s2.canWrite()).thenReturn(false); - assertEquals(s1, storageChooser.pick(event, s1, s2)); + assertEquals(s1, storageChooser.choose(event, s1, s2)); // case3 when(s1.isCorrupted()).thenReturn(true); - assertNull(storageChooser.pick(event, s1, s2)); + assertNull(storageChooser.choose(event, s1, s2)); } } From 36ea15aa005aab09499fc925bf4af51bedc10b33 Mon Sep 17 00:00:00 2001 From: Junfan Zhang Date: Thu, 4 May 2023 14:29:20 +0800 Subject: [PATCH 9/9] fix --- .../storage/local/AvailableSpaceStorageChoosingPolicy.java | 2 +- .../uniffle/server/storage/local/HashStorageChoosingPolicy.java | 2 +- .../uniffle/server/storage/local/StorageChoosingPolicy.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/apache/uniffle/server/storage/local/AvailableSpaceStorageChoosingPolicy.java b/server/src/main/java/org/apache/uniffle/server/storage/local/AvailableSpaceStorageChoosingPolicy.java index 43215bc29e..d5d9a310ba 100644 --- a/server/src/main/java/org/apache/uniffle/server/storage/local/AvailableSpaceStorageChoosingPolicy.java +++ b/server/src/main/java/org/apache/uniffle/server/storage/local/AvailableSpaceStorageChoosingPolicy.java @@ -28,7 +28,7 @@ public class AvailableSpaceStorageChoosingPolicy implements StorageChoosingPolicy { @Override - public LocalStorage choose(final ShuffleDataFlushEvent event, final LocalStorage... storages) { + public LocalStorage choose(ShuffleDataFlushEvent event, LocalStorage... storages) { final List candidates = Arrays.stream(storages) .filter(x -> x.canWrite() && !x.isCorrupted()) .collect(Collectors.toList()); diff --git a/server/src/main/java/org/apache/uniffle/server/storage/local/HashStorageChoosingPolicy.java b/server/src/main/java/org/apache/uniffle/server/storage/local/HashStorageChoosingPolicy.java index c506261c69..c214d95ac4 100644 --- a/server/src/main/java/org/apache/uniffle/server/storage/local/HashStorageChoosingPolicy.java +++ b/server/src/main/java/org/apache/uniffle/server/storage/local/HashStorageChoosingPolicy.java @@ -28,7 +28,7 @@ public class HashStorageChoosingPolicy implements StorageChoosingPolicy { @Override - public LocalStorage choose(final ShuffleDataFlushEvent event, final LocalStorage... storages) { + public LocalStorage choose(ShuffleDataFlushEvent event, LocalStorage... storages) { List candidates = Arrays.stream(storages) .filter(x -> x.canWrite() && !x.isCorrupted()) .collect(Collectors.toList()); diff --git a/server/src/main/java/org/apache/uniffle/server/storage/local/StorageChoosingPolicy.java b/server/src/main/java/org/apache/uniffle/server/storage/local/StorageChoosingPolicy.java index 18542f39b7..c2d28dd400 100644 --- a/server/src/main/java/org/apache/uniffle/server/storage/local/StorageChoosingPolicy.java +++ b/server/src/main/java/org/apache/uniffle/server/storage/local/StorageChoosingPolicy.java @@ -22,6 +22,6 @@ public interface StorageChoosingPolicy { - T choose(final ShuffleDataFlushEvent event, final T... candidates); + T choose(ShuffleDataFlushEvent event, T... candidates); }