Skip to content

Commit 97bd198

Browse files
committed
Use execSQL for replication slot creation
1 parent d440cb1 commit 97bd198

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

gpMgmt/bin/gppylib/commands/pg.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ def ensure_replication_slot_exists(source_host, source_port,
3636
if slot_exists > 0:
3737
return False
3838

39-
dbconn.querySingleton(
39+
dbconn.execSQL(
4040
conn,
41-
"SELECT slot_name "
42-
"FROM pg_catalog.pg_create_physical_replication_slot('{}')"
41+
"SELECT pg_catalog.pg_create_physical_replication_slot('{}')"
4342
.format(escaped_slot_name))
4443

4544
return True

gpMgmt/bin/gppylib/commands/test/unit/test_unit_pg_base_backup.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ def test_ensure_replication_slot_exists_returns_false_when_slot_exists(self, moc
6363
self.assertIn("FROM pg_catalog.pg_replication_slots", mock_query_singleton.call_args[0][1])
6464
mock_conn.close.assert_called_once_with()
6565

66-
@patch('gppylib.commands.pg.dbconn.querySingleton', side_effect=[0, 'slot_name'])
66+
@patch('gppylib.commands.pg.dbconn.execSQL')
67+
@patch('gppylib.commands.pg.dbconn.querySingleton', return_value=0)
6768
@patch('gppylib.commands.pg.dbconn.connect')
6869
@patch('gppylib.commands.pg.dbconn.DbURL')
6970
def test_ensure_replication_slot_exists_creates_missing_slot(self, mock_dburl,
7071
mock_connect,
71-
mock_query_singleton):
72+
mock_query_singleton,
73+
mock_exec_sql):
7274
mock_conn = Mock()
7375
mock_connect.return_value = mock_conn
7476

@@ -77,10 +79,11 @@ def test_ensure_replication_slot_exists_creates_missing_slot(self, mock_dburl,
7779
self.assertTrue(created)
7880
mock_dburl.assert_called_once_with(hostname='source-host', port=5432, dbname='template1')
7981
mock_connect.assert_called_once_with(mock_dburl.return_value, utility=True)
80-
self.assertEqual(2, mock_query_singleton.call_count)
81-
self.assertIn("FROM pg_catalog.pg_replication_slots", mock_query_singleton.call_args_list[0][0][1])
82+
self.assertEqual(1, mock_query_singleton.call_count)
83+
self.assertIn("FROM pg_catalog.pg_replication_slots", mock_query_singleton.call_args[0][1])
84+
mock_exec_sql.assert_called_once()
8285
self.assertIn("pg_create_physical_replication_slot('slot_name')",
83-
mock_query_singleton.call_args_list[1][0][1])
86+
mock_exec_sql.call_args[0][1])
8487
mock_conn.close.assert_called_once_with()
8588

8689
@patch('gppylib.commands.pg.dbconn.querySingleton')

0 commit comments

Comments
 (0)