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

introduce /druid/v3 query endpoint that gives query responseContext #3319

Closed
wants to merge 1 commit into from

Conversation

himanshug
Copy link
Contributor

@himanshug himanshug commented Aug 3, 2016

…in response json instead of HTTP header ("X-Druid-Response-Context")

this is primarily required to handle concerns regarding limits to the size of HTTP headers [in jetty and other places]. Currently we have a hack in place to always truncate context ( #2331 ) which makes responseContext somewhat unusable on the client side.

so, to ensure backward compatibility, this PR introduces a new query endpoint "/druid/v3" that has following response format...

{
"result": [ result1, result2,..... ],
"context": { "k1": < value > , .... }
}

Note that backward compatibility can also be achieved by utilizing a new value for HTTP "Accept" header instead of a new endpoint. But, chose new endpoint for "simplicity" (or at least thought it was simpler). I am willing to switch to that if others believe that is better than a new endpoint.

);

os.flush(); // Some types of OutputStream suppress flush errors in the .close() method.
os.close();
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be in a try with resources block to guarantee it is closed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, copy/pasta from base class code... not sure what happens if the close is not called in an exception situation. will put additional try-catch in both classes .... or may be refactor a bit more so that this part is also re-used.

only thing different in this class really is not dumping context header and passing it to jsonWriter instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@drcrallen updated with a try-finally

@@ -102,6 +101,7 @@ public void configure(Binder binder)

binder.bind(JettyServerInitializer.class).to(QueryJettyServerInitializer.class).in(LazySingleton.class);
Jerseys.addResource(binder, QueryResource.class);
Jerseys.addResource(binder, QueryResourceV3.class);
Copy link
Member

Choose a reason for hiding this comment

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

I believe this needs to be registered for router, historical, RT Index task and RT Nodes as well ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nishantmonu51 this PR is for only enabling the endpoint on broker.

full historical and realtime node support is being added in #3323

i have to admit that I had forgotten about the router, adding router in #3323 as well. (i guess router will be simpler than historical/realtime because router does not deserialize the response and just a pass through )

* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* /
Copy link
Contributor

Choose a reason for hiding this comment

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

license looks weird, can you re-apply?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated, not sure why my IDE license header got messed up.... it seems i need to re-apply in other PRs as well :(

@xvrl
Copy link
Member

xvrl commented Aug 8, 2016

@himanshug since we're updating the API, I wonder if it would make sense to define whether we always return the results before context. This would allow us to stream results back, as well as include some query stats (or other data that we only know after the fact) as part of the context.

try {
QueryResourceV3.serializeResponseToOS(
TestHelper.getObjectMapper().writer(),
new ByteArrayOutputStream(),
Copy link
Contributor

Choose a reason for hiding this comment

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

The thing I was concerned about was if the serializing fails before Jackson gets to the Yielder. This test wouldn't verify that (although it does verify a separate equally important thing).

Could you also do a test where the Yielder is just a normal Yielder (perhaps from a ResourceClosingSequence), but the output stream fails on all calls to write? I think that'd be enough to smoke out the case I'm thinking of.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added another test to verify OutputStream failure, yielder is closed as expected.

@himanshug himanshug force-pushed the context_in_resp branch 2 times, most recently from 2b8a8c0 to 9637a6d Compare August 9, 2016 19:58
@himanshug
Copy link
Contributor Author

@xvrl we discussed the ordering or result and context in #3319 (diff)
updated the querying documentation with information about new endpoint. I am marking it experimental for now so as to be able to change things in near future if a problem is discovered with the response format proposed here.

@himanshug himanshug modified the milestones: 0.9.3, 0.9.2 Aug 11, 2016
@himanshug
Copy link
Contributor Author

moved to 0.9.3 to unblock 0.9.2

@fjy
Copy link
Contributor

fjy commented Nov 8, 2016

@himanshug there's some merge conflicts

@himanshug
Copy link
Contributor Author

after some more thought on this recently, I'm planning to have both pre and post context, and, make the response format be...

{
"pre-context" : { "k": < value > , .... }
"result": [ result1, result2,..... ],
"post-context": { "k1": < value > , .... }
}

that can enable the cases where broker sends a query to some historical which does not have all the segments that broker thought it has (due to zookeeper+curator weirdness e.g.). in those cases, query fails currently.
we could envision a change where historical could quickly stream a pre-context with the list of segments it does not have and broker could try other historicals for those segments... in the end query would not have to fail.

@stale
Copy link

stale bot commented Feb 28, 2019

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@druid.apache.org list. Thank you for your contributions.

@stale stale bot added the stale label Feb 28, 2019
@stale
Copy link

stale bot commented Mar 7, 2019

This pull request has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@stale stale bot closed this Mar 7, 2019
seoeun25 pushed a commit to seoeun25/incubator-druid that referenced this pull request Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants