@@ -353,9 +353,17 @@ public void jobFails(Exception saveEx)
353
353
job .unlock (processZooKeeper );
354
354
JSONObject data = job .data ();
355
355
log4j .error ("ProcessJob.jobFail:" + saveEx .toString (), data );
356
+ if (lockKey != null ) {
357
+ releaseLock (lockKey );
358
+ }
356
359
357
360
} catch (Exception ex ) {
358
361
throw new TException (ex );
362
+
363
+ } finally {
364
+ if (lockKey != null ) {
365
+ releaseLock (lockKey );
366
+ }
359
367
}
360
368
}
361
369
@@ -366,9 +374,17 @@ public void jobOK()
366
374
processStatus = ProcessStatus .completed ;
367
375
job .setStatus (processZooKeeper , job .status ().success ());
368
376
job .unlock (processZooKeeper );
377
+ if (lockKey != null ) {
378
+ releaseLock (lockKey );
379
+ }
369
380
370
381
} catch (Exception ex ) {
371
382
throw new TException (ex );
383
+
384
+ } finally {
385
+ if (lockKey != null ) {
386
+ releaseLock (lockKey );
387
+ }
372
388
}
373
389
}
374
390
@@ -390,7 +406,9 @@ private boolean getLockRetry(String primaryID, int timeoutSeconds)
390
406
boolean gotLock = getLock (primaryID );
391
407
attempts ++;
392
408
if (gotLock ) {
393
- log4j .info ("Got lock:" + primaryID );
409
+ log4j .info ("getLockRetry(" + job .id () + ") lock OK"
410
+ + " - attempts=" + attempts
411
+ );
394
412
return true ;
395
413
}
396
414
@@ -399,13 +417,16 @@ private boolean getLockRetry(String primaryID, int timeoutSeconds)
399
417
} catch (Exception tmpEx ) { }
400
418
long elapsedMs = System .currentTimeMillis () - startMlSec ;
401
419
long totalTimeoutMs = timeoutSeconds * 1000 ;
402
- log4j .info ("getLockRetry(" + attempts + "): "
420
+ log4j .debug ("getLockRetry(" + job .id () + ") lock fail"
421
+ + " - attempts=" + attempts
403
422
+ " - elapsedMs=" + elapsedMs
404
423
+ " - totalTimeoutMs=" + totalTimeoutMs
405
424
);
406
425
if (elapsedMs > totalTimeoutMs ) {
407
426
throw new TException .GATEWAY_TIMEOUT ("lock not released Exception"
427
+ + " - job.id:" + job .id ()
408
428
+ " - primaryID:" + primaryID
429
+ + " - attempts=" + attempts
409
430
+ " - timeoutSeconds:" + timeoutSeconds
410
431
+ " - elapsedMs:" + elapsedMs
411
432
);
0 commit comments