Skip to content

Commit

Permalink
Remove GPDB4 codepaths
Browse files Browse the repository at this point in the history
GPDB4 has been out of support for a long time now.
This commit removes the code paths and tests specific to GPDB4.
  • Loading branch information
bmdoil committed Feb 15, 2024
1 parent 2930dcd commit 2782cd0
Show file tree
Hide file tree
Showing 46 changed files with 218 additions and 1,225 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ unit : $(GINKGO)
ginkgo $(GINKGO_FLAGS) $(SUBDIRS_HAS_UNIT) 2>&1

unit_all_gpdb_versions : $(GINKGO)
TEST_GPDB_VERSION=4.3.999 ginkgo $(GINKGO_FLAGS) $(SUBDIRS_HAS_UNIT) 2>&1
TEST_GPDB_VERSION=5.999.0 ginkgo $(GINKGO_FLAGS) $(SUBDIRS_HAS_UNIT) 2>&1
TEST_GPDB_VERSION=6.999.0 ginkgo $(GINKGO_FLAGS) $(SUBDIRS_HAS_UNIT) 2>&1
TEST_GPDB_VERSION=7.999.0 ginkgo $(GINKGO_FLAGS) $(SUBDIRS_HAS_UNIT) 2>&1 # GPDB main
Expand Down
33 changes: 1 addition & 32 deletions backup/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,6 @@ import (
* - Tables
* - Protocols
*/
func AddProtocolDependenciesForGPDB4(depMap DependencyMap, tables []Table, protocols []ExternalProtocol) {
protocolMap := make(map[string]UniqueID, len(protocols))
for _, p := range protocols {
protocolMap[p.Name] = p.GetUniqueID()
}
for _, table := range tables {
extTableDef := table.ExtTableDef
if extTableDef.Location.Valid && extTableDef.Location.String != "" {
protocolName := extTableDef.Location.String[0:strings.Index(extTableDef.Location.String, "://")]
if protocolEntry, ok := protocolMap[protocolName]; ok {
tableEntry := table.GetUniqueID()
if _, ok := depMap[tableEntry]; !ok {
depMap[tableEntry] = make(map[UniqueID]bool)
}
depMap[tableEntry][protocolEntry] = true
}
}
}
}

var (
PG_AGGREGATE_OID uint32 = 1255
Expand Down Expand Up @@ -285,19 +266,7 @@ FROM pg_depend d
LEFT JOIN pg_depend id1 ON (d.objid = id1.objid and d.classid = id1.classid and id1.deptype='i')
LEFT JOIN pg_depend id2 ON (d.refobjid = id2.objid and d.refclassid = id2.classid and id2.deptype='i')
WHERE d.classid != 0
AND d.deptype != 'i'
UNION
-- this converts function dependencies on array types to the underlying type
-- this is needed because pg_depend in 4.3.x doesn't have the info we need
SELECT
d.classid,
d.objid,
d.refclassid,
t.typelem AS refobjid
FROM pg_depend d
JOIN pg_type t ON d.refobjid = t.oid
WHERE d.classid = 'pg_proc'::regclass::oid
AND typelem != 0`
AND d.deptype != 'i'`

pgDependDeps := make([]SortableDependency, 0)
err := connectionPool.Select(&pgDependDeps, query)
Expand Down
4 changes: 1 addition & 3 deletions backup/metadata_globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,7 @@ func PrintCreateRoleStatements(metadataFile *utils.FileWithByteCount, objToc *to

attrs = append(attrs, fmt.Sprintf("RESOURCE QUEUE %s", role.ResQueue))

if connectionPool.Version.AtLeast("5") {
attrs = append(attrs, fmt.Sprintf("RESOURCE GROUP %s", role.ResGroup))
}
attrs = append(attrs, fmt.Sprintf("RESOURCE GROUP %s", role.ResGroup))

if role.Createrexthttp {
attrs = append(attrs, "CREATEEXTTABLE (protocol='http')")
Expand Down
7 changes: 2 additions & 5 deletions backup/metadata_globals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,9 @@ GRANT TEMPORARY,CONNECT ON DATABASE testdb TO testrole;`,
}

getResourceGroupReplace := func() (string, string) {
resourceGroupReplace1, resourceGroupReplace2 := "", ""
if connectionPool.Version.AtLeast("5") {
resourceGroupReplace1 = ` RESOURCE GROUP default_group`
resourceGroupReplace2 = `RESOURCE GROUP "testGroup" `
}

resourceGroupReplace1 := ` RESOURCE GROUP default_group`
resourceGroupReplace2 := `RESOURCE GROUP "testGroup" `
return resourceGroupReplace1, resourceGroupReplace2
}

Expand Down
5 changes: 1 addition & 4 deletions backup/predata_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ func PrintObjectMetadata(metadataFile *utils.FileWithByteCount, objToc *toc.TOC,
}

if owner := metadata.GetOwnerStatement(obj.FQN(), objectType); owner != "" {
if !(connectionPool.Version.Before("5") && entry.ObjectType == toc.OBJ_LANGUAGE) {
// Languages have implicit owners in 4.3, but do not support ALTER OWNER
statements = append(statements, strings.TrimSpace(owner))
}
statements = append(statements, strings.TrimSpace(owner))
}
if privileges := metadata.GetPrivilegesStatements(obj.FQN(), entry.ObjectType); privileges != "" {
statements = append(statements, strings.TrimSpace(privileges))
Expand Down
25 changes: 0 additions & 25 deletions backup/predata_externals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,6 @@ ENCODING 'UTF-8'`)
) ON COORDINATOR
FORMAT 'TEXT'
ENCODING 'UTF-8'`)
})
It("prints a CREATE block for a table using error logging with an error table", func() {
// Error tables were removed in GPDB 5
if connectionPool.Version.AtLeast("5") {
Skip("Test does not apply for GPDB versions after 5")
}
extTableDef.ErrTableName = "error_table"
extTableDef.ErrTableSchema = "error_table_schema"
backup.PrintExternalTableStatements(backupfile, tableName, extTableDef)
testhelper.ExpectRegexp(buffer, `LOCATION (
'file://host:port/path/file'
)
FORMAT 'TEXT'
ENCODING 'UTF-8'
LOG ERRORS INTO error_table_schema.error_table`)
})
It("prints a CREATE block for a table using error logging without an error table", func() {
extTableDef.LogErrors = true
Expand All @@ -281,16 +266,6 @@ FORMAT 'TEXT'
ENCODING 'UTF-8'
LOG ERRORS`)
})
It("prints a LOG ERRORS PERSISTENTLY block for an external table using persistent error logging", func() {
// PERSISTENTLY option is specifically for GPDB 5+
if connectionPool.Version.AtLeast("5") {
Skip("Test does not apply for GPDB versions after 5")
}
extTableDef.LogErrors = true
extTableDef.LogErrPersist = true
backup.PrintExternalTableStatements(backupfile, tableName, extTableDef)
testhelper.ExpectRegexp(buffer, `LOG ERRORS PERSISTENTLY`)
})
It("prints a CREATE block for a table with a row-based reject limit", func() {
extTableDef.RejectLimit = 2
extTableDef.RejectLimitType = "r"
Expand Down
12 changes: 4 additions & 8 deletions backup/predata_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,10 +836,8 @@ ALTER FUNCTION pg_catalog.plperl_validator(oid) OWNER TO testrole;`,
"ALTER FUNCTION pg_catalog.plpython_call_handler() OWNER TO testrole;",
"COMMENT ON LANGUAGE plpythonu IS 'This is a language comment.';",
}
if connectionPool.Version.AtLeast("5") {
// Languages have implicit owners in 4.3, but do not support ALTER OWNER
expectedStatements = append(expectedStatements, "ALTER LANGUAGE plpythonu OWNER TO testrole;")
}

expectedStatements = append(expectedStatements, "ALTER LANGUAGE plpythonu OWNER TO testrole;")
expectedStatements = append(expectedStatements, `REVOKE ALL ON LANGUAGE plpythonu FROM PUBLIC;
REVOKE ALL ON LANGUAGE plpythonu FROM testrole;
GRANT ALL ON LANGUAGE plpythonu TO testrole;`,
Expand All @@ -864,10 +862,8 @@ GRANT ALL ON LANGUAGE plpythonu TO testrole;`,
"ALTER FUNCTION pg_catalog.plperl_call_handler() OWNER TO owner%percentage;\nALTER FUNCTION pg_catalog.plperl_inline_handler(internal) OWNER TO owner%percentage;\nALTER FUNCTION pg_catalog.plperl_validator(oid) OWNER TO owner%percentage;",
`COMMENT ON LANGUAGE plperl IS 'This is a language comment.';`,
}
if connectionPool.Version.AtLeast("5") {
// Languages have implicit owners in 4.3, but do not support ALTER OWNER
expectedStatements = append(expectedStatements, `ALTER LANGUAGE plperl OWNER TO testrole;`)
}

expectedStatements = append(expectedStatements, `ALTER LANGUAGE plperl OWNER TO testrole;`)
expectedStatements = append(expectedStatements, `REVOKE ALL ON LANGUAGE plperl FROM PUBLIC;
REVOKE ALL ON LANGUAGE plperl FROM testrole;
GRANT ALL ON LANGUAGE plperl TO testrole;`,
Expand Down
4 changes: 0 additions & 4 deletions backup/predata_operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ CREATE OPERATOR %s.%s (
PrintObjectMetadata(metadataFile, objToc, operatorMetadata, operator, "", tier)
}

/*
* Operator families are not supported in GPDB 4.3, so this function
* is not used in a 4.3 backup.
*/
func PrintCreateOperatorFamilyStatements(metadataFile *utils.FileWithByteCount, objToc *toc.TOC, operatorFamilies []OperatorFamily, operatorFamilyMetadata MetadataMap) {
for _, operatorFamily := range operatorFamilies {
start := metadataFile.ByteCount
Expand Down
3 changes: 0 additions & 3 deletions backup/predata_textsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ package backup
* This file contains structs and functions related to backing up metadata on the
* coordinator for objects relating to built-in text search that needs to be restored
* before data is restored.
*
* Text search is not supported in GPDB 4.3, so none of these structs or functions
* are used in a 4.3 backup.
*/

import (
Expand Down
12 changes: 5 additions & 7 deletions backup/predata_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,11 @@ func PrintCreateBaseTypeStatement(metadataFile *utils.FileWithByteCount, objToc
if base.Send != "" {
metadataFile.MustPrintf(",\n\tSEND = %s", base.Send)
}
if connectionPool.Version.AtLeast("5") {
if base.ModIn != "" {
metadataFile.MustPrintf(",\n\tTYPMOD_IN = %s", base.ModIn)
}
if base.ModOut != "" {
metadataFile.MustPrintf(",\n\tTYPMOD_OUT = %s", base.ModOut)
}
if base.ModIn != "" {
metadataFile.MustPrintf(",\n\tTYPMOD_IN = %s", base.ModIn)
}
if base.ModOut != "" {
metadataFile.MustPrintf(",\n\tTYPMOD_OUT = %s", base.ModOut)
}
if base.InternalLength > 0 {
metadataFile.MustPrintf(",\n\tINTERNALLENGTH = %d", base.InternalLength)
Expand Down
26 changes: 8 additions & 18 deletions backup/predata_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,38 +117,28 @@ var _ = Describe("backup/predata_types tests", func() {
);`)
})
It("prints a base type where all optional arguments have default values where possible", func() {
expectedArgsReplace := ""
if connectionPool.Version.AtLeast("5") {
expectedArgsReplace = `
TYPMOD_IN = modin_fn,
TYPMOD_OUT = modout_fn,`
}

backup.PrintCreateBaseTypeStatement(backupfile, tocfile, basePartial, emptyMetadata)
testutils.AssertBufferContents(tocfile.PredataEntries, buffer, fmt.Sprintf(`CREATE TYPE public.base_type (
INPUT = input_fn,
OUTPUT = output_fn,
RECEIVE = receive_fn,
SEND = send_fn,%s
SEND = send_fn,
TYPMOD_IN = modin_fn,
TYPMOD_OUT = modout_fn,
DEFAULT = '42',
ELEMENT = int4,
DELIMITER = ','
);`, expectedArgsReplace))
);`))
})
It("prints a base type with all optional arguments provided", func() {
expectedArgsReplace := ""
if connectionPool.Version.AtLeast("5") {
expectedArgsReplace = `
TYPMOD_IN = modin_fn,
TYPMOD_OUT = modout_fn,`
}

backup.PrintCreateBaseTypeStatement(backupfile, tocfile, baseFull, emptyMetadata)
testutils.AssertBufferContents(tocfile.PredataEntries, buffer, fmt.Sprintf(`CREATE TYPE public.base_type (
INPUT = input_fn,
OUTPUT = output_fn,
RECEIVE = receive_fn,
SEND = send_fn,%s
SEND = send_fn,
TYPMOD_IN = modin_fn,
TYPMOD_OUT = modout_fn,
INTERNALLENGTH = 16,
PASSEDBYVALUE,
ALIGNMENT = int2,
Expand All @@ -162,7 +152,7 @@ var _ = Describe("backup/predata_types tests", func() {
);
ALTER TYPE public.base_type
SET DEFAULT ENCODING (compresstype=zlib, compresslevel=1, blocksize=32768);`, expectedArgsReplace))
SET DEFAULT ENCODING (compresstype=zlib, compresslevel=1, blocksize=32768);`))
})
It("prints a base type with double alignment and main storage", func() {
backup.PrintCreateBaseTypeStatement(backupfile, tocfile, basePermOne, emptyMetadata)
Expand Down
6 changes: 1 addition & 5 deletions backup/queries_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ func InitializeMetadataParams(connectionPool *dbconn.DBConn) {
}
TYPE_INDEX = MetadataQueryParams{ObjectType: toc.OBJ_INDEX, NameField: "relname", OidField: "indexrelid", OidTable: "pg_class", CommentTable: "pg_class", CatalogTable: "pg_index"}
TYPE_PROC_LANGUAGE = MetadataQueryParams{ObjectType: toc.OBJ_LANGUAGE, NameField: "lanname", ACLField: "lanacl", CatalogTable: "pg_language"}
if connectionPool.Version.Before("5") {
TYPE_PROC_LANGUAGE.OwnerField = "10" // In GPDB 4.3, there is no lanowner field in pg_language, but languages have an implicit owner
} else {
TYPE_PROC_LANGUAGE.OwnerField = "lanowner"
}
TYPE_PROC_LANGUAGE.OwnerField = "lanowner"
TYPE_OPERATOR = MetadataQueryParams{ObjectType: toc.OBJ_OPERATOR, NameField: "oprname", SchemaField: "oprnamespace", OidField: "oid", OwnerField: "oprowner", CatalogTable: "pg_operator"}
TYPE_OPERATOR_CLASS = MetadataQueryParams{ObjectType: toc.OBJ_OPERATOR_CLASS, NameField: "opcname", SchemaField: "opcnamespace", OidField: "oid", OwnerField: "opcowner", CatalogTable: "pg_opclass"}
TYPE_OPERATOR_FAMILY = MetadataQueryParams{ObjectType: toc.OBJ_OPERATOR_FAMILY, NameField: "opfname", SchemaField: "opfnamespace", OidField: "oid", OwnerField: "opfowner", CatalogTable: "pg_opfamily"}
Expand Down
35 changes: 5 additions & 30 deletions backup/queries_externals.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,10 @@ import (
func GetExternalTableDefinitions(connectionPool *dbconn.DBConn) map[uint32]ExternalTableDefinition {
gplog.Verbose("Retrieving external table information")

// In GPDB 4.3, we need to get the error table's fully-qualified name
// if `LOG ERRORS INTO <err_table_name>` was used. If `LOG ERRORS` was
// used, we can just check if reloid = fmterrtbl and avoid trying
// to get the FQN of a nonexistant error table.
version4Query := `
SELECT reloid AS oid,
CASE WHEN split_part(e.location[1], ':', 1) NOT IN ('ALL_SEGMENTS', 'HOST', 'MASTER_ONLY', 'PER_HOST', 'SEGMENT_ID', 'TOTAL_SEGS') THEN unnest(e.location) ELSE '' END AS location,
CASE WHEN split_part(e.location[1], ':', 1) IN ('ALL_SEGMENTS', 'HOST', 'MASTER_ONLY', 'PER_HOST', 'SEGMENT_ID', 'TOTAL_SEGS') THEN unnest(e.location) ELSE 'ALL_SEGMENTS' END AS execlocation,
e.fmttype AS formattype,
e.fmtopts AS formatopts,
coalesce(e.command, '') AS command,
coalesce(e.rejectlimit, 0) AS rejectlimit,
coalesce(e.rejectlimittype, '') AS rejectlimittype,
coalesce(quote_ident(c.relname), '') AS errtablename,
coalesce(quote_ident(n.nspname), '') AS errtableschema,
e.fmterrtbl IS NOT NULL AND e.reloid = e.fmterrtbl AS logerrors,
pg_encoding_to_char(e.encoding) AS encoding,
e.writable
FROM pg_exttable e
LEFT JOIN pg_class c ON e.fmterrtbl = c.oid AND e.fmterrtbl != e.reloid
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace`

// In GPDB 4.3, users can define an error table with `LOG ERRORS
// INTO <err_table_name>`. In GPDB 5+, error tables were removed
// but internal error logging is still available using `LOG ERRORS`
// with an optional `PERSISTENTLY` syntax to persist the error logs.
// The `PERSISTENTLY` part is stored in the pg_exttable.options array.
// In GPDB 5+, error tables were removed but internal error logging
// is still available using `LOG ERRORS`with an optional `PERSISTENTLY`
// syntax to persist the error logs. The `PERSISTENTLY` part is stored
// in the pg_exttable.options array.
version5Query := `
SELECT e.reloid AS oid,
CASE WHEN e.urilocation IS NOT NULL THEN unnest(e.urilocation) ELSE '' END AS location,
Expand Down Expand Up @@ -94,9 +71,7 @@ func GetExternalTableDefinitions(connectionPool *dbconn.DBConn) map[uint32]Exter
LEFT JOIN LATERAL unnest(urilocation) ljl_unnest ON urilocation IS NOT NULL`

var query string
if connectionPool.Version.Is("4") {
query = version4Query
} else if connectionPool.Version.Is("5") {
if connectionPool.Version.Is("5") {
query = version5Query
} else if connectionPool.Version.Is("6") {
query = version6Query
Expand Down
Loading

0 comments on commit 2782cd0

Please sign in to comment.