Skip to content

Commit

Permalink
feat: Retry twice to grab the lock on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
moeinxyz committed Oct 26, 2023
1 parent 2502d21 commit 6bf0ac3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/io/confluent/connect/hdfs/wal/QFSWAL.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -129,8 +130,18 @@ private Lock createOrRenameLock() {
this.storage.create(this.lockDir);
}

if (!findAliveLocks().isEmpty()) {
throw new ConnectException("Lock has been acquired by another process");
// It gives two chance of grabbing the lock on startup.
// This should help when the new task comes up sooner than the expiry of the previous lock.
if (!findAliveLocks().isEmpty()){
try {
Thread.sleep(this.lockTimeout.toMillis());
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

if (!findAliveLocks().isEmpty()) {
throw new ConnectException("Lock has been acquired by another process");
}
}

Lock newLock = getNewLock();
Expand Down

0 comments on commit 6bf0ac3

Please sign in to comment.