-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support customization of both document id and partition key for Cosmo…
…s DB grain persistence
- Loading branch information
1 parent
b4ef03e
commit 774631d
Showing
6 changed files
with
94 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/Azure/Orleans.Persistence.Cosmos/DefaultDocumentIdProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using static Orleans.Persistence.Cosmos.CosmosIdSanitizer; | ||
|
||
namespace Orleans.Persistence.Cosmos; | ||
|
||
/// <summary> | ||
/// The default implementation of <see cref="IDocumentIdProvider"/>. | ||
/// </summary> | ||
public sealed class DefaultDocumentIdProvider : IDocumentIdProvider | ||
{ | ||
private const string KEY_STRING_SEPARATOR = "__"; | ||
private readonly ClusterOptions _options; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DefaultDocumentIdProvider"/> class. | ||
/// </summary> | ||
/// <param name="options">The cluster options.</param> | ||
public DefaultDocumentIdProvider(IOptions<ClusterOptions> options) | ||
{ | ||
_options = options.Value; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public ValueTask<(string DocumentId, string PartitionKey)> GetDocumentId(string stateName, GrainId grainId) | ||
{ | ||
var documentId = $"{Sanitize(_options.ServiceId)}{KEY_STRING_SEPARATOR}{Sanitize(grainId.Type.ToString()!)}{SeparatorChar}{Sanitize(grainId.Key.ToString()!)}"; | ||
var partitionKey = Sanitize(stateName); | ||
return new((documentId, partitionKey)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/Azure/Orleans.Persistence.Cosmos/IDocumentIdProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Orleans.Persistence.Cosmos; | ||
|
||
/// <summary> | ||
/// Gets document and partition identifiers for grain state documents. | ||
/// </summary> | ||
public interface IDocumentIdProvider | ||
{ | ||
/// <summary> | ||
/// Gets the document identifier for the specified grain. | ||
/// </summary> | ||
/// <param name="stateName">The grain state name.</param> | ||
/// <param name="grainId">The grain identifier.</param> | ||
/// <returns>The document id and partition key.</returns> | ||
ValueTask<(string DocumentId, string PartitionKey)> GetDocumentId(string stateName, GrainId grainId); | ||
} |
20 changes: 0 additions & 20 deletions
20
src/Azure/Orleans.Persistence.Cosmos/IPartitionKeyProvider.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters