Skip to content

Commit

Permalink
Exclude subpartitions for given root partition in leaf-partition-data…
Browse files Browse the repository at this point in the history
… mode

gpbackup with the --leaf-partition-data and --exclude <root_partition> options
adds leaf partitions to the recovery plan, but the root partition is not
included in the schema creation script and gprestore fails with an error.

The solution is to exclude all leaf partitions for a given root partition
in leaf-partition-data mode.
  • Loading branch information
RekGRpth committed Sep 11, 2023
1 parent 7da3b6a commit f61d917
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions end_to_end/end_to_end_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/greenplum-db/gp-common-go-libs/testhelper"
"github.com/greenplum-db/gpbackup/backup"
"github.com/greenplum-db/gpbackup/filepath"
"github.com/greenplum-db/gpbackup/history"
"github.com/greenplum-db/gpbackup/testutils"
"github.com/greenplum-db/gpbackup/toc"
"github.com/greenplum-db/gpbackup/utils"
Expand Down Expand Up @@ -2511,4 +2512,61 @@ LANGUAGE plpgsql NO SQL;`)
}
})
})
Describe("Exclude subpartitions for given root partition in leaf-partition-data mode", func() {
BeforeEach(func() {
testhelper.AssertQueryRuns(backupConn,
"CREATE SCHEMA testschema")
testhelper.AssertQueryRuns(backupConn,
`CREATE TABLE testschema.p3_sales (id int, a int, b int, region text)
WITH (appendoptimized=true)
DISTRIBUTED BY (id)
PARTITION BY RANGE (a)
SUBPARTITION BY RANGE (b)
SUBPARTITION TEMPLATE (
START (1) END (3) EVERY (1))
SUBPARTITION BY LIST (region)
SUBPARTITION TEMPLATE (
SUBPARTITION usa VALUES ('usa'),
SUBPARTITION europe VALUES ('europe'))
( START (1) END (3) EVERY (1))`)
})
AfterEach(func() {
testhelper.AssertQueryRuns(backupConn,
"DROP SCHEMA IF EXISTS testschema CASCADE")

})
It("1. --leaf-partition-data is set and --exclude-table is set for root partition", func() {
timestamp := gpbackup(gpbackupPath, backupHelperPath, "--leaf-partition-data", "--include-schema", "testschema", "--exclude-table", "testschema.p3_sales")
defer assertArtifactsCleaned(restoreConn, timestamp)
historyDB, err := history.InitializeHistoryDatabase(historyFilePath)
Expect(err).ToNot(HaveOccurred())
backupConfig, err := history.GetBackupConfig(timestamp, historyDB)
Expect(err).ToNot(HaveOccurred())
Expect(backupConfig.LeafPartitionData).To(BeTrue())
Expect(backupConfig.RestorePlan).To(HaveLen(0))
})
It("2. --leaf-partition-data is set and --exclude-table is set for leaf partition", func() {
timestamp := gpbackup(gpbackupPath, backupHelperPath, "--leaf-partition-data", "--include-schema", "testschema", "--exclude-table", "testschema.p3_sales_1_prt_1_2_prt_1_3_prt_usa")
defer assertArtifactsCleaned(restoreConn, timestamp)
historyDB, err := history.InitializeHistoryDatabase(historyFilePath)
Expect(err).ToNot(HaveOccurred())
backupConfig, err := history.GetBackupConfig(timestamp, historyDB)
Expect(err).ToNot(HaveOccurred())
Expect(backupConfig.LeafPartitionData).To(BeTrue())
Expect(backupConfig.RestorePlan).To(HaveLen(1))
Expect(backupConfig.RestorePlan[0].Timestamp).To(Equal(timestamp))
Expect(backupConfig.RestorePlan[0].TableFQNs).To(HaveLen(7))
Expect(backupConfig.RestorePlan[0].TableFQNs).ToNot(ContainElement(`testschema.p3_sales_1_prt_1_2_prt_1_3_prt_usa`))
})
It("3. --leaf-partition-data is not set and --exclude-table is set for root partition", func() {
timestamp := gpbackup(gpbackupPath, backupHelperPath, "--include-schema", "testschema", "--exclude-table", "testschema.p3_sales")
defer assertArtifactsCleaned(restoreConn, timestamp)
historyDB, err := history.InitializeHistoryDatabase(historyFilePath)
Expect(err).ToNot(HaveOccurred())
backupConfig, err := history.GetBackupConfig(timestamp, historyDB)
Expect(err).ToNot(HaveOccurred())
Expect(backupConfig.LeafPartitionData).To(BeFalse())
Expect(backupConfig.RestorePlan).To(HaveLen(0))
})
})
})

0 comments on commit f61d917

Please sign in to comment.