imply-cheddar commented on code in PR #13564:
URL: https://github.com/apache/druid/pull/13564#discussion_r1049541232
##########
server/src/main/java/org/apache/druid/server/QueryResource.java:
##########
@@ -565,4 +501,142 @@ public static void transferEntityTag(ResponseContext
context, Response.ResponseB
builder.header(HEADER_ETAG, entityTag);
}
}
+
+ private class QueryResourceQueryMetricCounter implements QueryMetricCounter
+ {
+ @Override
+ public void incrementSuccess()
+ {
+ successfulQueryCount.incrementAndGet();
+ }
+
+ @Override
+ public void incrementFailed()
+ {
+ failedQueryCount.incrementAndGet();
+ }
+
+ @Override
+ public void incrementInterrupted()
+ {
+ interruptedQueryCount.incrementAndGet();
+ }
+
+ @Override
+ public void incrementTimedOut()
+ {
+ timedOutQueryCount.incrementAndGet();
+ }
+ }
+
+ private class QueryResourceResultPusher extends ResultPusher
+ {
+ private final HttpServletRequest req;
+ private final QueryLifecycle queryLifecycle;
+ private final ResourceIOReaderWriter io;
+
+ public QueryResourceResultPusher(
+ HttpServletRequest req,
+ QueryLifecycle queryLifecycle,
+ ResourceIOReaderWriter io,
+ HttpServletResponse response
+ )
+ {
+ super(
+ response,
+ QueryResource.this.jsonMapper,
+ QueryResource.this.responseContextConfig,
+ QueryResource.this.selfNode,
+ QueryResource.this.counter,
+ queryLifecycle.getQueryId(),
+ MediaType.valueOf(io.getResponseWriter().getResponseType())
+ );
+ this.req = req;
+ this.queryLifecycle = queryLifecycle;
+ this.io = io;
+ }
+
+ @Override
+ public ResultsWriter start()
+ {
+ return new ResultsWriter()
+ {
+ @Override
+ public QueryResponse<Object> start(HttpServletResponse response)
+ {
+ final QueryResponse<Object> queryResponse = queryLifecycle.execute();
+ final ResponseContext responseContext =
queryResponse.getResponseContext();
+ final String prevEtag = getPreviousEtag(req);
+
+ if (prevEtag != null &&
prevEtag.equals(responseContext.getEntityTag())) {
+ queryLifecycle.emitLogsAndMetrics(null, req.getRemoteAddr(), -1);
+ counter.incrementSuccess();
+ response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+ return null;
+ }
+
+ return queryResponse;
+ }
+
+ @Override
+ public Writer makeWriter(OutputStream out) throws IOException
+ {
+ final ObjectWriter objectWriter = queryLifecycle.newOutputWriter(io);
+ final SequenceWriter sequenceWriter =
objectWriter.writeValuesAsArray(out);
+ return new Writer()
+ {
+
+ @Override
+ public void writeResponseStart()
+ {
+ // Do nothing
+ }
+
+ @Override
+ public void writeRow(Object obj) throws IOException
+ {
+ sequenceWriter.write(obj);
+ }
+
+ @Override
+ public void writeResponseEnd()
+ {
+ // Do nothing
+ }
+
+ @Override
+ public void close() throws IOException
+ {
+ sequenceWriter.close();
+ }
+ };
+ }
+
+ @Override
+ public void recordSuccess(long numBytes)
Review Comment:
Heh. At one point in the code I had all of the methods on the Writer as
abstract methods on either the `Pusher` or `Accumulator`. In fact, some of the
methods showed up twice on both the Pusher and the Accumulator. As I was
working with it, I realized I needed the lifecycle stuff to actually do the
writing correctly and so had to create a separate object for that. Then I had
these straggler methods sitting as abstracts on the classes and also an
interface that needed to be implemented and I was like, "I'd rather have just
one thing to implement" so I moved them all over to the Writer. We do still
have the `QueryMetricCounter` object so there's technically two things being
passed in, but I'm half expecting that the `QueryMetricCounter` will either
disappear entirely OR become a shared object between both QueryResource and
SqlResource (not adding to it for SQL queries makes it's value dubious...), so
I'm less bothered by that being its own thing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]