You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by "aviralgarg05 (via GitHub)" <gi...@apache.org> on 2026/04/10 07:31:48 UTC

[PR] Fix recovery slot handling before pg_basebackup [cloudberry]

aviralgarg05 opened a new pull request, #1675:
URL: https://github.com/apache/cloudberry/pull/1675

   Fixes #1654
   
   ### What does this PR do?
   This PR fixes the recovery flow when the internal WAL replication slot does not already exist on the source segment.
   
   Before this change, both `gpsegrecovery` and `gpconfigurenewsegment` would start `pg_basebackup` first and only retry with slot creation after the backup failed. In practice, that meant a full base backup could run for a long time and then fail at the end because the slot was missing.
   
   This change fixes that at the root:
   - adds a shared helper to check whether the replication slot already exists
   - creates the slot up front when needed, before `pg_basebackup` starts
   - removes the fallback second `pg_basebackup` attempt from both recovery paths
   - updates unit tests to cover the new behavior and the new failure mode
   
   ### Type of Change
   - [x] Bug fix (non-breaking change)
   - [ ] New feature (non-breaking change)
   - [ ] Breaking change (fix or feature with breaking changes)
   - [ ] Documentation update
   
   ### Breaking Changes
   None.
   
   ### Test Plan
   Tested with focused management-script unit coverage and repeated verification runs.
   
   - [x] Unit tests added/updated
   - [ ] Integration tests added/updated
   - [ ] Passed `make installcheck`
   - [ ] Passed `make -C src/test installcheck-cbdb-parallel`
   
   Commands used:
   - `python3 -m py_compile gpMgmt/sbin/gpsegrecovery.py gpMgmt/bin/gppylib/commands/pg.py gpMgmt/bin/lib/gpconfigurenewsegment`
   - `PYTHONPATH=/Users/aviralgarg/Everything/cloudberry/gpMgmt/bin:/Users/aviralgarg/Everything/cloudberry/gpMgmt/sbin:/Users/aviralgarg/Everything/cloudberry/gpMgmt/bin/lib python3.11 -m unittest -v gpMgmt.bin.gppylib.commands.test.unit.test_unit_pg_base_backup gpMgmt.bin.gppylib.test.unit.test_unit_gpsegrecovery`
   
   The unit suite above was run multiple times and passed consistently.
   
   ### Impact
   **Performance:**
   This avoids wasting time on a full `pg_basebackup` that was destined to fail only because the replication slot was missing. Recovery becomes more predictable and avoids unnecessary duplicate work.
   
   **User-facing changes:**
   Recovery now fails less often in clusters where the internal replication slot has not been created yet, and it no longer relies on a second backup attempt to recover from that condition.
   
   **Dependencies:**
   No product dependencies were added.
   
   ### Checklist
   - [x] Followed [contribution guide](https://cloudberry.apache.org/contribute/code)
   - [ ] Added/updated documentation
   - [x] Reviewed code for security implications
   - [ ] Requested review from [cloudberry committers](https://github.com/orgs/apache/teams/cloudberry-committers)
   
   ### Additional Context
   The fix is intentionally narrow and only touches the recovery paths involved in the reported issue:
   - `gpMgmt/bin/gppylib/commands/pg.py`
   - `gpMgmt/sbin/gpsegrecovery.py`
   - `gpMgmt/bin/lib/gpconfigurenewsegment`
   - related unit tests
   
   I did not run the broader integration suites in this environment.
   
   ### CI Skip Instructions
   No CI skip requested.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Fix recovery slot handling before pg_basebackup [cloudberry]

Posted by "yjhjstz (via GitHub)" <gi...@apache.org>.
yjhjstz commented on code in PR #1675:
URL: https://github.com/apache/cloudberry/pull/1675#discussion_r3065658607


##########
gpMgmt/bin/gppylib/commands/pg.py:
##########
@@ -17,6 +19,31 @@
 
 GPHOME=os.environ.get('GPHOME')
 
+
+def ensure_replication_slot_exists(source_host, source_port,
+                                   replication_slot_name):
+    if not replication_slot_name:
+        return False
+
+    escaped_slot_name = replication_slot_name.replace("'", "''")
+    dburl = dbconn.DbURL(hostname=source_host, port=source_port,
+                         dbname='template1')
+    with closing(dbconn.connect(dburl, utility=True)) as conn:
+        slot_exists = dbconn.querySingleton(
+            conn,
+            "SELECT count(*) FROM pg_catalog.pg_replication_slots "
+            "WHERE slot_name = '{}'".format(escaped_slot_name))
+        if slot_exists > 0:
+            return False
+
+        dbconn.querySingleton(

Review Comment:
   use `dbconn.execSQL` ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Fix recovery slot handling before pg_basebackup [cloudberry]

Posted by "leborchuk (via GitHub)" <gi...@apache.org>.
leborchuk merged PR #1675:
URL: https://github.com/apache/cloudberry/pull/1675


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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