use of org.apache.solr.update.CommitUpdateCommand in project lucene-solr by apache.
the class IgnoreCommitOptimizeUpdateProcessorFactoryTest method processCommit.
SolrQueryResponse processCommit(final String chain, boolean optimize, Boolean commitEndPoint) throws IOException {
SolrCore core = h.getCore();
UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
assertNotNull("No Chain named: " + chain, pc);
SolrQueryResponse rsp = new SolrQueryResponse();
SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
if (commitEndPoint != null) {
((ModifiableSolrParams) req.getParams()).set(DistributedUpdateProcessor.COMMIT_END_POINT, commitEndPoint.booleanValue());
}
try {
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
CommitUpdateCommand cmd = new CommitUpdateCommand(req, false);
cmd.optimize = optimize;
UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
processor.processCommit(cmd);
} finally {
SolrRequestInfo.clearRequestInfo();
req.close();
}
return rsp;
}
use of org.apache.solr.update.CommitUpdateCommand in project lucene-solr by apache.
the class DocExpirationUpdateProcessorFactoryTest method testAutomaticDeletes.
public void testAutomaticDeletes() throws Exception {
// get a handle on our recorder
UpdateRequestProcessorChain chain = h.getCore().getUpdateProcessingChain("scheduled-delete");
assertNotNull(chain);
List<UpdateRequestProcessorFactory> factories = chain.getProcessors();
assertEquals("did number of processors configured in chain get changed?", 5, factories.size());
assertTrue("Expected [1] RecordingUpdateProcessorFactory: " + factories.get(1).getClass(), factories.get(1) instanceof RecordingUpdateProcessorFactory);
RecordingUpdateProcessorFactory recorder = (RecordingUpdateProcessorFactory) factories.get(1);
try {
recorder.startRecording();
// more then one iter to verify it's recurring
final int numItersToCheck = 1 + RANDOM_MULTIPLIER;
for (int i = 0; i < numItersToCheck; i++) {
UpdateCommand tmp;
// be generous in how long we wait, some jenkins machines are slooooow
tmp = recorder.commandQueue.poll(30, TimeUnit.SECONDS);
// we can be confident in the order because DocExpirationUpdateProcessorFactory
// uses the same request for both the delete & the commit -- and both
// RecordingUpdateProcessorFactory's getInstance & startRecording methods are
// synchronized. So it should not be possible to start recording in the
// middle of the two commands
assertTrue("expected DeleteUpdateCommand: " + tmp.getClass(), tmp instanceof DeleteUpdateCommand);
DeleteUpdateCommand delete = (DeleteUpdateCommand) tmp;
assertFalse(delete.isDeleteById());
assertNotNull(delete.getQuery());
assertTrue(delete.getQuery(), delete.getQuery().startsWith("{!cache=false}eXpField_tdt:[* TO "));
// commit should be immediately after the delete
tmp = recorder.commandQueue.poll(5, TimeUnit.SECONDS);
assertTrue("expected CommitUpdateCommand: " + tmp.getClass(), tmp instanceof CommitUpdateCommand);
CommitUpdateCommand commit = (CommitUpdateCommand) tmp;
assertTrue(commit.softCommit);
assertTrue(commit.openSearcher);
}
} finally {
recorder.stopRecording();
}
}
use of org.apache.solr.update.CommitUpdateCommand in project SearchServices by Alfresco.
the class SolrInformationServer method commit.
public boolean commit(boolean openSearcher) throws IOException {
canUpdate();
SolrQueryRequest request = null;
UpdateRequestProcessor processor = null;
boolean searcherOpened = false;
try {
request = getLocalSolrQueryRequest();
processor = this.core.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse());
CommitUpdateCommand command = new CommitUpdateCommand(request, false);
if (openSearcher) {
RefCounted<SolrIndexSearcher> active = null;
RefCounted<SolrIndexSearcher> newest = null;
try {
active = core.getSearcher();
newest = core.getNewestSearcher(false);
if (active.get() == newest.get()) {
searcherOpened = command.openSearcher = true;
command.waitSearcher = false;
} else {
searcherOpened = command.openSearcher = false;
}
} finally {
active.decref();
newest.decref();
}
}
processor.processCommit(command);
} finally {
if (processor != null) {
processor.finish();
}
if (request != null) {
request.close();
}
}
return searcherOpened;
}
use of org.apache.solr.update.CommitUpdateCommand in project SearchServices by Alfresco.
the class SolrInformationServer method hardCommit.
@Override
public void hardCommit() throws IOException {
// avoid multiple commits and warming searchers
commitAndRollbackLock.writeLock().lock();
try {
SolrQueryRequest request = null;
UpdateRequestProcessor processor = null;
try {
request = getLocalSolrQueryRequest();
processor = this.core.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse());
CommitUpdateCommand commitUpdateCommand = new CommitUpdateCommand(request, false);
commitUpdateCommand.openSearcher = false;
commitUpdateCommand.softCommit = false;
commitUpdateCommand.waitSearcher = false;
processor.processCommit(commitUpdateCommand);
} finally {
if (processor != null) {
processor.finish();
}
if (request != null) {
request.close();
}
}
} finally {
commitAndRollbackLock.writeLock().unlock();
}
}
use of org.apache.solr.update.CommitUpdateCommand in project SearchServices by Alfresco.
the class AlfrescoSolrUtils method addNode.
/**
* @param core
* @param dataModel
* @param txid
* @param dbid
* @param aclid
* @param type
* @param aspects
* @param properties
* @param content
* @param owner
* @param parentAssocs
* @param ancestors
* @param paths
* @param nodeRef
* @param commit
* @return
* @throws IOException
*/
public static NodeRef addNode(SolrCore core, AlfrescoSolrDataModel dataModel, int txid, int dbid, int aclid, QName type, QName[] aspects, Map<QName, PropertyValue> properties, Map<QName, String> content, String owner, ChildAssociationRef[] parentAssocs, NodeRef[] ancestors, String[] paths, NodeRef nodeRef, boolean commit) throws IOException {
SolrServletRequest solrQueryRequest = null;
try {
solrQueryRequest = new SolrServletRequest(core, null);
AddUpdateCommand addDocCmd = new AddUpdateCommand(solrQueryRequest);
addDocCmd.overwrite = true;
addDocCmd.solrDoc = createDocument(dataModel, new Long(txid), new Long(dbid), nodeRef, type, aspects, properties, content, new Long(aclid), paths, owner, parentAssocs, ancestors);
core.getUpdateHandler().addDoc(addDocCmd);
if (commit) {
core.getUpdateHandler().commit(new CommitUpdateCommand(solrQueryRequest, false));
}
} finally {
solrQueryRequest.close();
}
return nodeRef;
}
Aggregations