Skip to content

Conversation

@phrocker
Copy link
Contributor

…d and to use an atomic reference.

This is based only on JSTACKs across a running system. I've seen improvement as a result with local testing and will test at a larger scale as time permits. I can provide performance numbers if needed for the PR.

I'm basing this against 1.6 as that is where we will test it and use it. It should merge cleanly up to 1.7 and 1.8.

This is a very simple change. I added a unit test ( the last of which shows that we won't run into the problem of creating many )...though if it fails for you let me know!

}

return codec;
return codec.get();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

whether or not resultCodec is null, I'm returning the reference as the code requires someone to have set it based on the simple logic. Could get rid of resultCodec if there is heartburn about not using it above.

Copy link
Member

Choose a reason for hiding this comment

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

Seems like return resultCodec at the end would be more straightforward, no? Goes a bit to my other comment here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like return resultCodec at the end would be more straightforward, no?

Would be nice to avoid two reads of codec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was doing too many things at once and tried to account for the case where we didn't win the CAS operation. I could have checked the result of the compareAndSet method and returned codec.get() in that case and avoided the funny logic to account for that ( which is why I did what I did ). Now that I'm home that's all obvious; however, according to what Brian wrote above I may just take a different approach when I have time again..hopefully tomorrow. I think his tact is simpler and was hoping the PR would give me some insight for such a method.

@joshelser
Copy link
Member

I apparently clicked through to the commit and left a bunch of comments instead of commenting on the PR itself. Sorry about that.

Overall, this looks pretty good. Some nit-picky things on the test case (yay, tests!) and a similar recommendation to Marc's earlier note.

CompressionCodec getCodec() {
DefaultCodec resultCodec = codec.get();
if (null == resultCodec) {
DefaultCodec newCodec = new DefaultCodec();
Copy link
Member

Choose a reason for hiding this comment

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

If a bunch of threads all got to this point at the same time, they would all create a new DefaultCodec. Only one will succeed on the compareAndSet below, but the code is still potentially creating many DefaultCodec instances which will get garbage collected.
Since isSupported returns true, I'm wondering if it's possible to simply initialize the member variable at construction time, and then the AtomicReference wouldn't be needed either? But maybe I'm missing something obvious.

Copy link
Contributor

Choose a reason for hiding this comment

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

The merit of creating it at construction time depends on how costly the initialization is. I'm under the impression that it's not that bad, so eager initialization is probably ok here and we don't have to worry about concurrency at all. Good point, @brianloss.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just share a singleton codec instance for each kind of codec? Looking at the implementations (Default, Gzip, Bzip2), they're all effectively stateless (sans the Configuration object you can set on them) because they're factories for streams.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had tunnel vision when I looked at the change and didn't even spend much time looking or thinking about anything else. You guys are absolutely right and that negates the need for the AtomicReference. I'll try and apply some time tomorrow to make those changes.

@phrocker phrocker closed this Feb 24, 2016
@phrocker phrocker deleted the ACCUMULO4153 branch February 24, 2016 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants