PHILO-HE commented on code in PR #10591:
URL: 
https://github.com/apache/incubator-gluten/pull/10591#discussion_r2320603144


##########
gluten-celeborn/src/main/java/org/apache/spark/shuffle/gluten/celeborn/CelebornShuffleManager.java:
##########
@@ -68,46 +63,25 @@ public class CelebornShuffleManager
   private static final CelebornColumnarBatchSerializerFactory 
columnarBatchSerializerFactory;
 
   static {
-    final ServiceLoader<CelebornShuffleWriterFactory> loader =
-        ServiceLoader.load(CelebornShuffleWriterFactory.class);
-    final List<CelebornShuffleWriterFactory> factoryList =
-        Arrays.stream(Iterators.toArray(loader.iterator(), 
CelebornShuffleWriterFactory.class))
-            .collect(Collectors.toList());
+    final Iterator<CelebornShuffleWriterFactory> shuffleWriterFactoryIterator =
+        ServiceLoader.load(CelebornShuffleWriterFactory.class).iterator();
     Preconditions.checkState(
-        !factoryList.isEmpty(), "No factory found for Celeborn shuffle 
writer");
-    final Map<String, CelebornShuffleWriterFactory> factoryMap =
-        factoryList.stream()
-            
.collect(Collectors.toMap(CelebornShuffleWriterFactory::backendName, f -> f));
-
-    final String backendName = BackendsApiManager.getBackendName();
-    if (!factoryMap.containsKey(backendName)) {
-      throw new UnsupportedOperationException(
-          "No Celeborn shuffle writer factory found for backend " + 
backendName);
-    }
-    writerFactory = factoryMap.get(backendName);
-
-    final ServiceLoader<CelebornColumnarBatchSerializerFactory>
-        celebornColumnarBatchSerializerFactoriesLoader =
-            ServiceLoader.load(CelebornColumnarBatchSerializerFactory.class);
-    final List<CelebornColumnarBatchSerializerFactory> 
columnarBatchSerializerFactoryList =
-        Arrays.stream(
-                Iterators.toArray(
-                    celebornColumnarBatchSerializerFactoriesLoader.iterator(),
-                    CelebornColumnarBatchSerializerFactory.class))
-            .collect(Collectors.toList());
+        shuffleWriterFactoryIterator.hasNext(), "No Celeborn shuffle writer 
factory found");
+    writerFactory = shuffleWriterFactoryIterator.next();
+    Preconditions.checkState(
+        !shuffleWriterFactoryIterator.hasNext(),
+        "Multiple factory found for Celeborn shuffle writer");

Review Comment:
   factories



##########
gluten-celeborn/src/main/java/org/apache/spark/shuffle/gluten/celeborn/CelebornShuffleManager.java:
##########
@@ -68,46 +63,25 @@ public class CelebornShuffleManager
   private static final CelebornColumnarBatchSerializerFactory 
columnarBatchSerializerFactory;
 
   static {
-    final ServiceLoader<CelebornShuffleWriterFactory> loader =
-        ServiceLoader.load(CelebornShuffleWriterFactory.class);
-    final List<CelebornShuffleWriterFactory> factoryList =
-        Arrays.stream(Iterators.toArray(loader.iterator(), 
CelebornShuffleWriterFactory.class))
-            .collect(Collectors.toList());
+    final Iterator<CelebornShuffleWriterFactory> shuffleWriterFactoryIterator =
+        ServiceLoader.load(CelebornShuffleWriterFactory.class).iterator();
     Preconditions.checkState(
-        !factoryList.isEmpty(), "No factory found for Celeborn shuffle 
writer");
-    final Map<String, CelebornShuffleWriterFactory> factoryMap =
-        factoryList.stream()
-            
.collect(Collectors.toMap(CelebornShuffleWriterFactory::backendName, f -> f));
-
-    final String backendName = BackendsApiManager.getBackendName();
-    if (!factoryMap.containsKey(backendName)) {
-      throw new UnsupportedOperationException(
-          "No Celeborn shuffle writer factory found for backend " + 
backendName);
-    }
-    writerFactory = factoryMap.get(backendName);
-
-    final ServiceLoader<CelebornColumnarBatchSerializerFactory>
-        celebornColumnarBatchSerializerFactoriesLoader =
-            ServiceLoader.load(CelebornColumnarBatchSerializerFactory.class);
-    final List<CelebornColumnarBatchSerializerFactory> 
columnarBatchSerializerFactoryList =
-        Arrays.stream(
-                Iterators.toArray(
-                    celebornColumnarBatchSerializerFactoriesLoader.iterator(),
-                    CelebornColumnarBatchSerializerFactory.class))
-            .collect(Collectors.toList());
+        shuffleWriterFactoryIterator.hasNext(), "No Celeborn shuffle writer 
factory found");
+    writerFactory = shuffleWriterFactoryIterator.next();
+    Preconditions.checkState(
+        !shuffleWriterFactoryIterator.hasNext(),
+        "Multiple factory found for Celeborn shuffle writer");
+
+    final Iterator<CelebornColumnarBatchSerializerFactory> 
serializerFactoryIterator =
+        
ServiceLoader.load(CelebornColumnarBatchSerializerFactory.class).iterator();
 
     Preconditions.checkState(
-        !columnarBatchSerializerFactoryList.isEmpty(),
+        serializerFactoryIterator.hasNext(),
         "No factory found for Celeborn columnar batch serializer");
-    final Map<String, CelebornColumnarBatchSerializerFactory> 
columnarBatchSerializerFactoryMap =
-        columnarBatchSerializerFactoryList.stream()
-            
.collect(Collectors.toMap(CelebornColumnarBatchSerializerFactory::backendName, 
f -> f));
-
-    if (!columnarBatchSerializerFactoryMap.containsKey(backendName)) {
-      throw new UnsupportedOperationException(
-          "No Celeborn columnar batch serializer writer factory found for 
backend " + backendName);
-    }
-    columnarBatchSerializerFactory = 
columnarBatchSerializerFactoryMap.get(backendName);
+    columnarBatchSerializerFactory = serializerFactoryIterator.next();
+    Preconditions.checkState(
+        !serializerFactoryIterator.hasNext(),
+        "Multiple factory found for Celeborn columnar batch serializer");

Review Comment:
   ditto



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

Reply via email to