Skip to content

Commit

Permalink
Added debug check moved query plan check to IsMasterOperation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Willey committed Aug 11, 2020
1 parent 3d85fd1 commit 6c09061
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
14 changes: 4 additions & 10 deletions Microsoft.Azure.Cosmos/src/GatewayStoreModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.Azure.Cosmos
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
Expand Down Expand Up @@ -197,6 +198,7 @@ internal static void ApplySessionToken(
{
if (request.Headers == null)
{
Debug.Fail("DocumentServiceRequest does not have headers.");
return;
}

Expand All @@ -216,15 +218,6 @@ internal static void ApplySessionToken(
return; // User is explicitly controlling the session.
}

if (request.OperationType == OperationType.QueryPlan)
{
string isPlanOnlyString = request.Headers[HttpConstants.HttpHeaders.IsQueryPlanRequest];
if (bool.TryParse(isPlanOnlyString, out bool isPlanOnly) && isPlanOnly)
{
return; // for query plan session token is not needed
}
}

string requestConsistencyLevel = request.Headers[HttpConstants.HttpHeaders.ConsistencyLevel];

bool sessionConsistency =
Expand Down Expand Up @@ -256,7 +249,8 @@ internal static bool IsMasterOperation(
return ReplicatedResourceClient.IsMasterResource(resourceType) ||
GatewayStoreModel.IsStoredProcedureCrudOperation(resourceType, operationType) ||
resourceType == ResourceType.Trigger ||
resourceType == ResourceType.UserDefinedFunction;
resourceType == ResourceType.UserDefinedFunction ||
operationType == OperationType.QueryPlan;
}

internal static bool IsStoredProcedureCrudOperation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,25 @@ public void TestApplySessionForMasterOperation()
Assert.IsNull(dsr.Headers[HttpConstants.HttpHeaders.SessionToken]);
}
}

Assert.IsTrue(GatewayStoreModel.IsMasterOperation(
ResourceType.Document,
OperationType.QueryPlan));

DocumentServiceRequest dsrQueryPlan = DocumentServiceRequest.CreateFromName(
OperationType.QueryPlan,
"Test",
ResourceType.Document,
AuthorizationTokenType.PrimaryMasterKey);

dsrQueryPlan.Headers.Add(HttpConstants.HttpHeaders.SessionToken, Guid.NewGuid().ToString());

GatewayStoreModel.ApplySessionToken(
dsrQueryPlan,
ConsistencyLevel.Session,
new Mock<ISessionContainer>().Object);

Assert.IsNull(dsrQueryPlan.Headers[HttpConstants.HttpHeaders.SessionToken]);
}

[TestMethod]
Expand Down

0 comments on commit 6c09061

Please sign in to comment.