use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class ExportWriter method writeDocs.
protected void writeDocs(SolrQueryRequest req, IteratorWriter.ItemWriter writer, Sort sort) throws IOException {
//Write the data.
List<LeafReaderContext> leaves = req.getSearcher().getTopReaderContext().leaves();
SortDoc sortDoc = getSortDoc(req.getSearcher(), sort.getSort());
int count = 0;
int queueSize = 30000;
SortQueue queue = new SortQueue(queueSize, sortDoc);
SortDoc[] outDocs = new SortDoc[queueSize];
while (count < totalHits) {
//long begin = System.nanoTime();
queue.reset();
SortDoc top = queue.top();
for (int i = 0; i < leaves.size(); i++) {
sortDoc.setNextReader(leaves.get(i));
// cost is not useful here
DocIdSetIterator it = new BitSetIterator(sets[i], 0);
int docId = -1;
while ((docId = it.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
sortDoc.setValues(docId);
if (top.lessThan(sortDoc)) {
top.setValues(sortDoc);
top = queue.updateTop();
}
}
}
int outDocsIndex = -1;
for (int i = 0; i < queueSize; i++) {
SortDoc s = queue.pop();
if (s.docId > -1) {
outDocs[++outDocsIndex] = s;
}
}
//long end = System.nanoTime();
count += (outDocsIndex + 1);
try {
for (int i = outDocsIndex; i >= 0; --i) {
SortDoc s = outDocs[i];
writer.add((MapWriter) ew -> {
writeDoc(s, leaves, ew);
s.reset();
});
}
} catch (Throwable e) {
Throwable ex = e;
while (ex != null) {
String m = ex.getMessage();
if (m != null && m.contains("Broken pipe")) {
throw new IgnoreException();
}
ex = ex.getCause();
}
if (e instanceof IOException) {
throw ((IOException) e);
} else {
throw new IOException(e);
}
}
}
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class RestManager method getRestManager.
/**
* Locates the RestManager using ThreadLocal SolrRequestInfo.
*/
public static RestManager getRestManager(SolrRequestInfo solrRequestInfo) {
if (solrRequestInfo == null)
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "No SolrRequestInfo in this Thread!");
SolrQueryRequest req = solrRequestInfo.getReq();
RestManager restManager = (req != null) ? req.getCore().getRestManager() : null;
if (restManager == null)
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "No RestManager found!");
return restManager;
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class ReplicateFromLeader method startReplication.
/**
* Start a replication handler thread that will periodically pull indices from the shard leader
* @param switchTransactionLog if true, ReplicationHandler will rotate the transaction log once
* the replication is done
*/
public void startReplication(boolean switchTransactionLog) throws InterruptedException {
try (SolrCore core = cc.getCore(coreName)) {
if (core == null) {
if (cc.isShutDown()) {
return;
} else {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "SolrCore not found:" + coreName + " in " + cc.getLoadedCoreNames());
}
}
SolrConfig.UpdateHandlerInfo uinfo = core.getSolrConfig().getUpdateHandlerInfo();
String pollIntervalStr = "00:00:03";
if (uinfo.autoCommmitMaxTime != -1) {
pollIntervalStr = toPollIntervalStr(uinfo.autoCommmitMaxTime / 2);
} else if (uinfo.autoSoftCommmitMaxTime != -1) {
pollIntervalStr = toPollIntervalStr(uinfo.autoSoftCommmitMaxTime / 2);
}
LOG.info("Will start replication from leader with poll interval: {}", pollIntervalStr);
NamedList slaveConfig = new NamedList();
slaveConfig.add("fetchFromLeader", true);
slaveConfig.add("pollInterval", pollIntervalStr);
NamedList replicationConfig = new NamedList();
replicationConfig.add("slave", slaveConfig);
String lastCommitVersion = getCommitVersion(core);
if (lastCommitVersion != null) {
lastVersion = Long.parseLong(lastCommitVersion);
}
replicationProcess = new ReplicationHandler();
if (switchTransactionLog) {
replicationProcess.setPollListener((solrCore, pollSuccess) -> {
if (pollSuccess) {
String commitVersion = getCommitVersion(core);
if (commitVersion == null)
return;
if (Long.parseLong(commitVersion) == lastVersion)
return;
UpdateLog updateLog = solrCore.getUpdateHandler().getUpdateLog();
SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
CommitUpdateCommand cuc = new CommitUpdateCommand(req, false);
cuc.setVersion(Long.parseLong(commitVersion));
updateLog.copyOverOldUpdates(cuc);
lastVersion = Long.parseLong(commitVersion);
}
});
}
replicationProcess.init(replicationConfig);
replicationProcess.inform(core);
}
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class RecoveryStrategy method replay.
private final Future<RecoveryInfo> replay(SolrCore core) throws InterruptedException, ExecutionException {
if (testing_beforeReplayBufferingUpdates != null) {
testing_beforeReplayBufferingUpdates.run();
}
if (replicaType == Replica.Type.TLOG) {
// roll over all updates during buffering to new tlog, make RTG available
SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
core.getUpdateHandler().getUpdateLog().copyOverBufferingUpdates(new CommitUpdateCommand(req, false));
return null;
}
Future<RecoveryInfo> future = core.getUpdateHandler().getUpdateLog().applyBufferedUpdates();
if (future == null) {
// no replay needed\
LOG.info("No replay needed.");
} else {
LOG.info("Replaying buffered documents.");
// wait for replay
RecoveryInfo report = future.get();
if (report.failed) {
SolrException.log(LOG, "Replay failed");
throw new SolrException(ErrorCode.SERVER_ERROR, "Replay failed");
}
}
// solrcloud_debug
cloudDebugLog(core, "replayed");
return future;
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class DebugComponent method doDebugTrack.
private void doDebugTrack(ResponseBuilder rb) {
SolrQueryRequest req = rb.req;
String rid = req.getParams().get(CommonParams.REQUEST_ID);
if (rid == null || "".equals(rid)) {
rid = generateRid(rb);
ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
//add rid to the request so that shards see it
params.add(CommonParams.REQUEST_ID, rid);
req.setParams(params);
}
//to see it in the response
rb.addDebug(rid, "track", CommonParams.REQUEST_ID);
//to see it in the logs of the landing core
rb.rsp.addToLog(CommonParams.REQUEST_ID, rid);
}
Aggregations