massakam commented on a change in pull request #10790:
URL: https://github.com/apache/pulsar/pull/10790#discussion_r645689015
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentSubscription.java
##########
@@ -177,12 +178,28 @@ public boolean isReplicated() {
return replicatedSubscriptionSnapshotCache != null;
}
- void setReplicated(boolean replicated) {
- this.replicatedSubscriptionSnapshotCache = replicated
- ? new ReplicatedSubscriptionSnapshotCache(subName,
- topic.getBrokerService().pulsar().getConfiguration()
-
.getReplicatedSubscriptionsSnapshotMaxCachedPerSubscription())
- : null;
+ public void setReplicated(boolean replicated) {
+ ServiceConfiguration config =
topic.getBrokerService().getPulsar().getConfig();
+
+ if (!replicated || !config.isEnableReplicatedSubscriptions()) {
+ this.replicatedSubscriptionSnapshotCache = null;
+ } else if (this.replicatedSubscriptionSnapshotCache == null) {
+ this.replicatedSubscriptionSnapshotCache = new
ReplicatedSubscriptionSnapshotCache(subName,
+
config.getReplicatedSubscriptionsSnapshotMaxCachedPerSubscription());
+ }
+
+ if (this.cursor != null) {
+ Map<String, Long> properties = this.cursor.getProperties();
+ try {
+ if (replicated) {
+ properties.put(REPLICATED_SUBSCRIPTION_PROPERTY, 1L);
+ } else {
+ properties.remove(REPLICATED_SUBSCRIPTION_PROPERTY);
+ }
+ } catch (UnsupportedOperationException e) {
Review comment:
Even if `lastMarkDeleteEntry` is not null,
`lastMarkDeleteEntry.properties` can be `Collections.emptyMap()`, an immutable
map object. `UnsupportedOperationException` is thrown when trying to add a
property to this map. And I don't think there is a way to check if the map is
immutable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]