aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlog.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2020-07-13 13:49:51 -0400
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2020-07-13 13:49:51 -0400
commitb5b4c0fef9fb905d98f93c1f455397449c6e63a8 (patch)
tree2925bf719f5584e2ea3f2a09cbf9839d5275464c /src/backend/access/transam/xlog.c
parent25fe5ac45a736e50d2b85280a3cb0ce169f583f3 (diff)
downloadpostgresql-b5b4c0fef9fb905d98f93c1f455397449c6e63a8.tar.gz
postgresql-b5b4c0fef9fb905d98f93c1f455397449c6e63a8.zip
Fix uninitialized value in segno calculation
Remove previous hack in KeepLogSeg that added a case to deal with a (badly represented) invalid segment number. This was added for the sake of GetWALAvailability. But it's not needed if in that function we initialize the segment number to be retreated to the currently being written segment, so do that instead. Per valgrind-running buildfarm member skink, and some sparc64 animals. Discussion: https://postgr.es/m/1724648.1594230917@sss.pgh.pa.us
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r--src/backend/access/transam/xlog.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 28daf72a503..0a97b1d37fb 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -9523,13 +9523,13 @@ GetWALAvailability(XLogRecPtr targetLSN)
if (XLogRecPtrIsInvalid(targetLSN))
return WALAVAIL_INVALID_LSN;
- currpos = GetXLogWriteRecPtr();
-
/*
- * calculate the oldest segment currently reserved by all slots,
- * considering wal_keep_segments and max_slot_wal_keep_size
+ * Calculate the oldest segment currently reserved by all slots,
+ * considering wal_keep_segments and max_slot_wal_keep_size. Initialize
+ * oldestSlotSeg to the current segment.
*/
- XLByteToSeg(targetLSN, targetSeg, wal_segment_size);
+ currpos = GetXLogWriteRecPtr();
+ XLByteToSeg(currpos, oldestSlotSeg, wal_segment_size);
KeepLogSeg(currpos, &oldestSlotSeg);
/*
@@ -9548,6 +9548,9 @@ GetWALAvailability(XLogRecPtr targetLSN)
else
oldestSegMaxWalSize = 1;
+ /* the segment we care about */
+ XLByteToSeg(targetLSN, targetSeg, wal_segment_size);
+
/*
* No point in returning reserved or extended status values if the
* targetSeg is known to be lost.
@@ -9624,7 +9627,7 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo)
}
/* don't delete WAL segments newer than the calculated segment */
- if (XLogRecPtrIsInvalid(*logSegNo) || segno < *logSegNo)
+ if (segno < *logSegNo)
*logSegNo = segno;
}