You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by yj...@apache.org on 2025/01/22 01:12:12 UTC

(cloudberry) 16/17: Fix KeepLogSeg() unittest

This is an automated email from the ASF dual-hosted git repository.

yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit f0976cecf3c142d0bfadfa4b99f911f581eba758
Author: Asim R P <pa...@vmware.com>
AuthorDate: Tue May 18 21:58:06 2021 +0530

    Fix KeepLogSeg() unittest
    
    The current WAL record pointer passed by the test to KeepLogSeg was
    older that _logSegNo.  This cannot happen, so fix it by increasing it
    beyond _logSegNo.  The test needs to be refactored heavily to make use
    of new WAL format, but let's do it as a follow up.
    
    Reviewed by: Ashwin Agrawal <aa...@vmware.com>
    Reviewed by: Paul Guo <pa...@gmail.com>
    
    (cherry picked from commit e4ec851b151267fe3209af6804e438611836a875)
---
 src/backend/access/transam/test/xlog_test.c | 88 ++++++++++++++++++++++++++++-
 1 file changed, 85 insertions(+), 3 deletions(-)

diff --git a/src/backend/access/transam/test/xlog_test.c b/src/backend/access/transam/test/xlog_test.c
index 436a4cfb99..dacebb77a6 100644
--- a/src/backend/access/transam/test/xlog_test.c
+++ b/src/backend/access/transam/test/xlog_test.c
@@ -124,15 +124,97 @@ test_KeepLogSeg(void **state)
 	 ***********************************************/
 	/* Current Delete pointer */
 	wal_keep_size_mb = 0;
-	_logSegNo = 4 * XLogSegmentsPerXLogId(wal_segment_size) + 45;
+	_logSegNo = recptr / wal_segment_size - 3;
 
 	KeepLogSeg_wrapper(recptr, &_logSegNo);
-	assert_int_equal(_logSegNo, 4*XLogSegmentsPerXLogId(wal_segment_size) + 45);
+	assert_int_equal(_logSegNo, recptr / wal_segment_size - 3);
 
 	wal_keep_size_mb = -1;
 
 	KeepLogSeg_wrapper(recptr, &_logSegNo);
-	assert_int_equal(_logSegNo, 4*XLogSegmentsPerXLogId(wal_segment_size) + 45);
+	assert_int_equal(_logSegNo, recptr / wal_segment_size - 3);
+	/************************************************/
+}
+
+static void
+test_KeepLogSeg_max_slot_wal_keep_size(void **state)
+{
+	XLogRecPtr recptr;
+	XLogSegNo  _logSegNo;
+	XLogCtlData xlogctl;
+
+	xlogctl.replicationSlotMinLSN = ((uint64) 4) << 32 | (wal_segment_size * 0);
+	SpinLockInit(&xlogctl.info_lck);
+	XLogCtl = &xlogctl;
+
+	wal_keep_size_mb = 0;
+
+	/************************************************
+	 * Current Delete greater than what keep wants,
+	 * so, delete offset should get updated.
+	 * max_slot_wal_keep_size smaller than the segs
+	 * that keeps wants, cut to max_slot_wal_keep_size_mb
+	 ***********************************************/
+	/* Current Delete pointer */
+	_logSegNo = 4 * XLogSegmentsPerXLogId(wal_segment_size) + 20;
+
+	max_slot_wal_keep_size_mb = 5 * 64;
+
+	/*
+	 * Current xlog location (4, 10)
+	 * xrecoff = seg * 67108864 (64 MB segsize)
+	 */
+	recptr = ((uint64) 4) << 32 | (wal_segment_size * 10);
+
+	KeepLogSeg_wrapper(recptr, &_logSegNo);
+	/* 4 * 64 + 10 - 5 (max_slot_wal_keep_size) */
+	assert_int_equal(_logSegNo, 261);
+	/************************************************/
+
+
+	/************************************************
+	 * Current Delete greater than what keep wants,
+	 * so, delete offset should get updated.
+	 * max_slot_wal_keep_size smaller than the segs
+	 * that keeps wants, ignore max_slot_wal_keep_size_mb
+	 ***********************************************/
+	/* Current Delete pointer */
+	_logSegNo = 4 * XLogSegmentsPerXLogId(wal_segment_size) + 20;
+
+	max_slot_wal_keep_size_mb = 10 * 64;
+
+	/*
+	 * Current xlog location (4, 1)
+	 * xrecoff = seg * 67108864 (64 MB segsize)
+	 */
+	recptr = ((uint64) 4) << 32 | (wal_segment_size * 10);
+
+	KeepLogSeg_wrapper(recptr, &_logSegNo);
+	/* cut to the keep (xlogctl.replicationSlotMinLSN) */
+	assert_int_equal(_logSegNo, 256);
+	/************************************************/
+
+	wal_keep_size_mb = 15 * (wal_segment_size / (1024 * 1024));
+
+	/************************************************
+	 * Current Delete greater than what keep wants,
+	 * so, delete offset should get updated.
+	 * max_slot_wal_keep_size smaller than wal_keep_size,
+	 * max_slot_wal_keep_size doesn't take effect.
+	 ***********************************************/
+	/* Current Delete pointer */
+	_logSegNo = 4 * XLogSegmentsPerXLogId(wal_segment_size) + 20;
+	max_slot_wal_keep_size_mb = 5 * 64;
+
+	/*
+	 * Current xlog location (4, 1)
+	 * xrecoff = seg * 67108864 (64 MB segsize)
+	 */
+	recptr = ((uint64) 4) << 32 | (wal_segment_size * 10);
+
+	KeepLogSeg_wrapper(recptr, &_logSegNo);
+	/* 4 * 64 + 10 - 15 (wal_keep_size) */
+	assert_int_equal(_logSegNo, 251);
 	/************************************************/
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org