From 46d26635357254d8e2f89ffd32b84e1742b35338 Mon Sep 17 00:00:00 2001 From: Ryan Wynn Date: Tue, 19 Dec 2023 09:37:21 -0500 Subject: [PATCH] Ignore 404 status code for the purpose of backoff. Issue #705. --- monstache.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/monstache.go b/monstache.go index a383068..1e4c032 100644 --- a/monstache.go +++ b/monstache.go @@ -565,18 +565,17 @@ func (ic *indexClient) afterBulk() func(int64, []elastic.BulkableRequest, *elast if failed := response.Failed(); failed != nil { backoff := false for _, item := range failed { - if item.Status == 409 { + if item.Status == http.StatusConflict { // ignore version conflict since this simply means the doc // is already in the index continue } - backoff = true - json, err := json.Marshal(item) - if err != nil { - errorLog.Printf("Unable to marshal bulk response item: %s", err) - } else { - errorLog.Printf("Bulk response item: %s", string(json)) + logFailedResponseItem(item) + if item.Status == http.StatusNotFound { + // status not found should not initiate back off + continue } + backoff = true } if backoff { wait := ic.backoffDuration() @@ -591,6 +590,14 @@ func (ic *indexClient) afterBulk() func(int64, []elastic.BulkableRequest, *elast } } +func logFailedResponseItem(item *elastic.BulkResponseItem) { + if encoded, err := json.Marshal(item); err == nil { + errorLog.Printf("Bulk response item: %s", string(encoded)) + } else { + errorLog.Printf("Unable to marshal bulk response item: %s", err) + } +} + func (ic *indexClient) backoffDuration() time.Duration { consecutiveErrors := int(ic.bulkErrs.Load()) wait, ok := ic.bulkBackoff.Next(consecutiveErrors)