Skip to content

Commit bfe9cd7

Browse files
committed
Improve freeing lock 2
1 parent 54ae978 commit bfe9cd7

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

Diff for: inv-src/src/main/java/org/cdlib/mrt/inv/zoo/ProcessJob.java

+23-2
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,17 @@ public void jobFails(Exception saveEx)
353353
job.unlock(processZooKeeper);
354354
JSONObject data = job.data();
355355
log4j.error("ProcessJob.jobFail:" + saveEx.toString(), data);
356+
if (lockKey != null) {
357+
releaseLock(lockKey);
358+
}
356359

357360
} catch (Exception ex) {
358361
throw new TException(ex);
362+
363+
} finally {
364+
if (lockKey != null) {
365+
releaseLock(lockKey);
366+
}
359367
}
360368
}
361369

@@ -366,9 +374,17 @@ public void jobOK()
366374
processStatus = ProcessStatus.completed;
367375
job.setStatus(processZooKeeper, job.status().success());
368376
job.unlock(processZooKeeper);
377+
if (lockKey != null) {
378+
releaseLock(lockKey);
379+
}
369380

370381
} catch (Exception ex) {
371382
throw new TException(ex);
383+
384+
} finally {
385+
if (lockKey != null) {
386+
releaseLock(lockKey);
387+
}
372388
}
373389
}
374390

@@ -390,7 +406,9 @@ private boolean getLockRetry(String primaryID, int timeoutSeconds)
390406
boolean gotLock = getLock(primaryID);
391407
attempts++;
392408
if (gotLock) {
393-
log4j.info("Got lock:" + primaryID);
409+
log4j.info("getLockRetry(" + job.id() + ") lock OK"
410+
+ " - attempts=" + attempts
411+
);
394412
return true;
395413
}
396414

@@ -399,13 +417,16 @@ private boolean getLockRetry(String primaryID, int timeoutSeconds)
399417
} catch (Exception tmpEx) { }
400418
long elapsedMs= System.currentTimeMillis() - startMlSec;
401419
long totalTimeoutMs = timeoutSeconds * 1000;
402-
log4j.info("getLockRetry(" + attempts + "): "
420+
log4j.debug("getLockRetry(" + job.id() + ") lock fail"
421+
+ " - attempts=" + attempts
403422
+ " - elapsedMs=" + elapsedMs
404423
+ " - totalTimeoutMs=" + totalTimeoutMs
405424
);
406425
if (elapsedMs > totalTimeoutMs) {
407426
throw new TException.GATEWAY_TIMEOUT("lock not released Exception"
427+
+ " - job.id:" + job.id()
408428
+ " - primaryID:" + primaryID
429+
+ " - attempts=" + attempts
409430
+ " - timeoutSeconds:" + timeoutSeconds
410431
+ " - elapsedMs:" + elapsedMs
411432
);

0 commit comments

Comments
 (0)