[SEARCH-1994]

fix tmp files moves
This commit is contained in:
eliaporciani
2019-12-18 10:17:24 +01:00
parent ff46b147cd
commit 12e95b459a
2 changed files with 16 additions and 5 deletions

View File

@@ -236,9 +236,11 @@ public final class SolrContentStore implements Closeable, AccessMode
@Override
public long getLastCommittedVersion()
{
try(Stream<String> fileStream = Files.lines(Paths.get(root, ".version")) )
try
{
return fileStream.map(Long::parseLong)
return Files.readAllLines(Paths.get(root, ".version"))
.stream()
.map(Long::parseLong)
.findFirst()
.orElse(NO_VERSION_AVAILABLE);
}
@@ -251,20 +253,29 @@ public final class SolrContentStore implements Closeable, AccessMode
@Override
public void setLastCommittedVersion(long version)
{
File tmpFile = new File(root, ".version-" + new SimpleDateFormat(SnapShooter.DATE_FMT, Locale.ROOT).format(new Date()));
try
{
File tmpFile = new File(root, ".version-" + new SimpleDateFormat(SnapShooter.DATE_FMT, Locale.ROOT).format(new Date()));
FileWriter wr = new FileWriter(tmpFile);
wr.write(Long.toString(version));
wr.close();
// file.renameTo(..) does not work on windows. Use Files.move instead.
Files.move(tmpFile.toPath(), new File(root, ".version").toPath(), StandardCopyOption.REPLACE_EXISTING);
Files.move(tmpFile.toPath(), new File(root, ".version").toPath(), StandardCopyOption.ATOMIC_MOVE);
}
catch (IOException exception)
{
logger.error("Unable to persist the last committed content store version {}. See the stacktrace below for furtger details.", version, exception);
try
{
Files.delete(tmpFile.toPath());
}
catch (IOException e)
{
logger.error("Unable to delete tmp contentstore version file {}.", version);
}
}
}

View File

@@ -1714,7 +1714,7 @@ class AlfrescoIndexFetcher
try
{
Files.createDirectories(Paths.get(csFile.getParent()));
Files.copy(tmpFile.toPath(), csFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
Files.move(tmpFile.toPath(), csFile.toPath(), StandardCopyOption.ATOMIC_MOVE);
}
catch (IOException e)
{