Example usage for org.apache.solr.update.processor UpdateRequestProcessor processCommit

List of usage examples for org.apache.solr.update.processor UpdateRequestProcessor processCommit

Introduction

In this page you can find the example usage for org.apache.solr.update.processor UpdateRequestProcessor processCommit.

Prototype

public void processCommit(CommitUpdateCommand cmd) throws IOException 

Source Link

Usage

From source file:de.qaware.chronix.solr.ingestion.AbstractIngestionHandler.java

License:Apache License

@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    formatResponseAsJson(req);/*from   ww w  . j  a va  2  s  . com*/

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

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

    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);
        }

        LOGGER.debug("Committing transaction...");
        processor.processCommit(new CommitUpdateCommand(req, false));
        LOGGER.debug("Committed transaction");
    } finally {
        processor.finish();
    }
}

From source file:de.qaware.chronix.solr.retention.ChronixRetentionHandler.java

License:Apache License

/**
 * Triggers a commit to make the deletion visible on the index
 *
 * @param processor - the update processor do process deletions
 * @param req       - the solr query request information
 * @throws Exception//from www. j  av a 2 s .  c o m
 */
private void commitDeletions(UpdateRequestProcessor processor, SolrQueryRequest req) throws IOException {
    CommitUpdateCommand commit = new CommitUpdateCommand(req, optimizeAfterDeletion);
    commit.softCommit = softCommit;
    processor.processCommit(commit);
}

From source file:org.alfresco.solr.SolrInformationServer.java

License:Open Source License

@Override
public void commit() throws IOException {
    // avoid multiple commits and warming searchers
    commitAndRollbackLock.writeLock().lock();
    try {//from   w ww  .  ja  v  a 2  s.c  om
        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();
    }
}

From source file:org.alfresco.solr.SolrInformationServer.java

License:Open Source License

@Override
public void hardCommit() throws IOException {
    // avoid multiple commits and warming searchers
    commitAndRollbackLock.writeLock().lock();
    try {/*w w  w  . jav  a 2s  . c om*/
        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();
    }
}

From source file:org.alfresco.solr.SolrInformationServer.java

License:Open Source License

@Override
public boolean commit(boolean openSearcher) throws IOException {
    canUpdate();/*  w  w w . j a  v a2s.co  m*/
    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 {
                if (active != null) {
                    active.decref();
                }

                if (newest != null) {
                    newest.decref();
                }
            }
        }
        processor.processCommit(command);
    } finally {
        if (processor != null) {
            processor.finish();
        }
    }

    return searcherOpened;
}