use of java.nio.file.NoSuchFileException in project jdk8u_jdk by JetBrains.
the class FileUtils method deleteFileWithRetry0.
private static void deleteFileWithRetry0(Path path) throws IOException, InterruptedException {
int times = 0;
IOException ioe = null;
while (true) {
try {
Files.delete(path);
while (Files.exists(path)) {
times++;
if (times > MAX_RETRY_DELETE_TIMES)
throw new IOException("File still exists after " + times + " waits.");
Thread.sleep(RETRY_DELETE_MILLIS);
}
break;
} catch (NoSuchFileException | DirectoryNotEmptyException x) {
throw x;
} catch (IOException x) {
// Backoff/retry in case another process is accessing the file
times++;
if (ioe == null)
ioe = x;
else
ioe.addSuppressed(x);
if (times > MAX_RETRY_DELETE_TIMES)
throw ioe;
Thread.sleep(RETRY_DELETE_MILLIS);
}
}
}
use of java.nio.file.NoSuchFileException in project lucene-solr by apache.
the class SolrCore method getNewIndexDir.
/**
* Returns the indexdir as given in index.properties. If index.properties exists in dataDir and
* there is a property <i>index</i> available and it points to a valid directory
* in dataDir that is returned Else dataDir/index is returned. Only called for creating new indexSearchers
* and indexwriters. Use the getIndexDir() method to know the active index directory
*
* @return the indexdir as given in index.properties
*/
public String getNewIndexDir() {
String result = dataDir + "index/";
Properties p = new Properties();
Directory dir = null;
try {
dir = getDirectoryFactory().get(getDataDir(), DirContext.META_DATA, getSolrConfig().indexConfig.lockType);
IndexInput input;
try {
input = dir.openInput(IndexFetcher.INDEX_PROPERTIES, IOContext.DEFAULT);
} catch (FileNotFoundException | NoSuchFileException e) {
input = null;
}
if (input != null) {
final InputStream is = new PropertiesInputStream(input);
try {
p.load(new InputStreamReader(is, StandardCharsets.UTF_8));
String s = p.getProperty("index");
if (s != null && s.trim().length() > 0) {
result = dataDir + s;
}
} catch (Exception e) {
log.error("Unable to load " + IndexFetcher.INDEX_PROPERTIES, e);
} finally {
IOUtils.closeQuietly(is);
}
}
} catch (IOException e) {
SolrException.log(log, "", e);
} finally {
if (dir != null) {
try {
getDirectoryFactory().release(dir);
} catch (IOException e) {
SolrException.log(log, "", e);
}
}
}
if (!result.equals(lastNewIndexDir)) {
log.debug("New index directory detected: old=" + lastNewIndexDir + " new=" + result);
}
lastNewIndexDir = result;
return result;
}
use of java.nio.file.NoSuchFileException in project lucene-solr by apache.
the class IndexFetcher method compareFile.
protected static CompareResult compareFile(Directory indexDir, String filename, Long backupIndexFileLen, Long backupIndexFileChecksum) {
CompareResult compareResult = new CompareResult();
try {
try (final IndexInput indexInput = indexDir.openInput(filename, IOContext.READONCE)) {
long indexFileLen = indexInput.length();
long indexFileChecksum = 0;
if (backupIndexFileChecksum != null) {
try {
indexFileChecksum = CodecUtil.retrieveChecksum(indexInput);
compareResult.checkSummed = true;
} catch (Exception e) {
LOG.warn("Could not retrieve checksum from file.", e);
}
}
if (!compareResult.checkSummed) {
if (indexFileLen == backupIndexFileLen) {
compareResult.equal = true;
return compareResult;
} else {
LOG.info("File {} did not match. expected length is {} and actual length is {}", filename, backupIndexFileLen, indexFileLen);
compareResult.equal = false;
return compareResult;
}
}
if (indexFileLen == backupIndexFileLen && indexFileChecksum == backupIndexFileChecksum) {
compareResult.equal = true;
return compareResult;
} else {
LOG.warn("File {} did not match. expected checksum is {} and actual is checksum {}. " + "expected length is {} and actual length is {}", filename, backupIndexFileChecksum, indexFileChecksum, backupIndexFileLen, indexFileLen);
compareResult.equal = false;
return compareResult;
}
}
} catch (NoSuchFileException | FileNotFoundException e) {
compareResult.equal = false;
return compareResult;
} catch (IOException e) {
LOG.error("Could not read file " + filename + ". Downloading it again", e);
compareResult.equal = false;
return compareResult;
}
}
use of java.nio.file.NoSuchFileException in project lucene-solr by apache.
the class BaseDirectoryTestCase method testFsyncDoesntCreateNewFiles.
// this test backdoors the directory via the filesystem. so it must actually use the filesystem
// TODO: somehow change this test to
public void testFsyncDoesntCreateNewFiles() throws Exception {
Path path = createTempDir("nocreate");
Directory fsdir = getDirectory(path);
// if it's using two FSdirs and so on
if (fsdir instanceof FSDirectory == false) {
fsdir.close();
assumeTrue("test only works for FSDirectory subclasses", false);
}
// write a file
IndexOutput out = fsdir.createOutput("afile", newIOContext(random()));
out.writeString("boo");
out.close();
// delete it
Files.delete(path.resolve("afile"));
int fileCount = fsdir.listAll().length;
// fsync it
try {
fsdir.sync(Collections.singleton("afile"));
fail("didn't get expected exception, instead fsync created new files: " + Arrays.asList(fsdir.listAll()));
} catch (FileNotFoundException | NoSuchFileException expected) {
// ok
}
// no new files created
assertEquals(fileCount, fsdir.listAll().length);
fsdir.close();
}
use of java.nio.file.NoSuchFileException in project lucene-solr by apache.
the class BaseDirectoryTestCase method testNoDir.
// LUCENE-3382 -- make sure we get exception if the directory really does not exist.
public void testNoDir() throws Throwable {
Path tempDir = createTempDir("doesnotexist");
IOUtils.rm(tempDir);
Directory dir = getDirectory(tempDir);
try {
DirectoryReader.open(dir);
fail("did not hit expected exception");
} catch (NoSuchFileException | IndexNotFoundException nsde) {
// expected
}
dir.close();
}
Aggregations