简体   繁体   中英

How can I refresh the resolution of a network name in java?

I am currently writing a Java EE application to search over an index with Lucene.

My application resides in a Tomcat server on a Windows Machine and index data is on another machine.

Sometimes (apparently randomly), the network name becomes unreachable.

This is the exception I get:

12:29:39.011 [ajp-8039-5] ERROR o.f.c.d.p.viewmodel.PilotViewModel - The specified network name is no longer available: SimpleFSIndexInput(path="\\INDEXFILEPATH\indexfile.ext")
java.io.IOException: The specified network name is no longer available: SimpleFSIndexInput(path="\\INDEXFILEPATH\indexfile.ext")
at org.apache.lucene.store.SimpleFSDirectory$SimpleFSIndexInput.readInternal(SimpleFSDirectory.java:140) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]

Here is the relevant code. The exception is thrown on the FSDirectory.open

private void addReaderForRegistry(String indexDirectoryPath, List<IndexReader> readers) throws IOException{

    File indexFolder = new File(indexDirectoryPath);

    if (!(indexFolder.exists() || !(indexFolder.isDirectory()))) {
          throw new IOException(indexFolder.getName() + "is not a valid index location");
    }else{

        // search for subfolders
        List<String> subfolders = FileSystemHelper.listDirectories(indexFolder.getAbsolutePath());

        if(subfolders.isEmpty()){
            Directory fsDirectory = FSDirectory.open(indexFolder);
            IndexReader reader = IndexReader.open(fsDirectory);
            readers.add(reader);                
        }
    }
}

I am sure that the server is up.

To fix this I have to restart the Tomcat Application Server. Is there something I can do to do some errror recovery?

Note that the FSDirectory is opened at each request, so a simple bean reinitialization does not work.

thanks.

Edit: here is a more complete stacktrace

java.io.IOException: The specified network name is no longer available: SimpleFSIndexInput(path="\\hqwprceb1\DRMS-STRUCTURE\indexes_ready\AG\_o48.nrm")
at org.apache.lucene.store.SimpleFSDirectory$SimpleFSIndexInput.readInternal(SimpleFSDirectory.java:140) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.store.BufferedIndexInput.readBytes(BufferedIndexInput.java:156) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.index.SegmentNorms.bytes(SegmentNorms.java:164) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.index.SegmentReader.norms(SegmentReader.java:575) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.search.TermQuery$TermWeight.scorer(TermQuery.java:107) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.search.BooleanQuery$BooleanWeight.scorer(BooleanQuery.java:298) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.search.ConstantScoreQuery$ConstantWeight.scorer(ConstantScoreQuery.java:145) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.search.BooleanQuery$BooleanWeight.scorer(BooleanQuery.java:298) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:577) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:383) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]

I had a similar problem (loosing sometimes a network drive which later automatically came back; the IndexSearcher didn't recover from this).

My workaround was to catch the rarely occuring IOException of the IndexSearcher#search call and drop this IndexSearcher instance then (set the reference to it to null). The next request lazyly creates a new IndexSearcher instance (which can fail then, too) in hope of the network drive is available now. Sooner or later the system recovers itself.

I use lucene 3.5, JDK 1.6 and Windows 7.

If someone knows a better solutions -> thanks for pointing to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM