Files locked after indexing

不羁的心 提交于 2019-12-10 13:15:50

问题


I have the following workflow in my (web)application:

  • download a pdf file from an archive
  • index the file
  • delete the file

My problem is that after indexing the file, it remains locked and the delete-part throws an exception.

Here is my code-snippet for indexing the file:

try
{
   ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update/extract");
   req.addFile(file, type);
   req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);

   NamedList<Object> result = server.request(req);

   Assert.assertEquals(0, ((NamedList<?>) result.get("responseHeader")).get("status"));
}

Do I miss something?

EDIT:

I tried this way too, but with the same result...

ContentStream contentStream = null;

    try
    {
      contentStream = new ContentStreamBase.FileStream(document);

      ContentStreamUpdateRequest req = new ContentStreamUpdateRequest(UPDATE_EXTRACT_REQUEST);
//      req.addFile(document, context.getProperty(FTSConstants.CONTENT_TYPE_APPLICATION_PDF));
      req.addContentStream(contentStream);
      req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);

      NamedList<Object> result = server.request(req);

      if (!((NamedList<?>) result.get("responseHeader")).get("status").equals(0))
      {
        throw new IDSystemException(LOG, "Document could not be indexed. Status returned: " +
                                         ((NamedList<?>) result.get("responseHeader")).get("status"));
      }
    }
    catch (FileNotFoundException fnfe)
    {
      throw new IDSystemException(LOG, fnfe.getMessage(), fnfe);
    }
    catch (IOException ioe)
    {
      throw new IDSystemException(LOG, ioe.getMessage(), ioe);
    }
    catch (SolrServerException sse)
    {
      throw new IDSystemException(LOG, sse.getMessage(), sse);
    }
    finally
    {
      try
      {
        if(contentStream != null && contentStream.getStream() != null)
        {
          contentStream.getStream().close();
        }
      }
      catch (IOException ioe)
      {
        throw new IDSystemException(LOG, ioe.getMessage(), ioe);
      }
    }

回答1:


This seems like a bug,

a patch is proposed here https://issues.apache.org/jira/browse/SOLR-1744

Also checkout http://lucene.472066.n3.nabble.com/ContentStreamUpdateRequest-addFile-fails-to-close-Stream-td485429.html

you can check if the stream is not null and close it.




回答2:


It may be due to lock acquired by file system. Instead of addFile(), you can try the following.

ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update/extract");
ContentStreamBase.FileStream fileStream = new FileStream(file);
req.addContentStream(fileStream);

Shishir



来源:https://stackoverflow.com/questions/22035777/files-locked-after-indexing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!