Re: test: avoid redundant standby catchup in 049_wait_for_lsn - Mailing list pgsql-hackers

From Jobin Augustine
Subject Re: test: avoid redundant standby catchup in 049_wait_for_lsn
Date
Msg-id CAEpZXfeLrJUS2+5x6AxB2bF+BCusUvQTBgMxrcifURu9FdfwsQ@mail.gmail.com
Whole thread
In response to Re: test: avoid redundant standby catchup in 049_wait_for_lsn  (Xuneng Zhou <xunengzhou@gmail.com>)
Responses Re: test: avoid redundant standby catchup in 049_wait_for_lsn
List pgsql-hackers
Hi Xuneng, hackers,

I ran into the same pg_current_wal_insert_lsn() page-boundary problem discussed in this thread, independently, outside the regression tests, while evaluating WAIT FOR for read-your-writes on a standby using a custom coded application to test the usability of this feature.

At this boundary, pg_current_wal_insert_lsn() returns the next insertion address, which is after the header gap. The test thus waited for a position beyond the existing WAL, requiring another WAL record to make progress. The unrelated progression comes from the primary's background writer who generated a RUNNING_XACTS record, advancing WAL to 0/0301A050, and then notified the waiters.

About 1 in 2000 waits never succeeded and ran to the full TIMEOUT
Since all my sessions were using  WAIT FOR LSN, it was a complete stall, whenever it happens.

A client side workaround similar to the following is a temporary solution for me for my tests:
  CREATE FUNCTION wal_insert_end_lsn(l pg_lsn DEFAULT pg_current_wal_insert_lsn())
  RETURNS pg_lsn LANGUAGE sql STABLE AS $$
    SELECT CASE
      WHEN (l - '0/0'::pg_lsn) % pg_size_bytes(current_setting('wal_segment_size'))
           < current_setting('wal_block_size')::int     -- first page of a segment
      THEN CASE WHEN (l - '0/0'::pg_lsn) % current_setting('wal_block_size')::int = 40
                THEN l - 40 ELSE l END
      ELSE CASE WHEN (l - '0/0'::pg_lsn) % current_setting('wal_block_size')::int = 24
                THEN l - 24 ELSE l END
    END
  $$;

A server-side fix would be better
Could WAIT FOR itself also tolerate such targets? When the target points exactly past a page header treat it as the  page boundary.

Thanks for tracking this down in the test. It saved me from chasing what looked like a WAIT FOR wakeup bug.

Thanks and Regards,
Jobin.

--










pgsql-hackers by date:

Previous
From: Manu
Date:
Subject: Re: BUG #19686: Rolling back SET TABLESPACE
Next
From: Ashutosh Bapat
Date:
Subject: Re: [PATCH] Two remaining shmem attachment issues in single-user mode