Skip to content

Commit 853e973

Browse files
xinlian12annie-mac
andauthored
FixDefaultThroughputControlGroupWithTargetThroughput (Azure#34393)
* fix throughput control on default group when using target throughput --------- Co-authored-by: annie-mac <[email protected]>
1 parent 83cd9ee commit 853e973

File tree

6 files changed

+47
-2
lines changed

6 files changed

+47
-2
lines changed

sdk/cosmos/azure-cosmos-spark_3-1_2-12/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#### Breaking Changes
88

99
#### Bugs Fixed
10+
* Fixed an issue where throughput control is not triggered properly when `spark.cosmos.throughputControl.targetThroughput` is being used - See [PR 34393](https://github.com/Azure/azure-sdk-for-java/pull/34393)
1011

1112
#### Other Changes
1213

sdk/cosmos/azure-cosmos-spark_3-2_2-12/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#### Breaking Changes
88

99
#### Bugs Fixed
10+
* Fixed an issue where throughput control is not triggered properly when `spark.cosmos.throughputControl.targetThroughput` is being used - See [PR 34393](https://github.com/Azure/azure-sdk-for-java/pull/34393)
1011

1112
#### Other Changes
1213

sdk/cosmos/azure-cosmos-spark_3-3_2-12/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#### Breaking Changes
88

99
#### Bugs Fixed
10+
* Fixed an issue where throughput control is not triggered properly when `spark.cosmos.throughputControl.targetThroughput` is being used - See [PR 34393](https://github.com/Azure/azure-sdk-for-java/pull/34393)
1011

1112
#### Other Changes
1213

sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/throughputControl/ThroughputControlTests.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static Object[][] allowRequestToContinueOnInitErrorProvider() {
8989
}
9090

9191
@Test(groups = {"emulator"}, dataProvider = "operationTypeProvider", timeOut = TIMEOUT)
92-
public void throughputLocalControl(OperationType operationType) {
92+
public void throughputLocalControl_requestOptions(OperationType operationType) {
9393
this.ensureContainer();
9494
// The create document in this test usually takes around 6.29RU, pick a RU here relatively close, so to test throttled scenario
9595
ThroughputControlGroupConfig groupConfig =
@@ -116,6 +116,46 @@ public void throughputLocalControl(OperationType operationType) {
116116
BridgeInternal.getContextClient(client).getConnectionPolicy().getConnectionMode());
117117
}
118118

119+
@Test(groups = {"emulator"}, dataProvider = "operationTypeProvider", timeOut = TIMEOUT)
120+
public void throughputLocalControl_default(OperationType operationType) {
121+
this.ensureContainer();
122+
123+
CosmosAsyncClient client = null;
124+
try {
125+
client = new CosmosClientBuilder()
126+
.endpoint(TestConfigurations.HOST)
127+
.key(TestConfigurations.MASTER_KEY)
128+
.contentResponseOnWriteEnabled(true)
129+
.buildAsyncClient();
130+
131+
CosmosAsyncContainer testContainer = client.getDatabase(database.getId()).getContainer(container.getId());
132+
// The create document in this test usually takes around 6.29RU, pick a RU here relatively close, so to test throttled scenario
133+
ThroughputControlGroupConfig groupConfig =
134+
new ThroughputControlGroupConfigBuilder()
135+
.groupName("group-" + UUID.randomUUID())
136+
.targetThroughput(6)
137+
.defaultControlGroup(true)
138+
.build();
139+
testContainer.enableLocalThroughputControlGroup(groupConfig);
140+
141+
CosmosItemResponse<TestItem> createItemResponse = testContainer.createItem(getDocumentDefinition()).block();
142+
TestItem createdItem = createItemResponse.getItem();
143+
this.validateRequestNotThrottled(
144+
createItemResponse.getDiagnostics().toString(),
145+
BridgeInternal.getContextClient(client).getConnectionPolicy().getConnectionMode());
146+
147+
// second request to group-1. which will get throttled
148+
CosmosDiagnostics cosmosDiagnostics = performDocumentOperation(testContainer, operationType, createdItem, groupConfig.getGroupName());
149+
this.validateRequestThrottled(
150+
cosmosDiagnostics.toString(),
151+
BridgeInternal.getContextClient(client).getConnectionPolicy().getConnectionMode());
152+
} finally {
153+
if (client != null) {
154+
client.close();
155+
}
156+
}
157+
}
158+
119159
@Test(groups = {"emulator"}, timeOut = TIMEOUT)
120160
public void throughputLocalControlWithThroughputQuery() {
121161
// Will need to use a new client here to make sure the throughput query mono will be passed down to throughputContainerController

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#### Breaking Changes
88

99
#### Bugs Fixed
10+
* Fixed an issue where throughput control is not triggered properly when target throughput is being used - See [PR 34393](https://github.com/Azure/azure-sdk-for-java/pull/34393)
1011

1112
#### Other Changes
1213

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/throughputControl/controller/container/ThroughputContainerController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ private Mono<ThroughputContainerController> resolveContainerMaxThroughput() {
177177
.flatMap(maxThroughput -> {
178178
this.maxContainerThroughput.set(maxThroughput);
179179
return Mono.just(this);
180-
});
180+
})
181+
.switchIfEmpty(Mono.just(this));
181182
}
182183

183184
private Mono<Integer> resolveContainerMaxThroughputCore() {

0 commit comments

Comments
 (0)