Skip to content
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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ClientOfficialVersion>3.57.0</ClientOfficialVersion>
<ClientPreviewVersion>3.58.0</ClientPreviewVersion>
<ClientPreviewSuffixVersion>preview.0</ClientPreviewSuffixVersion>
<DirectVersion>3.42.0</DirectVersion>
<DirectVersion>3.42.2</DirectVersion>
<FaultInjectionVersion>1.0.0</FaultInjectionVersion>
<FaultInjectionSuffixVersion>beta.0</FaultInjectionSuffixVersion>
<EncryptionOfficialVersion>2.0.5</EncryptionOfficialVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ abstract class DistributedTransaction
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A <see cref="Task{TResult}"/> containing a <see cref="DistributedTransactionResponse"/> that represents the result of the transaction.</returns>
public abstract Task<DistributedTransactionResponse> CommitTransactionAsync(CancellationToken cancellationToken);
public abstract Task<DistributedTransactionResponse> CommitTransactionAsync(CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private async Task<DistributedTransactionResponse> ExecuteCommitAsync(
using (MemoryStream bodyStream = serverRequest.TransferBodyStream())
{
ResponseMessage responseMessage = await this.clientContext.ProcessResourceOperationStreamAsync(
resourceUri: DistributedTransactionConstants.EndpointPath,
resourceUri: DistributedTransactionCommitter.GetResourceUri(),
resourceType: ResourceType.DistributedTransactionBatch,
operationType: OperationType.CommitDistributedTransaction,
requestOptions: null,
Expand All @@ -86,13 +86,17 @@ private async Task<DistributedTransactionResponse> ExecuteCommitAsync(
}
}

private static string GetResourceUri()
{
return Paths.OperationsPathSegment + "/" + Paths.Operations_Dtc;
}

private static void EnrichRequestMessage(RequestMessage requestMessage, DistributedTransactionServerRequest serverRequest)
{
// Set DTC-specific headers
//TODO: update to headers in HttpConstants.HttpHeaders
requestMessage.Headers.Add(DistributedTransactionConstants.IdempotencyTokenHeader, serverRequest.IdempotencyToken.ToString());
requestMessage.Headers.Add(DistributedTransactionConstants.OperationTypeHeader, requestMessage.OperationType.ToString());
requestMessage.Headers.Add(DistributedTransactionConstants.ResourceTypeHeader, requestMessage.ResourceType.ToString());
requestMessage.Headers.Add(HttpConstants.HttpHeaders.IdempotencyToken, serverRequest.IdempotencyToken.ToString());
requestMessage.Headers.Add(HttpConstants.HttpHeaders.OperationType, requestMessage.OperationType.ToString());
requestMessage.Headers.Add(HttpConstants.HttpHeaders.ResourceType, requestMessage.ResourceType.ToString());
requestMessage.UseGatewayMode = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace Microsoft.Azure.Cosmos

internal static class DistributedTransactionConstants
{
public const string EndpointPath = "/operations/dtc";
public const string AuthorizationResourceType = "databaseaccount";
public const string IdempotencyTokenHeader = "x-ms-cosmos-idempotency-token";
public const string OperationTypeHeader = "x-ms-cosmos-operation-type";
public const string ResourceTypeHeader = "x-ms-cosmos-resource-type";

public static bool IsDistributedTransactionRequest(OperationType operationType, ResourceType resourceType)
{
return operationType == OperationType.CommitDistributedTransaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ namespace Microsoft.Azure.Cosmos
#endif
class DistributedTransactionResponse : IReadOnlyList<DistributedTransactionOperationResult>, IDisposable
{
private const string IdempotencyTokenHeader = "x-ms-dtc-operation-id";

private List<DistributedTransactionOperationResult> results;
private bool isDisposed;

Expand Down Expand Up @@ -272,7 +270,7 @@ protected virtual void Dispose(bool disposing)
private static Guid GetIdempotencyTokenFromHeaders(Headers headers, Guid fallbackToken)
{
if (headers != null &&
headers.TryGetValue(IdempotencyTokenHeader, out string tokenValue) &&
headers.TryGetValue(HttpConstants.HttpHeaders.IdempotencyToken, out string tokenValue) &&
Guid.TryParse(tokenValue, out Guid idempotencyToken))
{
return idempotencyToken;
Expand Down
15 changes: 3 additions & 12 deletions Microsoft.Azure.Cosmos/src/GatewayStoreModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,9 @@ await GatewayStoreModel.ApplySessionTokenAsync(
this.thinClientStoreClient != null &&
GatewayStoreModel.IsOperationSupportedByThinClient(request);

Uri physicalAddress;

if (DistributedTransactionConstants.IsDistributedTransactionRequest(request.OperationType, request.ResourceType))
Comment thread
Meghana-Palaparthi marked this conversation as resolved.
{
physicalAddress = new Uri(this.endpointManager.ResolveServiceEndpoint(request), DistributedTransactionConstants.EndpointPath);
}
else
{
physicalAddress = ThinClientStoreClient.IsFeedRequest(request.OperationType)
? this.GetFeedUri(request)
: this.GetEntityUri(request);
}
Uri physicalAddress = ThinClientStoreClient.IsFeedRequest(request.OperationType)
? this.GetFeedUri(request)
: this.GetEntityUri(request);

if (canUseThinClient)
{
Expand Down
6 changes: 1 addition & 5 deletions Microsoft.Azure.Cosmos/src/Handler/TransportHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,10 @@ internal async Task<ResponseMessage> ProcessMessageAsync(
ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum = new ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow, request.Trace);
serviceRequest.RequestContext.ClientRequestStatistics = clientSideRequestStatisticsTraceDatum;

string resourceTypeForAuth = DistributedTransactionConstants.IsDistributedTransactionRequest(request.OperationType, request.ResourceType)
? DistributedTransactionConstants.AuthorizationResourceType
: PathsHelper.GetResourcePath(request.ResourceType);

//TODO: extract auth into a separate handler
string authorization = await ((ICosmosAuthorizationTokenProvider)this.client.DocumentClient).GetUserAuthorizationTokenAsync(
serviceRequest.ResourceAddress,
resourceTypeForAuth,
PathsHelper.GetResourcePath(request.ResourceType),
request.Method.ToString(),
serviceRequest.Headers,
AuthorizationTokenType.PrimaryMasterKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;
using Microsoft.Azure.Documents;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OperationType = Documents.OperationType;
using PartitionKey = Cosmos.PartitionKey;

[TestClass]
public class DistributedTransactionE2ETests : BaseCosmosClientHelper
{
private const string IdempotencyTokenHeader = "x-ms-cosmos-idempotency-token";
private const string IdempotencyTokenHeader = HttpConstants.HttpHeaders.IdempotencyToken;
private const string PartitionKeyPath = "/pk";

private Container container;
Expand Down
Loading