Skip to content

Commit

Permalink
merge: #8277
Browse files Browse the repository at this point in the history
8277: [Backport stable/1.2] Fix data race between `AtomixServerTransport` and `RequestHandler`s r=oleschoenburg a=github-actions[bot]

# Description
Backport of #8272 to `stable/1.2`.

relates to #8269 #8257

Co-authored-by: Ole Schönburg <[email protected]>
  • Loading branch information
zeebe-bors-cloud[bot] and lenaschoenburg authored Nov 25, 2021
2 parents 764962f + cf9d5a8 commit 5fd6471
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicLong;
import org.agrona.DirectBuffer;
import org.agrona.collections.Int2ObjectHashMap;
import org.agrona.collections.Long2ObjectHashMap;
import org.agrona.concurrent.UnsafeBuffer;
Expand All @@ -33,15 +32,13 @@ public class AtomixServerTransport extends Actor implements ServerTransport {
private final Int2ObjectHashMap<Long2ObjectHashMap<CompletableFuture<byte[]>>>
partitionsRequestMap;
private final AtomicLong requestCount;
private final DirectBuffer reusableRequestBuffer;
private final MessagingService messagingService;
private final String actorName;

public AtomixServerTransport(final int nodeId, final MessagingService messagingService) {
this.messagingService = messagingService;
partitionsRequestMap = new Int2ObjectHashMap<>();
requestCount = new AtomicLong(0);
reusableRequestBuffer = new UnsafeBuffer(0, 0);
actorName = buildActorName(nodeId, "ServerTransport");
}

Expand Down Expand Up @@ -122,9 +119,13 @@ private CompletableFuture<byte[]> handleAtomixRequest(
}

try {
reusableRequestBuffer.wrap(requestBytes);
requestHandler.onRequest(
this, partitionId, requestId, reusableRequestBuffer, 0, requestBytes.length);
this,
partitionId,
requestId,
new UnsafeBuffer(requestBytes),
0,
requestBytes.length);
if (LOG.isTraceEnabled()) {
LOG.trace(
"Handled request {} for topic {}",
Expand Down

0 comments on commit 5fd6471

Please sign in to comment.