From 2a02bf5bf5222338d915e182c3e01ad948826762 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Sat, 9 May 2026 07:51:47 -0700 Subject: [PATCH] Fix Cosmos indexing paths Use scalar and array terminal index paths in Cosmos indexing policies so newer emulator builds accept provider container creation. Keep grain state indexing opt-in by switching the persistence provider to an excluded-root policy with explicit metadata and configured state field includes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Membership/CosmosMembershipTable.cs | 18 +++++++++--------- .../CosmosGrainStorage.cs | 15 +++++++++++++-- .../CosmosReminderTable.cs | 4 ++-- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/Azure/Orleans.Clustering.Cosmos/Membership/CosmosMembershipTable.cs b/src/Azure/Orleans.Clustering.Cosmos/Membership/CosmosMembershipTable.cs index f27c7f512b5..bb2b9a46767 100644 --- a/src/Azure/Orleans.Clustering.Cosmos/Membership/CosmosMembershipTable.cs +++ b/src/Azure/Orleans.Clustering.Cosmos/Membership/CosmosMembershipTable.cs @@ -352,15 +352,15 @@ private async Task TryCreateCosmosResources() var containerProperties = new ContainerProperties(_options.ContainerName, PARTITION_KEY); containerProperties.IndexingPolicy.IndexingMode = IndexingMode.Consistent; containerProperties.IndexingPolicy.IncludedPaths.Add(new IncludedPath { Path = "/*" }); - containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/Address/*" }); - containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/Port/*" }); - containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/Generation/*" }); - containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/Hostname/*" }); - containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/SiloName/*" }); - containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/\"SuspectingSilos\"/*" }); - containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/\"SuspectingTimes\"/*" }); - containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/StartTime/*" }); - containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/IAmAliveTime/*" }); + containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/Address/?" }); + containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/Port/?" }); + containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/Generation/?" }); + containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/Hostname/?" }); + containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/SiloName/?" }); + containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/\"SuspectingSilos\"/[]/?" }); + containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/\"SuspectingTimes\"/[]/?" }); + containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/StartTime/?" }); + containerProperties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/IAmAliveTime/?" }); const int maxRetries = 3; for (var retry = 0; retry <= maxRetries; ++retry) diff --git a/src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs b/src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs index f21772e52cf..8ac4953a176 100644 --- a/src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs +++ b/src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs @@ -317,8 +317,9 @@ private async Task TryCreateResources() var stateContainer = new ContainerProperties(_options.ContainerName, _options.PartitionKeyPath); stateContainer.IndexingPolicy.IndexingMode = IndexingMode.Consistent; - stateContainer.IndexingPolicy.IncludedPaths.Add(new IncludedPath { Path = "/*" }); - stateContainer.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/\"State\"/*" }); + stateContainer.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/*" }); + stateContainer.IndexingPolicy.IncludedPaths.Add(new IncludedPath { Path = $"/{nameof(GrainStateEntity.GrainType)}/?" }); + stateContainer.IndexingPolicy.IncludedPaths.Add(new IncludedPath { Path = ToScalarIndexPath(_options.PartitionKeyPath) }); if (_options.StateFieldsToIndex != null) { @@ -369,6 +370,16 @@ private async Task TryDeleteDatabase() } } + private static string ToScalarIndexPath(string path) + { + if (path.EndsWith("/?", StringComparison.Ordinal)) + { + return path; + } + + return path.EndsWith("/", StringComparison.Ordinal) ? $"{path}?" : $"{path}/?"; + } + private void ResetGrainState(IGrainState grainState) { grainState.State = CreateInstance(); diff --git a/src/Azure/Orleans.Reminders.Cosmos/CosmosReminderTable.cs b/src/Azure/Orleans.Reminders.Cosmos/CosmosReminderTable.cs index dac9f3e2717..32186f34c53 100644 --- a/src/Azure/Orleans.Reminders.Cosmos/CosmosReminderTable.cs +++ b/src/Azure/Orleans.Reminders.Cosmos/CosmosReminderTable.cs @@ -343,8 +343,8 @@ private async Task TryCreateCosmosResourcesCore() remindersCollection.IndexingPolicy.IndexingMode = IndexingMode.Consistent; remindersCollection.IndexingPolicy.IncludedPaths.Add(new IncludedPath { Path = "/*" }); - remindersCollection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/StartAt/*" }); - remindersCollection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/Period/*" }); + remindersCollection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/StartAt/?" }); + remindersCollection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/Period/?" }); remindersCollection.IndexingPolicy.IndexingMode = IndexingMode.Consistent; const int maxRetries = 3;