Java Code Examples for org.apache.solr.update.processor.UpdateRequestProcessor#finish()

The following examples show how to use org.apache.solr.update.processor.UpdateRequestProcessor#finish() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileFloatSource.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp)
    throws Exception {
  FileFloatSource.resetCache();
  log.debug("readerCache has been reset.");

  UpdateRequestProcessor processor = req.getCore().getUpdateProcessingChain(null).createProcessor(req, rsp);
  try {
    RequestHandlerUtils.handleCommit(req, processor, req.getParams(), true);
  } finally {
    try {
      processor.finish();
    } finally {
      processor.close();
    }
  }
}
 
Example 2
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void deleteByQuery(String query) throws IOException
{
    UpdateRequestProcessor processor = null;
    try (SolrQueryRequest request = newSolrQueryRequest())
    {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());
        DeleteUpdateCommand delDocCmd = new DeleteUpdateCommand(request);
        delDocCmd.setQuery(query);
        processor.processDelete(delDocCmd);
    }
    finally
    {
        if (processor != null)
        {
            processor.finish();
        }
    }
}
 
Example 3
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void capIndex(long dbid) throws IOException
{
    UpdateRequestProcessor processor = null;
    try (SolrQueryRequest request = newSolrQueryRequest())
    {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());

        SolrInputDocument input = new SolrInputDocument();
        input.addField(FIELD_SOLR4_ID, INDEX_CAP_ID);
        input.addField(FIELD_VERSION, 0);
        input.addField(FIELD_DBID, -dbid); //Making this negative to ensure it is never confused with node DBID
        input.addField(FIELD_DOC_TYPE, DOC_TYPE_STATE);

        AddUpdateCommand cmd = new AddUpdateCommand(request);
        cmd.overwrite = true;
        cmd.solrDoc = input;
        processor.processAdd(cmd);
    }
    finally
    {
        if (processor != null) processor.finish();
    }
}
 
Example 4
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void updateTransaction(Transaction txn) throws IOException
{
    canUpdate();
    UpdateRequestProcessor processor = null;
    try (SolrQueryRequest request = newSolrQueryRequest())
    {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());

        AddUpdateCommand cmd = new AddUpdateCommand(request);
        cmd.overwrite = true;
        SolrInputDocument input = new SolrInputDocument();
        input.addField(FIELD_SOLR4_ID, AlfrescoSolrDataModel.getTransactionDocumentId(txn.getId()));
        input.addField(FIELD_VERSION, 1);
        input.addField(FIELD_TXID, txn.getId());
        input.addField(FIELD_INTXID, txn.getId());
        input.addField(FIELD_TXCOMMITTIME, txn.getCommitTimeMs());
        input.addField(FIELD_DOC_TYPE, DOC_TYPE_TX);
        if (cascadeTrackingEnabled())
        {
            input.addField(FIELD_CASCADE_FLAG, 0);
        }
        cmd.solrDoc = input;
        processor.processAdd(cmd);
    }
    finally
    {
        if (processor != null)
        {
            processor.finish();
        }
    }
}
 
Example 5
Source File: AbstractIngestionHandler.java    From chronix.server with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    formatResponseAsJson(req);

    if (req.getContentStreams() == null) {
        LOGGER.warn("no content stream");
        rsp.add("error", "No content stream");
        return;
    }

    boolean commit = Boolean.parseBoolean(req.getParams().get("commit", "true"));

    InputStream stream = req.getContentStreams().iterator().next().getStream();
    stream = detectGzip(stream);

    MetricTimeSeriesConverter converter = new MetricTimeSeriesConverter();

    UpdateRequestProcessorChain processorChain = req.getCore().getUpdateProcessorChain(req.getParams());
    UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp);
    try {
        for (MetricTimeSeries series : formatParser.parse(stream)) {
            SolrInputDocument document = new SolrInputDocument();
            converter.to(series).getFields().forEach(document::addField);
            storeDocument(document, processor, req);
        }

        if (commit) {
            LOGGER.debug("Committing transaction...");
            processor.processCommit(new CommitUpdateCommand(req, false));
            LOGGER.debug("Committed transaction");
        } else {
            LOGGER.debug("Only adding documents.");
        }
    } finally {
        processor.finish();
    }
}
 
Example 6
Source File: ContentStreamHandlerBase.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
  SolrParams params = req.getParams();
  UpdateRequestProcessorChain processorChain =
      req.getCore().getUpdateProcessorChain(params);

  UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp);

  try {
    ContentStreamLoader documentLoader = newLoader(req, processor);


    Iterable<ContentStream> streams = req.getContentStreams();
    if (streams == null) {
      if (!RequestHandlerUtils.handleCommit(req, processor, params, false) && !RequestHandlerUtils.handleRollback(req, processor, params, false)) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "missing content stream");
      }
    } else {

      for (ContentStream stream : streams) {
        documentLoader.load(req, rsp, stream, processor);
      }

      // Perhaps commit from the parameters
      RequestHandlerUtils.handleCommit(req, processor, params, false);
      RequestHandlerUtils.handleRollback(req, processor, params, false);
    }
  } finally {
    // finish the request
    try {
      processor.finish();
    } finally {
      processor.close();
    }
  }
}
 
Example 7
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void rollback() throws IOException
{
    commitAndRollbackLock.writeLock().lock();
    try
    {
        activeTrackerThreadsLock.writeLock().lock();
        try
        {
            activeTrackerThreads.clear();

            UpdateRequestProcessor processor = null;
            try (SolrQueryRequest request = newSolrQueryRequest())
            {
                processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());
                processor.processRollback(new RollbackUpdateCommand(request));
            }
            finally
            {
                if (processor != null)
                {
                    processor.finish();
                }
            }
        }
        finally
        {
            activeTrackerThreadsLock.writeLock().unlock();
        }
    }
    finally
    {
        commitAndRollbackLock.writeLock().unlock();
    }
}
 
Example 8
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Index information of a node that does not belong to the current shard.
 * These information are necessary for cascade tracker to work properly.
 * The information stored are:
 *      nodeDocumentId, cascadeTx
 */
private void indexNonShardCascade(NodeMetaData nodeMetaData) throws IOException
{

    UpdateRequestProcessor processor = null;
    try (SolrQueryRequest request = newSolrQueryRequest())
    {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());
        StringPropertyValue stringPropertyValue = (StringPropertyValue) nodeMetaData.getProperties().get(ContentModel.PROP_CASCADE_TX);
        List<FieldInstance> fieldInstances = AlfrescoSolrDataModel.getInstance().getIndexedFieldNamesForProperty(ContentModel.PROP_CASCADE_TX).getFields();
        FieldInstance fieldInstance = fieldInstances.get(0);
        AddUpdateCommand cmd = new AddUpdateCommand(request);
        SolrInputDocument input = new SolrInputDocument();
        input.addField(FIELD_SOLR4_ID, AlfrescoSolrDataModel.getNodeDocumentId(nodeMetaData.getTenantDomain(), nodeMetaData.getId()));
        input.addField(FIELD_VERSION, 0);
        input.addField(fieldInstance.getField(), stringPropertyValue.getValue());
        cmd.solrDoc = input;
        processor.processAdd(cmd);

    }
    finally
    {
        if (processor != null)
        {
            processor.finish();
        }
    }
}
 
Example 9
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void commit() throws IOException
{
    // avoid multiple commits and warming searchers
    commitAndRollbackLock.writeLock().lock();
    try
    {
        canUpdate();
        UpdateRequestProcessor processor = null;
        try (SolrQueryRequest request = newSolrQueryRequest())
        {
            processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());
            processor.processCommit(new CommitUpdateCommand(request, false));
        }
        finally
        {
            if (processor != null)
            {
                processor.finish();
            }
        }
    }
    finally
    {
        commitAndRollbackLock.writeLock().unlock();
    }
}
 
Example 10
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void cascadeNodes(List<NodeMetaData> nodeMetaDatas, boolean overwrite) throws IOException, JSONException
{
    UpdateRequestProcessor processor = null;
    try (SolrQueryRequest request = newSolrQueryRequest())
    {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());
        for (NodeMetaData nodeMetaData : nodeMetaDatas)
        {
            if (mayHaveChildren(nodeMetaData))
            {
                cascadeUpdateV2(nodeMetaData, overwrite, request, processor);
            }
        }
    }
    catch (Exception exception)
    {
        LOGGER.error("Exception while processing cascading updates from the parent nodes. " +
                "See the stacktrace below for further details.",
                exception);
    }
    finally
    {
        if (processor != null)
        {
            processor.finish();
        }
    }
}
 
