Search in sources :

Example 1 with FastInputStream

use of org.apache.solr.common.util.FastInputStream in project lucene-solr by apache.

the class FSDataFastInputStream method lookup.

/* This method is thread safe */
@Override
public Object lookup(long pos) {
    // update the version map.  This is OK since the node won't be ACTIVE when this happens.
    if (pos < 0)
        return null;
    try {
        // make sure any unflushed buffer has been flushed
        ensureFlushed();
        FSDataFastInputStream dis = new FSDataFastInputStream(fs.open(tlogFile), pos);
        try {
            dis.seek(pos);
            LogCodec codec = new LogCodec(resolver);
            return codec.readVal(new FastInputStream(dis));
        } finally {
            dis.close();
        }
    } catch (IOException e) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "pos=" + pos, e);
    }
}
Also used : IOException(java.io.IOException) FastInputStream(org.apache.solr.common.util.FastInputStream) SolrException(org.apache.solr.common.SolrException)

Example 2 with FastInputStream

use of org.apache.solr.common.util.FastInputStream in project lucene-solr by apache.

the class JavabinLoader method parseAndLoadDocs.

private void parseAndLoadDocs(final SolrQueryRequest req, SolrQueryResponse rsp, InputStream stream, final UpdateRequestProcessor processor) throws IOException {
    UpdateRequest update = null;
    JavaBinUpdateRequestCodec.StreamingUpdateHandler handler = new JavaBinUpdateRequestCodec.StreamingUpdateHandler() {

        private AddUpdateCommand addCmd = null;

        @Override
        public void update(SolrInputDocument document, UpdateRequest updateRequest, Integer commitWithin, Boolean overwrite) {
            if (document == null) {
                // Perhaps commit from the parameters
                try {
                    RequestHandlerUtils.handleCommit(req, processor, updateRequest.getParams(), false);
                    RequestHandlerUtils.handleRollback(req, processor, updateRequest.getParams(), false);
                } catch (IOException e) {
                    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "ERROR handling commit/rollback");
                }
                return;
            }
            if (addCmd == null) {
                addCmd = getAddCommand(req, updateRequest.getParams());
            }
            addCmd.solrDoc = document;
            if (commitWithin != null) {
                addCmd.commitWithin = commitWithin;
            }
            if (overwrite != null) {
                addCmd.overwrite = overwrite;
            }
            if (updateRequest.isLastDocInBatch()) {
                // this is a hint to downstream code that indicates we've sent the last doc in a batch
                addCmd.isLastDocInBatch = true;
            }
            try {
                processor.processAdd(addCmd);
                addCmd.clear();
            } catch (IOException e) {
                throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "ERROR adding document " + document, e);
            }
        }
    };
    FastInputStream in = FastInputStream.wrap(stream);
    for (; ; ) {
        try {
            update = new JavaBinUpdateRequestCodec().unmarshal(in, handler);
        } catch (EOFException e) {
            // this is expected
            break;
        }
        if (update.getDeleteByIdMap() != null || update.getDeleteQuery() != null) {
            delete(req, update, processor);
        }
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) EOFException(java.io.EOFException) IOException(java.io.IOException) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) JavaBinUpdateRequestCodec(org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec) SolrException(org.apache.solr.common.SolrException) FastInputStream(org.apache.solr.common.util.FastInputStream)

Aggregations

IOException (java.io.IOException)2 SolrException (org.apache.solr.common.SolrException)2 FastInputStream (org.apache.solr.common.util.FastInputStream)2 EOFException (java.io.EOFException)1 JavaBinUpdateRequestCodec (org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec)1 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)1