|
47 | 47 |
|
48 | 48 | import org.springframework.beans.factory.DisposableBean; |
49 | 49 | import org.springframework.dao.CannotAcquireLockException; |
| 50 | +import org.springframework.dao.InvalidDataAccessApiUsageException; |
| 51 | +import org.springframework.data.redis.RedisSystemException; |
50 | 52 | import org.springframework.data.redis.connection.Message; |
51 | 53 | import org.springframework.data.redis.connection.MessageListener; |
52 | 54 | import org.springframework.data.redis.connection.RedisConnectionFactory; |
@@ -584,40 +586,34 @@ public final void unlock() { |
584 | 586 |
|
585 | 587 | private void removeLockKey() { |
586 | 588 | if (RedisLockRegistry.this.unlinkAvailable) { |
587 | | - Boolean unlinkResult = null; |
588 | 589 | try { |
589 | | - // Attempt to UNLINK the lock key; an exception indicates lack of UNLINK support |
590 | | - unlinkResult = removeLockKeyInnerUnlink(); |
| 590 | + boolean unlinkResult = removeLockKeyInnerUnlink(); |
| 591 | + if (unlinkResult) { |
| 592 | + // Lock key successfully unlinked |
| 593 | + stopRenew(); |
| 594 | + } else { |
| 595 | + throw new ConcurrentModificationException("Lock was released in the store due to expiration. " + |
| 596 | + "The integrity of data protected by this lock may have been compromised."); |
| 597 | + } |
591 | 598 | } |
592 | | - catch (Exception ex) { |
| 599 | + catch (InvalidDataAccessApiUsageException | RedisSystemException ex) { |
| 600 | + // Redis 3 or earlier lacks of UNLINK support |
| 601 | + // jedis throws InvalidDataAccessApiUsageException, lettuce RedisSystemException |
| 602 | + LOGGER.warn("The UNLINK command has failed (not supported on the Redis server?); " + |
| 603 | + "falling back to the regular DELETE command", ex); |
593 | 604 | RedisLockRegistry.this.unlinkAvailable = false; |
594 | | - if (LOGGER.isDebugEnabled()) { |
595 | | - LOGGER.debug("The UNLINK command has failed (not supported on the Redis server?); " + |
596 | | - "falling back to the regular DELETE command", ex); |
597 | | - } |
598 | | - else { |
599 | | - LOGGER.warn("The UNLINK command has failed (not supported on the Redis server?); " + |
600 | | - "falling back to the regular DELETE command: " + ex.getMessage()); |
601 | | - } |
| 605 | + removeLockKey(); // retry with delete branch |
602 | 606 | } |
603 | | - |
604 | | - if (Boolean.TRUE.equals(unlinkResult)) { |
605 | | - // Lock key successfully unlinked |
| 607 | + } else { |
| 608 | + boolean deleteResult = removeLockKeyInnerDelete(); |
| 609 | + if (deleteResult) { |
| 610 | + // Lock key successfully deleted |
606 | 611 | stopRenew(); |
607 | | - return; |
608 | | - } |
609 | | - else if (Boolean.FALSE.equals(unlinkResult)) { |
| 612 | + } else { |
610 | 613 | throw new ConcurrentModificationException("Lock was released in the store due to expiration. " + |
611 | 614 | "The integrity of data protected by this lock may have been compromised."); |
612 | 615 | } |
613 | 616 | } |
614 | | - if (!removeLockKeyInnerDelete()) { |
615 | | - throw new ConcurrentModificationException("Lock was released in the store due to expiration. " + |
616 | | - "The integrity of data protected by this lock may have been compromised."); |
617 | | - } |
618 | | - else { |
619 | | - stopRenew(); |
620 | | - } |
621 | 617 | } |
622 | 618 |
|
623 | 619 | protected final boolean renew(long expireAfter) { |
|
0 commit comments