Skip to content

Commit

Permalink
Rename a few properties in SearchIndexingBufferedSenderOptions (Azure…
Browse files Browse the repository at this point in the history
…#18285)

* Rename a few properties in SearchIndexingBufferedSenderOptions

* Update samples and API using scripts

* Update Batching.Publisher.BatchActionCount when handling a 413
  • Loading branch information
Mohit-Chakraborty authored Feb 7, 2021
1 parent 9de4d4d commit c11c9f9
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ public SearchIndexingBufferedSenderOptions() { }
public System.Threading.CancellationToken FlushCancellationToken { get { throw null; } set { } }
public int? InitialBatchActionCount { get { throw null; } set { } }
public System.Func<T, string> KeyFieldAccessor { get { throw null; } set { } }
public int MaxRetries { get { throw null; } set { } }
public System.TimeSpan MaxRetryDelay { get { throw null; } set { } }
public System.TimeSpan RetryDelay { get { throw null; } set { } }
public int MaxRetriesPerIndexAction { get { throw null; } set { } }
public System.TimeSpan MaxThrottlingDelay { get { throw null; } set { } }
public System.TimeSpan ThrottlingDelay { get { throw null; } set { } }
}
public partial class SearchIndexingBufferedSender<T> : System.IAsyncDisposable, System.IDisposable
{
protected SearchIndexingBufferedSender() { }
public SearchIndexingBufferedSender(Azure.Search.Documents.SearchClient searchClient, Azure.Search.Documents.SearchIndexingBufferedSenderOptions<T> options = null) { }
public virtual System.Uri Endpoint { get { throw null; } }
public virtual string IndexName { get { throw null; } }
public virtual string ServiceName { get { throw null; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ again.

```C# Snippet:Azure_Search_Documents_Tests_Samples_Sample05_IndexingDocuments_BufferedSender1
await using SearchIndexingBufferedSender<Product> indexer =
searchClient.CreateIndexingBufferedSender<Product>();
new SearchIndexingBufferedSender<Product>(searchClient);
await indexer.UploadDocumentsAsync(GenerateCatalog(count: 100000));
```

Expand Down
4 changes: 2 additions & 2 deletions sdk/search/Azure.Search.Documents/src/Batching/Publisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ public int IndexingActionsCount
protected CancellationToken PublisherCancellationToken { get; }

/// <summary>
/// Gets a value indicating the number of actions to group into a batch
/// Gets or sets a value indicating the number of actions to group into a batch
/// when tuning the behavior of the publisher.
/// </summary>
protected int BatchActionCount { get; } // TODO: Not automatically tuning yet
protected int BatchActionCount { get; set; }

/// <summary>
/// Gets a value indicating the number of bytes to use when tuning the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class SearchIndexingBufferedSender<T> : IDisposable, IAsyncDisposable
/// The single publisher responsible for submitting requests.
/// </summary>
#pragma warning disable CA2213 // Member should be disposed. Disposed in DisposeAsync
private SearchIndexingPublisher<T> _publisher;
private readonly SearchIndexingPublisher<T> _publisher;
#pragma warning restore CA2213 // Member should be disposed. Disposed in DisposeAsync

/// <summary>
Expand Down Expand Up @@ -103,15 +103,21 @@ public class SearchIndexingBufferedSender<T> : IDisposable, IAsyncDisposable
protected SearchIndexingBufferedSender() { }

/// <summary>
/// Creates a new instance of the SearchIndexingBufferedSender.
/// Creates a new instance of <see cref="SearchIndexingBufferedSender{T}"/> that
/// can be used to index search documents with intelligent batching,
/// automatic flushing, and retries for failed indexing actions.
/// </summary>
/// <param name="searchClient">
/// The SearchClient used to send requests to the service.
/// </param>
/// <param name="options">
/// Provides the configuration options for the sender.
/// The <see cref="SearchIndexingBufferedSenderOptions{T}"/> to
/// customize the sender's behavior.
/// </param>
internal SearchIndexingBufferedSender(
/// <exception cref="ArgumentNullException">
/// Thrown when the <paramref name="searchClient"/> is null.
/// </exception>
public SearchIndexingBufferedSender(
SearchClient searchClient,
SearchIndexingBufferedSenderOptions<T> options = null)
{
Expand All @@ -126,9 +132,9 @@ internal SearchIndexingBufferedSender(
options.AutoFlushInterval,
options.InitialBatchActionCount,
options.BatchPayloadSize,
options.MaxRetries,
options.RetryDelay,
options.MaxRetryDelay,
options.MaxRetriesPerIndexAction,
options.ThrottlingDelay,
options.MaxThrottlingDelay,
options.FlushCancellationToken);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class SearchIndexingBufferedSenderOptions<T>
/// to control the number of attempts we will make to submit an indexing
/// action.
/// </summary>
public int MaxRetries { get; set; } = 3;
public int MaxRetriesPerIndexAction { get; set; } = 3;

/// <summary>
/// The initial retry delay. The delay will increase exponentially with
Expand All @@ -73,7 +73,7 @@ public class SearchIndexingBufferedSenderOptions<T>
/// is used to add delay between additional batch submissions when our
/// requests are being throttled by the service.
/// </summary>
public TimeSpan RetryDelay { get; set; } = TimeSpan.FromSeconds(0.8);
public TimeSpan ThrottlingDelay { get; set; } = TimeSpan.FromSeconds(0.8);

/// <summary>
/// The maximum permissible delay between retry attempts. Note that
Expand All @@ -82,7 +82,7 @@ public class SearchIndexingBufferedSenderOptions<T>
/// property is used to add delay between additional batch
/// submissions when our requests are being throttled by the service.
/// </summary>
public TimeSpan MaxRetryDelay { get; set; } = TimeSpan.FromMinutes(1);
public TimeSpan MaxThrottlingDelay { get; set; } = TimeSpan.FromMinutes(1);

/// <summary>
/// Gets or sets a function that can be used to access the index key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ protected override async Task<bool> OnSubmitBatchAsync(IList<PublisherAction<Ind
catch (RequestFailedException ex) when (ex.Status == 413) // Payload Too Large
{
// Split the batch and try with smaller payloads
int half = (int)Math.Floor((double)batch.Count / 2.0);
var smaller = new List<PublisherAction<IndexDocumentsAction<T>>>(batch.Take(half));
foreach (PublisherAction<IndexDocumentsAction<T>> action in batch.Skip(half))
// Update 'BatchActionCount' so future submissions can avoid this error.
BatchActionCount = (int)Math.Floor((double)batch.Count / 2.0);

var smaller = new List<PublisherAction<IndexDocumentsAction<T>>>(batch.Take(BatchActionCount));
foreach (PublisherAction<IndexDocumentsAction<T>> action in batch.Skip(BatchActionCount))
{
// Add the second half to the retry queue without
// counting this as a retry attempt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1184,8 +1184,8 @@ public async Task Behavior_MaxRetries()
client.CreateIndexingBufferedSender(
new SearchIndexingBufferedSenderOptions<SimpleDocument>()
{
MaxRetries = 5,
MaxRetryDelay = TimeSpan.FromSeconds(1)
MaxRetriesPerIndexAction = 5,
MaxThrottlingDelay = TimeSpan.FromSeconds(1)
});

// Keep 503ing to count the retries
Expand Down Expand Up @@ -1213,8 +1213,8 @@ public async Task Behavior_RetryDelay()
client.CreateIndexingBufferedSender(
new SearchIndexingBufferedSenderOptions<SimpleDocument>()
{
MaxRetries = 1,
RetryDelay = TimeSpan.FromSeconds(3)
MaxRetriesPerIndexAction = 1,
ThrottlingDelay = TimeSpan.FromSeconds(3)
});

// Keep 503ing to trigger delays
Expand Down Expand Up @@ -1245,8 +1245,8 @@ public async Task Behavior_MaxRetryDelay()
client.CreateIndexingBufferedSender(
new SearchIndexingBufferedSenderOptions<SimpleDocument>()
{
MaxRetries = 10,
MaxRetryDelay = TimeSpan.FromSeconds(1)
MaxRetriesPerIndexAction = 10,
MaxThrottlingDelay = TimeSpan.FromSeconds(1)
});

// Keep 503ing to trigger delays
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public async Task BufferedSender()
{
#region Snippet:Azure_Search_Documents_Tests_Samples_Sample05_IndexingDocuments_BufferedSender1
await using SearchIndexingBufferedSender<Product> indexer =
searchClient.CreateIndexingBufferedSender<Product>();
new SearchIndexingBufferedSender<Product>(searchClient);
await indexer.UploadDocumentsAsync(GenerateCatalog(count: 100000));
#endregion
}
Expand Down

0 comments on commit c11c9f9

Please sign in to comment.