Skip to content

Commit 8e24c39

Browse files
author
Chris Hoffman
committed
extra cleanup
1 parent c78f16e commit 8e24c39

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

redis_cluster.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
NUM_SLOTS = 16384
1515

1616

17-
def make_parts(n):
17+
def _make_parts(n):
1818
p = NUM_SLOTS/n
1919
remain = NUM_SLOTS-(p*n)
2020

@@ -34,6 +34,28 @@ def make_parts(n):
3434
return partitions
3535

3636

37+
def _map_cluster(node_host, node_port):
38+
cluster = {}
39+
slaves = []
40+
node_port = int(node_port)
41+
nodes, master = redistrib.command.list_nodes(node_host, node_port)
42+
for node in nodes:
43+
if 'master' in node.role_in_cluster:
44+
if node.node_id not in cluster:
45+
cluster[node.node_id] = {'self': node, 'slaves': []}
46+
else:
47+
slaves.append(node)
48+
49+
for slave in slaves:
50+
cluster[slave.master_id]['slaves'].append(slave)
51+
52+
if slaves:
53+
cluster_replication_factor = int(len(cluster) / len(slaves))
54+
else:
55+
cluster_replication_factor = 0
56+
return cluster, slaves, cluster_replication_factor
57+
58+
3759
def create(new_nodes, replicas=0):
3860
"""
3961
Function to create a new cluster ONLY from nodes not already initialized. NOTE: this function replicates
@@ -80,28 +102,6 @@ def create(new_nodes, replicas=0):
80102
return True
81103

82104

83-
def _map_cluster(node_host, node_port):
84-
cluster = {}
85-
slaves = []
86-
node_port = int(node_port)
87-
nodes, master = redistrib.command.list_nodes(node_host, node_port)
88-
for node in nodes:
89-
if 'master' in node.role_in_cluster:
90-
if node.node_id not in cluster:
91-
cluster[node.node_id] = {'self': node, 'slaves': []}
92-
else:
93-
slaves.append(node)
94-
95-
for slave in slaves:
96-
cluster[slave.master_id]['slaves'].append(slave)
97-
98-
if slaves:
99-
cluster_replication_factor = int(len(cluster) / len(slaves))
100-
else:
101-
cluster_replication_factor = 0
102-
return cluster, slaves, cluster_replication_factor
103-
104-
105105
def expand_cluster(master_host, master_port, new_nodes, num_new_masters=None):
106106
"""
107107
function to add a set of nodes to an existing cluster. NOTE: this function presumes that the list of new nodes are
@@ -205,7 +205,7 @@ def expand_cluster(master_host, master_port, new_nodes, num_new_masters=None):
205205
new_master_node['host'], int(new_master_node['port']))
206206

207207

208-
def validate_and_run(new_hosts, replication_factor=None, new_masters=None):
208+
def _validate_and_run(new_hosts, replication_factor=None, new_masters=None):
209209
new_nodes = []
210210
cluster_nodes = []
211211

@@ -269,7 +269,7 @@ def remove_cluster(cluster_nodes):
269269
reset_node(master['self'])
270270

271271

272-
def decode_hosts(host_list):
272+
def _decode_hosts(host_list):
273273
hosts = []
274274
for host in host_list:
275275
try:
@@ -285,7 +285,7 @@ def decode_hosts(host_list):
285285

286286

287287
# from http://stackoverflow.com/questions/14117415
288-
def check_negative(value):
288+
def _check_negative(value):
289289
ivalue = int(value)
290290
if ivalue < 0:
291291
raise argparse.ArgumentTypeError("%s is an invalid positive int value" % value)
@@ -322,16 +322,16 @@ def main():
322322
args = parser.parse_args()
323323

324324
if args.replication_factor:
325-
args.replication_factor = check_negative(args.replication_factor)
325+
args.replication_factor = _check_negative(args.replication_factor)
326326

327327
if args.new_masters:
328-
args.new_masters = check_negative(args.new_masters)
328+
args.new_masters = _check_negative(args.new_masters)
329329

330330
if not args.clear_cluster:
331-
new_hosts = decode_hosts(args.new_hosts)
332-
validate_and_run(new_hosts, args.replication_factor, args.new_masters)
331+
new_hosts = _decode_hosts(args.new_hosts)
332+
_validate_and_run(new_hosts, args.replication_factor, args.new_masters)
333333
else:
334-
hosts = decode_hosts(args.new_hosts)
334+
hosts = _decode_hosts(args.new_hosts)
335335
remove_cluster(hosts)
336336

337337

0 commit comments

Comments
 (0)