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

Diagnostics: Add synchronization context Part 3 for remaining types #1667

Merged
merged 7 commits into from
Jun 26, 2020
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
25 changes: 15 additions & 10 deletions Microsoft.Azure.Cosmos/src/Batch/BatchCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,21 @@ public virtual Task<TransactionalBatchResponse> ExecuteAsync(
RequestOptions requestOptions,
CancellationToken cancellationToken = default(CancellationToken))
{
CosmosDiagnosticsContext diagnosticsContext = CosmosDiagnosticsContext.Create(requestOptions);
BatchExecutor executor = new BatchExecutor(
container: this.container,
partitionKey: this.partitionKey,
operations: this.operations,
batchOptions: requestOptions,
diagnosticsContext: diagnosticsContext);

this.operations = new List<ItemBatchOperation>();
return executor.ExecuteAsync(cancellationToken);
return this.container.ClientContext.OperationHelperAsync(
nameof(ExecuteAsync),
requestOptions,
(diagnostics) =>
{
BatchExecutor executor = new BatchExecutor(
container: this.container,
partitionKey: this.partitionKey,
operations: this.operations,
batchOptions: requestOptions,
diagnosticsContext: diagnostics);

this.operations = new List<ItemBatchOperation>();
return executor.ExecuteAsync(cancellationToken);
});
}

/// <summary>
Expand Down
53 changes: 28 additions & 25 deletions Microsoft.Azure.Cosmos/src/Resource/Conflict/ConflictsCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ namespace Microsoft.Azure.Cosmos
using Microsoft.Azure.Documents;

