Skip to content

Commit

Permalink
[HUDI-4505] Returns instead of throws if lock file exists for FileSys…
Browse files Browse the repository at this point in the history
…temBasedLockProvider (#6242)

To avoid unnecessary exception throws
  • Loading branch information
danny0405 authored Jul 29, 2022
1 parent a1cf401 commit e04b318
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public class FileSystemBasedLockProvider implements LockProvider<String>, Serial
private static final String LOCK_FILE_NAME = "lock";

private final int lockTimeoutMinutes;
private transient FileSystem fs;
private transient Path lockFile;
private final transient FileSystem fs;
private final transient Path lockFile;
protected LockConfiguration lockConfiguration;

public FileSystemBasedLockProvider(final LockConfiguration lockConfiguration, final Configuration configuration) {
Expand Down Expand Up @@ -87,8 +87,13 @@ public boolean tryLock(long time, TimeUnit unit) {
try {
synchronized (LOCK_FILE_NAME) {
// Check whether lock is already expired, if so try to delete lock file
if (fs.exists(this.lockFile) && checkIfExpired()) {
fs.delete(this.lockFile, true);
if (fs.exists(this.lockFile)) {
if (checkIfExpired()) {
fs.delete(this.lockFile, true);
LOG.warn("Delete expired lock file: " + this.lockFile);
} else {
return false;
}
}
acquireLock();
return fs.exists(this.lockFile);
Expand Down Expand Up @@ -123,7 +128,7 @@ private boolean checkIfExpired() {
}
try {
long modificationTime = fs.getFileStatus(this.lockFile).getModificationTime();
if (System.currentTimeMillis() - modificationTime > lockTimeoutMinutes * 60 * 1000) {
if (System.currentTimeMillis() - modificationTime > lockTimeoutMinutes * 60 * 1000L) {
return true;
}
} catch (IOException | HoodieIOException e) {
Expand Down

0 comments on commit e04b318

Please sign in to comment.