@@ -595,6 +595,7 @@ public int hashCode() {
595
595
return Objects .hash (nextAssignedStreamId , streamMetadataList (), nodeMetadataList (), streamEndOffsets ());
596
596
}
597
597
598
+ // caller use this value should be protected by registryRef lock
598
599
public TimelineHashMap <Integer , NodeS3StreamSetObjectMetadataImage > timelineNodeMetadata () {
599
600
return nodeMetadataMap ;
600
601
}
@@ -610,10 +611,15 @@ List<NodeS3StreamSetObjectMetadataImage> nodeMetadataList() {
610
611
});
611
612
}
612
613
614
+ // caller use this value should be protected by registryRef lock
613
615
public TimelineHashMap <Long , S3StreamMetadataImage > timelineStreamMetadata () {
614
616
return streamMetadataMap ;
615
617
}
616
618
619
+ public void inLockRun (Runnable runnable ) {
620
+ registryRef .inLock (runnable );
621
+ }
622
+
617
623
List <S3StreamMetadataImage > streamMetadataList () {
618
624
if (registryRef == RegistryRef .NOOP ) {
619
625
return Collections .emptyList ();
@@ -630,30 +636,33 @@ public long nextAssignedStreamId() {
630
636
}
631
637
632
638
public OptionalLong streamEndOffset (long streamId ) {
633
- Long endOffset = streamEndOffsets .get (streamId );
634
- if (endOffset != null ) {
635
- return OptionalLong .of (endOffset );
636
- }
637
- // There is no record in a new stream
638
- if (streamMetadataMap .containsKey (streamId )) {
639
- return OptionalLong .of (0L );
640
- } else {
639
+ if (registryRef == RegistryRef .NOOP ) {
641
640
return OptionalLong .empty ();
642
641
}
642
+ return registryRef .inLock (() -> {
643
+ Long endOffset = streamEndOffsets .get (streamId );
644
+ if (endOffset != null ) {
645
+ return OptionalLong .of (endOffset );
646
+ }
647
+ // There is no record in a new stream
648
+ if (streamMetadataMap .containsKey (streamId )) {
649
+ return OptionalLong .of (0L );
650
+ } else {
651
+ return OptionalLong .empty ();
652
+ }
653
+ });
643
654
}
644
655
656
+ // caller use this value should be protected by registryRef lock
645
657
TimelineHashMap <TopicIdPartition , Set <Long >> partition2streams () {
646
658
return partition2streams ;
647
659
}
648
660
661
+ // caller use this value should be protected by registryRef lock
649
662
TimelineHashMap <Long , TopicIdPartition > stream2partition () {
650
663
return stream2partition ;
651
664
}
652
665
653
- RegistryRef registryRef () {
654
- return registryRef ;
655
- }
656
-
657
666
// caller use this value should be protected by registryRef lock
658
667
TimelineHashMap <Long , Long > timelineStreamEndOffsets () {
659
668
return streamEndOffsets ;
@@ -671,6 +680,10 @@ Map<Long, Long> streamEndOffsets() {
671
680
});
672
681
}
673
682
683
+ RegistryRef registryRef () {
684
+ return registryRef ;
685
+ }
686
+
674
687
@ Override
675
688
public String toString () {
676
689
return "S3StreamsMetadataImage{nextAssignedStreamId=" + nextAssignedStreamId + '}' ;
0 commit comments