You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by le...@apache.org on 2026/10/05 14:28:08 UTC

(cloudberry) branch main updated: gpexpand: make new-segment shutdown mode configurable (#2041)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 993e87701ca gpexpand: make new-segment shutdown mode configurable (#2041)
993e87701ca is described below

commit 993e87701ca86fc66d7ebb5b2bf0da0dfbb1bf0c
Author: Yaroslav Chirkov <Ai...@yandex.ru>
AuthorDate: Mon Oct 5 17:28:03 2026 +0300

    gpexpand: make new-segment shutdown mode configurable (#2041)
    
    * Make gpexpand's new-segment shutdown mode configurable
    
    gpexpand stops newly configured primary segments during the
    initialization phase. Allow callers to choose the pg_ctl shutdown mode
    instead of fixing it in the implementation.
    
    Add -M/--mode to the -i workflow with smart, fast, and immediate as
    valid values. Keep smart as the default to preserve existing behavior,
    and document that the option does not apply to interactive input-file
    generation or table redistribution.
---
 gpMgmt/bin/gpexpand                                | 12 +++++++++---
 gpMgmt/bin/gppylib/test/unit/test_unit_gpexpand.py | 13 +++++++++++++
 gpMgmt/doc/gpexpand_help                           | 11 +++++++++--
 3 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/gpMgmt/bin/gpexpand b/gpMgmt/bin/gpexpand
index 1d36a5a563e..2421cc3cbd4 100755
--- a/gpMgmt/bin/gpexpand
+++ b/gpMgmt/bin/gpexpand
@@ -95,7 +95,7 @@ Remaining TODO items:
 
 _usage = """[-f hosts_file]
 
-gpexpand -i input_file [-B batch_size] [-t segment_tar_dir] [-S]
+gpexpand -i input_file [-B batch_size] [-M shutdown_mode] [-t segment_tar_dir] [-S]
 
 gpexpand [-d duration[hh][:mm[:ss]] | [-e 'YYYY-MM-DD hh:mm:ss']]
          [-a] [-n parallel_processes]
@@ -137,6 +137,9 @@ def parseargs():
                       help='Expansion configuration batch size. Valid values are 1-%d' % MAX_BATCH_SIZE)
     parser.add_option('-n', '--parallel', type="int", default=1, metavar="<parallel_processes>",
                       help='number of tables to expand at a time. Valid values are 1-%d.' % MAX_PARALLEL_EXPANDS)
+    parser.add_option('-M', '--mode', type='choice', choices=['fast', 'immediate', 'smart'],
+                      default='smart', metavar='smart|fast|immediate',
+                      help='shutdown mode for newly initialized segments.')
     parser.add_option('-v', '--verbose', action='store_true',
                       help='debug output.')
     parser.add_option('-S', '--simple-progress', action='store_true',
@@ -588,6 +591,7 @@ class SegmentTemplate:
     def __init__(self, logger, statusLogger, pool,
                  gparray, coordinatorDataDirectory,
                  dburl, conn, tempDir, batch_size, is_hba_hostnames,
+                 shutdown_mode,
                  segTarDir='.', schemaTarFile='gpexpand_schema.tar'):
         self.logger = logger
         self.statusLogger = statusLogger
@@ -595,6 +599,7 @@ class SegmentTemplate:
         self.gparray = gparray
         self.tempDir = tempDir
         self.batch_size = batch_size
+        self.shutdown_mode = shutdown_mode
         self.dburl = dburl
         self.conn = conn
         self.coordinatorDataDirectory = coordinatorDataDirectory
@@ -808,7 +813,7 @@ class SegmentTemplate:
             segStopCmd = SegmentStop(
                 name="Stopping new segment dbid %s on host %s." % (str(seg.getSegmentDbId), seg.getSegmentHostName())
                 , dataDir=seg.getSegmentDataDirectory()
-                , mode='smart'
+                , mode=self.shutdown_mode
                 , nowait=False
                 , ctxt=REMOTE
                 , remoteHost=seg.getSegmentHostName()
@@ -1330,7 +1335,8 @@ class gpexpand:
                                            tempDir=self.tempDir,
                                            segTarDir=self.options.tardir,
                                            batch_size=self.options.batch_size,
-                                           is_hba_hostnames=self.options.hba_hostnames)
+                                           is_hba_hostnames=self.options.hba_hostnames,
+                                           shutdown_mode=self.options.mode)
         try:
             self.segTemplate.build_segment_template(newTableSpaceInfo)
             self.segTemplate.build_new_segments()
diff --git a/gpMgmt/bin/gppylib/test/unit/test_unit_gpexpand.py b/gpMgmt/bin/gppylib/test/unit/test_unit_gpexpand.py
index 4dff31a4448..5eee2741ccc 100644
--- a/gpMgmt/bin/gppylib/test/unit/test_unit_gpexpand.py
+++ b/gpMgmt/bin/gppylib/test/unit/test_unit_gpexpand.py
@@ -72,6 +72,19 @@ class GpExpand(GpTestCase):
         sys.argv = self.old_sys_argv
         super(GpExpand, self).tearDown()
 
+    def test_stop_new_primary_segments_uses_configured_shutdown_mode(self):
+        segment_template = self.subject.SegmentTemplate.__new__(self.subject.SegmentTemplate)
+        segment_template.gparray = Mock()
+        segment_template.gparray.getExpansionSegDbList.return_value = [self.primary0]
+        segment_template.pool = Mock()
+        segment_template.shutdown_mode = 'fast'
+
+        with patch('gpexpand.SegmentStop') as segment_stop:
+            segment_template._stop_new_primary_segments()
+
+        segment_stop.assert_called_once()
+        self.assertEqual('fast', segment_stop.call_args[1]['mode'])
+
     @patch('gpexpand.is_cluster_up_and_balanced', return_value=True)
     def test_validate_heap_checksums_aborts_when_cluster_inconsistent(self, mock1):
         self.options.filename = '/tmp/doesnotexist' # Replacement of the sys.argv
diff --git a/gpMgmt/doc/gpexpand_help b/gpMgmt/doc/gpexpand_help
index 60f0e3ef3e9..adcc4b39fd5 100644
--- a/gpMgmt/doc/gpexpand_help
+++ b/gpMgmt/doc/gpexpand_help
@@ -8,7 +8,8 @@ SYNOPSIS
 
 gpexpand 
       [-f <hosts_file>]
-      | -i <input_file> [-B <batch_size>] [-V] [-t segment_tar_dir] [-S]
+      | -i <input_file> [-B <batch_size>] [-M <shutdown_mode>] [-V]
+        [-t segment_tar_dir] [-S]
       | {-d <hh:mm:ss> | -e '<YYYY-MM-DD hh:mm:ss>'} 
         [-analyze] [-n <parallel_processes>]
       | --hba-hostnames
@@ -137,6 +138,13 @@ OPTIONS
   ...
 
 
+-M <fast | immediate | smart> | --mode <fast | immediate | smart>
+ Specifies the pg_ctl shutdown mode used to stop newly configured primary
+ segments during the initialization phase with -i. This option does not apply
+ when generating an input file interactively or during table redistribution.
+ The default is smart.
+
+
 -n <parallel_processes>
  The number of tables to redistribute simultaneously. Valid values 
  are 1 - 96. Each table redistribution process requires two database
@@ -200,4 +208,3 @@ SEE ALSO
 ******************************************************
 
 gpssh-exkeys
-


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