|
43 | 43 | import java.util.concurrent.TimeUnit; |
44 | 44 | import java.util.concurrent.TimeoutException; |
45 | 45 | import java.util.concurrent.atomic.AtomicLong; |
46 | | -import java.util.concurrent.locks.StampedLock; |
47 | 46 | import java.util.stream.Collectors; |
48 | 47 | import javax.annotation.concurrent.ThreadSafe; |
49 | 48 | import lombok.Getter; |
@@ -94,8 +93,6 @@ public static record SnapshotKey(long ledgerId, long entryId) {} |
94 | 93 |
|
95 | 94 | private final AtomicLong numberDelayedMessages = new AtomicLong(0); |
96 | 95 |
|
97 | | - // Thread safety locks |
98 | | - private final StampedLock stampedLock = new StampedLock(); |
99 | 96 |
|
100 | 97 | @Getter |
101 | 98 | @VisibleForTesting |
@@ -577,24 +574,7 @@ public synchronized boolean hasMessageAvailable() { |
577 | 574 | } |
578 | 575 |
|
579 | 576 | @Override |
580 | | - protected long nextDeliveryTime() { |
581 | | - // Use optimistic read for frequently called method |
582 | | - long stamp = stampedLock.tryOptimisticRead(); |
583 | | - long result = nextDeliveryTimeUnsafe(); |
584 | | - |
585 | | - |
586 | | - if (!stampedLock.validate(stamp)) { |
587 | | - stamp = stampedLock.readLock(); |
588 | | - try { |
589 | | - result = nextDeliveryTimeUnsafe(); |
590 | | - } finally { |
591 | | - stampedLock.unlockRead(stamp); |
592 | | - } |
593 | | - } |
594 | | - return result; |
595 | | - } |
596 | | - |
597 | | - private long nextDeliveryTimeUnsafe() { |
| 577 | + protected synchronized long nextDeliveryTime() { |
598 | 578 | if (lastMutableBucket.isEmpty() && !sharedBucketPriorityQueue.isEmpty()) { |
599 | 579 | return sharedBucketPriorityQueue.peekN1(); |
600 | 580 | } else if (sharedBucketPriorityQueue.isEmpty() && !lastMutableBucket.isEmpty()) { |
@@ -788,25 +768,7 @@ private boolean removeIndexBit(long ledgerId, long entryId) { |
788 | 768 | .orElse(false); |
789 | 769 | } |
790 | 770 |
|
791 | | - public boolean containsMessage(long ledgerId, long entryId) { |
792 | | - // Try optimistic read first for best performance |
793 | | - long stamp = stampedLock.tryOptimisticRead(); |
794 | | - boolean result = containsMessageUnsafe(ledgerId, entryId); |
795 | | - |
796 | | - |
797 | | - if (!stampedLock.validate(stamp)) { |
798 | | - // Fall back to read lock if validation fails |
799 | | - stamp = stampedLock.readLock(); |
800 | | - try { |
801 | | - result = containsMessageUnsafe(ledgerId, entryId); |
802 | | - } finally { |
803 | | - stampedLock.unlockRead(stamp); |
804 | | - } |
805 | | - } |
806 | | - return result; |
807 | | - } |
808 | | - |
809 | | - private boolean containsMessageUnsafe(long ledgerId, long entryId) { |
| 771 | + public synchronized boolean containsMessage(long ledgerId, long entryId) { |
810 | 772 | if (lastMutableBucket.containsMessage(ledgerId, entryId)) { |
811 | 773 | return true; |
812 | 774 | } |
|
0 commit comments