// TODO: This class should inherit from ConflictsInternal to avoid the downcasting hacks.
j82w marked this conversation as resolved.
Show resolved Hide resolved
internal class ConflictsCore : Conflicts
internal abstract class ConflictsCore : Conflicts
{
private readonly ContainerInternal container;
private readonly CosmosClientContext clientContext;

public ConflictsCore(
CosmosClientContext clientContext,
Expand All @@ -31,10 +30,13 @@ public ConflictsCore(
}

this.container = container;
this.clientContext = clientContext;
this.ClientContext = clientContext;
}

public override Task<ResponseMessage> DeleteAsync(
protected CosmosClientContext ClientContext { get; }

public Task<ResponseMessage> DeleteAsync(
CosmosDiagnosticsContext diagnosticsContext,
ConflictProperties conflict,
PartitionKey partitionKey,
CancellationToken cancellationToken = default(CancellationToken))
Expand All @@ -44,12 +46,12 @@ public override Task<ResponseMessage> DeleteAsync(
throw new ArgumentNullException(nameof(conflict));
}

Uri conflictLink = this.clientContext.CreateLink(
Uri conflictLink = this.ClientContext.CreateLink(
parentLink: this.container.LinkUri.OriginalString,
uriPathSegment: Paths.ConflictsPathSegment,
id: conflict.Id);

return this.clientContext.ProcessResourceOperationStreamAsync(
return this.ClientContext.ProcessResourceOperationStreamAsync(
resourceUri: conflictLink,
resourceType: ResourceType.Conflict,
operationType: OperationType.Delete,
Expand All @@ -58,14 +60,14 @@ public override Task<ResponseMessage> DeleteAsync(
partitionKey: partitionKey,
streamPayload: null,
requestEnricher: null,
diagnosticsContext: null,
diagnosticsContext: diagnosticsContext,
cancellationToken: cancellationToken);
}

public override FeedIterator GetConflictQueryStreamIterator(
string queryText = null,
string continuationToken = null,
QueryRequestOptions requestOptions = null)
string queryText,
string continuationToken,
QueryRequestOptions requestOptions)
{
QueryDefinition queryDefinition = null;
if (queryText != null)
Expand All @@ -80,9 +82,9 @@ public override FeedIterator GetConflictQueryStreamIterator(
}

public override FeedIterator<T> GetConflictQueryIterator<T>(
string queryText = null,
string continuationToken = null,
QueryRequestOptions requestOptions = null)
string queryText,
string continuationToken,
QueryRequestOptions requestOptions)
{
QueryDefinition queryDefinition = null;
if (queryText != null)
Expand All @@ -97,9 +99,9 @@ public override FeedIterator<T> GetConflictQueryIterator<T>(
}

public override FeedIterator GetConflictQueryStreamIterator(
QueryDefinition queryDefinition,
string continuationToken = null,
QueryRequestOptions requestOptions = null)
QueryDefinition queryDefinition,
string continuationToken = null,
QueryRequestOptions requestOptions = null)
{
return FeedRangeIteratorCore.Create(
containerCore: this.container,
Expand All @@ -124,12 +126,13 @@ public override FeedIterator<T> GetConflictQueryIterator<T>(

return new FeedIteratorCore<T>(
databaseStreamIterator,
(response) => this.clientContext.ResponseFactory.CreateQueryFeedResponse<T>(
(response) => this.ClientContext.ResponseFactory.CreateQueryFeedResponse<T>(
responseMessage: response,
resourceType: ResourceType.Conflict));
}

public override async Task<ItemResponse<T>> ReadCurrentAsync<T>(
public async Task<ItemResponse<T>> ReadCurrentAsync<T>(
CosmosDiagnosticsContext diagnosticsContext,
ConflictProperties cosmosConflict,
PartitionKey partitionKey,
CancellationToken cancellationToken = default(CancellationToken))
Expand All @@ -144,22 +147,22 @@ public override async Task<ItemResponse<T>> ReadCurrentAsync<T>(
string databaseResourceId = await databaseCore.GetRIDAsync(cancellationToken);
string containerResourceId = await this.container.GetRIDAsync(cancellationToken);

Uri dbLink = this.clientContext.CreateLink(
Uri dbLink = this.ClientContext.CreateLink(
parentLink: string.Empty,
uriPathSegment: Paths.DatabasesPathSegment,
id: databaseResourceId);

Uri containerLink = this.clientContext.CreateLink(
Uri containerLink = this.ClientContext.CreateLink(
parentLink: dbLink.OriginalString,
uriPathSegment: Paths.CollectionsPathSegment,
id: containerResourceId);

Uri itemLink = this.clientContext.CreateLink(
Uri itemLink = this.ClientContext.CreateLink(
parentLink: containerLink.OriginalString,
uriPathSegment: Paths.DocumentsPathSegment,
id: cosmosConflict.SourceResourceId);

ResponseMessage response = await this.clientContext.ProcessResourceOperationStreamAsync(
ResponseMessage response = await this.ClientContext.ProcessResourceOperationStreamAsync(
resourceUri: itemLink,
resourceType: ResourceType.Document,
operationType: OperationType.Read,
Expand All @@ -168,10 +171,10 @@ public override async Task<ItemResponse<T>> ReadCurrentAsync<T>(
partitionKey: partitionKey,
streamPayload: null,
requestEnricher: null,
diagnosticsContext: null,
diagnosticsContext: diagnosticsContext,
cancellationToken: cancellationToken);

return this.clientContext.ResponseFactory.CreateItemResponse<T>(response);
return this.ClientContext.ResponseFactory.CreateItemResponse<T>(response);
}

public override T ReadConflictContent<T>(ConflictProperties cosmosConflict)
Expand All @@ -191,7 +194,7 @@ public override T ReadConflictContent<T>(ConflictProperties cosmosConflict)
writer.Write(cosmosConflict.Content);
writer.Flush();
stream.Position = 0;
return this.clientContext.SerializerCore.FromStream<T>(stream);
return this.ClientContext.SerializerCore.FromStream<T>(stream);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Microsoft.Azure.Cosmos
{
using System;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -25,13 +24,16 @@ public override Task<ResponseMessage> DeleteAsync(
PartitionKey partitionKey,
CancellationToken cancellationToken = default(CancellationToken))
{
return TaskHelper.RunInlineIfNeededAsync(() => base.DeleteAsync(conflict, partitionKey, cancellationToken));
return this.ClientContext.OperationHelperAsync(
operationName: nameof(DeleteAsync),
requestOptions: null,
task: (diagnostics) => base.DeleteAsync(diagnostics, conflict, partitionKey, cancellationToken));
}

public override FeedIterator GetConflictQueryStreamIterator(
string queryText = null,
string continuationToken = null,
QueryRequestOptions requestOptions = null)
string queryText = null,
string continuationToken = null,
QueryRequestOptions requestOptions = null)
{
return new FeedIteratorInlineCore(base.GetConflictQueryStreamIterator(
queryText,
Expand Down Expand Up @@ -77,7 +79,10 @@ public override Task<ItemResponse<T>> ReadCurrentAsync<T>(
PartitionKey partitionKey,
CancellationToken cancellationToken = default(CancellationToken))
{
return TaskHelper.RunInlineIfNeededAsync(() => base.ReadCurrentAsync<T>(cosmosConflict, partitionKey, cancellationToken));
return this.ClientContext.OperationHelperAsync(
operationName: nameof(ReadCurrentAsync),
requestOptions: null,
task: (diagnostics) => base.ReadCurrentAsync<T>(diagnostics, cosmosConflict, partitionKey, cancellationToken));
}

public override T ReadConflictContent<T>(ConflictProperties cosmosConflict)
Expand Down
Loading