GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||
GeezerVison is showing github.com — feat(cosmos): support custom document IDs and partition keys by ReubenBond · Pull Request #8699 · dotnet/orleans Conversation
|
|
@ReubenBond, Looking ahead at the capabilities for the Microsoft.Extensions.Configuration support you implemented in #9204 should this PR include the ability to configure the type to call from DI for the IDocumentIdProvider of a given provider when configuring via IConfiguration? The wiring might not be there yet but should the configuration value be present on the CosmosGrainStorageOptions class? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This PR updates the Orleans Cosmos DB grain storage provider to support customizing both the document id and partition key via a new IDocumentIdProvider, replacing the prior partition-key-only abstraction (IPartitionKeyProvider) as a breaking change.
Changes:
IPartitionKeyProvider with IDocumentIdProvider and introduced DefaultDocumentIdProvider.CosmosGrainStorage to use the new provider for id/partition key generation and adjusted clear-state behavior.| File | Description |
|---|---|
| test/Extensions/Tester.Cosmos/PersistenceProviderTests_Cosmos.cs | Updates test setup to construct storage using DefaultDocumentIdProvider. |
| src/Azure/Orleans.Persistence.Cosmos/IPartitionKeyProvider.cs | Removes the old partition-key-only provider interface and default implementation. |
| src/Azure/Orleans.Persistence.Cosmos/IDocumentIdProvider.cs | Adds the new interface for generating document ids and partition keys. |
| src/Azure/Orleans.Persistence.Cosmos/HostingExtensions.cs | Switches DI wiring from partition key provider to document id provider and updates extension methods. |
| src/Azure/Orleans.Persistence.Cosmos/DefaultDocumentIdProvider.cs | Adds the default implementation for document id + partition key generation. |
| src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs | Uses IDocumentIdProvider for read/write/clear and updates legacy /GrainType compatibility checks. |
src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs:369
if (_partitionKeyPath == GRAINTYPE_PARTITION_KEY_PATH &&
_documentIdProvider is not DefaultDocumentIdProvider)
src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs:370
if (_partitionKeyPath == GRAINTYPE_PARTITION_KEY_PATH &&
_documentIdProvider is not DefaultDocumentIdProvider)
throw new OrleansConfigurationException("Custom partition key provider is not compatible with partition key path set to /GrainType");
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
…s DB grain persistence
Co-authored-by: Copilot App <[email protected]> Copilot-Session: e82f060d-d09b-42f9-8b0f-34da38b386fa
7991079 to
7d3abdd
Compare
Co-authored-by: Copilot App <[email protected]> Copilot-Session: e82f060d-d09b-42f9-8b0f-34da38b386fa
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs:178
{
try
src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs:202
await _executor.ExecuteOperation(static args =>
{
var (self, id, pk, requestOptions) = args;
return self._container.DeleteItemAsync<GrainStateEntity<T>>(id, pk, requestOptions);
src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs:168
This issue also appears in the following locations of the same file:
public async Task ClearStateAsync<T>(string grainType, GrainId grainId, IGrainState<T> grainState)
{
var (id, partitionKey) = await _documentIdProvider.GetDocumentIdentifiers(grainType, grainId);
LogTraceClearingState(grainType, id, grainId, grainState.ETag, _options.DeleteStateOnClear, _options.ContainerName, partitionKey);
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs:333
if (_partitionKeyPath == GRAINTYPE_PARTITION_KEY_PATH &&
(_documentIdProvider is not DefaultDocumentIdProvider defaultProvider || defaultProvider.HasCustomPartitionKeyProvider))
throw new OrleansConfigurationException("Custom document id or partition key providers are not compatible with partition key path set to /GrainType");
src/Azure/Orleans.Persistence.Cosmos/HostingExtensions.cs:40
class), so invalid types compile and fail only at runtime via AddIdentifierProvider. Consider adding a new constrained generic overload for IDocumentIdProvider and keeping legacy IPartitionKeyProvider-based overloads as [Obsolete] to preserve compile-time safety for the primary API. public static ISiloBuilder AddCosmosGrainStorageAsDefault<TProvider>(
this ISiloBuilder builder,
Action<CosmosGrainStorageOptions> configureOptions) where TProvider : class
{
return builder.AddCosmosGrainStorage<TProvider>(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME, configureOptions);
}
/// <summary>
/// Configure silo to use Azure Cosmos DB storage for grain storage using a custom document id provider
/// or a legacy partition key provider.
/// </summary>
/// <typeparam name="TProvider">The document id or partition key provider.</typeparam>
/// <param name="builder">The silo builder.</param>
/// <param name="name">The storage provider name.</param>
/// <param name="configureOptions">The delegate used to configure the provider.</param>
public static ISiloBuilder AddCosmosGrainStorage<TProvider>(
this ISiloBuilder builder,
string name,
Action<CosmosGrainStorageOptions> configureOptions) where TProvider : class
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Copilot App <[email protected]> Copilot-Session: e82f060d-d09b-42f9-8b0f-34da38b386fa
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs:333
Either relax this restriction for custom IDocumentIdProvider implementations, or validate/enforce that the returned partition key matches grainType when PartitionKeyPath is "/GrainType" (and update the exception message accordingly).
if (_partitionKeyPath == GRAINTYPE_PARTITION_KEY_PATH &&
(_documentIdProvider is not DefaultDocumentIdProvider defaultProvider || defaultProvider.HasCustomPartitionKeyProvider))
throw new OrleansConfigurationException("Custom document id or partition key providers are not compatible with partition key path set to /GrainType");
src/Azure/Orleans.Persistence.Cosmos/HostingExtensions.cs:26
Consider restoring compile-time safety by splitting into two overloads (one constrained to IDocumentIdProvider, plus an [Obsolete] overload constrained to IPartitionKeyProvider for legacy), or introducing a shared marker interface. This will require regenerating the API surface file.
public static ISiloBuilder AddCosmosGrainStorageAsDefault<TProvider>(
this ISiloBuilder builder,
Action<CosmosGrainStorageOptions> configureOptions) where TProvider : class
{
return builder.AddCosmosGrainStorage<TProvider>(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME, configureOptions);
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@OmnipotentOwl Addressed in #10326. Configuration now accepts |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.