Skip to content

Commit fca593e

Browse files
authored
Allow the close action to ignore sync flush fails (#1460)
If closing a very large batch of indices, potentially with some being live at runtime, a failure to perform a synced flush is a real possibility. This new option for the ``close`` action, ``ignore_sync_failures``, will allow index closures to continue. Fixes #1248
1 parent a0bf89f commit fca593e

File tree

14 files changed

+152
-15
lines changed

14 files changed

+152
-15
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,4 @@ Contributors:
8585
* Juraj Seffer (jurajseffer)
8686
* Roger Steneteg (rsteneteg)
8787
* Muhammad Junaid Muzammil (junmuz)
88+
* Loet Avramson (psypuff)

curator/actions.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from copy import deepcopy
55
from datetime import datetime
66
from curator import exceptions, utils
7-
from elasticsearch.exceptions import RequestError
7+
from elasticsearch.exceptions import ConflictError, RequestError
88

99
class Alias(object):
1010
def __init__(self, name=None, extra_settings={}, **kwargs):
@@ -256,14 +256,17 @@ def do_action(self):
256256

257257

258258
class Close(object):
259-
def __init__(self, ilo, delete_aliases=False, skip_flush=False):
259+
def __init__(self, ilo, delete_aliases=False, skip_flush=False, ignore_sync_failures=False):
260260
"""
261261
:arg ilo: A :class:`curator.indexlist.IndexList` object
262262
:arg delete_aliases: If `True`, will delete any associated aliases
263263
before closing indices.
264264
:type delete_aliases: bool
265265
:arg skip_flush: If `True`, will not flush indices before closing.
266266
:type skip_flush: bool
267+
:arg ignore_sync_failures: If `True`, will not fail if there are failures while attempting
268+
a synced flush.
269+
:type ignore_sync_failures: bool
267270
"""
268271
utils.verify_index_list(ilo)
269272
#: Instance variable.
@@ -276,9 +279,12 @@ def __init__(self, ilo, delete_aliases=False, skip_flush=False):
276279
#: Internal reference to `skip_flush`
277280
self.skip_flush = skip_flush
278281
#: Instance variable.
282+
#: Internal reference to `ignore_sync_failures`
283+
self.ignore_sync_failures = ignore_sync_failures
284+
#: Instance variable.
279285
#: The Elasticsearch Client object derived from `ilo`
280-
self.client = ilo.client
281-
self.loggit = logging.getLogger('curator.actions.close')
286+
self.client = ilo.client
287+
self.loggit = logging.getLogger('curator.actions.close')
282288

283289

284290
def do_dry_run(self):
@@ -295,7 +301,10 @@ def do_action(self):
295301
self.index_list.filter_closed()
296302
self.index_list.empty_list_check()
297303
self.loggit.info(
298-
'Closing {0} selected indices: {1}'.format(len(self.index_list.indices), self.index_list.indices))
304+
'Closing %s selected indices: %s' % (
305+
len(self.index_list.indices), self.index_list.indices
306+
)
307+
)
299308
try:
300309
index_lists = utils.chunk_index_list(self.index_list.indices)
301310
for l in index_lists:
@@ -312,8 +321,16 @@ def do_action(self):
312321
' {0}'.format(e)
313322
)
314323
if not self.skip_flush:
315-
self.client.indices.flush_synced(
316-
index=utils.to_csv(l), ignore_unavailable=True)
324+
try:
325+
self.client.indices.flush_synced(
326+
index=utils.to_csv(l), ignore_unavailable=True)
327+
except ConflictError as err:
328+
if not self.ignore_sync_failures:
329+
raise ConflictError(err.status_code, err.error, err.info)
330+
else:
331+
self.loggit.warn(
332+
'Ignoring flushed sync failures: %s %s' % (err.error, err.info)
333+
)
317334
self.client.indices.close(
318335
index=utils.to_csv(l), ignore_unavailable=True)
319336
except Exception as e:

curator/defaults/option_defaults.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def ignore_empty_list():
5757
def ignore_existing():
5858
return { Optional('ignore_existing', default=False): Any(bool, All(Any(*string_types), Boolean())) }
5959