Example 11
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void indexAclTransaction(AclChangeSet changeSet, boolean overwrite) throws IOException
{
    canUpdate();
    UpdateRequestProcessor processor = null;
    try (SolrQueryRequest request = newSolrQueryRequest())
    {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());

        SolrInputDocument aclTx = new SolrInputDocument();
        aclTx.addField(FIELD_SOLR4_ID, getAclChangeSetDocumentId(changeSet.getId()));
        aclTx.addField(FIELD_VERSION, "0");
        aclTx.addField(FIELD_ACLTXID, changeSet.getId());
        aclTx.addField(FIELD_INACLTXID, changeSet.getId());
        aclTx.addField(FIELD_ACLTXCOMMITTIME, changeSet.getCommitTimeMs());
        aclTx.addField(FIELD_DOC_TYPE, DOC_TYPE_ACL_TX);

        AddUpdateCommand cmd = new AddUpdateCommand(request);
        cmd.overwrite = overwrite;
        cmd.solrDoc = aclTx;
        processor.processAdd(cmd);

        putAclTransactionState(processor, request, changeSet);
    }
    finally
    {
        if (processor != null) processor.finish();
    }
}
 
Example 12
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void hardCommit() throws IOException
{
    // avoid multiple commits and warming searchers
    commitAndRollbackLock.writeLock().lock();
    try
    {
        UpdateRequestProcessor processor = null;
        try (SolrQueryRequest request = newSolrQueryRequest())
        {
            processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());
            CommitUpdateCommand commitUpdateCommand = new CommitUpdateCommand(request, false);
            commitUpdateCommand.openSearcher = false;
            commitUpdateCommand.softCommit = false;
            commitUpdateCommand.waitSearcher = false;
            processor.processCommit(commitUpdateCommand);
        }
        finally
        {
            if (processor != null)
            {
                processor.finish();
            }
        }
    }
    finally
    {
        commitAndRollbackLock.writeLock().unlock();
    }
}
 
Example 13
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void indexTransaction(Transaction info, boolean overwrite) throws IOException
{
    canUpdate();
    UpdateRequestProcessor processor = null;
    try (SolrQueryRequest request = newSolrQueryRequest())
    {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());

        AddUpdateCommand cmd = new AddUpdateCommand(request);
        cmd.overwrite = overwrite;
        SolrInputDocument input = new SolrInputDocument();
        input.addField(FIELD_SOLR4_ID, AlfrescoSolrDataModel.getTransactionDocumentId(info.getId()));
        input.addField(FIELD_VERSION, 0);
        input.addField(FIELD_TXID, info.getId());
        input.addField(FIELD_INTXID, info.getId());
        input.addField(FIELD_TXCOMMITTIME, info.getCommitTimeMs());
        input.addField(FIELD_DOC_TYPE, DOC_TYPE_TX);

        /*
            For backwards compat reasons adding 3 new stored fields. 2 of these fields are duplicate data but there are needed so that
            we can properly update the transaction record for ACE-4284.
        */
        //This fields will be used to update the transaction record
        //They will only be on the record until the cascading updates for this transaction are processed
        input.addField(FIELD_S_TXID, info.getId());
        input.addField(FIELD_S_TXCOMMITTIME, info.getCommitTimeMs());

        if (cascadeTrackingEnabled())
        {
            //Set the cascade flag to 1. This means cascading updates have not been done yet.
            input.addField(FIELD_CASCADE_FLAG, 1);
        }

        cmd.solrDoc = input;
        processor.processAdd(cmd);

        putTransactionState(processor, request, info);
    }
    finally
    {
        if (processor != null)
        {
            processor.finish();
        }
    }
}
 
Example 14
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void updateContent(TenantDbId docRef) throws Exception
{
    LOGGER.debug("Text content of Document DBID={} is going to be updated.", docRef.dbId);

    UpdateRequestProcessor processor = null;
    try (SolrQueryRequest request = newSolrQueryRequest())
    {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());

        SolrInputDocument doc = new PartialSolrInputDocument();
        doc.removeField(FIELD_DBID);
        doc.addField(FIELD_DBID, docRef.dbId);
        doc.setField(FIELD_SOLR4_ID,
                AlfrescoSolrDataModel.getNodeDocumentId(
                        docRef.tenant,
                        docRef.dbId));

        if (docRef.optionalBag.containsKey(CONTENT_LOCALE_FIELD))
        {
            addContentToDoc(docRef, doc, docRef.dbId);
        }

        LOGGER.debug("Text content of Document DBID={} has been updated (not yet indexed)", docRef.dbId);

        final Long latestAppliedVersionId =
                    ofNullable(docRef.optionalBag.get(LATEST_APPLIED_CONTENT_VERSION_ID))
                            .map(String.class::cast)
                            .map(Long::parseLong)
                            .orElse(CONTENT_UPDATED_MARKER);

        markAsContentInSynch(doc, latestAppliedVersionId);

        // Add to index
        AddUpdateCommand addDocCmd = new AddUpdateCommand(request);
        addDocCmd.overwrite = true;
        addDocCmd.solrDoc = doc;

        processor.processAdd(addDocCmd);

        LOGGER.debug(
                "Text content of Document DBID={} has been marked as updated (latest content version ID = {})",
                docRef.dbId,
                (latestAppliedVersionId == CONTENT_UPDATED_MARKER ? "N.A." : latestAppliedVersionId));
    }
    catch (Exception exception)
    {
        LOGGER.error("Unable to update the text content of node {}. See the stacktrace below for further details.", docRef.dbId, exception);
    }
    finally
    {
        if(processor != null) {processor.finish();}
    }
}
 
