Skip to content

Conversation

@felixbarny
Copy link
Member

No description provided.

@felixbarny felixbarny self-assigned this Nov 4, 2018
@felixbarny felixbarny requested a review from eyalkoren November 4, 2018 12:57
Copy link
Contributor

@eyalkoren eyalkoren left a comment

Choose a reason for hiding this comment

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

Very cool!
Just a few comments, besides a compilation error.
Why would we keep the old implementation?

public class Db implements Recyclable {

private final ObjectPool<CharBuffer> charBufferPool = new QueueBasedObjectPool<CharBuffer>(new MpmcAtomicArrayQueue<>(128), false,
new Allocator<CharBuffer>() {
Copy link
Contributor

Choose a reason for hiding this comment

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

stay consistent with the other pool initialization, not through usage of new

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean I should add a static initializer for creating a QueueBasedObjectPool with an Allocator and Resetter? Or do you mean I should not use an anonymous inner class for Allocator?

Copy link
Member Author

Choose a reason for hiding this comment

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

created QueueBasedObjectPool.of static initializer

Copy link
Contributor

Choose a reason for hiding this comment

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

I was referring to the ObjectPool- I saw you changed all others to use a static initializer, so I wondered why not this one as well.
Anyway, not very important

return this;
}

public CharBuffer withStatementBuffer() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add documentation that user of this method is not allowed to hold a reference to the buffer

}

@Nullable
public CharBuffer getStatementBuffer() {
Copy link
Contributor

Choose a reason for hiding this comment

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

same

final CharsetDecoder charsetDecoder = threadLocalCharsetDecoder.get();
try (is) {
final byte[] bufferArray = buffer.array();
for (int read = is.read(bufferArray); read != -1; read = is.read(bufferArray)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Start by checking whether this is UTF-8 encoded indeed (by checking whether first byte is {)

Copy link
Member Author

Choose a reason for hiding this comment

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

This is handled neatly by the coder result return value of charsetDecoder.decode. In case a character could not be mapped, coderResult.isError() returns true. However, I should clear() the CharBuffer in that case, so that it does not get serialized.

Copy link
Contributor

Choose a reason for hiding this comment

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

If encoding was done using UTF-16, you won't necessarily get an error decoding with UTF-8. You may just get the wrong decoding.
But right about the clearing buffer whenever decoding fails!

Copy link
Member Author

Choose a reason for hiding this comment

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

I have a test exactly for this which asserts that the encoding fails if the steam is encoded in UTF-16: https://github.com/elastic/apm-agent-java/pull/283/files#diff-97c7f94f59c329dd827193f8a343fc90R82

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, since the first char is always {, a UTF-16 will produce a first 0x00 byte...

@felixbarny
Copy link
Member Author

+1 on removing the old code

@codecov-io
Copy link

Codecov Report

Merging #283 into master will decrease coverage by 0.06%.
The diff coverage is 65.71%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #283      +/-   ##
============================================
- Coverage     73.29%   73.23%   -0.07%     
- Complexity     1158     1165       +7     
============================================
  Files           124      126       +2     
  Lines          4322     4372      +50     
  Branches        431      437       +6     
============================================
+ Hits           3168     3202      +34     
- Misses          947      961      +14     
- Partials        207      209       +2
Impacted Files Coverage Δ Complexity Δ
...lastic/apm/plugin/api/ApiScopeInstrumentation.java 71.42% <ø> (ø) 5 <0> (ø) ⬇️
...o/elastic/apm/objectpool/impl/MixedObjectPool.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...tic/apm/objectpool/impl/ThreadLocalObjectPool.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...java/co/elastic/apm/objectpool/NoopObjectPool.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...lastic/apm/objectpool/impl/AbstractObjectPool.java 56.25% <100%> (ø) 3 <0> (ø) ⬇️
.../java/co/elastic/apm/objectpool/impl/Resetter.java 100% <100%> (ø) 0 <0> (?)
...ain/java/co/elastic/apm/impl/ElasticApmTracer.java 77.21% <100%> (ø) 43 <0> (ø) ⬇️
...lastic/apm/report/serialize/DslJsonSerializer.java 81.58% <14.28%> (-0.9%) 108 <0> (ø)
.../main/java/co/elastic/apm/impl/transaction/Db.java 59.45% <30.76%> (-15.55%) 12 <0> (ø)
...stic/apm/objectpool/impl/QueueBasedObjectPool.java 39.39% <83.33%> (+6.06%) 8 <5> (+2) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 32a3642...5c2d8aa. Read the comment docs.


@VisibleForAdvice
public class ESRestClientInstrumentationHelper {
public class IOUtils {
Copy link
Contributor

Choose a reason for hiding this comment

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

Great solution, thanks!

@felixbarny felixbarny merged commit 6f6f609 into elastic:master Nov 4, 2018
@felixbarny felixbarny deleted the es-statement-allocation-free branch November 4, 2018 14:53
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.

3 participants