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

gfphoenix78 pushed a commit to branch sync-with-upstream
in repository https://gitbox.apache.org/repos/asf/cloudberry-gpbackup.git


The following commit(s) were added to refs/heads/sync-with-upstream by this 
push:
     new d86c16a7 refactor(restore): Adapt legacy backup detection for 
multi-database support (#34)
d86c16a7 is described below

commit d86c16a71e2d5d3da51bf49b72c73302421555a9
Author: Robert Mu <[email protected]>
AuthorDate: Fri Sep 5 14:44:16 2025 +0800

    refactor(restore): Adapt legacy backup detection for multi-database support 
(#34)
    
    The original logic for detecting pre-GPDB6 backups was designed for a
    Greenplum-only environment. In that context, the `gpbackup` process
    stripped the `(Greenplum Database ...)` prefix, and the restore logic
    correctly parsed the raw version number from `config.yaml`.
    
    With the introduction of support for Cloudberry, `config.yaml` now
    retains the full, prefixed version string to differentiate between
    database vendors. The existing restore logic was not designed to handle
    these prefixed strings and would fail to parse the major version
    correctly, leading to improper `gp_use_legacy_hashops` settings and
    data distribution errors.
    
    This commit refactors the detection mechanism to be database-aware.
    It now uses the standard `dbconn.GPDBVersion.ParseVersionInfo` to robustly
    handle various version formats. The logic now explicitly checks if the
    backup is from Greenplum (`IsGPDB()`) before checking if it is a legacy
    version (`Before("6")`).
    
    This ensures restore operations are reliable in a multi-database
    environment, correctly applying legacy settings only to actual legacy
    Greenplum backups while properly handling modern Cloudberry and Greenplum
    backups.
---
 restore/wrappers.go | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/restore/wrappers.go b/restore/wrappers.go
index f4454b13..b8f38f8d 100644
--- a/restore/wrappers.go
+++ b/restore/wrappers.go
@@ -3,7 +3,6 @@ package restore
 import (
        "fmt"
        path "path/filepath"
-       "strconv"
        "strings"
 
        "github.com/cloudberrydb/gp-common-go-libs/dbconn"
@@ -106,8 +105,9 @@ SET default_with_oids = off;
                // the tables, unless we're restoring to a cluster of
                // a different size since in that case the data will be
                // redistributed during the restore process.
-               backupConfigMajorVer, _ := 
strconv.Atoi(strings.Split(backupConfig.DatabaseVersion, ".")[0])
-               if backupConfigMajorVer < 6 && !resizeRestore {
+               var backupVersionInfo dbconn.GPDBVersion
+               backupVersionInfo.ParseVersionInfo(backupConfig.DatabaseVersion)
+               if backupVersionInfo.IsGPDB() && backupVersionInfo.Before("6") 
&& !resizeRestore {
                        setupQuery += "SET gp_use_legacy_hashops = on;\n"
                        gplog.Warn("This backup set was taken on a version of 
Greenplum prior to 6.x. This restore will use the legacy hash operators when 
loading data.")
                        gplog.Warn("To use the new Greenplum 6.x default hash 
operators, these tables will need to be redistributed.")
@@ -131,6 +131,8 @@ SET default_with_oids = off;
        // GPDB7 removed support for QuickLZ.  To support creating tables
        // from backups done with QuickLZ, a GUC was added to allow silent
        // fallback to zstd
+
+       // Cloudberry does not support QuickLZ.
        if connectionPool.Version.IsGPDB() && 
connectionPool.Version.AtLeast("7") {
                setupQuery += "SET gp_quicklz_fallback = on;\n"
        }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to