Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Variable size ByteBuffer implementation #99

Closed
wants to merge 3 commits into from
Closed

Variable size ByteBuffer implementation #99

wants to merge 3 commits into from

Conversation

gkumar7
Copy link

@gkumar7 gkumar7 commented Feb 16, 2017

This patch includes an implementation of a variable-size BinaryHolder to abstract away size calculation for a ByteBuffer. The BinaryHolder is flexible enough to be used as a replacement for the Binary format. For more information, see #95.

@bensigelman, @yurishkuro, @wu-sheng, @mabn, @michaelsembwever could you please review?

@gkumar7 gkumar7 changed the title Variable size ByteBuffer implementation (Implementation of #95) Variable size ByteBuffer implementation Feb 16, 2017
@bhs
Copy link
Contributor

bhs commented Mar 9, 2017

@gkumar7 sorry for the insane delay, I am looking at pending issues/PRs briefly. This branch has a merge conflict right now which is problematic... can you address?

@gkumar7
Copy link
Author

gkumar7 commented Mar 9, 2017

@bhs Thanks for the response! Seems like there were a few conflicting changes while this review was out, fixed now.

Copy link
Contributor

@bhs bhs left a comment

Choose a reason for hiding this comment

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

@yurishkuro WDYT?

@@ -79,6 +79,16 @@ private Builtin(String name) {
public final static Format<ByteBuffer> BINARY = new Builtin<ByteBuffer>("BINARY");

/**
* The BINARY_HOLDER format allows for variable binary encoding of SpanContext state for Tracer.inject and
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "... variable-length binary ..."


/**
* If no initial ByteBuffer was allocated for the BinaryHolder, the payload becomes the wrapped ByteBuffer.
* Otherwise, the payload is placed in existent ByteBuffer.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "existing"

*
* @param payload a ByteBuffer.
*/
public void addPayload(ByteBuffer payload) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why addPayload and getCarrier? shouldn't the names be symmetric?

Copy link
Author

Choose a reason for hiding this comment

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

Good point, fixed.

@yurishkuro
Copy link
Member

@bhs I don't have strong feeling about it. I never particularly liked the ByteBuffer-based API, I would rather use java.io streams.

@gkumar7
Copy link
Author

gkumar7 commented Mar 17, 2017

java.io.streams would be an interesting approach, although a bit tricky as there are both input and output streams. I do not think one Format specification will be able to handle both cases

@yurishkuro
Copy link
Member

bit tricky as there are both input and output streams. I do not think one Format specification will be able to handle both cases

@gkumar7 that's why my original proposal for Format was not Format<C> but Format<R, W>, but it was shot down as "confusing" ¯_(ツ)_/¯

@gkumar7
Copy link
Author

gkumar7 commented Mar 17, 2017

Ah, that makes sense. @bhs could we merge these changes for now so people have a workaround to the ByteBuffer format and then we can discuss more about the Format specification in a separate issue?

@yurishkuro
Copy link
Member

could we merge these changes for now

@gkumar7 I'd want to be careful, because merging this has implications, it becomes a requirement for all existing tracers to support this new carrier.

@gkumar7
Copy link
Author

gkumar7 commented Mar 22, 2017

Yes, very true, but I would argue that tracers should support a BinaryHolder to provide users of the library an alternative to the fundamental limitation of a ByteBuffer.

The ByteBuffer format is there, but many java tracing libraries do not formally provide an example usage. Anyone using the ByteBuffer will hit a roadblock when having to specify the size of the ByteBuffer before serialization occurs.

@bhs
Copy link
Contributor

bhs commented Apr 1, 2017

@gkumar7 FYI, I have been thinking about this some more, apologies for the insanely high latency.

I would like to merge this change, but not until we're close to cutting a new major release for OT-Java... maybe we can get rid of the other binary format altogether at that point (since we're introducing breaking changes anyway).

I created a milestone for a 1.0 release, btw: https://github.com/opentracing/opentracing-java/milestone/1

@gkumar7
Copy link
Author

gkumar7 commented Apr 2, 2017

@bhs Sounds good, I will keep this pr open until then. Thanks!

@tedsuo
Copy link
Member

tedsuo commented Nov 9, 2017

@gkumar7 @yurishkuro I propose this change should get rolled into 0.31. We'll need to update this PR to point at the opentracing:v0.31.0 branch.

I'm wondering if anyone supports the current BINARY carrier type in java, and whether we can change that type rather than add BINARY_HOLDER.

@gkumar7
Copy link
Author

gkumar7 commented Nov 16, 2017

+1 to update BINARY type, our team has not been using it.

@malafeev
Copy link

+1
I need it to implement cassandra server side tracing. Payload is sent using ByteBuffer there.


@Test
public void testBinaryHolderWithSufficientCapacity() {
System.out.println("binary holder with sufficient capacity");
Copy link
Collaborator

Choose a reason for hiding this comment

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

When/if we get this PR merged, we should get rid of these println lines ;)

Copy link
Author

@gkumar7 gkumar7 Dec 1, 2017

Choose a reason for hiding this comment

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

As you might have noticed this pull request was hanging around for about 9 months. The opentracing-java code has changed quite a bit since then. Initially, the structure of the test code in opentracing-impl (this module has been removed) had test classes with a println at the beginning of each method. Even I was not sure of the reason for this, but included similar lines in this pull request to remain consistent with the rest of the codebase.

@carlosalberto
Copy link
Collaborator

So my impression, after going through the comments and #95, is that people need some kind of binary format now. So what about:

  • Removing/deprecating the current BINARY format.
  • Adding this BinaryHolder format?
  • Later, as/when needed, add a BINARY_STREAM format?

That way, we could have people use their code using the required binary format, and later on offer to a stream-based binary format.

Opinions?

@yurishkuro
Copy link
Member

@carlosalberto I'm not seeing the benefits of such approach, it just creates an API churn. The holder class is already new/breaking API, why not just define an equivalent of Go's io.Reader/io.Writer now and make it the only BINARY format? Those are very small interfaces. The holder class can be an adapter for them.

@tedsuo
Copy link
Member

tedsuo commented Nov 29, 2017

I agree, let's go with a streaming BINARY format. Since this will be a breaking change, let's get it in on v31.

@carlosalberto
Copy link
Collaborator

@gkumar7 @malafeev Hey, would you mind jumping into the discussion/review of #223 ? You may be interested as that's an effort to support BINARY through a stream-friendly interface (the PR itself inspired in this one ;) )

@malafeev
Copy link

malafeev commented Dec 1, 2017

@carlosalberto I added comment to #223 .
Without seeing how it would work in MockTracer inject/extract it's hard to say.

@gkumar7
Copy link
Author

gkumar7 commented Dec 1, 2017

@carlosalberto, thanks for creating a new pull request (although it would have been nice to make changes to the existing one). Regardless, I would agree with @malafeev that some example usage would be helpful.

@gkumar7
Copy link
Author

gkumar7 commented Dec 6, 2017

Closing as #223 is merged.

@gkumar7 gkumar7 closed this Dec 6, 2017
@gkumar7 gkumar7 deleted the variable-byte-buffer-holder branch December 6, 2017 19:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants