This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch rel/0.12
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/0.12 by this push:
new 7d6a8d5 [To rel/0.12][IOTDB-1893] Can not release file lock in sync
verify singleton (#4253)
7d6a8d5 is described below
commit 7d6a8d582702286e646a4432bca7d916efb180bf
Author: yschengzi <[email protected]>
AuthorDate: Thu Oct 28 15:40:57 2021 +0800
[To rel/0.12][IOTDB-1893] Can not release file lock in sync verify
singleton (#4253)
---
.../apache/iotdb/db/sync/sender/transfer/SyncClient.java | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git
a/server/src/main/java/org/apache/iotdb/db/sync/sender/transfer/SyncClient.java
b/server/src/main/java/org/apache/iotdb/db/sync/sender/transfer/SyncClient.java
index d197f9f..434e0bd 100644
---
a/server/src/main/java/org/apache/iotdb/db/sync/sender/transfer/SyncClient.java
+++
b/server/src/main/java/org/apache/iotdb/db/sync/sender/transfer/SyncClient.java
@@ -172,16 +172,19 @@ public class SyncClient implements ISyncClient {
* @param lockFile lock file
*/
private boolean lockInstance(File lockFile) {
- try (final RandomAccessFile randomAccessFile = new
RandomAccessFile(lockFile, "rw")) {
+ RandomAccessFile randomAccessFile = null;
+ try {
+ randomAccessFile = new RandomAccessFile(lockFile, "rw");
final FileLock fileLock = randomAccessFile.getChannel().tryLock();
if (fileLock != null) {
+ final RandomAccessFile randomAccessFile2 = randomAccessFile;
Runtime.getRuntime()
.addShutdownHook(
new Thread(
() -> {
try {
fileLock.release();
- randomAccessFile.close();
+ randomAccessFile2.close();
} catch (Exception e) {
logger.error("Unable to remove lock file: {}",
lockFile, e);
}
@@ -190,6 +193,14 @@ public class SyncClient implements ISyncClient {
}
} catch (Exception e) {
logger.error("Unable to create and/or lock file: {}", lockFile, e);
+ } finally {
+ if (randomAccessFile != null) {
+ try {
+ randomAccessFile.close();
+ } catch (Exception e) {
+ logger.error("Unable to close randomAccessFile: {}",
randomAccessFile, e);
+ }
+ }
}
return false;
}