Skip to content

Commit

Permalink
Fix Error: "compressed lz4 data is corrupt" when dropping database
Browse files Browse the repository at this point in the history
Previously, when dropping a database, the error is raised with a
message: "compressed lz4 data is corrupt", due to inaccurate comparison
method used for Name type. Now, with correct comparison method for the
specific type, the error is not thrown when database is being dropped.

Task: BABEL-3655

Signed-off-by: Ray Kim <raydhkim@amazon.com>
  • Loading branch information
raydhkim authored Nov 10, 2022
1 parent 0d522ce commit dbf4d5f
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tsql/src/catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ clean_up_bbf_function_ext(int16 dbid)
/* Search and drop the entry */
ScanKeyInit(&scanKey[0],
Anum_bbf_function_ext_nspname,
BTEqualStrategyNumber, F_TEXTEQ,
BTEqualStrategyNumber, F_NAMEEQ,
nspname);

funcscan = systable_beginscan(bbf_function_ext_rel,
Expand Down
6 changes: 5 additions & 1 deletion contrib/babelfishpg_tsql/src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,7 @@ pltsql_store_func_default_positions(ObjectAddress address, List *parameters, con
bool new_record_replaces[BBF_FUNCTION_EXT_NUM_COLS];
HeapTuple tuple, proctup, oldtup;
Form_pg_proc form_proctup;
NameData *schema_name_NameData;
char *physical_schemaname;
char *func_signature;
char *original_name = NULL;
Expand Down Expand Up @@ -2231,7 +2232,10 @@ pltsql_store_func_default_positions(ObjectAddress address, List *parameters, con
if (pltsql_quoted_identifier)
flag_values |= FLAG_USES_QUOTED_IDENTIFIER;

new_record[Anum_bbf_function_ext_nspname -1] = CStringGetDatum(physical_schemaname);
schema_name_NameData = (NameData *) palloc0(NAMEDATALEN);
snprintf(schema_name_NameData->data, NAMEDATALEN, "%s", physical_schemaname);

new_record[Anum_bbf_function_ext_nspname -1] = NameGetDatum(schema_name_NameData);
new_record[Anum_bbf_function_ext_funcname -1] = NameGetDatum(&form_proctup->proname);
if (original_name)
new_record[Anum_bbf_function_ext_orig_name -1] = CStringGetTextDatum(original_name);
Expand Down
18 changes: 18 additions & 0 deletions test/JDBC/expected/BABEL-3655-vu-prepare.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
USE MASTER
GO

CREATE DATABASE babel_3655_test_db
GO

USE babel_3655_test_db
GO

CREATE SCHEMA babel_3655_test_s1
GO

CREATE FUNCTION babel_3655_test_f1()
RETURNS INT AS
BEGIN
RETURN 1;
END
GO
5 changes: 5 additions & 0 deletions test/JDBC/expected/BABEL-3655-vu-verify.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
USE MASTER
GO

DROP DATABASE babel_3655_test_db
GO
75 changes: 75 additions & 0 deletions test/JDBC/expected/BABEL-3655.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
-- psql
ALTER SYSTEM SET babelfishpg_tsql.migration_mode = 'multi-db';
SELECT pg_reload_conf();
GO
~~START~~
bool
t
~~END~~

-- Wait to sync with another session
SELECT pg_sleep(1);
GO
~~START~~
void

~~END~~

SHOW "babelfishpg_tsql.migration_mode";
GO
~~START~~
text
multi-db
~~END~~


-- tsql
USE MASTER
GO

CREATE DATABASE babel_3655_test_db
GO

USE babel_3655_test_db
GO

CREATE SCHEMA babel_3655_test_s1
GO

CREATE FUNCTION babel_3655_test_f1()
RETURNS INT AS
BEGIN
RETURN 1;
END
GO

USE MASTER
GO

DROP DATABASE babel_3655_test_db
GO

-- psql
ALTER SYSTEM SET babelfishpg_tsql.migration_mode = 'single-db';
SELECT pg_reload_conf();
GO
~~START~~
bool
t
~~END~~

-- Wait to sync with another session
SELECT pg_sleep(1);
GO
~~START~~
void

~~END~~

SHOW "babelfishpg_tsql.migration_mode";
GO
~~START~~
text
single-db
~~END~~

18 changes: 18 additions & 0 deletions test/JDBC/input/BABEL-3655-vu-prepare.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
USE MASTER
GO

CREATE DATABASE babel_3655_test_db
GO

USE babel_3655_test_db
GO

CREATE SCHEMA babel_3655_test_s1
GO

CREATE FUNCTION babel_3655_test_f1()
RETURNS INT AS
BEGIN
RETURN 1;
END
GO
5 changes: 5 additions & 0 deletions test/JDBC/input/BABEL-3655-vu-verify.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
USE MASTER
GO

DROP DATABASE babel_3655_test_db
GO
45 changes: 45 additions & 0 deletions test/JDBC/input/BABEL-3655.mix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- psql
ALTER SYSTEM SET babelfishpg_tsql.migration_mode = 'multi-db';
SELECT pg_reload_conf();
GO
-- Wait to sync with another session
SELECT pg_sleep(1);
GO
SHOW "babelfishpg_tsql.migration_mode";
GO

-- tsql
USE MASTER
GO

CREATE DATABASE babel_3655_test_db
GO

USE babel_3655_test_db
GO

CREATE SCHEMA babel_3655_test_s1
GO

CREATE FUNCTION babel_3655_test_f1()
RETURNS INT AS
BEGIN
RETURN 1;
END
GO

USE MASTER
GO

DROP DATABASE babel_3655_test_db
GO

-- psql
ALTER SYSTEM SET babelfishpg_tsql.migration_mode = 'single-db';
SELECT pg_reload_conf();
GO
-- Wait to sync with another session
SELECT pg_sleep(1);
GO
SHOW "babelfishpg_tsql.migration_mode";
GO
2 changes: 2 additions & 0 deletions test/JDBC/jdbc_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ ignore#!#Test-Prep-Statements-vu-verify
ignore#!#Test-Prep-Statements-vu-cleanup
ignore#!#BABEL-3117-vu-prepare
ignore#!#BABEL-3117-vu-verify
ignore#!#BABEL-3655-vu-prepare
ignore#!#BABEL-3655-vu-verify

# These tests are meant for upgrade scenario prior to (potential) 14_5 release
ignore#!#BABEL-3147-before-14_5-vu-prepare
Expand Down
1 change: 1 addition & 0 deletions test/JDBC/upgrade/13_4/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,5 @@ BABEL_GRANT_CONNECT
BABEL-sp_helpdb
BABEL-2795
BABEL-PG-SYSTEM-FUNCTIONS
BABEL-3655
sys-table_types_internal
1 change: 1 addition & 0 deletions test/JDBC/upgrade/13_5/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,5 @@ BABEL_GRANT_CONNECT
BABEL-sp_helpdb
BABEL-2795
BABEL-PG-SYSTEM-FUNCTIONS
BABEL-3655
sys-table_types_internal
1 change: 1 addition & 0 deletions test/JDBC/upgrade/13_6/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,6 @@ BABEL_GRANT_CONNECT
BABEL-sp_helpdb
BABEL-2795
BABEL-PG-SYSTEM-FUNCTIONS
BABEL-3655
sys-table_types_internal
BABEL-3640
1 change: 1 addition & 0 deletions test/JDBC/upgrade/13_7/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,6 @@ BABEL_GRANT_CONNECT
BABEL-sp_helpdb
BABEL-2795
BABEL-PG-SYSTEM-FUNCTIONS
BABEL-3655
sys-table_types_internal
BABEL-3640
1 change: 1 addition & 0 deletions test/JDBC/upgrade/13_8/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,6 @@ BABEL_GRANT_CONNECT
BABEL-sp_helpdb
BABEL-2795
BABEL-PG-SYSTEM-FUNCTIONS
BABEL-3655
sys-table_types_internal
BABEL-3640
1 change: 1 addition & 0 deletions test/JDBC/upgrade/14_3/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,6 @@ BABEL_GRANT_CONNECT
BABEL-sp_helpdb
BABEL-2795
BABEL-PG-SYSTEM-FUNCTIONS
BABEL-3655
sys-table_types_internal
BABEL-3640
1 change: 1 addition & 0 deletions test/JDBC/upgrade/14_5/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,6 @@ BABEL_GRANT_CONNECT
BABEL-sp_helpdb
BABEL-2795
BABEL-PG-SYSTEM-FUNCTIONS
BABEL-3655
sys-table_types_internal
BABEL-3640
1 change: 1 addition & 0 deletions test/JDBC/upgrade/latest/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ BABEL-2795
babelfish_integrity_checker
get_tds_id
BABEL-PG-SYSTEM-FUNCTIONS
BABEL-3655
sys-table_types_internal
sys-table_types_internal-dep
BABEL-3640

0 comments on commit dbf4d5f

Please sign in to comment.