Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
magibney committed Oct 4, 2024
1 parent c9dcfb0 commit 088bda0
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 33 deletions.
3 changes: 2 additions & 1 deletion solr/core/src/java/org/apache/solr/core/CoreContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public class CoreContainer {

final SolrCores solrCores;

private final ExecutorService storedFieldsExecutor = ExecutorUtil.newMDCAwareCachedThreadPool("storedFieldsExecutor");
private final ExecutorService storedFieldsExecutor =
ExecutorUtil.newMDCAwareCachedThreadPool("storedFieldsExecutor");

public void storedFieldsExecute(Callable<Void> callable) throws IOException {
Future<Void> future = storedFieldsExecutor.submit(callable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,24 @@ public void process(ResponseBuilder rb) throws IOException {

try {

req.getCoreContainer().storedFieldsExecute(() -> {
extracted(rb, reqIds, fieldType, params, searcherInfo, ulog, mustUseRealtimeSearcher, core, transformer, rsp, req, docList);
return null;
});
req.getCoreContainer()
.storedFieldsExecute(
() -> {
extracted(
rb,
reqIds,
fieldType,
params,
searcherInfo,
ulog,
mustUseRealtimeSearcher,
core,
transformer,
rsp,
req,
docList);
return null;
});

} finally {
searcherInfo.clear();
Expand All @@ -247,7 +261,20 @@ public void process(ResponseBuilder rb) throws IOException {
addDocListToResponse(rb, docList);
}

private static void extracted(ResponseBuilder rb, IdsRequested reqIds, FieldType fieldType, SolrParams params, SearcherInfo searcherInfo, UpdateLog ulog, boolean mustUseRealtimeSearcher, SolrCore core, DocTransformer transformer, SolrQueryResponse rsp, SolrQueryRequest req, SolrDocumentList docList) throws IOException {
private static void extracted(
ResponseBuilder rb,
IdsRequested reqIds,
FieldType fieldType,
SolrParams params,
SearcherInfo searcherInfo,
UpdateLog ulog,
boolean mustUseRealtimeSearcher,
SolrCore core,
DocTransformer transformer,
SolrQueryResponse rsp,
SolrQueryRequest req,
SolrDocumentList docList)
throws IOException {
// this is initialized & set on the context *after* any searcher (re-)opening
ResultContext resultContext = null;
boolean opennedRealtimeSearcher = false;
Expand Down Expand Up @@ -320,8 +347,7 @@ private static void extracted(ResponseBuilder rb, IdsRequested reqIds, FieldType
case UpdateLog.DELETE:
break;
default:
throw new SolrException(
ErrorCode.SERVER_ERROR, "Unknown Operation! " + oper);
throw new SolrException(ErrorCode.SERVER_ERROR, "Unknown Operation! " + oper);
}
if (o != null) continue;
}
Expand Down Expand Up @@ -363,8 +389,7 @@ private static void extracted(ResponseBuilder rb, IdsRequested reqIds, FieldType
searcherInfo.getSearcher().doc(docid, rsp.getReturnFields().getLuceneFieldNames());
SolrDocument doc = toSolrDoc(luceneDocument, core.getLatestSchema());
SolrDocumentFetcher docFetcher = searcherInfo.getSearcher().getDocFetcher();
docFetcher.decorateDocValueFields(
doc, docid, docFetcher.getNonStoredDVs(true), reuseDvIters);
docFetcher.decorateDocValueFields(doc, docid, docFetcher.getNonStoredDVs(true), reuseDvIters);
if (null != transformer) {
if (null == resultContext) {
// either first pass, or we've re-opened searcher - either way now we setContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,28 @@ public static void writeQueryResponse(
String contentType)
throws IOException {

solrRequest.getCoreContainer().storedFieldsExecute(() -> {
if (responseWriter instanceof JacksonJsonWriter) {
JacksonJsonWriter binWriter = (JacksonJsonWriter) responseWriter;
BufferedOutputStream bos = new BufferedOutputStream(new NonFlushingStream(outputStream));
binWriter.write(bos, solrRequest, solrResponse);
bos.flush();
} else if (responseWriter instanceof BinaryQueryResponseWriter) {
BinaryQueryResponseWriter binWriter = (BinaryQueryResponseWriter) responseWriter;
binWriter.write(outputStream, solrRequest, solrResponse);
} else {
OutputStream out = new NonFlushingStream(outputStream);
Writer writer = buildWriter(out, ContentStreamBase.getCharsetFromContentType(contentType));
responseWriter.write(writer, solrRequest, solrResponse);
writer.flush();
}
return null;
});
solrRequest
.getCoreContainer()
.storedFieldsExecute(
() -> {
if (responseWriter instanceof JacksonJsonWriter) {
JacksonJsonWriter binWriter = (JacksonJsonWriter) responseWriter;
BufferedOutputStream bos =
new BufferedOutputStream(new NonFlushingStream(outputStream));
binWriter.write(bos, solrRequest, solrResponse);
bos.flush();
} else if (responseWriter instanceof BinaryQueryResponseWriter) {
BinaryQueryResponseWriter binWriter = (BinaryQueryResponseWriter) responseWriter;
binWriter.write(outputStream, solrRequest, solrResponse);
} else {
OutputStream out = new NonFlushingStream(outputStream);
Writer writer =
buildWriter(out, ContentStreamBase.getCharsetFromContentType(contentType));
responseWriter.write(writer, solrRequest, solrResponse);
writer.flush();
}
return null;
});
}

private static Writer buildWriter(OutputStream outputStream, String charset)
Expand Down
14 changes: 8 additions & 6 deletions solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,14 @@ public static void optimizePreFetchDocs(
// get documents
DocIterator iter = docs.iterator();
Set<String> fieldFilterF = fieldFilter;
req.getCoreContainer().storedFieldsExecute(() -> {
for (int i = 0; i < docs.size(); i++) {
searcher.doc(iter.nextDoc(), fieldFilterF);
}
return null;
});
req.getCoreContainer()
.storedFieldsExecute(
() -> {
for (int i = 0; i < docs.size(); i++) {
searcher.doc(iter.nextDoc(), fieldFilterF);
}
return null;
});
}
}

Expand Down

0 comments on commit 088bda0

Please sign in to comment.