Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made decrementing pendingPublishAcks more thread safe #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,15 @@ private boolean verifyChecksum(ByteBuf headersAndPayload) {
}

private void startPublishOperation(int batchSize, long msgSize) {
// A single thread is incrementing/decrementing this counter, so we can use lazySet which doesn't involve a mem
// barrier
pendingPublishAcksUpdater.lazySet(this, pendingPublishAcks + 1);
// Since different threads can start and complete the publish operation, we need a strong concurrency guarantee
pendingPublishAcksUpdater.incrementAndGet(this);
// increment publish-count
this.getTopic().incrementPublishCount(batchSize, msgSize);
}

private void publishOperationCompleted() {
long newPendingPublishAcks = this.pendingPublishAcks - 1;
pendingPublishAcksUpdater.lazySet(this, newPendingPublishAcks);

// Check the close future to avoid grabbing the mutex every time the pending acks goes down to 0
if (newPendingPublishAcks == 0 && !closeFuture.isDone()) {
if (pendingPublishAcksUpdater.decrementAndGet(this) <= 0 && !closeFuture.isDone()) {
synchronized (this) {
if (isClosed && !closeFuture.isDone()) {
closeNow(true);
Expand Down