Skip to content

Commit

Permalink
fix bug on server-name, and host
Browse files Browse the repository at this point in the history
- make all host to ip, not use hostname, because sentinel always use ip
- slave use same server-name as master
- in active_master, we will find the old instance, not construce a new
  one
  • Loading branch information
idning committed Jan 9, 2014
1 parent 1856c88 commit fe48f8e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
28 changes: 13 additions & 15 deletions bin/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, name, user, host_port, path):
self.args = {
'name' : name,
'user' : user,
'host' : host_port.split(':')[0],
'host' : socket.gethostbyname(host_port.split(':')[0]),
'port' : int(host_port.split(':')[1]),
'path' : path,

Expand Down Expand Up @@ -421,10 +421,13 @@ class Cluster(object, Monitor, Benchmark):
def __init__(self, args):
self.args = args
self.all_redis = [ RedisServer(self.args['user'], hp, path) for hp, path in self.args['redis'] ]
self.all_masters = masters = self.all_redis[::2]
for m in masters:
m.args['cluster_name'] = args['cluster_name']
m.args['server_name'] = TT('$cluster_name-$port', m.args)
pairs = zip(self.all_redis[::2], self.all_redis[1::2])

for m, s in pairs: #slave use same name as master
s.args['cluster_name'] = m.args['cluster_name'] = args['cluster_name']
s.args['server_name'] = m.args['server_name'] = TT('$cluster_name-$port', m.args)

masters = self.all_redis[::2]

self.all_sentinel = [Sentinel(self.args['user'], hp, path, masters) for hp, path in self.args['sentinel'] ]
self.all_nutcracker = [NutCracker(self.args['user'], hp, path, masters) for hp, path in self.args['nutcracker'] ]
Expand Down Expand Up @@ -455,18 +458,13 @@ def _active_masters(self):
'''return the current master list on sentinel'''
new_masters = self._get_available_sentinel().get_masters()
new_masters = sorted(new_masters, key=lambda x: x[1])
def find_redis_path(input_host_port):
for host_port, path in self.args['redis']:
if host_port == input_host_port:
return path
logging.warn('we can not find redis path for %s in config' % input_host_port)
return ''

def make_master(host_port, name): # make master instance
m = RedisServer(self.args['user'], host_port, find_redis_path(host_port))
m.args['cluster_name'] = self.args['cluster_name']
m.args['server_name'] = name
return m
host = host_port.split(':')[0]
port = int(host_port.split(':')[1])
for r in self.all_redis:
if r.args['host'] == host and r.args['port'] == port:
return r

masters = [make_master(host_port, name) for host_port, name in new_masters]
return masters
Expand Down
4 changes: 2 additions & 2 deletions lib/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ def nbench(self):
run benchmark against nutcracker
'''
for s in self.all_nutcracker:
cmd = TT('bin/redis-benchmark --csv -h $host -p $port -r 100000 -t set,get -n 100000 -c 100 ', s.args)
cmd = TT('bin/redis-benchmark --csv -h $host -p $port -r 100000 -t set,get -n 10000000 -c 100 ', s.args)
BenchThread(random.choice(self._active_masters()), cmd).start()

def mbench(self):
'''
run benchmark against redis master
'''
for s in self._active_masters():
cmd = TT('bin/redis-benchmark --csv -h $host -p $port -r 100000 -t set,get -n 100000 -c 100 ', s.args)
cmd = TT('bin/redis-benchmark --csv -h $host -p $port -r 100000 -t set,get -n 10000000 -c 100 ', s.args)
BenchThread(s, cmd).start()

def stopbench(self):
Expand Down
1 change: 1 addition & 0 deletions lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
import copy
import thread
import socket
import threading
import logging
import inspect
Expand Down

0 comments on commit fe48f8e

Please sign in to comment.