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

Gateway: Fixes container recreate scenarios for Gateway Mode in session consistency #2530

Merged
merged 1 commit into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 9 additions & 6 deletions Microsoft.Azure.Cosmos/src/GatewayStoreModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,15 @@ private static async Task<Tuple<bool, PartitionKeyRange>> TryResolvePartitionKey
NoOpTrace.Singleton);
}

partitonKeyRange = AddressResolver.TryResolveServerPartitionByPartitionKey(
request: request,
partitionKeyString: partitionKeyString,
collectionCacheUptoDate: false,
collection: collection,
routingMap: collectionRoutingMap);
if (collectionRoutingMap != null)
{
partitonKeyRange = AddressResolver.TryResolveServerPartitionByPartitionKey(
request: request,
partitionKeyString: partitionKeyString,
collectionCacheUptoDate: false,
collection: collection,
routingMap: collectionRoutingMap);
}
}
else if (request.PartitionKeyRangeIdentity != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,34 @@ public async Task PatchItemStreamTest()
}
}

[TestMethod]
public async Task ContainerRecreateScenarioGatewayTest()
{
ContainerResponse response = await this.database.CreateContainerAsync(
new ContainerProperties(id: Guid.NewGuid().ToString(), partitionKeyPath: "/pk"));

Container createdContainer = (ContainerInlineCore)response;

CosmosClient client1 = TestCommon.CreateCosmosClient(useGateway: true);
CosmosClient client2 = TestCommon.CreateCosmosClient(useGateway: true);

Container container1 = client1.GetContainer(this.database.Id, createdContainer.Id);
Container container2 = client2.GetContainer(this.database.Id, createdContainer.Id);
Cosmos.Database database2 = client2.GetDatabase(this.database.Id);

ToDoActivity item = ToDoActivity.CreateRandomToDoActivity("pk2002", "id2002");
await container1.CreateItemAsync<ToDoActivity>(item);

await container2.DeleteContainerAsync();
await database2.CreateContainerAsync(createdContainer.Id, "/pk");

container2 = database2.GetContainer(this.Container.Id);
await container2.CreateItemAsync<ToDoActivity>(item);

// should not throw exception
await this.Container.ReadItemAsync<ToDoActivity>("id2002", new Cosmos.PartitionKey("pk2002"));
}

[Ignore]
[TestMethod]
public async Task BatchPatchConditionTest()
Expand Down