Skip to content

Commit 9876717

Browse files
Fixes for pr60 (#66)
* Fix some things that were not caught in #60 now that it's rebased on a 'main' that can build and run tests. * Update docs to match changes.
1 parent 6bbd98d commit 9876717

File tree

7 files changed

+80
-105
lines changed

7 files changed

+80
-105
lines changed

Readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,12 @@ The specific settings available for the new session state module and providers a
3434
- [Microsoft.AspNet.SessionState.SessionStateModule](docs/SessionStateModule.md)
3535
- [Microsoft.AspNet.SessionState.SqlSessionStateProviderAsync](docs/SqlSessionStateProviderAsync.md)
3636
- [Microsoft.AspNet.SessionState.CosmosDBSessionStateProviderAsync](docs/CosmosDBSessionStateProviderAsync.md)
37+
38+
<a name="updates"></a>
39+
## V1.2 Updates:
40+
* :warning: ***Breaking Change*** - CosmosDB partition-related parameters are ignored. All containers use `/id` as the partition path now. Using an existing container with a different partition key path will result in exceptions.
41+
> The original design around partition use in the CosmosDB provider was influenced by experience with the older SQL partition paradigms. There was an effort to enable them for scalability, but keep them reasonable for managability. In reality, CosmosDB encourages the use of as many "logical" partitions as can be used so long as they make sense. The complexity of managing and scaling is all handled magically by CosmosDB.
42+
>
43+
> The most logical partition field for session state is the session ID. The CosmosDB provider has been updated to alway use `"/id"` as the partition key path with the full session ID as the partition value. Pre-existing containers that use a different partition key path (which is any that opted into using partitions previously) will need to migrate to a container that uses `"/id"` as the partition key path. The data is all still good - although, the old partition key path can be dropped when migrating. There is unfortunately no way to simply update the partition key path on an existing container right now. [This blog post](https://devblogs.microsoft.com/cosmosdb/how-to-change-your-partition-key/) is a guide for migrating to a new container with the correct partition key path.
44+
* CosmosDB `collectionId` is now `containerId` in keeping with the updated terminology from the CosmosDB offering. Please use the updated parameter name when configuring your provider. (The old name will continue to work just the same.)
45+
* CosmosDB `connectionProtocol` is obsolete. It will not cause errors to have it in configuration, but it is ignored. The current [CosmosDB SDK chooses the protocol based on connection mode](https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/sdk-connection-modes).

docs/CosmosDBSessionStateProviderAsync.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ Then, register your new provider like so:
88
<sessionState cookieless="false" regenerateExpiredSessionId="true" mode="Custom" customProvider="CosmosDBSessionStateProviderAsync">
99
<providers>
1010
<add name="CosmosDBSessionStateProviderAsync" cosmosDBEndPointSettingKey="cosmosDBEndPointSetting" cosmosDBAuthKeySettingKey="cosmosDBAuthKeySetting"
11-
databaseId="[DataBaseId]" collectionId="[CollectionId]" offerThroughput="5000" connectionMode="Direct" connectionProtocol="Tcp" requestTimeout="5"
12-
maxConnectionLimit="50" maxRetryAttemptsOnThrottledRequests="10" maxRetryWaitTimeInSeconds="10" preferredLocations="" partitionKeyPath="pKey"
13-
partitionNumUsedByProvider="*"
11+
databaseId="[DataBaseId]" collectionId="[CollectionId]" offerThroughput="5000" connectionMode="Direct" requestTimeout="5"
12+
maxConnectionLimit="50" maxRetryAttemptsOnThrottledRequests="10" maxRetryWaitTimeInSeconds="10" preferredLocations=""
1413
type="Microsoft.AspNet.SessionState.CosmosDBSessionStateProviderAsync, Microsoft.AspNet.SessionState.CosmosDBSessionStateProviderAsync, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
1514
</providers>
1615
</sessionState>
@@ -27,18 +26,12 @@ Then, register your new provider like so:
2726

2827
4. *connectionMode* - Direct | Gateway
2928

30-
5. *connectionProtocol* - Https | Tcp
29+
5. *requestTimeout* - The request timeout in seconds when connecting to the Azure DocumentDB database service.
3130

32-
6. *requestTimeout* - The request timeout in seconds when connecting to the Azure DocumentDB database service.
31+
6. *maxConnectionLimit* - maximum number of concurrent connections allowed for the target service endpoint in the Azure DocumentDB database service.
3332

34-
7. *maxConnectionLimit* - maximum number of concurrent connections allowed for the target service endpoint in the Azure DocumentDB database service.
33+
7. *maxRetryAttemptsOnThrottledRequests* - the maximum number of retries in the case where the request fails because the Azure DocumentDB database service has applied rate limiting on the client.
3534

36-
8. *maxRetryAttemptsOnThrottledRequests* - the maximum number of retries in the case where the request fails because the Azure DocumentDB database service has applied rate limiting on the client.
35+
8. *maxRetryWaitTimeInSeconds* - The maximum retry time in seconds for the Azure DocumentDB database service.
3736

38-
9. *maxRetryWaitTimeInSeconds* - The maximum retry time in seconds for the Azure DocumentDB database service.
39-
40-
10. *preferredLocations* - Sets the preferred locations(regions) for geo-replicated database accounts in the Azure DocumentDB database service. Use ';' to split multiple locations. e.g. "East US;South Central US;North Europe"
41-
42-
11. *partitionKeyPath* - The name of the key to use for logically partitioning the collection. This key name should be different from 'id' unless "wildcard" partitioning is being used.
43-
44-
12. *partitionNumUsedByProvider* - The number of partition can be used for sessionstate. This was designed with the thought that multiple Cosmos partitions would be an extra cost. CosmosDB as it stands today encourages as many diverse logical partitions as you can imagine, as more partitions allow for better horizontal scaling. Setting this to an integer value will effectively reduce the partition count to 32 or less, even if the specified value is much greater. This is a result of how session ID's were translated to partition ID's by this provider. ***It is now recommended to specify "\*" for this option if possible.*** This will reuse the full session ID for partitioning, allowing Cosmos maximum ability for horizontal scaling.
37+
9. *preferredLocations* - Sets the preferred locations(regions) for geo-replicated database accounts in the Azure DocumentDB database service. Use ';' to split multiple locations. e.g. "East US;South Central US;North Europe"

src/CosmosDBSessionStateProviderAsync/CosmosDBSessionStateProviderAsync.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class CosmosDBSessionStateProviderAsync : SessionStateStoreProviderAsyncB
4646
};
4747

4848
#region CosmosDB Stored Procedures
49-
private static readonly string CreateSessionStateItemSPID = "CreateSessionStateItemInPartition";
49+
private static readonly string CreateSessionStateItemSPID = "CreateSessionStateItem";
5050
private static readonly string GetStateItemSPID = "GetStateItem";
5151
private static readonly string GetStateItemExclusiveSPID = "GetStateItemExclusive";
5252
private static readonly string ReleaseItemExclusiveSPID = "ReleaseItemExclusive";
@@ -801,7 +801,7 @@ internal static void ParseCosmosDbEndPointSettings(NameValueCollection providerC
801801
if (string.IsNullOrEmpty(s_containerId))
802802
{
803803
s_containerId = providerConfig["collectionId"];
804-
if (string.IsNullOrEmpty(s_collectionId))
804+
if (string.IsNullOrEmpty(s_containerId))
805805
{
806806
throw new ConfigurationErrorsException(string.Format(SR.EmptyConfig_WithName, "containerId"));
807807
}
@@ -889,7 +889,7 @@ private static async Task CreateContainerIfNotExistsAsync()
889889

890890
ContainerResponse response = await database.CreateContainerIfNotExistsAsync(containerProperties, s_offerThroughput).ConfigureAwait(false);
891891

892-
if (response.Resource?.PartitionKeyPath != partitionKeyPath)
892+
if (response?.Resource?.PartitionKeyPath != partitionKeyPath)
893893
{
894894
throw new Exception(String.Format(CultureInfo.CurrentCulture, SR.Container_PKey_Does_Not_Match, s_containerId, partitionKeyPath));
895895
}

src/CosmosDBSessionStateProviderAsync/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
// The following GUID is for the ID of the typelib if this project is exposed to COM
2626
[assembly: Guid("4cfb2896-d5c1-4e96-a3da-d57c58539209")]
2727
[assembly: InternalsVisibleTo("Microsoft.AspNet.SessionState.CosmosDBSessionStateProviderAsync.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
28-
28+
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]

src/CosmosDBSessionStateProviderAsync/Resources/SR.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/packages/CosmosDBSessionStateProviderAsync.nupkg/content/Net462/web.config.install.xdt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
offerThroughput: The offer throughput provisioned for a collection in measurement of Requests-per-Unit in the Azure DocumentDB database service.
2626
If the collection provided doesn't exist, the provider will create a collection with this offerThroughput.
2727
connectionMode: Direct | Gateway
28-
connectionProtocol: Https | Tcp
2928
requestTimeout: the request timeout in seconds when connecting to the Azure DocumentDB database service.
3029
maxConnectionLimit: maximum number of concurrent connections allowed for the target service endpoint in the Azure DocumentDB database service.
3130
maxRetryAttemptsOnThrottledRequests: the maximum number of retries in the case where the request fails because the Azure DocumentDB database service has applied rate limiting on the client.
@@ -34,8 +33,8 @@
3433
partitionKey: the partition key name of the collection
3534
partitionNumUsedByProvider: the number of partition can be used for sessionstate
3635
-->
37-
<add name="CosmosDBSessionStateProviderAsync" cosmosDBEndPointSettingKey="cosmosDBEndPointSetting" cosmosDBAuthKeySettingKey="cosmosDBAuthKeySetting" databaseId="[DataBaseId]" collectionId="[CollectionId]" offerThroughput="5000"
38-
connectionMode="Direct" connectionProtocol="Tcp" requestTimeout="5" maxConnectionLimit="50" maxRetryAttemptsOnThrottledRequests="10" maxRetryWaitTimeInSeconds="10" preferredLocations="" partitionKey="" partitionNumUsedByProvider=""
36+
<add name="CosmosDBSessionStateProviderAsync" cosmosDBEndPointSettingKey="cosmosDBEndPointSetting" cosmosDBAuthKeySettingKey="cosmosDBAuthKeySetting" databaseId="[DataBaseId]" containerId="[ContainerId]" offerThroughput="5000"
37+
connectionMode="Direct" requestTimeout="5" maxConnectionLimit="50" maxRetryAttemptsOnThrottledRequests="10" maxRetryWaitTimeInSeconds="10" preferredLocations=""
3938
type="Microsoft.AspNet.SessionState.CosmosDBSessionStateProviderAsync, Microsoft.AspNet.SessionState.CosmosDBSessionStateProviderAsync, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
4039
xdt:Transform="InsertIfMissing" />
4140
</providers>

0 commit comments

Comments
 (0)