mirror of https://github.com/citusdata/citus.git
AcquireDistributedLockOnRelations: escape relation names
parent
e8ecbbfcb3
commit
ad86c1b866
|
@ -25,11 +25,12 @@
|
||||||
#include "distributed/transaction_management.h"
|
#include "distributed/transaction_management.h"
|
||||||
#include "distributed/worker_transaction.h"
|
#include "distributed/worker_transaction.h"
|
||||||
#include "storage/lmgr.h"
|
#include "storage/lmgr.h"
|
||||||
|
#include "utils/builtins.h"
|
||||||
#include "utils/lsyscache.h"
|
#include "utils/lsyscache.h"
|
||||||
#include "utils/rel.h"
|
#include "utils/rel.h"
|
||||||
|
|
||||||
|
|
||||||
#define LOCK_RELATION_IF_EXISTS "SELECT lock_relation_if_exists('%s', '%s');"
|
#define LOCK_RELATION_IF_EXISTS "SELECT lock_relation_if_exists(%s, '%s');"
|
||||||
|
|
||||||
|
|
||||||
/* Local functions forward declarations for unsupported command checks */
|
/* Local functions forward declarations for unsupported command checks */
|
||||||
|
@ -253,7 +254,8 @@ AcquireDistributedLockOnRelations(List *relationIdList, LOCKMODE lockMode)
|
||||||
ListCell *workerNodeCell = NULL;
|
ListCell *workerNodeCell = NULL;
|
||||||
|
|
||||||
appendStringInfo(lockRelationCommand, LOCK_RELATION_IF_EXISTS,
|
appendStringInfo(lockRelationCommand, LOCK_RELATION_IF_EXISTS,
|
||||||
qualifiedRelationName, lockModeText);
|
quote_literal_cstr(qualifiedRelationName),
|
||||||
|
lockModeText);
|
||||||
|
|
||||||
foreach(workerNodeCell, workerNodeList)
|
foreach(workerNodeCell, workerNodeList)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,8 +5,8 @@ SET citus.next_placement_id TO 2380000;
|
||||||
SET citus.shard_replication_factor TO 1;
|
SET citus.shard_replication_factor TO 1;
|
||||||
SET citus.shard_count TO 6;
|
SET citus.shard_count TO 6;
|
||||||
SET citus.replication_model TO streaming;
|
SET citus.replication_model TO streaming;
|
||||||
CREATE TABLE referece_table(id int PRIMARY KEY);
|
CREATE TABLE "refer'ence_table"(id int PRIMARY KEY);
|
||||||
SELECT create_reference_table('referece_table');
|
SELECT create_reference_table('refer''ence_table');
|
||||||
create_reference_table
|
create_reference_table
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ SELECT create_distributed_table('on_update_fkey_table', 'id');
|
||||||
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
ALTER TABLE on_update_fkey_table ADD CONSTRAINT fkey FOREIGN KEY(value_1) REFERENCES referece_table(id) ON UPDATE CASCADE;
|
ALTER TABLE on_update_fkey_table ADD CONSTRAINT fkey FOREIGN KEY(value_1) REFERENCES "refer'ence_table"(id) ON UPDATE CASCADE;
|
||||||
INSERT INTO referece_table SELECT i FROM generate_series(0, 100) i;
|
INSERT INTO "refer'ence_table" SELECT i FROM generate_series(0, 100) i;
|
||||||
INSERT INTO on_update_fkey_table SELECT i, i % 100 FROM generate_series(0, 1000) i;
|
INSERT INTO on_update_fkey_table SELECT i, i % 100 FROM generate_series(0, 1000) i;
|
||||||
-- first, make sure that truncate from the coordinator workers as expected
|
-- first, make sure that truncate from the coordinator workers as expected
|
||||||
TRUNCATE on_update_fkey_table;
|
TRUNCATE on_update_fkey_table;
|
||||||
|
@ -33,7 +33,7 @@ SELECT count(*) FROM on_update_fkey_table;
|
||||||
-- fill the table again
|
-- fill the table again
|
||||||
INSERT INTO on_update_fkey_table SELECT i, i % 100 FROM generate_series(0, 1000) i;
|
INSERT INTO on_update_fkey_table SELECT i, i % 100 FROM generate_series(0, 1000) i;
|
||||||
-- now, show that TRUNCATE CASCADE works expected from the coordinator
|
-- now, show that TRUNCATE CASCADE works expected from the coordinator
|
||||||
TRUNCATE referece_table CASCADE;
|
TRUNCATE "refer'ence_table" CASCADE;
|
||||||
NOTICE: truncate cascades to table "on_update_fkey_table"
|
NOTICE: truncate cascades to table "on_update_fkey_table"
|
||||||
SELECT count(*) FROM on_update_fkey_table;
|
SELECT count(*) FROM on_update_fkey_table;
|
||||||
count
|
count
|
||||||
|
@ -41,14 +41,14 @@ SELECT count(*) FROM on_update_fkey_table;
|
||||||
0
|
0
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT count(*) FROM referece_table;
|
SELECT count(*) FROM "refer'ence_table";
|
||||||
count
|
count
|
||||||
-------
|
-------
|
||||||
0
|
0
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- load some data for the next tests
|
-- load some data for the next tests
|
||||||
INSERT INTO referece_table SELECT i FROM generate_series(0, 100) i;
|
INSERT INTO "refer'ence_table" SELECT i FROM generate_series(0, 100) i;
|
||||||
INSERT INTO on_update_fkey_table SELECT i, i % 100 FROM generate_series(0, 1000) i;
|
INSERT INTO on_update_fkey_table SELECT i, i % 100 FROM generate_series(0, 1000) i;
|
||||||
-- make sure that DDLs along with TRUNCATE worker fine
|
-- make sure that DDLs along with TRUNCATE worker fine
|
||||||
BEGIN;
|
BEGIN;
|
||||||
|
@ -74,7 +74,7 @@ SELECT count(*) FROM on_update_fkey_table;
|
||||||
-- load some data
|
-- load some data
|
||||||
INSERT INTO on_update_fkey_table SELECT i, i % 100 FROM generate_series(0, 1000) i;
|
INSERT INTO on_update_fkey_table SELECT i, i % 100 FROM generate_series(0, 1000) i;
|
||||||
-- now, show that TRUNCATE CASCADE works expected from the worker
|
-- now, show that TRUNCATE CASCADE works expected from the worker
|
||||||
TRUNCATE referece_table CASCADE;
|
TRUNCATE "refer'ence_table" CASCADE;
|
||||||
NOTICE: truncate cascades to table "on_update_fkey_table"
|
NOTICE: truncate cascades to table "on_update_fkey_table"
|
||||||
SELECT count(*) FROM on_update_fkey_table;
|
SELECT count(*) FROM on_update_fkey_table;
|
||||||
count
|
count
|
||||||
|
@ -82,7 +82,7 @@ SELECT count(*) FROM on_update_fkey_table;
|
||||||
0
|
0
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT count(*) FROM referece_table;
|
SELECT count(*) FROM "refer'ence_table";
|
||||||
count
|
count
|
||||||
-------
|
-------
|
||||||
0
|
0
|
||||||
|
@ -94,20 +94,20 @@ BEGIN;
|
||||||
ROLLBACK;
|
ROLLBACK;
|
||||||
-- test within transaction blocks
|
-- test within transaction blocks
|
||||||
BEGIN;
|
BEGIN;
|
||||||
TRUNCATE referece_table CASCADE;
|
TRUNCATE "refer'ence_table" CASCADE;
|
||||||
NOTICE: truncate cascades to table "on_update_fkey_table"
|
NOTICE: truncate cascades to table "on_update_fkey_table"
|
||||||
ROLLBACK;
|
ROLLBACK;
|
||||||
-- test with sequential mode and CASCADE
|
-- test with sequential mode and CASCADE
|
||||||
BEGIN;
|
BEGIN;
|
||||||
SET LOCAL citus.multi_shard_modify_mode TO sequential;
|
SET LOCAL citus.multi_shard_modify_mode TO sequential;
|
||||||
TRUNCATE on_update_fkey_table;
|
TRUNCATE on_update_fkey_table;
|
||||||
TRUNCATE referece_table CASCADE;
|
TRUNCATE "refer'ence_table" CASCADE;
|
||||||
NOTICE: truncate cascades to table "on_update_fkey_table"
|
NOTICE: truncate cascades to table "on_update_fkey_table"
|
||||||
ROLLBACK;
|
ROLLBACK;
|
||||||
-- fill some data for the next test
|
-- fill some data for the next test
|
||||||
\c - - - :master_port
|
\c - - - :master_port
|
||||||
SET search_path TO 'truncate_from_workers';
|
SET search_path TO 'truncate_from_workers';
|
||||||
INSERT INTO referece_table SELECT i FROM generate_series(0, 100) i;
|
INSERT INTO "refer'ence_table" SELECT i FROM generate_series(0, 100) i;
|
||||||
\c - - - :worker_1_port
|
\c - - - :worker_1_port
|
||||||
SET search_path TO 'truncate_from_workers';
|
SET search_path TO 'truncate_from_workers';
|
||||||
-- make sure that DMLs-SELECTs works along with TRUNCATE worker fine
|
-- make sure that DMLs-SELECTs works along with TRUNCATE worker fine
|
||||||
|
@ -240,6 +240,6 @@ BEGIN;
|
||||||
COMMIT;
|
COMMIT;
|
||||||
DROP SCHEMA truncate_from_workers CASCADE;
|
DROP SCHEMA truncate_from_workers CASCADE;
|
||||||
NOTICE: drop cascades to 2 other objects
|
NOTICE: drop cascades to 2 other objects
|
||||||
DETAIL: drop cascades to table truncate_from_workers.referece_table
|
DETAIL: drop cascades to table truncate_from_workers."refer'ence_table"
|
||||||
drop cascades to table truncate_from_workers.on_update_fkey_table
|
drop cascades to table truncate_from_workers.on_update_fkey_table
|
||||||
SET search_path TO public;
|
SET search_path TO public;
|
||||||
|
|
|
@ -8,15 +8,15 @@ SET citus.shard_replication_factor TO 1;
|
||||||
SET citus.shard_count TO 6;
|
SET citus.shard_count TO 6;
|
||||||
SET citus.replication_model TO streaming;
|
SET citus.replication_model TO streaming;
|
||||||
|
|
||||||
CREATE TABLE referece_table(id int PRIMARY KEY);
|
CREATE TABLE "refer'ence_table"(id int PRIMARY KEY);
|
||||||
SELECT create_reference_table('referece_table');
|
SELECT create_reference_table('refer''ence_table');
|
||||||
|
|
||||||
CREATE TABLE on_update_fkey_table(id int PRIMARY KEY, value_1 int);
|
CREATE TABLE on_update_fkey_table(id int PRIMARY KEY, value_1 int);
|
||||||
SELECT create_distributed_table('on_update_fkey_table', 'id');
|
SELECT create_distributed_table('on_update_fkey_table', 'id');
|
||||||
|
|
||||||
ALTER TABLE on_update_fkey_table ADD CONSTRAINT fkey FOREIGN KEY(value_1) REFERENCES referece_table(id) ON UPDATE CASCADE;
|
ALTER TABLE on_update_fkey_table ADD CONSTRAINT fkey FOREIGN KEY(value_1) REFERENCES "refer'ence_table"(id) ON UPDATE CASCADE;
|
||||||
|
|
||||||
INSERT INTO referece_table SELECT i FROM generate_series(0, 100) i;
|
INSERT INTO "refer'ence_table" SELECT i FROM generate_series(0, 100) i;
|
||||||
INSERT INTO on_update_fkey_table SELECT i, i % 100 FROM generate_series(0, 1000) i;
|
INSERT INTO on_update_fkey_table SELECT i, i % 100 FROM generate_series(0, 1000) i;
|
||||||
|
|
||||||
-- first, make sure that truncate from the coordinator workers as expected
|
-- first, make sure that truncate from the coordinator workers as expected
|
||||||
|
@ -27,12 +27,12 @@ SELECT count(*) FROM on_update_fkey_table;
|
||||||
INSERT INTO on_update_fkey_table SELECT i, i % 100 FROM generate_series(0, 1000) i;
|
INSERT INTO on_update_fkey_table SELECT i, i % 100 FROM generate_series(0, 1000) i;
|
||||||
|
|
||||||
-- now, show that TRUNCATE CASCADE works expected from the coordinator
|
-- now, show that TRUNCATE CASCADE works expected from the coordinator
|
||||||
TRUNCATE referece_table CASCADE;
|
TRUNCATE "refer'ence_table" CASCADE;
|
||||||
SELECT count(*) FROM on_update_fkey_table;
|
SELECT count(*) FROM on_update_fkey_table;
|
||||||
SELECT count(*) FROM referece_table;
|
SELECT count(*) FROM "refer'ence_table";
|
||||||
|
|
||||||
-- load some data for the next tests
|
-- load some data for the next tests
|
||||||
INSERT INTO referece_table SELECT i FROM generate_series(0, 100) i;
|
INSERT INTO "refer'ence_table" SELECT i FROM generate_series(0, 100) i;
|
||||||
INSERT INTO on_update_fkey_table SELECT i, i % 100 FROM generate_series(0, 1000) i;
|
INSERT INTO on_update_fkey_table SELECT i, i % 100 FROM generate_series(0, 1000) i;
|
||||||
|
|
||||||
-- make sure that DDLs along with TRUNCATE worker fine
|
-- make sure that DDLs along with TRUNCATE worker fine
|
||||||
|
@ -54,9 +54,9 @@ SELECT count(*) FROM on_update_fkey_table;
|
||||||
INSERT INTO on_update_fkey_table SELECT i, i % 100 FROM generate_series(0, 1000) i;
|
INSERT INTO on_update_fkey_table SELECT i, i % 100 FROM generate_series(0, 1000) i;
|
||||||
|
|
||||||
-- now, show that TRUNCATE CASCADE works expected from the worker
|
-- now, show that TRUNCATE CASCADE works expected from the worker
|
||||||
TRUNCATE referece_table CASCADE;
|
TRUNCATE "refer'ence_table" CASCADE;
|
||||||
SELECT count(*) FROM on_update_fkey_table;
|
SELECT count(*) FROM on_update_fkey_table;
|
||||||
SELECT count(*) FROM referece_table;
|
SELECT count(*) FROM "refer'ence_table";
|
||||||
|
|
||||||
-- test within transaction blocks
|
-- test within transaction blocks
|
||||||
BEGIN;
|
BEGIN;
|
||||||
|
@ -65,20 +65,20 @@ ROLLBACK;
|
||||||
|
|
||||||
-- test within transaction blocks
|
-- test within transaction blocks
|
||||||
BEGIN;
|
BEGIN;
|
||||||
TRUNCATE referece_table CASCADE;
|
TRUNCATE "refer'ence_table" CASCADE;
|
||||||
ROLLBACK;
|
ROLLBACK;
|
||||||
|
|
||||||
-- test with sequential mode and CASCADE
|
-- test with sequential mode and CASCADE
|
||||||
BEGIN;
|
BEGIN;
|
||||||
SET LOCAL citus.multi_shard_modify_mode TO sequential;
|
SET LOCAL citus.multi_shard_modify_mode TO sequential;
|
||||||
TRUNCATE on_update_fkey_table;
|
TRUNCATE on_update_fkey_table;
|
||||||
TRUNCATE referece_table CASCADE;
|
TRUNCATE "refer'ence_table" CASCADE;
|
||||||
ROLLBACK;
|
ROLLBACK;
|
||||||
|
|
||||||
-- fill some data for the next test
|
-- fill some data for the next test
|
||||||
\c - - - :master_port
|
\c - - - :master_port
|
||||||
SET search_path TO 'truncate_from_workers';
|
SET search_path TO 'truncate_from_workers';
|
||||||
INSERT INTO referece_table SELECT i FROM generate_series(0, 100) i;
|
INSERT INTO "refer'ence_table" SELECT i FROM generate_series(0, 100) i;
|
||||||
|
|
||||||
\c - - - :worker_1_port
|
\c - - - :worker_1_port
|
||||||
SET search_path TO 'truncate_from_workers';
|
SET search_path TO 'truncate_from_workers';
|
||||||
|
|
Loading…
Reference in New Issue