Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThroughputControl-Global #19183

Merged
merged 73 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
0b5ef5e
fix requestTimeline
Dec 1, 2020
86d7521
clean
Dec 1, 2020
e4f60d4
resolve comments
Dec 1, 2020
77cfb0b
something works
Dec 18, 2020
3ad3e00
Merge branch 'master' into ThroughputControlDraft
Jan 4, 2021
f6b3447
Squashed commit of the following:
Jan 6, 2021
c3e5bc5
revert back some unrelated change
Jan 6, 2021
e7dd70c
clean
Jan 6, 2021
833981b
resolve compilation failure
Jan 6, 2021
fdb144b
resolve some comments
Jan 11, 2021
37c4f21
Merge branch 'master' into ThroughputControl-Local
Jan 11, 2021
eb8a709
merge master and resolve conflicts
Jan 15, 2021
2b365e1
track throughput usage per region
Jan 17, 2021
d72f169
clean some code
Jan 20, 2021
8675381
resolve comments
Jan 23, 2021
cbdc812
enable throughput control for CosmosClient
Jan 23, 2021
15ecac2
merge and resolve conflicts
Jan 27, 2021
2e8856b
clean code
Jan 27, 2021
e6fa22b
some cleaning
Jan 28, 2021
48be906
merge master and resolve
Jan 28, 2021
c0c6b71
clean and resolve comemnts
Jan 28, 2021
b7a183f
resolve compilation issue
Jan 28, 2021
10cdaba
resolve comments
Jan 28, 2021
89031cc
resolve comments
Jan 29, 2021
11d1f27
fix tests
Jan 29, 2021
1216900
fix tests
Jan 29, 2021
3234d04
resolve comments
Jan 30, 2021
7b1e3bf
add more unit tests
Feb 1, 2021
1d6a436
resolve comments
Feb 2, 2021
5bd6270
resolve comments and refactor
Feb 2, 2021
d33f201
Merge branch 'master' into ThroughputControl-Local
Feb 2, 2021
c59b709
fix tests
Feb 2, 2021
3e739a1
add commit
Feb 3, 2021
997e1e5
Merge branch 'master' into ThroughputControl-Local
Feb 3, 2021
0893f5f
fix javadoc
Feb 3, 2021
cb058c9
move ThroughputControlMode to implementation
Feb 3, 2021
420e00e
fix tests
Feb 4, 2021
935f60f
Throughput global control:
Feb 8, 2021
7839bcf
update beta version to 4.13
Feb 8, 2021
4534b8a
Merge branch 'master' into ThroughputControl-Local
Feb 9, 2021
7c04370
Merge branch 'master' into ThroughputControl-Global
Feb 9, 2021
14ff524
Merge branch 'ThroughputControl-Local' into ThroughputControl-Global
Feb 9, 2021
0870b18
Merge branch 'master' into ThroughputControl-Global
Feb 10, 2021
698ecae
Merge branch 'master' into ThroughputControl-Local
Feb 10, 2021
11b3c87
update beta version to 4.13.0
Feb 10, 2021
e363ba6
merge from throughputControl-Local and resolve conflicts
Feb 10, 2021
1aa4419
merge master and resolve conflicts
Feb 11, 2021
db0a330
refactor tests
Feb 11, 2021
18eee2a
clean
Feb 11, 2021
67b5b70
several code change to help improve perf
Feb 11, 2021
166fbef
fix
Feb 11, 2021
3dfc69d
several fixes
Feb 11, 2021
6878657
fix
Feb 11, 2021
e27e670
hide ThroughputControlGroupInternal from public surface
Feb 11, 2021
b159122
resolve comments, add tests for query
Feb 16, 2021
dbe5cbc
resolve comments
Feb 16, 2021
86f9823
refactor, resolve comments
Feb 17, 2021
12a215e
refactor
Feb 17, 2021
63234e1
Merge branch 'master' into ThroughputControl-Global
Feb 24, 2021
cffb40e
resolve comments and fix
Feb 25, 2021
d4b7a3f
merge and resolve conflicts
Feb 25, 2021
3204a3c
add allocatedThroughput for clientItem
Feb 25, 2021
9a8051d
add code snippet for throughput control
Feb 26, 2021
dda3655
fix
Feb 26, 2021
3bd7bdc
add LinkedCancellationTokenSource
Feb 26, 2021
6ea4241
clean
Feb 26, 2021
9a228f1
fix tests
Feb 26, 2021
8a6e547
fixTest
Feb 26, 2021
6f4bd1f
resolve comments
Feb 27, 2021
a1ea366
resolve comments
Feb 27, 2021
8a0ed91
Merge branch 'master' into ThroughputControl-Global
Feb 27, 2021
a9b8683
Merge branch 'master' into ThroughputControl-Global
Mar 2, 2021
39711df
disable throughput control for gateway, remove region concept
Mar 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sdk/cosmos/azure-cosmos-spark_3-0_2-12/scalastyle-output.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="5.0">

</checkstyle>
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import com.azure.cosmos.implementation.query.QueryInfo;
import com.azure.cosmos.implementation.query.metrics.ClientSideMetrics;
import com.azure.cosmos.implementation.routing.PartitionKeyInternal;
import com.azure.cosmos.implementation.throughputControl.ThroughputControlMode;
import com.azure.cosmos.models.CosmosItemResponse;
import com.azure.cosmos.models.CosmosStoredProcedureProperties;
import com.azure.cosmos.models.FeedResponse;
Expand Down Expand Up @@ -796,18 +795,13 @@ public static List<PatchOperation> getPatchOperationsFromCosmosPatch(CosmosPatch
return cosmosPatchOperations.getPatchOperations();
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
public static ThroughputControlMode getThroughputControlMode(ThroughputControlGroup throughputControlGroup) {
return throughputControlGroup.getControlMode();
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
public static SqlQuerySpec getOfferQuerySpecFromResourceId(CosmosAsyncContainer container, String resourceId) {
return container.getDatabase().getOfferQuerySpecFromResourceId(resourceId);
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
public static CosmosAsyncContainer getTargetContainerFromThroughputControlGroup(ThroughputControlGroup controlGroup) {
return controlGroup.getTargetContainer();
public static CosmosAsyncContainer getControlContainerFromThroughputGlobalControlConfig(GlobalThroughputControlConfig globalControlConfig) {
return globalControlConfig.getControlContainer();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.azure.cosmos.implementation.HttpConstants;
import com.azure.cosmos.implementation.TracerProvider;
import com.azure.cosmos.implementation.directconnectivity.rntbd.RntbdMetrics;
import com.azure.cosmos.implementation.throughputControl.config.ThroughputControlGroupInternal;
import com.azure.cosmos.models.CosmosDatabaseProperties;
import com.azure.cosmos.models.CosmosDatabaseRequestOptions;
import com.azure.cosmos.models.CosmosDatabaseResponse;
Expand All @@ -23,6 +24,7 @@
import com.azure.cosmos.models.ModelBridgeInternal;
import com.azure.cosmos.models.SqlQuerySpec;
import com.azure.cosmos.models.ThroughputProperties;
import com.azure.cosmos.util.Beta;
import com.azure.cosmos.util.CosmosPagedFlux;
import com.azure.cosmos.util.UtilBridgeInternal;
import io.micrometer.core.instrument.MeterRegistry;
Expand Down Expand Up @@ -471,11 +473,23 @@ TracerProvider getTracerProvider(){
*
* @param group Throughput control group going to be enabled.
*/
void enableThroughputControlGroup(ThroughputControlGroup group) {
void enableThroughputControlGroup(ThroughputControlGroupInternal group) {
checkNotNull(group, "Throughput control group cannot be null");
this.asyncDocumentClient.enableThroughputControlGroup(group);
}

/**
* Create global throughput control config builder which will be used to build {@link GlobalThroughputControlConfig}.
*
* @param databaseId The database id of the control container.
* @param containerId The container id of the control container.
* @return A {@link GlobalThroughputControlConfigBuilder}.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public GlobalThroughputControlConfigBuilder createGlobalThroughputControlConfigBuilder(String databaseId, String containerId) {
return new GlobalThroughputControlConfigBuilder(this, databaseId, containerId);
}

private CosmosPagedFlux<CosmosDatabaseProperties> queryDatabasesInternal(SqlQuerySpec querySpec, CosmosQueryRequestOptions options){
return UtilBridgeInternal.createCosmosPagedFlux(pagedFluxOptions -> {
pagedFluxOptions.setTracerInformation(this.tracerProvider, "queryDatabases", this.serviceEndpoint, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import com.azure.cosmos.implementation.batch.BatchExecutor;
import com.azure.cosmos.implementation.batch.BulkExecutor;
import com.azure.cosmos.implementation.query.QueryInfo;
import com.azure.cosmos.implementation.throughputControl.ThroughputControlMode;
import com.azure.cosmos.implementation.throughputControl.config.ThroughputControlGroupFactory;
import com.azure.cosmos.implementation.throughputControl.config.ThroughputGlobalControlGroup;
import com.azure.cosmos.implementation.throughputControl.config.ThroughputLocalControlGroup;
import com.azure.cosmos.models.CosmosChangeFeedRequestOptions;
import com.azure.cosmos.models.CosmosConflictProperties;
import com.azure.cosmos.models.CosmosContainerProperties;
Expand Down Expand Up @@ -51,7 +53,6 @@
import static com.azure.core.util.FluxUtil.withContext;
import static com.azure.cosmos.implementation.Utils.getEffectiveCosmosChangeFeedRequestOptions;
import static com.azure.cosmos.implementation.Utils.setContinuationTokenAndMaxItemCount;
import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkArgument;
import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull;

/**
Expand Down Expand Up @@ -1436,65 +1437,35 @@ public Mono<List<FeedRange>> getFeedRanges() {
}

/**
* Enable the throughput control group with local control mode.
*
* @param groupName The throughput control group name.
* @param targetThroughput The target throughput for the control group.
* {@codesnippet com.azure.cosmos.throughputControl.localControl}
*
* @return A {@link ThroughputControlGroup}.
* @param groupConfig A {@link ThroughputControlGroupConfig}.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
ThroughputControlGroup enableThroughputLocalControlGroup(String groupName, int targetThroughput) {
return this.enableThroughputLocalControlGroup(groupName, targetThroughput, false);
public void enableLocalThroughputControlGroup(ThroughputControlGroupConfig groupConfig) {
ThroughputLocalControlGroup localControlGroup = ThroughputControlGroupFactory.createThroughputLocalControlGroup(groupConfig, this);
this.database.getClient().enableThroughputControlGroup(localControlGroup);
}

/**
* Enable the throughput control group with global control mode.
* The defined throughput limit will be shared across different clients.
*
* @param groupName The throughput control group name.
* @param targetThroughput The target throughput for the control group.
* @param isDefault Flag to indicate whether this group will be used as default.
* {@codesnippet com.azure.cosmos.throughputControl.globalControl}
*
* @return A {@link ThroughputControlGroup}.
* @param groupConfig The throughput control group configuration, see {@link ThroughputGlobalControlGroup}.
* @param globalControlConfig The global throughput control configuration, see {@link GlobalThroughputControlConfig}.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
ThroughputControlGroup enableThroughputLocalControlGroup(String groupName, int targetThroughput, boolean isDefault) {
return this.enableThroughputControlGroup(groupName, targetThroughput, null, ThroughputControlMode.LOCAL, isDefault);
}

/**
*
* @param groupName The throughput control group name.
* @param targetThroughputThreshold The target throughput threshold for the control group.
*
* @return A {@link ThroughputControlGroup}.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
ThroughputControlGroup enableThroughputLocalControlGroup(String groupName, double targetThroughputThreshold) {
return this.enableThroughputLocalControlGroup(groupName, targetThroughputThreshold, false);
}

/**
*
* @param groupName The throughput control group name.
* @param targetThroughputThreshold The target throughput threshold for the control group.
* @param isDefault Flag to indicate whether this group will be used as default.
* @return A {@link ThroughputControlGroup}.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
ThroughputControlGroup enableThroughputLocalControlGroup(String groupName, double targetThroughputThreshold, boolean isDefault) {
return this.enableThroughputControlGroup(groupName, null, targetThroughputThreshold, ThroughputControlMode.LOCAL, isDefault);
}

private ThroughputControlGroup enableThroughputControlGroup(
String groupName,
Integer targetThroughput,
Double targetThroughputThreshold,
ThroughputControlMode controlMode,
boolean isDefault) {
public void enableGlobalThroughputControlGroup(
ThroughputControlGroupConfig groupConfig,
GlobalThroughputControlConfig globalControlConfig) {

ThroughputControlGroup throughputControlGroup = new ThroughputControlGroup(
groupName, this, targetThroughput, targetThroughputThreshold, controlMode, isDefault);
this.database.getClient().enableThroughputControlGroup(throughputControlGroup);
ThroughputGlobalControlGroup globalControlGroup =
ThroughputControlGroupFactory.createThroughputGlobalControlGroup(groupConfig, globalControlConfig, this);

return throughputControlGroup;
this.database.getClient().enableThroughputControlGroup(globalControlGroup);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.azure.cosmos.models.CosmosQueryRequestOptions;
import com.azure.cosmos.models.SqlQuerySpec;
import com.azure.cosmos.models.ThroughputProperties;
import com.azure.cosmos.util.Beta;
import com.azure.cosmos.util.CosmosPagedFlux;
import com.azure.cosmos.util.CosmosPagedIterable;
import com.azure.cosmos.util.UtilBridgeInternal;
Expand Down Expand Up @@ -213,4 +214,16 @@ public void close() {
private <T> CosmosPagedIterable<T> getCosmosPagedIterable(CosmosPagedFlux<T> cosmosPagedFlux) {
return UtilBridgeInternal.createCosmosPagedIterable(cosmosPagedFlux);
}

/**
* Create global throughput control config builder which will be used to build {@link GlobalThroughputControlConfig}.
*
* @param databaseId The database id of the control container.
* @param containerId The container id of the control container.
* @return A {@link GlobalThroughputControlConfigBuilder}.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public GlobalThroughputControlConfigBuilder createGlobalThroughputControlConfigBuilder(String databaseId, String containerId) {
return new GlobalThroughputControlConfigBuilder(this.asyncClientWrapper, databaseId, containerId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.cosmos;

import com.azure.cosmos.implementation.throughputControl.config.ThroughputGlobalControlGroup;
import com.azure.cosmos.models.CosmosChangeFeedRequestOptions;
import com.azure.cosmos.models.CosmosItemIdentity;
import com.azure.cosmos.models.CosmosItemResponse;
Expand Down Expand Up @@ -744,52 +745,28 @@ public List<FeedRange> getFeedRanges() {
}

/**
* Enable the throughput control group with local control mode.
*
* @param groupName The throughput control group name.
* @param targetThroughput The target throughput for the control group.
* {@codesnippet com.azure.cosmos.throughputControl.localControl}
*
* @return A {@link ThroughputControlGroup}.
* @param groupConfig A {@link GlobalThroughputControlConfig}.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
ThroughputControlGroup enableThroughputLocalControlGroup(String groupName, int targetThroughput) {
return this.asyncContainer.enableThroughputLocalControlGroup(groupName, targetThroughput);
public void enableLocalThroughputControlGroup(ThroughputControlGroupConfig groupConfig) {
this.asyncContainer.enableLocalThroughputControlGroup(groupConfig);
}

/**
* Enable the throughput control group with global control mode.
* The defined throughput limit will be shared across different clients.
*
* @param groupName The throughput control group name.
* @param targetThroughput The target throughput for the control group.
* @param isDefault Flag to indicate whether this group will be used as default.
* {@codesnippet com.azure.cosmos.throughputControl.globalControl}
*
* @return A {@link ThroughputControlGroup}.
* @param groupConfig The throughput control group configuration, see {@link ThroughputGlobalControlGroup}.
* @param globalControlConfig The global throughput control configuration, see {@link GlobalThroughputControlConfig}.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
ThroughputControlGroup enableThroughputLocalControlGroup(String groupName, int targetThroughput, boolean isDefault) {
return this.asyncContainer.enableThroughputLocalControlGroup(groupName, targetThroughput, isDefault);
}

/**
*
* @param groupName The throughput control group name.
* @param targetThroughputThreshold The target throughput threshold for the control group.
*
* @return A {@link ThroughputControlGroup}.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
ThroughputControlGroup enableThroughputLocalControlGroup(String groupName, double targetThroughputThreshold) {
return this.asyncContainer.enableThroughputLocalControlGroup(groupName, targetThroughputThreshold);
}

/**
*
* @param groupName The throughput control group name.
* @param targetThroughputThreshold The target throughput threshold for the control group.
* @param isDefault Flag to indicate whether this group will be used as default.
*
* @return A {@link ThroughputControlGroup}.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
ThroughputControlGroup enableThroughputLocalControlGroup(String groupName, double targetThroughputThreshold, boolean isDefault) {
return this.asyncContainer.enableThroughputLocalControlGroup(groupName, targetThroughputThreshold, isDefault);
public void enableGlobalThroughputControlGroup(ThroughputControlGroupConfig groupConfig, GlobalThroughputControlConfig globalControlConfig) {
this.asyncContainer.enableGlobalThroughputControlGroup(groupConfig, globalControlConfig);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos;

import com.azure.cosmos.util.Beta;

import java.time.Duration;

/**
* This configuration is used for throughput global control mode.
* It contains configuration about the extra container which will track all the clients throughput usage for a certain control group.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public class GlobalThroughputControlConfig {
private final CosmosAsyncContainer controlContainer;
private final Duration controlItemRenewInterval;
private final Duration controlItemExpireInterval;


GlobalThroughputControlConfig(
CosmosAsyncContainer controlContainer,
Duration controlItemRenewInterval,
Duration controlItemExpireInterval) {

this.controlContainer = controlContainer;
this.controlItemRenewInterval = controlItemRenewInterval;
this.controlItemExpireInterval = controlItemExpireInterval;
}

/**
* Get the control container.
* This is the container to track all other clients throughput usage.
*
* @return The {@link CosmosAsyncContainer}.
*/
CosmosAsyncContainer getControlContainer() {
return controlContainer;
}

/**
* Get the control item renew interval.
*
* This controls how often the client is going to update the throughput usage of itself
* and adjust its own throughput share based on the throughput usage of other clients.
*
* In short words, it controls how quickly the shared throughput will reload balanced across different clients.
*
* @return The control item renew interval.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public Duration getControlItemRenewInterval() {
return this.controlItemRenewInterval;
}

/**
* Get the control item expire interval.
*
* A client may be offline due to various reasons (being shutdown, network issue... ).
* This controls how quickly we will detect the client has been offline and hence allow its throughput share to be taken by other clients.
**
* @return The control item renew interval.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public Duration getControlItemExpireInterval() {
return this.controlItemExpireInterval;
}
}
Loading