Skip to content

Commit bf6b99a

Browse files
committed
Explicitly ignore errors when deleting data from unavailable indexes
1 parent 0079941 commit bf6b99a

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

internal/benchrunner/runners/rally/runner.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"errors"
1313
"fmt"
1414
"io"
15-
"net/http"
1615
"os"
1716
"os/exec"
1817
"path/filepath"
@@ -337,14 +336,16 @@ func (r *runner) collectAndSummarizeMetrics() (*metricsSummary, error) {
337336

338337
func (r *runner) deleteDataStreamDocs(dataStream string) error {
339338
body := strings.NewReader(`{ "query": { "match_all": {} } }`)
340-
resp, err := r.options.ESAPI.DeleteByQuery([]string{dataStream}, body)
339+
resp, err := r.options.ESAPI.DeleteByQuery([]string{dataStream}, body,
340+
// Unavailable index is ok, this means that data is already not there.
341+
r.options.ESAPI.DeleteByQuery.WithIgnoreUnavailable(true),
342+
)
341343
if err != nil {
342344
return fmt.Errorf("failed to delete data stream docs for data stream %s: %w", dataStream, err)
343345
}
344346
defer resp.Body.Close()
345347

346-
// Not found error is fine here, this means that data was already not there.
347-
if resp.IsError() && resp.StatusCode != http.StatusNotFound {
348+
if resp.IsError() {
348349
return fmt.Errorf("failed to delete data stream docs for data stream %s: %s", dataStream, resp.String())
349350
}
350351

internal/benchrunner/runners/system/runner.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"errors"
1212
"fmt"
1313
"io"
14-
"net/http"
1514
"os"
1615
"path/filepath"
1716
"strings"
@@ -334,14 +333,16 @@ func (r *runner) collectAndSummarizeMetrics() (*metricsSummary, error) {
334333

335334
func (r *runner) deleteDataStreamDocs(dataStream string) error {
336335
body := strings.NewReader(`{ "query": { "match_all": {} } }`)
337-
resp, err := r.options.ESAPI.DeleteByQuery([]string{dataStream}, body)
336+
resp, err := r.options.ESAPI.DeleteByQuery([]string{dataStream}, body,
337+
// Unavailable index is ok, this means that data is already not there.
338+
r.options.ESAPI.DeleteByQuery.WithIgnoreUnavailable(true),
339+
)
338340
if err != nil {
339341
return fmt.Errorf("failed to delete docs for data stream %s: %w", dataStream, err)
340342
}
341343
defer resp.Body.Close()
342344

343-
// Not found error is fine here, this means that data was already not there.
344-
if resp.IsError() && resp.StatusCode != http.StatusNotFound {
345+
if resp.IsError() {
345346
return fmt.Errorf("failed to delete data stream docs for data stream %s: %s", dataStream, resp.String())
346347
}
347348

internal/testrunner/runners/system/runner.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -395,22 +395,18 @@ func (r *runner) getDocs(dataStream string) (*hits, error) {
395395
r.options.API.Search.WithSize(elasticsearchQuerySize),
396396
r.options.API.Search.WithSource("true"),
397397
r.options.API.Search.WithBody(strings.NewReader(allFieldsBody)),
398+
r.options.API.Search.WithIgnoreUnavailable(true),
398399
)
399400
if err != nil {
400401
return nil, fmt.Errorf("could not search data stream: %w", err)
401402
}
402403
defer resp.Body.Close()
403404

404-
if resp.StatusCode == http.StatusNotFound {
405-
// No docs yet.
406-
return &hits{}, nil
407-
}
408405
if resp.StatusCode == http.StatusServiceUnavailable && strings.Contains(resp.String(), "no_shard_available_action_exception") {
409406
// Index is being created, but no shards are available yet.
410407
// See https://github.com/elastic/elasticsearch/issues/65846
411408
return &hits{}, nil
412409
}
413-
414410
if resp.IsError() {
415411
return nil, fmt.Errorf("failed to search docs for data stream %s: %s", dataStream, resp.String())
416412
}
@@ -1186,14 +1182,16 @@ func (r *runner) previewTransform(transformId string) ([]common.MapStr, error) {
11861182

11871183
func deleteDataStreamDocs(api *elasticsearch.API, dataStream string) error {
11881184
body := strings.NewReader(`{ "query": { "match_all": {} } }`)
1189-
resp, err := api.DeleteByQuery([]string{dataStream}, body)
1185+
resp, err := api.DeleteByQuery([]string{dataStream}, body,
1186+
// Unavailable index is ok, this means that data is already not there.
1187+
r.options.ESAPI.DeleteByQuery.WithIgnoreUnavailable(true),
1188+
)
11901189
if err != nil {
11911190
return fmt.Errorf("failed to delete data stream docs: %w", err)
11921191
}
11931192
defer resp.Body.Close()
11941193

1195-
// Not found error is fine here, this means that data was already not there.
1196-
if resp.IsError() && resp.StatusCode != http.StatusNotFound {
1194+
if resp.IsError() {
11971195
return fmt.Errorf("failed to delete data stream docs for data stream %s: %s", dataStream, resp.String())
11981196
}
11991197

0 commit comments

Comments
 (0)