Search in sources :

Example 6 with CommitUpdateCommand

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;
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 7 with CommitUpdateCommand

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();
    }
}
Also used : UpdateRequestProcessorFactory(org.apache.solr.update.processor.UpdateRequestProcessorFactory) DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) UpdateCommand(org.apache.solr.update.UpdateCommand) UpdateRequestProcessorChain(org.apache.solr.update.processor.UpdateRequestProcessorChain) DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand)

Example 8 with CommitUpdateCommand

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;
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) UpdateRequestProcessor(org.apache.solr.update.processor.UpdateRequestProcessor) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher)

Example 9 with CommitUpdateCommand

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();
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) UpdateRequestProcessor(org.apache.solr.update.processor.UpdateRequestProcessor) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand)

Example 10 with CommitUpdateCommand

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;
}
Also used : SolrServletRequest(org.alfresco.solr.AbstractAlfrescoSolrTests.SolrServletRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand)

Aggregations

CommitUpdateCommand (org.apache.solr.update.CommitUpdateCommand)21 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)12 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)12 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)8 SolrException (org.apache.solr.common.SolrException)7 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)6 SolrCore (org.apache.solr.core.SolrCore)5 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)5 UpdateRequestProcessor (org.apache.solr.update.processor.UpdateRequestProcessor)4 Date (java.util.Date)3 SolrInputDocument (org.apache.solr.common.SolrInputDocument)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ExecutionException (java.util.concurrent.ExecutionException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 QName (org.alfresco.service.namespace.QName)2 SolrServletRequest (org.alfresco.solr.AbstractAlfrescoSolrTests.SolrServletRequest)2 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2