You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2021/09/29 03:34:53 UTC
[iotdb] branch master updated: [IOTDB-1749] sync-tool's
lockInstance() dose not take effect (#4052)
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 0163d3a [IOTDB-1749] sync-tool's lockInstance() dose not take effect (#4052)
0163d3a is described below
commit 0163d3aa76d452fe2c1d864790451dcfd3d5cd5e
Author: Jamber <ja...@sina.com>
AuthorDate: Wed Sep 29 11:34:28 2021 +0800
[IOTDB-1749] sync-tool's lockInstance() dose not take effect (#4052)
---
.../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 b7f0540..ed37490 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
@@ -171,16 +171,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);
}
@@ -189,6 +192,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;
}