Example 15
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public long indexAcl(List<AclReaders> aclReaderList, boolean overwrite) throws IOException
{
    long start = System.nanoTime();

    UpdateRequestProcessor processor = null;
    try (SolrQueryRequest request = newSolrQueryRequest())
    {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());
        for (AclReaders aclReaders : notNullOrEmpty(aclReaderList))
        {
            SolrInputDocument acl = new SolrInputDocument();

            acl.addField(FIELD_SOLR4_ID, getAclDocumentId(aclReaders.getTenantDomain(), aclReaders.getId()));
            acl.addField(FIELD_VERSION, "0");
            acl.addField(FIELD_ACLID, aclReaders.getId());
            acl.addField(FIELD_INACLTXID, aclReaders.getAclChangeSetId());

            String tenant = aclReaders.getTenantDomain();
            for (String reader : notNullOrEmpty(aclReaders.getReaders()))
            {
                reader = addTenantToAuthority(reader, tenant);
                acl.addField(FIELD_READER, reader);
            }

            for (String denied : aclReaders.getDenied())
            {
                denied = addTenantToAuthority(denied, tenant);
                acl.addField(FIELD_DENIED, denied);
            }
            acl.addField(FIELD_DOC_TYPE, DOC_TYPE_ACL);

            AddUpdateCommand cmd = new AddUpdateCommand(request);
            cmd.overwrite = overwrite;
            cmd.solrDoc = acl;
            processor.processAdd(cmd);
        }
    }
    finally
    {
        if (processor != null) processor.finish();
    }

    return (System.nanoTime() - start);
}
 
Example 16
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean commit(boolean openSearcher) throws IOException
{
    canUpdate();

    UpdateRequestProcessor processor = null;
    boolean searcherOpened = false;
    try (SolrQueryRequest request = newSolrQueryRequest())
    {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());
        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
            {
                ofNullable(active).ifPresent(RefCounted::decref);
                ofNullable(newest).ifPresent(RefCounted::decref);
            }
        }
        processor.processCommit(command);
    }
    finally
    {
        if (processor != null)
        {
            processor.finish();
        }
    }

    return searcherOpened;
}
 
Example 17
Source File: TestSearchPerf.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
void createIndex2(int nDocs, String... fields) throws IOException {
  Set<String> fieldSet = new HashSet<>(Arrays.asList(fields));

  SolrQueryRequest req = lrf.makeRequest();
  SolrQueryResponse rsp = new SolrQueryResponse();
  UpdateRequestProcessorChain processorChain = req.getCore().getUpdateProcessingChain(null);
  UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp);

  boolean foomany_s = fieldSet.contains("foomany_s");
  boolean foo1_s = fieldSet.contains("foo1_s");
  boolean foo2_s = fieldSet.contains("foo2_s");
  boolean foo4_s = fieldSet.contains("foo4_s");
  boolean foo8_s = fieldSet.contains("foo8_s");
  boolean t10_100_ws = fieldSet.contains("t10_100_ws");

  
  for (int i=0; i<nDocs; i++) {
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id",Float.toString(i));
    if (foomany_s) {
      doc.addField("foomany_s",t(r.nextInt(nDocs*10)));
    }
    if (foo1_s) {
      doc.addField("foo1_s",t(0));
    }
    if (foo2_s) {
      doc.addField("foo2_s",r.nextInt(2));
    }
    if (foo4_s) {
      doc.addField("foo4_s",r.nextInt(4));
    }
    if (foo8_s) {
      doc.addField("foo8_s",r.nextInt(8));
    }
    if (t10_100_ws) {
      StringBuilder sb = new StringBuilder(9*100);
      for (int j=0; j<100; j++) {
        sb.append(' ');
        sb.append(t(r.nextInt(10)));
      }
      doc.addField("t10_100_ws", sb.toString());
    }

    AddUpdateCommand cmd = new AddUpdateCommand(req);
    cmd.solrDoc = doc;
    processor.processAdd(cmd);
  }
  processor.finish();
  processor.close();
  req.close();

  assertU(commit());

  req = lrf.makeRequest();
  assertEquals(nDocs, req.getSearcher().maxDoc());
  req.close();
}