clean up some debugging statements

This commit is contained in:
Christopher Winslett
2015-03-16 08:30:15 -07:00
parent c96972ee3c
commit 450b9912d7
3 changed files with 3 additions and 29 deletions
-24
View File
@@ -31,78 +31,54 @@ class Ha:
def run_cycle(self):
try:
print lineno()
if self.state_handler.is_healthy():
print lineno()
if self.is_unlocked():
print lineno()
if self.state_handler.is_healthiest_node():
print lineno()
if self.acquire_lock():
print lineno()
if not self.state_handler.is_leader():
print lineno()
self.state_handler.promote()
return "promoted self to leader by acquiring session lock"
print lineno()
return "acquired session lock as a leader"
else:
print lineno()
if self.state_handler.is_leader():
print lineno()
self.state_handler.demote(self.fetch_current_leader())
return "demoted self due after trying and failing to obtain lock"
else:
print lineno()
self.state_handler.follow_the_leader(self.fetch_current_leader())
return "following new leader after trying and failing to obtain lock"
else:
print lineno()
if self.state_handler.is_leader():
print lineno()
self.state_handler.demote(self.fetch_current_leader())
return "demoting self because i am not the healthiest node"
else:
print lineno()
self.state_handler.follow_the_leader(self.fetch_current_leader())
return "following a different leader because i am not the healthiest node"
else:
print lineno()
if self.has_lock():
print lineno()
self.update_lock()
if not self.state_handler.is_leader():
print lineno()
self.state_handler.promote()
return "promoted self to leader because i had the session lock"
else:
print lineno()
return "no action. i am the leader with the lock"
else:
print lineno()
print "does not have lock"
if self.state_handler.is_leader():
print lineno()
self.state_handler.demote(self.fetch_current_leader())
return "demoting self because i do not have the lock and i was a leader"
else:
print lineno()
self.state_handler.follow_the_leader(self.fetch_current_leader())
return "no action. i am a secondary and i am following a leader"
else:
print lineno()
return "no action. not healthy enough to do anything."
except helpers.errors.CurrentLeaderError:
print lineno()
print "failed to fetch current leader from etcd"
except psycopg2.OperationalError:
print lineno()
print "Error communicating with Postgresql. Will try again."
except helpers.errors.HealthiestMemberError:
print lineno()
print "failed to determine healthiest member fromt etcd"
def run(self):
+2 -2
View File
@@ -75,7 +75,7 @@ class Postgresql:
return not self.query("SELECT pg_is_in_recovery();").fetchone()[0]
def is_running(self):
return os.system("pg_ctl status -D %s" % self.data_dir) == 0
return os.system("pg_ctl status -D %s > /dev/null" % self.data_dir) == 0
def start(self):
command_code = os.system("postgres -D %s %s &" % (self.data_dir, self.server_options()))
@@ -136,7 +136,7 @@ recovery_target_timeline = 'latest'
def follow_the_leader(self, leader_hash):
leader = urlparse(leader_hash["address"])
if os.system("grep 'host=%(hostname)s port=%(port)s' %(data_dir)s/recovery.conf" % {"hostname": leader.hostname, "port": leader.port, "data_dir": self.data_dir}) != 0:
if os.system("grep 'host=%(hostname)s port=%(port)s' %(data_dir)s/recovery.conf > /dev/null" % {"hostname": leader.hostname, "port": leader.port, "data_dir": self.data_dir}) != 0:
self.write_recovery_conf(leader_hash);
self.restart()
return True
+1 -3
View File
@@ -9,8 +9,6 @@ f = open(sys.argv[1], "r")
config = yaml.load(f.read())
f.close()
print config
etcd = Etcd(config["etcd"])
postgresql = Postgresql(config["postgresql"])
ha = Ha(postgresql, etcd)
@@ -44,7 +42,7 @@ if postgresql.data_directory_empty():
leader = etcd.current_leader()
if leader == None:
time.sleep(5)
next
continue
if postgresql.sync_from_leader(leader):
postgresql.write_recovery_conf(leader)
postgresql.start()