From 5faefcd01fa894c9d8845d96cc0f07ca4cfa7968 Mon Sep 17 00:00:00 2001 From: xuzifu666 Date: Wed, 27 Dec 2023 13:13:31 +0800 Subject: [PATCH] [MINOR] DataStream need in closeure in FileSystemBasedLockProvider (#10411) Co-authored-by: xuyu <11161569@vivo.com> --- .../transaction/lock/FileSystemBasedLockProvider.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/transaction/lock/FileSystemBasedLockProvider.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/transaction/lock/FileSystemBasedLockProvider.java index da7e71a20580..1d32620b043a 100644 --- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/transaction/lock/FileSystemBasedLockProvider.java +++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/transaction/lock/FileSystemBasedLockProvider.java @@ -163,12 +163,10 @@ private boolean checkIfExpired() { } private void acquireLock() { - try { + try (FSDataOutputStream fos = fs.create(this.lockFile, false)) { if (!fs.exists(this.lockFile)) { - FSDataOutputStream fos = fs.create(this.lockFile, false); initLockInfo(); fos.writeBytes(lockInfo.toString()); - fos.close(); } } catch (IOException e) { throw new HoodieIOException(generateLogStatement(LockState.FAILED_TO_ACQUIRE), e); @@ -182,11 +180,9 @@ public void initLockInfo() { } public void reloadCurrentOwnerLockInfo() { - try { + try (FSDataInputStream fis = fs.open(this.lockFile)) { if (fs.exists(this.lockFile)) { - FSDataInputStream fis = fs.open(this.lockFile); this.currentOwnerLockInfo = FileIOUtils.readAsUTFString(fis); - fis.close(); } else { this.currentOwnerLockInfo = ""; }