mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Always return checkpoint location as integer (#2349)
before it was also returning a str in some cases
This commit is contained in:
@@ -428,11 +428,11 @@ class Postgresql(object):
|
||||
# If the cluster is shutdown with archive_mode=on, WAL is switched before writing the checkpoint.
|
||||
# In this case we want to take the LSN of previous record (switch) as the last known WAL location.
|
||||
if parse_lsn(lsn) == prev and desc.strip() in ('xlog switch', 'SWITCH'):
|
||||
return str(prev)
|
||||
return prev
|
||||
except Exception as e:
|
||||
logger.error('Exception when parsing WAL pg_%sdump output: %r', self.wal_name, e)
|
||||
if isinstance(checkpoint_lsn, six.integer_types):
|
||||
return str(checkpoint_lsn)
|
||||
return checkpoint_lsn
|
||||
|
||||
def is_running(self):
|
||||
"""Returns PostmasterProcess if one is running on the data directory or None. If most recently seen process
|
||||
@@ -668,7 +668,7 @@ class Postgresql(object):
|
||||
while postmaster.is_running():
|
||||
data = self.controldata()
|
||||
if data.get('Database cluster state', '') == 'shut down':
|
||||
on_shutdown(int(self.latest_checkpoint_location()))
|
||||
on_shutdown(self.latest_checkpoint_location())
|
||||
break
|
||||
elif data.get('Database cluster state', '').startswith('shut down'): # shut down in recovery
|
||||
break
|
||||
|
||||
@@ -347,7 +347,7 @@ class TestPostgresql(BaseTestPostgresql):
|
||||
@patch('subprocess.Popen')
|
||||
def test_latest_checkpoint_location(self, mock_popen):
|
||||
mock_popen.return_value.communicate.return_value = (None, None)
|
||||
self.assertEqual(self.p.latest_checkpoint_location(), '28163096')
|
||||
self.assertEqual(self.p.latest_checkpoint_location(), 28163096)
|
||||
# 9.3 and 9.4 format
|
||||
mock_popen.return_value.communicate.side_effect = [
|
||||
(b'rmgr: XLOG len (rec/tot): 72/ 104, tx: 0, lsn: 0/01ADBC18, prev 0/01ADBBB8, ' +
|
||||
@@ -355,14 +355,14 @@ class TestPostgresql(BaseTestPostgresql):
|
||||
b' 1; offset 0; oldest xid 715 in DB 1; oldest multi 1 in DB 1; oldest running xid 0; shutdown', None),
|
||||
(b'rmgr: Transaction len (rec/tot): 64/ 96, tx: 726, lsn: 0/01ADBBB8, prev 0/01ADBB70, ' +
|
||||
b'bkp: 0000, desc: commit: 2021-02-26 11:19:37.900918 CET; inval msgs: catcache 11 catcache 10', None)]
|
||||
self.assertEqual(self.p.latest_checkpoint_location(), '28163096')
|
||||
self.assertEqual(self.p.latest_checkpoint_location(), 28163096)
|
||||
mock_popen.return_value.communicate.side_effect = [
|
||||
(b'rmgr: XLOG len (rec/tot): 72/ 104, tx: 0, lsn: 0/01ADBC18, prev 0/01ADBBB8, ' +
|
||||
b'bkp: 0000, desc: checkpoint: redo 0/1ADBC18; tli 1; prev tli 1; fpw true; xid 0/727; oid 16386; multi' +
|
||||
b' 1; offset 0; oldest xid 715 in DB 1; oldest multi 1 in DB 1; oldest running xid 0; shutdown', None),
|
||||
(b'rmgr: XLOG len (rec/tot): 0/ 32, tx: 0, lsn: 0/01ADBBB8, prev 0/01ADBBA0, ' +
|
||||
b'bkp: 0000, desc: xlog switch ', None)]
|
||||
self.assertEqual(self.p.latest_checkpoint_location(), '28163000')
|
||||
self.assertEqual(self.p.latest_checkpoint_location(), 28163000)
|
||||
# 9.5+ format
|
||||
mock_popen.return_value.communicate.side_effect = [
|
||||
(b'rmgr: XLOG len (rec/tot): 114/ 114, tx: 0, lsn: 0/01ADBC18, prev 0/018260F8, ' +
|
||||
@@ -371,7 +371,7 @@ class TestPostgresql(BaseTestPostgresql):
|
||||
b' oldest running xid 0; shutdown', None),
|
||||
(b'rmgr: XLOG len (rec/tot): 24/ 24, tx: 0, lsn: 0/018260F8, prev 0/01826080, ' +
|
||||
b'desc: SWITCH ', None)]
|
||||
self.assertEqual(self.p.latest_checkpoint_location(), '25321720')
|
||||
self.assertEqual(self.p.latest_checkpoint_location(), 25321720)
|
||||
|
||||
def test_reload(self):
|
||||
self.assertTrue(self.p.reload())
|
||||
|
||||
Reference in New Issue
Block a user