Skip to content
Snippets Groups Projects
Commit 5a563868 authored by Mohamed, Fawzi Roberto (fawzi)'s avatar Mohamed, Fawzi Roberto (fawzi)
Browse files

Improve locking

parent 46d5f386
No related branches found
Tags 1.9.0
No related merge requests found
......@@ -239,8 +239,10 @@ class FileH5(
override def release0(): Unit = {
logger.debug(s"closing file $path")
if (h5FileGroup >= 0)
if (h5FileGroup >= 0) {
H5Lib.fileFlush(h5FileGroup)
H5Lib.fileClose(h5FileGroup)
}
if (releaseLock)
FileH5.release(path, writeable)
}
......
......@@ -130,19 +130,18 @@ class CalculationBackend(
try {
parsingResult match {
case ParseResult.ParseSuccess | ParseResult.ParseWithWarnings =>
if (Files.exists(targetPath)) {
val targetF = h5.FileH5.open(targetPath, write = true, acquired = true)
val sourceF = h5.FileH5.open(tmpPath)
try {
lab.h5.Merge.fileInFile(sourceF, targetF)
} finally {
targetF.release()
}
sourceF.release()
} else {
Files.move(tmpPath, targetPath, StandardCopyOption.ATOMIC_MOVE)
Files.copy(targetPath, tmpPath, StandardCopyOption.COPY_ATTRIBUTES)
val targetF = if (!Files.exists(targetPath))
h5.FileH5.create(targetPath, acquired = true)
else
h5.FileH5.open(targetPath, write = true, acquired = true)
val sourceF = h5.FileH5.open(tmpPath)
try {
lab.h5.Merge.fileInFile(sourceF, targetF)
} finally {
targetF.release()
Thread.sleep(1000)
}
sourceF.release()
case ParseResult.ParseFailure =>
Files.delete(tmpPath) // should be logged in the hdf5
case ParseResult.ParseSkipped =>
......
......@@ -57,6 +57,10 @@ object H5Lib extends StrictLogging {
throw new HdfException(errorMsg)
}
def fileFlush(fileId: Long): Unit = {
throw new HdfException(errorMsg)
}
def fileClose(fileId: Long): Unit = {
throw new HdfException(errorMsg)
}
......
......@@ -76,6 +76,12 @@ object H5Lib extends StrictLogging {
H5.H5Fopen(filePath, flags, HDF5Constants.H5P_DEFAULT)
}
def fileFlush(fileId: Long): Unit = {
val err = H5.H5Fflush(fileId, HDF5Constants.H5F_SCOPE_GLOBAL)
if (err < 0)
logger.warn(s"Error $err while closing file with id $fileId")
}
def fileClose(fileId: Long): Unit = {
val err = H5.H5Fclose(fileId)
if (err < 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment