mirror of https://github.com/citusdata/citus.git
Fix crash when trying to replicate a ref table that is actually dropped (#6595)
DESCRIPTION: Fix crash when trying to replicate a ref table that is actually dropped see #6592 We should have a real solution for it. (cherry picked from commitrelease-11.0-ahmetbc3383170e
) (cherry picked from commit9e32e34313
)
parent
1f03f13665
commit
2027d592a1
|
@ -1419,6 +1419,15 @@ EnsureShardCanBeCopied(int64 shardId, const char *sourceNodeName, int32 sourceNo
|
|||
shardId)));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Make sure the relation exists. In some cases the relation is actually dropped but
|
||||
* the metadata remains, such as dropping table while citus.enable_ddl_propagation
|
||||
* is set to off.
|
||||
*/
|
||||
ShardInterval *shardInterval = LoadShardInterval(shardId);
|
||||
Oid distributedTableId = shardInterval->relationId;
|
||||
EnsureRelationExists(distributedTableId);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -657,6 +657,12 @@ ReplicateAllReferenceTablesToNode(WorkerNode *workerNode)
|
|||
ShardInterval *shardInterval = NULL;
|
||||
foreach_ptr(shardInterval, referenceShardIntervalList)
|
||||
{
|
||||
/*
|
||||
* Make sure the relation exists. In some cases the relation is
|
||||
* actually dropped but the metadata remains, such as dropping table
|
||||
* while citus.enable_ddl_propagation is set to off.
|
||||
*/
|
||||
EnsureRelationExists(shardInterval->relationId);
|
||||
uint64 shardId = shardInterval->shardId;
|
||||
|
||||
LockShardDistributionMetadata(shardId, ExclusiveLock);
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
-- https://github.com/citusdata/citus/issues/6592
|
||||
SET citus.next_shard_id TO 180000;
|
||||
CREATE TABLE ref_table_to_be_dropped_6592 (key int);
|
||||
SELECT create_reference_table('ref_table_to_be_dropped_6592');
|
||||
create_reference_table
|
||||
---------------------------------------------------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
CREATE TABLE ref_table_oid AS SELECT oid FROM pg_class WHERE relname = 'ref_table_to_be_dropped_6592';
|
||||
SET citus.enable_ddl_propagation TO OFF;
|
||||
DROP TABLE ref_table_to_be_dropped_6592 CASCADE; -- citus_drop_all_shards doesn't drop shards and metadata
|
||||
RESET citus.enable_ddl_propagation;
|
||||
-- error out for the dropped reference table
|
||||
SET client_min_messages to ERROR;
|
||||
SELECT 1 FROM master_add_node('localhost', :master_port, groupId => 0);
|
||||
ERROR: relation with OID XXXX does not exist
|
||||
RESET client_min_messages;
|
||||
\c - - - :worker_1_port
|
||||
SET citus.enable_ddl_propagation TO OFF;
|
||||
DELETE FROM pg_dist_partition WHERE logicalrelid = 'ref_table_to_be_dropped_6592'::regclass;
|
||||
DELETE FROM pg_dist_placement WHERE shardid = 180000;
|
||||
DELETE FROM pg_dist_shard WHERE shardid = 180000;
|
||||
DROP TABLE IF EXISTS ref_table_to_be_dropped_6592;
|
||||
DROP TABLE IF EXISTS ref_table_to_be_dropped_6592_180000;
|
||||
\c - - - :worker_2_port
|
||||
SET citus.enable_ddl_propagation TO OFF;
|
||||
DELETE FROM pg_dist_partition WHERE logicalrelid = 'ref_table_to_be_dropped_6592'::regclass;
|
||||
DELETE FROM pg_dist_placement WHERE shardid = 180000;
|
||||
DELETE FROM pg_dist_shard WHERE shardid = 180000;
|
||||
DROP TABLE IF EXISTS ref_table_to_be_dropped_6592;
|
||||
DROP TABLE IF EXISTS ref_table_to_be_dropped_6592_180000;
|
||||
\c - - - :master_port
|
||||
DELETE FROM pg_dist_placement WHERE shardid = 180000;
|
||||
DELETE FROM pg_dist_shard WHERE shardid = 180000;
|
||||
DELETE FROM pg_dist_partition WHERE logicalrelid IN (SELECT oid FROM ref_table_oid);
|
||||
DROP TABLE ref_table_oid;
|
|
@ -67,6 +67,8 @@ test: distributed_locks
|
|||
test: local_shard_execution_dropped_column
|
||||
test: metadata_sync_helpers
|
||||
|
||||
test: issue_6592
|
||||
|
||||
# test that no tests leaked intermediate results. This should always be last
|
||||
test: ensure_no_intermediate_data_leak
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
-- https://github.com/citusdata/citus/issues/6592
|
||||
SET citus.next_shard_id TO 180000;
|
||||
CREATE TABLE ref_table_to_be_dropped_6592 (key int);
|
||||
SELECT create_reference_table('ref_table_to_be_dropped_6592');
|
||||
CREATE TABLE ref_table_oid AS SELECT oid FROM pg_class WHERE relname = 'ref_table_to_be_dropped_6592';
|
||||
SET citus.enable_ddl_propagation TO OFF;
|
||||
DROP TABLE ref_table_to_be_dropped_6592 CASCADE; -- citus_drop_all_shards doesn't drop shards and metadata
|
||||
RESET citus.enable_ddl_propagation;
|
||||
|
||||
-- error out for the dropped reference table
|
||||
SET client_min_messages to ERROR;
|
||||
SELECT 1 FROM master_add_node('localhost', :master_port, groupId => 0);
|
||||
RESET client_min_messages;
|
||||
|
||||
\c - - - :worker_1_port
|
||||
SET citus.enable_ddl_propagation TO OFF;
|
||||
DELETE FROM pg_dist_partition WHERE logicalrelid = 'ref_table_to_be_dropped_6592'::regclass;
|
||||
DELETE FROM pg_dist_placement WHERE shardid = 180000;
|
||||
DELETE FROM pg_dist_shard WHERE shardid = 180000;
|
||||
DROP TABLE IF EXISTS ref_table_to_be_dropped_6592;
|
||||
DROP TABLE IF EXISTS ref_table_to_be_dropped_6592_180000;
|
||||
\c - - - :worker_2_port
|
||||
SET citus.enable_ddl_propagation TO OFF;
|
||||
DELETE FROM pg_dist_partition WHERE logicalrelid = 'ref_table_to_be_dropped_6592'::regclass;
|
||||
DELETE FROM pg_dist_placement WHERE shardid = 180000;
|
||||
DELETE FROM pg_dist_shard WHERE shardid = 180000;
|
||||
DROP TABLE IF EXISTS ref_table_to_be_dropped_6592;
|
||||
DROP TABLE IF EXISTS ref_table_to_be_dropped_6592_180000;
|
||||
\c - - - :master_port
|
||||
DELETE FROM pg_dist_placement WHERE shardid = 180000;
|
||||
DELETE FROM pg_dist_shard WHERE shardid = 180000;
|
||||
DELETE FROM pg_dist_partition WHERE logicalrelid IN (SELECT oid FROM ref_table_oid);
|
||||
DROP TABLE ref_table_oid;
|
Loading…
Reference in New Issue