SolrJ addFile keeps documents open

2019-08-29 05:39发布

问题:

I've already submitted a similar question, but I've broken down the problem to its simplest form, so I'm gonna post it again:

The problem is, that SolrJ seems to keep file handles open, if I add the same file more than once.

I use the following method to submit a document to Solr:

public boolean addDocument( File doc ) throws IOException, SolrServerException {

    ContentStreamUpdateRequest csur = new ContentStreamUpdateRequest( "/update/extract" );

    csur.addFile( doc );
    csur.setParam( "literal.id", Utils.getAbsolutePath( doc ) );
    csur.setAction( AbstractUpdateRequest.ACTION.COMMIT, true, true );
    NamedList<Object> result = this.solr.request( csur );


    return result != null;
}

And this method to remove documents:

public void removeDocument( File doc ) throws IOException,
        SolrServerException {

    this.solr.deleteById( Utils.getAbsolutePath( doc ) );
    this.solr.commit();
}

But that seems to leave some File Handles lingering:

The following snippet demonstrates the problem:

File doc = new File( "../../testpdf/bbb.pdf" );
solr.addDocument( doc );
//solr.removeDocument( doc );   // Without these 2 lines, all handles
//solr.addDocument( doc );      // are released correctly

If I add the same document twice, SolrJ somehow keeps the handles alive, and the added document cannot be modified by any other processes.

I've already tried calling using csur.addContentStream() instead of csur.addFile() in addDocument and then closing the underlying Stream and Reader of the added stream, with no effect.

thx for any suggestions in advance

回答1:

Couldn't fix it, did a workaround by writing a custom ContentStream that buffers the document.



标签: java solrj solr