github.com/tuhaihe/gpbackup@v1.0.3/integration/gpexpand_not_running_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  
     8  	"github.com/tuhaihe/gp-common-go-libs/dbconn"
     9  	"github.com/tuhaihe/gp-common-go-libs/iohelper"
    10  	"github.com/tuhaihe/gp-common-go-libs/testhelper"
    11  	"github.com/tuhaihe/gpbackup/backup"
    12  	"github.com/tuhaihe/gpbackup/restore"
    13  	"github.com/tuhaihe/gpbackup/testutils"
    14  	"github.com/tuhaihe/gpbackup/utils"
    15  
    16  	. "github.com/onsi/ginkgo/v2"
    17  	. "github.com/onsi/gomega"
    18  )
    19  
    20  var _ = Describe("gpexpand_sensor", func() {
    21  	BeforeEach(func() {
    22  		testutils.SkipIfBefore6(connectionPool)
    23  	})
    24  
    25  	It("should prevent gprestore from starting when gpexpand is in phase 1", func() {
    26  		coordinatorDataDir, err := dbconn.SelectString(connectionPool, utils.CoordinatorDataDirQuery)
    27  		if err != nil {
    28  			Fail("cannot get coordinator data dir from db")
    29  		}
    30  
    31  		// SIMULATE that gpexpand is running by creating its status file
    32  		path := filepath.Join(coordinatorDataDir, utils.GpexpandStatusFilename)
    33  		oidFp := iohelper.MustOpenFileForWriting(path)
    34  		err = oidFp.Close()
    35  		Expect(err).ToNot(HaveOccurred())
    36  
    37  		defer func() {
    38  			err = os.Remove(path)
    39  			if err != nil {
    40  				Fail(fmt.Sprintf("IMPORTANT: failed to delete gpexpand.status file, which will prevent any future run of gpbackup! Manually delete file at: %s\n", path))
    41  			}
    42  		}()
    43  
    44  		defer testhelper.ShouldPanicWithMessage(`[CRITICAL]:-Greenplum expansion currently in process.  Once expansion is complete, it will be possible to restart gprestore, but please note existing backup sets taken with a different cluster configuration may no longer be compatible with the newly expanded cluster configuration`)
    45  		restore.DoSetup()
    46  	})
    47  	It("should prevent gprestore from starting when gpexpand is in phase 2", func() {
    48  		postgresConn := dbconn.NewDBConnFromEnvironment("postgres")
    49  		postgresConn.MustConnect(1)
    50  		defer postgresConn.Close()
    51  
    52  		testhelper.AssertQueryRuns(postgresConn, "CREATE SCHEMA gpexpand")
    53  		defer testhelper.AssertQueryRuns(postgresConn, "DROP SCHEMA gpexpand CASCADE")
    54  		testhelper.AssertQueryRuns(postgresConn, "CREATE TABLE gpexpand.status (status text, updated timestamp)")
    55  		testhelper.AssertQueryRuns(postgresConn, "INSERT INTO gpexpand.status VALUES ('IN PROGRESS', now())")
    56  
    57  		defer testhelper.ShouldPanicWithMessage(`[CRITICAL]:-Greenplum expansion currently in process.  Once expansion is complete, it will be possible to restart gprestore, but please note existing backup sets taken with a different cluster configuration may no longer be compatible with the newly expanded cluster configuration`)
    58  		restore.DoSetup()
    59  	})
    60  	It("should prevent gpbackup from starting when gpexpand is in phase 1", func() {
    61  		coordinatorDataDir, err := dbconn.SelectString(connectionPool, utils.CoordinatorDataDirQuery)
    62  		if err != nil {
    63  			Fail("cannot get coordinator data dir from db")
    64  		}
    65  
    66  		// SIMULATE that gpexpand is running by creating its status file
    67  		path := filepath.Join(coordinatorDataDir, utils.GpexpandStatusFilename)
    68  		oidFp := iohelper.MustOpenFileForWriting(path)
    69  		err = oidFp.Close()
    70  		Expect(err).ToNot(HaveOccurred())
    71  
    72  		defer func() {
    73  			err = os.Remove(path)
    74  			if err != nil {
    75  				Fail(fmt.Sprintf("IMPORTANT: failed to delete gpexpand.status file, which will prevent any future run of gpbackup! Manually delete file at: %s\n", path))
    76  			}
    77  		}()
    78  
    79  		defer testhelper.ShouldPanicWithMessage(`[CRITICAL]:-Greenplum expansion currently in process, please re-run gpbackup when the expansion has completed`)
    80  		backup.DoSetup()
    81  	})
    82  	It("should prevent gpbackup from starting when gpexpand is in phase 2", func() {
    83  		postgresConn := dbconn.NewDBConnFromEnvironment("postgres")
    84  		postgresConn.MustConnect(1)
    85  		defer postgresConn.Close()
    86  
    87  		testhelper.AssertQueryRuns(postgresConn, "CREATE SCHEMA gpexpand")
    88  		defer testhelper.AssertQueryRuns(postgresConn, "DROP SCHEMA gpexpand CASCADE")
    89  		testhelper.AssertQueryRuns(postgresConn, "CREATE TABLE gpexpand.status (status text, updated timestamp)")
    90  		testhelper.AssertQueryRuns(postgresConn, "INSERT INTO gpexpand.status VALUES ('IN PROGRESS', now())")
    91  
    92  		defer testhelper.ShouldPanicWithMessage(`[CRITICAL]:-Greenplum expansion currently in process, please re-run gpbackup when the expansion has completed`)
    93  		backup.DoSetup()
    94  	})
    95  })