Prevent pg_dist_node changes during master_create_empty_shard

pull/1407/head
Marco Slot 2017-08-09 11:46:11 +02:00
parent 5cb9466255
commit 08ed6d8269
3 changed files with 114 additions and 6 deletions

View File

@ -44,6 +44,7 @@
#include "distributed/transaction_management.h"
#include "distributed/worker_manager.h"
#include "distributed/worker_protocol.h"
#include "storage/lmgr.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/inval.h"
@ -94,6 +95,12 @@ master_create_empty_shard(PG_FUNCTION_ARGS)
EnsureTablePermissions(relationId, ACL_INSERT);
CheckDistributedTable(relationId);
/* don't allow the table to be dropped */
LockRelationOid(relationId, AccessShareLock);
/* don't allow concurrent node list changes that require an exclusive lock */
LockRelationOid(DistNodeRelationId(), RowShareLock);
/*
* We check whether the table is a foreign table or not. If it is, we set
* storage type as foreign also. Only exception is if foreign table is a

View File

@ -364,7 +364,7 @@ master_remove_node
starting permutation: s1-add-node-2 s1-begin s2-create-table-2 s1-remove-node-2 s1-commit s2-select
starting permutation: s1-add-node-2 s2-begin s2-create-table-2 s1-remove-node-2 s2-commit s2-select
node_name node_port
localhost 57637
@ -374,7 +374,7 @@ step s1-add-node-2:
?column?
1
step s1-begin:
step s2-begin:
BEGIN;
step s2-create-table-2:
@ -388,11 +388,12 @@ create_distributed_table
step s1-remove-node-2:
SELECT * FROM master_remove_node('localhost', 57638);
ERROR: you cannot remove the primary node of a node group which has shard placements
step s1-commit:
<waiting ...>
step s2-commit:
COMMIT;
step s1-remove-node-2: <... completed>
error in steps s2-commit s1-remove-node-2: ERROR: you cannot remove the primary node of a node group which has shard placements
step s2-select:
SELECT * FROM dist_table;
@ -402,3 +403,91 @@ master_remove_node
starting permutation: s1-add-node-2 s1-begin s1-remove-node-2 s2-create-append-table s1-commit s2-select
node_name node_port
localhost 57637
step s1-add-node-2:
SELECT 1 FROM master_add_node('localhost', 57638);
?column?
1
step s1-begin:
BEGIN;
step s1-remove-node-2:
SELECT * FROM master_remove_node('localhost', 57638);
master_remove_node
step s2-create-append-table:
SET citus.shard_replication_factor TO 1;
CREATE TABLE dist_table (x int, y int);
SELECT create_distributed_table('dist_table', 'x', 'append');
SELECT 1 FROM master_create_empty_shard('dist_table');
<waiting ...>
step s1-commit:
COMMIT;
step s2-create-append-table: <... completed>
create_distributed_table
?column?
1
step s2-select:
SELECT * FROM dist_table;
x y
master_remove_node
starting permutation: s1-add-node-2 s2-begin s2-create-append-table s1-remove-node-2 s2-commit s2-select
node_name node_port
localhost 57637
step s1-add-node-2:
SELECT 1 FROM master_add_node('localhost', 57638);
?column?
1
step s2-begin:
BEGIN;
step s2-create-append-table:
SET citus.shard_replication_factor TO 1;
CREATE TABLE dist_table (x int, y int);
SELECT create_distributed_table('dist_table', 'x', 'append');
SELECT 1 FROM master_create_empty_shard('dist_table');
create_distributed_table
?column?
1
step s1-remove-node-2:
SELECT * FROM master_remove_node('localhost', 57638);
<waiting ...>
step s2-commit:
COMMIT;
step s1-remove-node-2: <... completed>
master_remove_node
step s2-select:
SELECT * FROM dist_table;
x y
master_remove_node

View File

@ -83,6 +83,14 @@ step "s2-create-table-2"
SELECT create_distributed_table('dist_table', 'x');
}
step "s2-create-append-table"
{
SET citus.shard_replication_factor TO 1;
CREATE TABLE dist_table (x int, y int);
SELECT create_distributed_table('dist_table', 'x', 'append');
SELECT 1 FROM master_create_empty_shard('dist_table');
}
step "s2-select"
{
SELECT * FROM dist_table;
@ -105,4 +113,8 @@ permutation "s1-add-node-2" "s2-begin" "s2-create-table-1" "s1-remove-node-2" "s
# session 1 removes a node, session 2 creates a distributed table with replication factor 2, should throw a sane error
permutation "s1-add-node-2" "s1-begin" "s1-remove-node-2" "s2-create-table-2" "s1-commit" "s2-select"
permutation "s1-add-node-2" "s1-begin" "s2-create-table-2" "s1-remove-node-2" "s1-commit" "s2-select"
permutation "s1-add-node-2" "s2-begin" "s2-create-table-2" "s1-remove-node-2" "s2-commit" "s2-select"
# session 1 removes a node, session 2 creates a shard in an append-distributed table
permutation "s1-add-node-2" "s1-begin" "s1-remove-node-2" "s2-create-append-table" "s1-commit" "s2-select"
permutation "s1-add-node-2" "s2-begin" "s2-create-append-table" "s1-remove-node-2" "s2-commit" "s2-select"