You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@celeborn.apache.org by "FMX (via GitHub)" <gi...@apache.org> on 2025/09/03 09:15:52 UTC

Re: [PR] [CELEBORN-2059] Support reusing dfs output stream with DFS storage [celeborn]

FMX commented on code in PR #3366:
URL: https://github.com/apache/celeborn/pull/3366#discussion_r2318321293


##########
worker/src/main/java/org/apache/celeborn/service/deploy/worker/storage/hdfs/StreamsManager.java:
##########
@@ -41,9 +43,6 @@ public final class StreamsManager {
     private final FileSystem fileSystem;

Review Comment:
   These two fields are not used. You can try to remove them.



##########
worker/src/main/java/org/apache/celeborn/service/deploy/worker/storage/hdfs/StreamsManager.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.celeborn.service.deploy.worker.storage.hdfs;
+
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.CacheStats;
+import com.google.common.cache.LoadingCache;
+import com.google.common.cache.RemovalListener;
+import com.google.common.cache.RemovalNotification;
+
+import org.apache.celeborn.common.CelebornConf;
+
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+public final class StreamsManager {
+    public static final Logger log = LoggerFactory.getLogger(StreamsManager.class);
+
+    LoadingCache<Path, FSDataOutputStream> cache;
+    private final CelebornConf conf;
+    private final FileSystem fileSystem;
+    private final int maxCapacity;
+    private final long maxStreamIdleMs;
+
+    private final int concurrentLevel;
+    public StreamsManager(CelebornConf conf, FileSystem fileSystem) {
+        this.conf = conf;
+        this.fileSystem = fileSystem;
+        this.maxCapacity = conf.workerOpenHDFSOutputStreamMax();
+        this.maxStreamIdleMs = conf.workerHDFSOutputStreamIdleMsMax();
+        this.concurrentLevel = conf.workerHDFSOutputStreamConcurrentLevel();
+        RemovalListener<Path, FSDataOutputStream> listener = new RemovalListener<Path, FSDataOutputStream>() {

Review Comment:
   You can add a map<Path, Lock> to make sure that a path won't get multiple data output stream objects. 



##########
worker/src/main/java/org/apache/celeborn/service/deploy/worker/storage/hdfs/StreamsManager.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.celeborn.service.deploy.worker.storage.hdfs;
+
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.CacheStats;
+import com.google.common.cache.LoadingCache;
+import com.google.common.cache.RemovalListener;
+import com.google.common.cache.RemovalNotification;
+
+import org.apache.celeborn.common.CelebornConf;
+
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+public final class StreamsManager {
+    public static final Logger log = LoggerFactory.getLogger(StreamsManager.class);
+
+    LoadingCache<Path, FSDataOutputStream> cache;
+    private final CelebornConf conf;
+    private final FileSystem fileSystem;
+    private final int maxCapacity;
+    private final long maxStreamIdleMs;
+
+    private final int concurrentLevel;
+    public StreamsManager(CelebornConf conf, FileSystem fileSystem) {
+        this.conf = conf;
+        this.fileSystem = fileSystem;
+        this.maxCapacity = conf.workerOpenHDFSOutputStreamMax();
+        this.maxStreamIdleMs = conf.workerHDFSOutputStreamIdleMsMax();
+        this.concurrentLevel = conf.workerHDFSOutputStreamConcurrentLevel();
+        RemovalListener<Path, FSDataOutputStream> listener = new RemovalListener<Path, FSDataOutputStream>() {

Review Comment:
   You can refer to this doc(https://github.com/google/guava/wiki/CachesExplained#removal-listeners) and decorate a RemovalListener to operate asynchronously. 



-- 
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@celeborn.apache.org

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