Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Files locked after indexing

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);
      }
    }
like image 919
Francesco Avatar asked Feb 26 '14 08:02

Francesco


People also ask

What causes a file to be locked?

The file might be locked because: The file is shared and another user is currently editing it. An instance of the Office app is running in the background with the file already opened. The file has been marked as Final and can no longer be updated.

How do I release a locked file?

Right-click on the file. In the menu that appears, select Lock File. To unlock, right-click the file and select Unlock File.

What does it mean when files are locked?

File locking is a feature that prevents a file from being edited.

How do I unlock a locked Windows file?

Sometimes when you try to delete, rename or move a file in Windows, you may see a message that the file is busy/locked/used by another process. Usually the name of the program that keeps the file open is shown right in the File Explorer message window. To unlock the file, it is enough just to close the program.


2 Answers

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.

like image 52
Syler Avatar answered Sep 19 '22 13:09

Syler


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

like image 34
Shishir Kumar Avatar answered Sep 21 '22 13:09

Shishir Kumar