Skip to content

Fix non-atomic volatile update - #6606

Merged
sijie merged 4 commits into
apache:masterfrom
yjshen:volatile_atomic
Mar 26, 2020
Merged

Fix non-atomic volatile update#6606
sijie merged 4 commits into
apache:masterfrom
yjshen:volatile_atomic

Conversation

@yjshen

@yjshen yjshen commented Mar 26, 2020

Copy link
Copy Markdown
Member

No description provided.

@yjshen

yjshen commented Mar 26, 2020

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@sijie sijie added this to the 2.6.0 milestone Mar 26, 2020
@sijie sijie added the type/cleanup Code or doc cleanups e.g. remove the outdated documentation or remove the code no longer in use label Mar 26, 2020
@yjshen

yjshen commented Mar 26, 2020

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@yjshen

yjshen commented Mar 26, 2020

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

1 similar comment
@yjshen

yjshen commented Mar 26, 2020

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@sijie
sijie merged commit d298c8b into apache:master Mar 26, 2020
@merlimat

merlimat commented Apr 8, 2020

Copy link
Copy Markdown
Contributor

What is the motivation for this change? There were different specific reasons for not using volatile in these components.

Volatile has a performance penalty and should only be used if strictly needed. Also, it's not a panacea that fixes all concurrency issue.

As it is, I think this commit should be reverted.

@yjshen @sijie

LongPair item = new LongPair(data[index], data[index + 1]);
data[index] = EmptyItem;
data[index + 1] = EmptyItem;
--this.size;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already protected by a write lock. No need to use updater. The volatile is only used to ensure readers are reading the last value of the size.

}

public void startSendOperation(Producer producer, int msgSize) {
messagePublishBufferSize += msgSize;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All operations on a connection are happening on same thread

@merlimat

merlimat commented Apr 8, 2020

Copy link
Copy Markdown
Contributor

I take back the argument on performance impact.. since this is only adding the static updaters. Though in most cases these updaters are not necessary because the variables are designed to be updated from a single thread or already within the context of a mutex.

@sijie

sijie commented Apr 8, 2020

Copy link
Copy Markdown
Member

Yeah, this change is more about adding the static updaters. It doesn't change the existing behaviors. The change here is more about making the volatile updates atomic and ensure a consistent pattern across the code. Since it is always a good practice to follow across the whole pulsar code base. Did you see any other problems with this change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/cleanup Code or doc cleanups e.g. remove the outdated documentation or remove the code no longer in use

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants