Skip to content

Commit 3f6d3c8

Browse files
Synchronizing populatePropertyBag as additional fallback to avoid transient invalid json in Changefeed state (Azure#21020)
It is not fully clear yet how we occasionally end-up with invalid json for the ChangeFeedStartFrom settings (json would have "Type": "Now", "Type": "Now") - the populate property bag method uses Map<>.put (LinkedHashMap) to add the property - which should never result in duplicates. Synchronizing this part is just an attempt to reduce risk - not because there is a known multi-threaded usage that could result in the duplicates.
1 parent 98f1e6b commit 3f6d3c8

File tree

4 files changed

+41
-32
lines changed

4 files changed

+41
-32
lines changed

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/implementation/ChangeFeedStartFromBeginningImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ public ChangeFeedStartFromBeginningImpl() {
1616
public void populatePropertyBag() {
1717
super.populatePropertyBag();
1818

19-
setProperty(
20-
this,
21-
Constants.Properties.CHANGE_FEED_START_FROM_TYPE,
22-
ChangeFeedStartFromTypes.BEGINNING);
19+
synchronized(this) {
20+
setProperty(
21+
this,
22+
Constants.Properties.CHANGE_FEED_START_FROM_TYPE,
23+
ChangeFeedStartFromTypes.BEGINNING);
24+
}
2325
}
2426

2527
@Override

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/implementation/ChangeFeedStartFromETagAndFeedRangeImpl.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,21 @@ public void populateRequest(RxDocumentServiceRequest request) {
8282
public void populatePropertyBag() {
8383
super.populatePropertyBag();
8484

85-
setProperty(
86-
this,
87-
Constants.Properties.CHANGE_FEED_START_FROM_TYPE,
88-
ChangeFeedStartFromTypes.LEASE);
89-
90-
setProperty(
91-
this,
92-
Constants.Properties.CHANGE_FEED_START_FROM_ETAG,
93-
this.eTag);
94-
95-
this.feedRange.setProperties(
96-
this,
97-
true);
85+
synchronized(this) {
86+
setProperty(
87+
this,
88+
Constants.Properties.CHANGE_FEED_START_FROM_TYPE,
89+
ChangeFeedStartFromTypes.LEASE);
90+
91+
setProperty(
92+
this,
93+
Constants.Properties.CHANGE_FEED_START_FROM_ETAG,
94+
this.eTag);
95+
96+
this.feedRange.setProperties(
97+
this,
98+
true);
99+
}
98100
}
99101

100102
@Override

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/implementation/ChangeFeedStartFromNowImpl.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ public ChangeFeedStartFromNowImpl() {
1616

1717
@Override
1818
public void populatePropertyBag() {
19-
super.populatePropertyBag();
20-
21-
setProperty(
22-
this,
23-
Constants.Properties.CHANGE_FEED_START_FROM_TYPE,
24-
ChangeFeedStartFromTypes.NOW);
19+
20+
super.populatePropertyBag();
21+
22+
synchronized(this) {
23+
setProperty(
24+
this,
25+
Constants.Properties.CHANGE_FEED_START_FROM_TYPE,
26+
ChangeFeedStartFromTypes.NOW);
27+
}
2528
}
2629

2730
@Override

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/implementation/ChangeFeedStartFromPointInTimeImpl.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,17 @@ public void populatePropertyBag() {
4949

5050
super.populatePropertyBag();
5151

52-
setProperty(
53-
this,
54-
com.azure.cosmos.implementation.Constants.Properties.CHANGE_FEED_START_FROM_TYPE,
55-
ChangeFeedStartFromTypes.POINT_IN_TIME);
56-
57-
setProperty(
58-
this,
59-
Constants.Properties.CHANGE_FEED_START_FROM_POINT_IN_TIME_MS,
60-
this.pointInTime.toEpochMilli());
52+
synchronized(this) {
53+
setProperty(
54+
this,
55+
com.azure.cosmos.implementation.Constants.Properties.CHANGE_FEED_START_FROM_TYPE,
56+
ChangeFeedStartFromTypes.POINT_IN_TIME);
57+
58+
setProperty(
59+
this,
60+
Constants.Properties.CHANGE_FEED_START_FROM_POINT_IN_TIME_MS,
61+
this.pointInTime.toEpochMilli());
62+
}
6163
}
6264

6365
@Override

0 commit comments

Comments
 (0)