You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@celeborn.apache.org by GitBox <gi...@apache.org> on 2023/01/06 03:40:06 UTC

[GitHub] [incubator-celeborn] waitinfuture commented on a diff in pull request #1069: [CELEBORN-124]Add buffer stream.

waitinfuture commented on code in PR #1069:
URL: https://github.com/apache/incubator-celeborn/pull/1069#discussion_r1063066592


##########
common/src/main/java/org/apache/celeborn/common/network/server/BufferStreamManager.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.celeborn.common.network.server;
+
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
+
+import io.netty.channel.Channel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BufferStreamManager {
+  private static final Logger logger = LoggerFactory.getLogger(BufferStreamManager.class);
+  private final AtomicLong nextStreamId;
+  protected final ConcurrentHashMap<Long, StreamStat> streams;
+
+  protected class StreamStat {

Review Comment:
   StreamState



##########
common/src/main/java/org/apache/celeborn/common/network/protocol/ReadData.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.common.network.protocol;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+
+public class ReadData extends RequestMessage {
+  private long streamId;
+  private int backlog;
+  private int[] offsets;
+  private ByteBuf buf;
+
+  public ReadData(long streamId, int backlog, int[] offsets, ByteBuf buf) {
+    this.streamId = streamId;
+    this.backlog = backlog;
+    this.offsets = offsets;
+    this.buf = buf;
+  }
+
+  @Override
+  public int encodedLength() {
+    return 8 + 4 + 4 + offsets.length * 4 + 4 + buf.readableBytes();
+  }
+
+  @Override
+  public void encode(ByteBuf buf) {
+    buf.writeLong(streamId);
+    buf.writeInt(backlog);
+    buf.writeInt(offsets.length);
+    for (int offset : offsets) {
+      buf.writeInt(offset);
+    }
+    buf.writeInt(this.buf.readableBytes());
+    buf.writeBytes(this.buf);
+  }
+
+  public static ReadData decode(ByteBuf buf) {
+    long streamId = buf.readLong();
+    int credit = buf.readInt();

Review Comment:
   backlog? we should be consistent



##########
common/src/main/java/org/apache/celeborn/common/network/server/BufferStreamManager.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.celeborn.common.network.server;
+
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
+
+import io.netty.channel.Channel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BufferStreamManager {
+  private static final Logger logger = LoggerFactory.getLogger(BufferStreamManager.class);
+  private final AtomicLong nextStreamId;
+  protected final ConcurrentHashMap<Long, StreamStat> streams;
+
+  protected class StreamStat {
+    private Channel associatedChannel;
+    private int bufferSize;
+
+    public StreamStat(Channel associatedChannel, int bufferSize) {
+      this.associatedChannel = associatedChannel;
+      this.bufferSize = bufferSize;
+    }
+
+    public Channel getAssociatedChannel() {
+      return associatedChannel;
+    }
+
+    public int getBufferSize() {
+      return bufferSize;
+    }
+  }
+
+  public BufferStreamManager() {
+    nextStreamId = new AtomicLong((long) new Random().nextInt(Integer.MAX_VALUE) * 1000);
+    streams = new ConcurrentHashMap<>();
+  }
+
+  public long registerStream(Channel channel, int bufferSize) {
+    long streamId = nextStreamId.getAndIncrement();
+    streams.put(streamId, new StreamStat(channel, bufferSize));
+    return streamId;
+  }
+
+  public void addCredit(int numCredit, long streamId) {}
+
+  public void connectionTerminated(Channel channel) {
+    for (Map.Entry<Long, StreamStat> entry : streams.entrySet()) {
+      if (entry.getValue().getAssociatedChannel().equals(channel)) {

Review Comment:
   I think we can use == to be consistent with ChunkStreamManager. Although seems it will never be null so NPE will not happen.



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