Skip to content

Commit 3fb6173

Browse files
author
Derek Legenzoff
committed
updating v11 retry mechanism
1 parent 3288358 commit 3fb6173

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

optimize-data-indexing/v11/OptimizeDataIndexing/ExponentialBackoff.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ private static async Task<IndexDocumentsResult> ExponentialBackoffAsync(SearchCl
3434

3535
var failedDocuments = result.Results.Where(r => r.Succeeded != true).ToList();
3636

37+
// handle partial failure
3738
if (failedDocuments.Count > 0)
3839
{
39-
Console.WriteLine("BATCH STARTING AT DOC {0}:", id);
40-
Console.WriteLine("[Attempt: {0} of {1} Failed] - Error: {2} \n", attempts, maxRetryAttempts);
41-
40+
4241
if (attempts == maxRetryAttempts)
4342
{
44-
Console.WriteLine("BATCH STARTING AT DOC {0}:", id);
4543
Console.WriteLine("[MAX RETRIES HIT] - Giving up on the batch starting at {0}", id);
4644
break;
4745
}
4846
else
4947
{
50-
Console.WriteLine("BATCH STARTING AT DOC {0}:", id);
51-
Console.WriteLine("[Attempt: {0} of {1} Failed] - Error: {2} \n", attempts, maxRetryAttempts);
52-
Console.WriteLine("{0} documents failed:", failedDocuments.Count);
48+
Console.WriteLine("[Batch starting at doc {0} had partial failure]", id);
49+
//Console.WriteLine("[Attempt: {0} of {1} Failed]", attempts, maxRetryAttempts);
50+
Console.WriteLine("[Retrying {0} failed documents] \n", failedDocuments.Count);
51+
52+
// creating a batch of failed documents to retry
5353
var failedDocumentKeys = failedDocuments.Select(doc => doc.Key).ToList();
5454
hotels = hotels.Where(h => failedDocumentKeys.Contains(h.HotelId)).ToList();
5555
batch = IndexDocumentsBatch.Upload(hotels);
@@ -65,8 +65,9 @@ private static async Task<IndexDocumentsResult> ExponentialBackoffAsync(SearchCl
6565
}
6666
catch (RequestFailedException ex)
6767
{
68-
Console.WriteLine("BATCH STARTING AT DOC {0}:", id);
69-
Console.WriteLine("[Attempt: {0} of {1} Failed] - Error: {2} \n", attempts, maxRetryAttempts, ex.Message);
68+
Console.WriteLine("[Batch starting at doc {0} failed]", id);
69+
//Console.WriteLine("[Attempt: {0} of {1} Failed] - Error: {2} \n", attempts, maxRetryAttempts, ex.Message);
70+
Console.WriteLine("[Retrying entire batch] \n");
7071

7172
if (attempts == maxRetryAttempts)
7273
{

optimize-data-indexing/v11/OptimizeDataIndexing/Program.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ public static async Task Main(string[] args)
3535
Console.WriteLine("{0}", "Creating index...\n");
3636
await CreateIndexAsync(indexName, indexClient);
3737

38-
//Console.WriteLine("{0}", "Finding optimal batch size...\n");
39-
//await TestBatchSizesAsync(searchClient, numTries: 3);
38+
Console.WriteLine("{0}", "Finding optimal batch size...\n");
39+
await TestBatchSizesAsync(searchClient, numTries: 3);
4040

41-
long numDocuments = 100000;
42-
DataGenerator dg = new DataGenerator();
43-
List<Hotel> hotels = dg.GetHotels(numDocuments, "large");
41+
//long numDocuments = 100000;
42+
//DataGenerator dg = new DataGenerator();
43+
//List<Hotel> hotels = dg.GetHotels(numDocuments, "large");
4444

45-
Console.WriteLine("{0}", "Uploading using exponential backoff...\n");
46-
await ExponentialBackoff.IndexDataAsync(searchClient, hotels, 500, 20); //8
45+
//Console.WriteLine("{0}", "Uploading using exponential backoff...\n");
46+
//await ExponentialBackoff.IndexDataAsync(searchClient, hotels, 1000, 8);
4747

48-
Console.WriteLine("{0}", "Validating all data was indexed...\n");
49-
await ValidateIndexAsync(indexClient, indexName, numDocuments);
48+
//Console.WriteLine("{0}", "Validating all data was indexed...\n");
49+
//await ValidateIndexAsync(indexClient, indexName, numDocuments);
5050

5151
Console.WriteLine("{0}", "Complete. Press any key to end application...\n");
5252
Console.ReadKey();

0 commit comments

Comments
 (0)