fix header so it passes the entire context

This commit is contained in:
jisookim0513 2014-06-19 14:38:11 -07:00
parent 35e080bbc1
commit 8e85097999
2 changed files with 21 additions and 14 deletions

View File

@ -54,6 +54,7 @@ import io.druid.query.QueryToolChest;
import io.druid.query.QueryToolChestWarehouse; import io.druid.query.QueryToolChestWarehouse;
import io.druid.query.QueryWatcher; import io.druid.query.QueryWatcher;
import io.druid.query.Result; import io.druid.query.Result;
import io.druid.query.RetryQueryRunner;
import io.druid.query.SegmentDescriptor; import io.druid.query.SegmentDescriptor;
import io.druid.query.aggregation.MetricManipulatorFns; import io.druid.query.aggregation.MetricManipulatorFns;
import org.jboss.netty.handler.codec.http.HttpChunk; import org.jboss.netty.handler.codec.http.HttpChunk;
@ -64,8 +65,8 @@ import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
@ -160,18 +161,24 @@ public class DirectDruidClient<T> implements QueryRunner<T>
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
byteCount += response.getContent().readableBytes(); byteCount += response.getContent().readableBytes();
if (!response.getHeader("Missing-Segments").equals("")) {
LinkedList missingSegments = new LinkedList(); List missingSegments = new ArrayList();
try { try {
missingSegments = objectMapper.readValue(response.getHeader("Missing-Segments"), LinkedList.class); Map<String, Object> headerContext = objectMapper.readValue(response.getHeader("Context"), Map.class);
for (int i = missingSegments.size(); i > 0; i--) { missingSegments = (List)headerContext.get(RetryQueryRunner.missingSegments);
missingSegments.add(objectMapper.convertValue(missingSegments.remove(0), SegmentDescriptor.class)); for (int i = missingSegments.size(); i > 0; i--) {
} missingSegments.add(
objectMapper.convertValue(
missingSegments.remove(0),
SegmentDescriptor.class
)
);
} }
catch (IOException e) {
}
((List) context.get("missingSegments")).addAll(missingSegments);
} }
catch (IOException e) {
e.printStackTrace();
}
((List) context.get("missingSegments")).addAll(missingSegments);
return super.handleResponse(response); return super.handleResponse(response);
} }

View File

@ -166,9 +166,9 @@ public class QueryResource
) )
) { ) {
String missingSegments = ""; String headerContext = "";
if (!((List)context.get("missingSegments")).isEmpty()) { if (!((List)context.get("missingSegments")).isEmpty()) {
missingSegments = jsonMapper.writeValueAsString(context.get("missingSegments")); headerContext = jsonMapper.writeValueAsString(context);
} }
long requestTime = System.currentTimeMillis() - start; long requestTime = System.currentTimeMillis() - start;
@ -213,7 +213,7 @@ public class QueryResource
isSmile ? APPLICATION_JSON : APPLICATION_SMILE isSmile ? APPLICATION_JSON : APPLICATION_SMILE
) )
.header("X-Druid-Query-Id", queryId) .header("X-Druid-Query-Id", queryId)
.header("Missing-Segments", missingSegments) .header("Context", headerContext)
.build(); .build();
} }
} }