[PATCH] Implement condition variable-based WAL waiting for logical decoding - Mailing list pgsql-hackers

From Arkady Skvorcov
Subject [PATCH] Implement condition variable-based WAL waiting for logical decoding
Date
Msg-id CAChax7wDNrWOFLbDBwta=ZS8WY43ybE4mTEbY3mQbk9d_K6X-A@mail.gmail.com
Whole thread Raw
List pgsql-hackers
Hello contributors

This patch implements a condition variable-based approach for WAL waiting
in logical decoding, replacing the previous polling mechanism. The new
system provides significant efficiency improvements by eliminating
unnecessary CPU cycles during WAL waiting periods.

Key changes:

1. Implemented LogicalWaitForWal() function to handle both immediate   return (non-waiting) and conditional waiting paths
2. Maintained backward compatibility with existing APIs
3. Added comprehensive regression tests

Performance benefits:
- Eliminates busy-waiting during logical replication slot advancement
- Reduces CPU usage during periods of low WAL activity
- Maintains same latency characteristics for high-activity scenarios

Testing:
- Added two new regression tests (logical_cv_waiting, logical_cv_edge_case)
- Verified both non-waiting (common case) and waiting (edge case) paths
- Tests cover basic functionality, multiple transactions, and slot advancement
- All existing regression tests pass

The implementation follows the existing pattern for condition variables
in PostgreSQL and integrates seamlessly with the current logical decoding
infrastructure.

Looking forward to your feedback.

Regards,
Arkady Skvorcov
Attachment

pgsql-hackers by date:

Previous
From: Arseniy Mukhin
Date:
Subject: Re: LISTEN/NOTIFY bug: VACUUM sets frozenxid past a xid in async queue
Next
From: Álvaro Herrera
Date:
Subject: Re: [PATCH] Add pg_get_tablespace_ddl() function to reconstruct CREATE TABLESPACE statement