-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathes-autoflush-enable
executable file
·112 lines (76 loc) · 2.65 KB
/
es-autoflush-enable
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python
# Copyright (c) 2014 Anchor Systems
# https://github.com/anchor/elasticsearch-scripts
"""
NAME
es-autoflush-enable - enable automatic transaction log flushing
across an ElasticSearch cluster
SYNOPSIS
es-autoflush-enable [HOST[:PORT]]
DESCRIPTION
Connect to the ElasticSearch HTTP server at HOST:PORT (defaults to
localhost:9200), and submit an API request to enable automatic
transaction log flushing.
You may supply the HOST:PORT of any one of the servers in your
ElasticSearch cluster. The server that receives our request will
forward it on to its peers.
RETURN VALUES
es-autoflush-enable will return zero on success; non-zero on
failure. Success is defined by the underlying ElasticSearch API.
See BACKGROUND INFORMATION.
BACKGROUND INFORMATION
- http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings.html
- http://www.elasticsearch.org/guide/reference/index-modules/translog.html
- https://github.com/elasticsearch/elasticsearch/issues/906
SEE ALSO
es-autoflush-disable
"""
DEFAULT_HOST = "localhost"
DEFAULT_PORT = 9200
from esadmin import Connection
import logging
import os
import socket
import sys
logger = logging.getLogger(__name__)
def usage(argv):
print >>sys.stderr, ("Usage:\n\t%s [HOST[:PORT]]\n" %
os.path.basename(argv[0]))
def main(argv=None):
if argv is None:
argv = sys.argv
host = DEFAULT_HOST
port = DEFAULT_PORT
try:
address = sys.argv[1]
except IndexError:
pass
else:
if address.find(":") == -1:
host = address
else:
host, port = address.split(":")
try:
port = int(port)
except ValueError:
usage(argv)
return 2
logger.info("Enabling automatic transaction log flushes...")
with Connection(host, port) as conn:
if len(conn.indices()) == 0:
logger.info("No indices. Nothing to do.")
return 0
old_status = conn.flushing_disabled()
logger.info("Old status: %s" % old_status.upper())
conn.put('/_settings', '{"index":{"translog.disable_flush":false}}')
new_status = conn.flushing_disabled()
logger.info("New status: %s" % new_status.upper())
assert new_status == "enabled"
logger.info("Done")
return 0
if __name__ == '__main__':
hostname = socket.gethostname()
fmt = ('[%s] [%%(process)d]: [%%(levelname)s] '
'%%(message)s' % hostname)
logging.basicConfig(level=logging.INFO, format=fmt)
sys.exit(main(sys.argv))