Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion gpMgmt/bin/gppylib/operations/segment_reconfigurer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def reconfigure(self):
start_time = time.time()
while True:
time.sleep(1)
conn = None
try:
# Empty block of 'BEGIN' and 'END' won't start a distributed transaction,
# execute a DDL query to start a distributed transaction.
Expand All @@ -42,7 +43,8 @@ def reconfigure(self):
except Exception as e:
# Should close conn here
# Otherwise, the postmaster will be blocked by abort transaction
conn.close()
if conn is not None:
conn.close()
now = time.time()
if now < start_time + self.timeout:
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ def test_it_retries_the_connection(self):
self.connect.assert_has_calls([call(self.db_url), call(self.db_url), call(self.db_url), ])
self.conn.close.assert_any_call()

def test_it_closes_each_connection_only_once(self):
failed_conn = Mock(name='failed_conn')
failed_conn.cursor.return_value.execute.side_effect = pgdb.DatabaseError
self.connect.side_effect = [failed_conn, pgdb.DatabaseError, self.conn]

reconfigurer = SegmentReconfigurer(logger=self.logger,
worker_pool=self.worker_pool, timeout=self.timeout)
reconfigurer.reconfigure()

failed_conn.close.assert_called_once_with()
self.conn.close.assert_called_once_with()

@patch('time.time')
def test_it_gives_up_after_600_seconds(self, now_mock):
start_datetime = datetime.datetime(2018, 5, 9, 16, 0, 0)
Expand All @@ -83,7 +95,8 @@ def fail_for_five_minutes():
worker_pool=self.worker_pool, timeout=self.timeout)
with self.assertRaises(RuntimeError) as context:
reconfigurer.reconfigure()
self.assertEqual("Mirror promotion did not complete in {0} seconds.".format(self.timeout), context.exception.message)
self.assertEqual("Mirror promotion did not complete in {0} seconds.".format(self.timeout),
str(context.exception))

self.connect.assert_has_calls([call(self.db_url), call(self.db_url), ])
self.conn.close.assert_has_calls([])
self.assertFalse(self.conn.close.called)