60+
def ignore_sync_failures():
61+
return { Optional('ignore_sync_failures', default=False): Any(bool, All(Any(*string_types), Boolean())) }
62+
6063
def ignore_unavailable():
6164
return { Optional('ignore_unavailable', default=False): Any(bool, All(Any(*string_types), Boolean())) }
6265

curator/validators/options.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def action_specific(action):
1919
],
2020
'close' : [
2121
option_defaults.delete_aliases(),
22-
option_defaults.skip_flush()
22+
option_defaults.skip_flush(),
23+
option_defaults.ignore_sync_failures(),
2324
],
2425
'cluster_routing' : [
2526
option_defaults.routing_type(),

docs/Changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Changelog
88

99
**New**
1010

11+
* Require ``elasticsearch-py`` version 7.0.4
1112
* New client configuration option: api_key - used in the X-Api-key header in
1213
requests to Elasticsearch when set, which may be required if ReadonlyREST
1314
plugin is configured to require api-key. Requested in #1409 (vetler)
@@ -25,6 +26,8 @@ Changelog
2526
* Add support for ``freeze`` and ``unfreeze`` indexes using curator. Requires
2627
Elasticsearch version 6.6 or greater with xpack enabled. Requested in issue
2728
#1399 and rasied in PR #1454. (junmuz)
29+
* Allow the ``close`` action to ignore synced flush failures with the new
30+
``ignore_sync_failures`` option. Raised in #1248. (untergeek)
2831

2932
**Bug Fixes**
3033

docs/asciidoc/actions.asciidoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ TIP: See an example of this action in an <<actionfile,actionfile>>
175175
action: close
176176
description: "Close selected indices"
177177
options:
178-
delete_aliases: False
179-
skip_flush: False
178+
delete_aliases: false
179+
skip_flush: false
180+
ignore_sync_failures: false
180181
filters:
181182
- filtertype: ...
182183
-------------
@@ -192,6 +193,7 @@ aliases beforehand.
192193

193194
* <<option_delete_aliases,delete_aliases>>
194195
* <<option_skip_flush,skip_flush>>
196+
* <<option_ignore_sync_failures,ignore_sync_failures>>
195197
* <<option_ignore_empty,ignore_empty_list>>
196198
* <<option_timeout_override,timeout_override>>
197199
* <<option_continue,continue_if_exception>>

docs/asciidoc/examples.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ actions:
136136
options:
137137
skip_flush: False
138138
delete_aliases: False
139+
ignore_sync_failures: True
139140
disable_action: True
140141
filters:
141142
- filtertype: pattern

docs/asciidoc/index.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
:curator_version: 5.8.0
22
:curator_major: 5
33
:curator_doc_tree: 5.8
4-
:es_py_version: 7.0.2
4+
:es_py_version: 7.0.4
55
:es_doc_tree: 7.3
66
:stack_doc_tree: 7.3
77
:pybuild_ver: 3.6.8

docs/asciidoc/options.asciidoc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,28 @@ an ERROR level message will be logged, and Curator will exit with code 1.
458458

459459
The default value of this setting is `False`
460460

461+
[[option_ignore_sync_failures]]
462+
== ignore_sync_failures
463+
464+
NOTE: This setting is only used by the <<close,close action>>, and is
465+
optional.
466+
467+
[source,yaml]
468+
-------------
469+
action: close
470+
description: "Close selected indices"
471+
options:
472+
ignore_sync_failures: false
473+
filters:
474+
- filtertype: ...
475+
-------------
476+
477+
If `ignore_sync_failures` is set to `true`, Curator will ignore failures during
478+
the synced flush that normally takes place before closing. This may be useful
479+
for closing a list of indices which may include active indices.
480+
481+
The default value is `false`.
482+
461483
[[option_ignore]]
462484
== ignore_unavailable
463485

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
voluptuous>=0.9.3
2-
elasticsearch>=7.0.2,<8.0.0
2+
elasticsearch>=7.0.4,<8.0.0
33
urllib3>=1.24.2,<1.25
44
requests>=2.20.0
55
boto3>=1.9.142

0 commit comments

Comments
 (0)