Skip to content

Commit

Permalink
Fixing Container Recreate scenarios for Gateway Mode (#2530)
Browse files Browse the repository at this point in the history
This was introduced in PR #2165

The issue is when one client deletes and recreates a container, any request on another client gives a NullReferenceException.
  • Loading branch information
asketagarwal authored Jun 11, 2021
1 parent a665371 commit 602657e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
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

0 comments on commit 602657e

Please sign in to comment.