Skip to content

Commit

Permalink
[NO ISSUE][NET] Ensure Thread Safety in FullFrameChannelReadInterface
Browse files Browse the repository at this point in the history
- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- Use a blocking deque in FullFrameChannelReadInterface
  to ensure thread safety between frame consumer and
  the networking thread.

Change-Id: I33f0171e49b0ff972730a678e8b61a2070dc8832
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2921
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
Reviewed-by: Michael Blow <mblow@apache.org>
  • Loading branch information
mhubail committed Aug 19, 2018
1 parent 167518f commit 0b99332
Showing 1 changed file with 8 additions and 10 deletions.
Expand Up @@ -21,8 +21,8 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

import org.apache.hyracks.api.comm.IBufferFactory;
import org.apache.hyracks.api.comm.IChannelControlBlock;
Expand All @@ -33,22 +33,20 @@
public class FullFrameChannelReadInterface extends AbstractChannelReadInterface {

private static final Logger LOGGER = LogManager.getLogger();
private final Deque<ByteBuffer> riEmptyStack;
private final BlockingDeque<ByteBuffer> riEmptyStack;
private final IChannelControlBlock ccb;

FullFrameChannelReadInterface(IChannelControlBlock ccb) {
this.ccb = ccb;
riEmptyStack = new ArrayDeque<>();
riEmptyStack = new LinkedBlockingDeque<>();
credits = 0;

emptyBufferAcceptor = buffer -> {
int delta = buffer.remaining();
synchronized (ccb) {
if (ccb.isRemotelyClosed()) {
return;
}
riEmptyStack.push(buffer);
if (ccb.isRemotelyClosed()) {
return;
}
riEmptyStack.push(buffer);
final int delta = buffer.remaining();
ccb.addPendingCredits(delta);
};
}
Expand Down

0 comments on commit 0b99332

Please sign in to comment.