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

Rename Batch as TransactionalBatch #965

Merged
merged 4 commits into from
Nov 4, 2019
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 Microsoft.Azure.Cosmos/src/Batch/BatchAsyncBatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public virtual bool TryAdd(ItemBatchOperation operation)
{
foreach (ItemBatchOperation itemBatchOperation in batchResponse.Operations)
{
BatchOperationResult response = batchResponse[itemBatchOperation.OperationIndex];
TransactionalBatchOperationResult response = batchResponse[itemBatchOperation.OperationIndex];
itemBatchOperation.Context.Diagnostics.AppendDiagnostics(batchResponse.Diagnostics);
if (!response.IsSuccessStatusCode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public BatchAsyncContainerExecutor(
this.retryOptions = cosmosClientContext.ClientOptions.GetConnectionPolicy().RetryOptions;
}

public virtual async Task<BatchOperationResult> AddAsync(
public virtual async Task<TransactionalBatchOperationResult> AddAsync(
ItemBatchOperation operation,
ItemRequestOptions itemRequestOptions = null,
CancellationToken cancellationToken = default(CancellationToken))
Expand Down Expand Up @@ -237,7 +237,7 @@ private async Task<PartitionKeyRangeBatchExecutionResult> ExecuteAsync(
requestEnricher: requestMessage => BatchAsyncContainerExecutor.AddHeadersToRequestMessage(requestMessage, serverRequest.PartitionKeyRangeId),
cancellationToken: cancellationToken).ConfigureAwait(false);

BatchResponse serverResponse = await BatchResponse.FromResponseMessageAsync(responseMessage, serverRequest, this.cosmosClientContext.CosmosSerializer).ConfigureAwait(false);
TransactionalBatchResponse serverResponse = await TransactionalBatchResponse.FromResponseMessageAsync(responseMessage, serverRequest, this.cosmosClientContext.CosmosSerializer).ConfigureAwait(false);

return new PartitionKeyRangeBatchExecutionResult(serverRequest.PartitionKeyRangeId, serverRequest.Operations, serverResponse);
}
Expand Down
48 changes: 24 additions & 24 deletions Microsoft.Azure.Cosmos/src/Batch/BatchCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.Azure.Cosmos
using System.Threading.Tasks;
using Microsoft.Azure.Documents;

internal class BatchCore : Batch
internal class BatchCore : TransactionalBatch
{
private readonly PartitionKey partitionKey;

Expand All @@ -33,9 +33,9 @@ internal BatchCore(
this.operations = new List<ItemBatchOperation>();
}

public override Batch CreateItem<T>(
public override TransactionalBatch CreateItem<T>(
T item,
BatchItemRequestOptions requestOptions = null)
TransactionalBatchItemRequestOptions requestOptions = null)
{
if (item == null)
{
Expand All @@ -51,9 +51,9 @@ public override Batch CreateItem<T>(
return this;
}

public override Batch CreateItemStream(
public override TransactionalBatch CreateItemStream(
Stream streamPayload,
BatchItemRequestOptions requestOptions = null)
TransactionalBatchItemRequestOptions requestOptions = null)
{
if (streamPayload == null)
{
Expand All @@ -69,9 +69,9 @@ public override Batch CreateItemStream(
return this;
}

public override Batch ReadItem(
public override TransactionalBatch ReadItem(
string id,
BatchItemRequestOptions requestOptions = null)
TransactionalBatchItemRequestOptions requestOptions = null)
{
if (id == null)
{
Expand All @@ -87,9 +87,9 @@ public override Batch ReadItem(
return this;
}

public override Batch UpsertItem<T>(
public override TransactionalBatch UpsertItem<T>(
T item,
BatchItemRequestOptions requestOptions = null)
TransactionalBatchItemRequestOptions requestOptions = null)
{
if (item == null)
{
Expand All @@ -105,9 +105,9 @@ public override Batch UpsertItem<T>(
return this;
}

public override Batch UpsertItemStream(
public override TransactionalBatch UpsertItemStream(
Stream streamPayload,
BatchItemRequestOptions requestOptions = null)
TransactionalBatchItemRequestOptions requestOptions = null)
{
if (streamPayload == null)
{
Expand All @@ -123,10 +123,10 @@ public override Batch UpsertItemStream(
return this;
}

public override Batch ReplaceItem<T>(
public override TransactionalBatch ReplaceItem<T>(
string id,
T item,
BatchItemRequestOptions requestOptions = null)
TransactionalBatchItemRequestOptions requestOptions = null)
{
if (id == null)
{
Expand All @@ -148,10 +148,10 @@ public override Batch ReplaceItem<T>(
return this;
}

public override Batch ReplaceItemStream(
public override TransactionalBatch ReplaceItemStream(
string id,
Stream streamPayload,
BatchItemRequestOptions requestOptions = null)
TransactionalBatchItemRequestOptions requestOptions = null)
{
if (id == null)
{
Expand All @@ -173,9 +173,9 @@ public override Batch ReplaceItemStream(
return this;
}

public override Batch DeleteItem(
public override TransactionalBatch DeleteItem(
string id,
BatchItemRequestOptions requestOptions = null)
TransactionalBatchItemRequestOptions requestOptions = null)
{
if (id == null)
{
Expand All @@ -191,7 +191,7 @@ public override Batch DeleteItem(
return this;
}

public override Task<BatchResponse> ExecuteAsync(
public override Task<TransactionalBatchResponse> ExecuteAsync(
CancellationToken cancellationToken = default(CancellationToken))
{
return this.ExecuteAsync(
Expand All @@ -204,8 +204,8 @@ public override Task<BatchResponse> ExecuteAsync(
/// </summary>
/// <param name="requestOptions">Options that apply to the batch. Used only for EPK routing.</param>
/// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
/// <returns>An awaitable <see cref="BatchResponse"/> which contains the completion status and results of each operation.</returns>
public virtual Task<BatchResponse> ExecuteAsync(
/// <returns>An awaitable <see cref="TransactionalBatchResponse"/> which contains the completion status and results of each operation.</returns>
public virtual Task<TransactionalBatchResponse> ExecuteAsync(
RequestOptions requestOptions,
CancellationToken cancellationToken = default(CancellationToken))
{
Expand All @@ -219,12 +219,12 @@ public virtual Task<BatchResponse> ExecuteAsync(
/// </summary>
/// <param name="id">The cosmos item id.</param>
/// <param name="patchStream">A <see cref="Stream"/> containing the patch specification.</param>
/// <param name="requestOptions">(Optional) The options for the item request. <see cref="BatchItemRequestOptions"/>.</param>
/// <returns>The <see cref="Batch"/> instance with the operation added.</returns>
public virtual Batch PatchItemStream(
/// <param name="requestOptions">(Optional) The options for the item request. <see cref="TransactionalBatchItemRequestOptions"/>.</param>
/// <returns>The <see cref="TransactionalBatch"/> instance with the operation added.</returns>
public virtual TransactionalBatch PatchItemStream(
string id,
Stream patchStream,
BatchItemRequestOptions requestOptions = null)
TransactionalBatchItemRequestOptions requestOptions = null)
{
this.operations.Add(new ItemBatchOperation(
operationType: OperationType.Patch,
Expand Down
6 changes: 3 additions & 3 deletions Microsoft.Azure.Cosmos/src/Batch/BatchExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public BatchExecutor(
this.batchOptions = batchOptions;
}

public async Task<BatchResponse> ExecuteAsync(CancellationToken cancellationToken)
public async Task<TransactionalBatchResponse> ExecuteAsync(CancellationToken cancellationToken)
{
BatchExecUtils.EnsureValid(this.inputOperations, this.batchOptions);

Expand All @@ -63,7 +63,7 @@ public async Task<BatchResponse> ExecuteAsync(CancellationToken cancellationToke
/// <param name="serverRequest">A server request with a set of operations on items.</param>
/// <param name="cancellationToken"><see cref="CancellationToken"/> representing request cancellation.</param>
/// <returns>Response from the server.</returns>
private async Task<BatchResponse> ExecuteServerRequestAsync(
private async Task<TransactionalBatchResponse> ExecuteServerRequestAsync(
SinglePartitionKeyServerBatchRequest serverRequest,
CancellationToken cancellationToken)
{
Expand All @@ -86,7 +86,7 @@ private async Task<BatchResponse> ExecuteServerRequestAsync(
},
cancellationToken);

return await BatchResponse.FromResponseMessageAsync(
return await TransactionalBatchResponse.FromResponseMessageAsync(
responseMessage,
serverRequest,
this.clientContext.CosmosSerializer);
Expand Down
12 changes: 6 additions & 6 deletions Microsoft.Azure.Cosmos/src/Batch/ItemBatchOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ItemBatchOperation(
PartitionKey partitionKey,
string id = null,
Stream resourceStream = null,
BatchItemRequestOptions requestOptions = null)
TransactionalBatchItemRequestOptions requestOptions = null)
{
this.OperationType = operationType;
this.OperationIndex = operationIndex;
Expand All @@ -46,7 +46,7 @@ public ItemBatchOperation(
int operationIndex,
string id = null,
Stream resourceStream = null,
BatchItemRequestOptions requestOptions = null)
TransactionalBatchItemRequestOptions requestOptions = null)
{
this.OperationType = operationType;
this.OperationIndex = operationIndex;
Expand All @@ -63,7 +63,7 @@ public ItemBatchOperation(

public Stream ResourceStream { get; protected set; }

public BatchItemRequestOptions RequestOptions { get; }
public TransactionalBatchItemRequestOptions RequestOptions { get; }

public int OperationIndex { get; internal set; }

Expand Down Expand Up @@ -147,7 +147,7 @@ internal static Result WriteOperation(ref RowWriter writer, TypeArgument typeArg

if (operation.RequestOptions != null)
{
BatchItemRequestOptions options = operation.RequestOptions;
TransactionalBatchItemRequestOptions options = operation.RequestOptions;
if (options.IndexingDirective.HasValue)
{
string indexingDirectiveString = IndexingDirectiveStrings.FromIndexingDirective(options.IndexingDirective.Value);
Expand Down Expand Up @@ -339,7 +339,7 @@ public ItemBatchOperation(
PartitionKey partitionKey,
T resource,
string id = null,
BatchItemRequestOptions requestOptions = null)
TransactionalBatchItemRequestOptions requestOptions = null)
: base(operationType, operationIndex, partitionKey: partitionKey, id: id, requestOptions: requestOptions)
{
this.Resource = resource;
Expand All @@ -350,7 +350,7 @@ public ItemBatchOperation(
int operationIndex,
T resource,
string id = null,
BatchItemRequestOptions requestOptions = null)
TransactionalBatchItemRequestOptions requestOptions = null)
: base(operationType, operationIndex, id: id, requestOptions: requestOptions)
{
this.Resource = resource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ internal class ItemBatchOperationContext : IDisposable

public BatchAsyncBatcher CurrentBatcher { get; set; }

public Task<BatchOperationResult> OperationTask => this.taskCompletionSource.Task;
public Task<TransactionalBatchOperationResult> OperationTask => this.taskCompletionSource.Task;

public ItemBatchOperationStatistics Diagnostics { get; } = new ItemBatchOperationStatistics();

private readonly IDocumentClientRetryPolicy retryPolicy;

private TaskCompletionSource<BatchOperationResult> taskCompletionSource = new TaskCompletionSource<BatchOperationResult>();
private TaskCompletionSource<TransactionalBatchOperationResult> taskCompletionSource = new TaskCompletionSource<TransactionalBatchOperationResult>();

public ItemBatchOperationContext(
string partitionKeyRangeId,
Expand All @@ -39,7 +39,7 @@ public ItemBatchOperationContext(
/// Based on the Retry Policy, if a failed response should retry.
/// </summary>
public Task<ShouldRetryResult> ShouldRetryAsync(
BatchOperationResult batchOperationResult,
TransactionalBatchOperationResult batchOperationResult,
CancellationToken cancellationToken)
{
if (this.retryPolicy == null
Expand All @@ -54,7 +54,7 @@ public Task<ShouldRetryResult> ShouldRetryAsync(

public void Complete(
BatchAsyncBatcher completer,
BatchOperationResult result)
TransactionalBatchOperationResult result)
{
if (this.AssertBatcher(completer))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ internal class PartitionKeyRangeBatchExecutionResult
{
public string PartitionKeyRangeId { get; }

public BatchResponse ServerResponse { get; }
public TransactionalBatchResponse ServerResponse { get; }

public IEnumerable<ItemBatchOperation> Operations { get; }

public PartitionKeyRangeBatchExecutionResult(
string pkRangeId,
IEnumerable<ItemBatchOperation> operations,
BatchResponse serverResponse)
TransactionalBatchResponse serverResponse)
{
this.PartitionKeyRangeId = pkRangeId;
this.ServerResponse = serverResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// Response of a cross partition key batch request.
/// </summary>
internal class PartitionKeyRangeBatchResponse : BatchResponse
internal class PartitionKeyRangeBatchResponse : TransactionalBatchResponse
{
// Results sorted in the order operations had been added.
private readonly BatchOperationResult[] resultsByOperationIndex;
private readonly BatchResponse serverResponse;
private readonly TransactionalBatchOperationResult[] resultsByOperationIndex;
private readonly TransactionalBatchResponse serverResponse;
private bool isDisposed;

/// <summary>
Expand All @@ -28,13 +28,13 @@ internal class PartitionKeyRangeBatchResponse : BatchResponse
/// <param name="serializer">Serializer to deserialize response resource body streams.</param>
internal PartitionKeyRangeBatchResponse(
int originalOperationsCount,
BatchResponse serverResponse,
TransactionalBatchResponse serverResponse,
CosmosSerializer serializer)
{
this.StatusCode = serverResponse.StatusCode;

this.serverResponse = serverResponse;
this.resultsByOperationIndex = new BatchOperationResult[originalOperationsCount];
this.resultsByOperationIndex = new TransactionalBatchOperationResult[originalOperationsCount];

StringBuilder errorMessageBuilder = new StringBuilder();
List<ItemBatchOperation> itemBatchOperations = new List<ItemBatchOperation>();
Expand Down Expand Up @@ -78,39 +78,39 @@ internal PartitionKeyRangeBatchResponse(
public override int Count => this.resultsByOperationIndex.Length;

/// <inheritdoc />
public override BatchOperationResult this[int index] => this.resultsByOperationIndex[index];
public override TransactionalBatchOperationResult this[int index] => this.resultsByOperationIndex[index];

/// <summary>
/// Gets the result of the operation at the provided index in the batch - the returned result has a Resource of provided type.
/// </summary>
/// <typeparam name="T">Type to which the Resource in the operation result needs to be deserialized to, when present.</typeparam>
/// <param name="index">0-based index of the operation in the batch whose result needs to be returned.</param>
/// <returns>Result of batch operation that contains a Resource deserialized to specified type.</returns>
public override BatchOperationResult<T> GetOperationResultAtIndex<T>(int index)
public override TransactionalBatchOperationResult<T> GetOperationResultAtIndex<T>(int index)
{
if (index >= this.Count)
{
throw new IndexOutOfRangeException();
}

BatchOperationResult result = this.resultsByOperationIndex[index];
TransactionalBatchOperationResult result = this.resultsByOperationIndex[index];

T resource = default(T);
if (result.ResourceStream != null)
{
resource = this.Serializer.FromStream<T>(result.ResourceStream);
}

return new BatchOperationResult<T>(result, resource);
return new TransactionalBatchOperationResult<T>(result, resource);
}

/// <summary>
/// Gets an enumerator over the operation results.
/// </summary>
/// <returns>Enumerator over the operation results.</returns>
public override IEnumerator<BatchOperationResult> GetEnumerator()
public override IEnumerator<TransactionalBatchOperationResult> GetEnumerator()
{
foreach (BatchOperationResult result in this.resultsByOperationIndex)
foreach (TransactionalBatchOperationResult result in this.resultsByOperationIndex)
{
yield return result;
}
Expand Down
Loading