mirror of https://github.com/citusdata/citus.git
Mark autoConverted=false when cascading
parent
561948d7d4
commit
89b14bb03e
|
@ -87,7 +87,8 @@ CascadeOperationForRelationIdList(List *relationIdList, LOCKMODE lockMode,
|
||||||
{
|
{
|
||||||
LockRelationsWithLockMode(relationIdList, lockMode);
|
LockRelationsWithLockMode(relationIdList, lockMode);
|
||||||
|
|
||||||
if (cascadeOperationType == CASCADE_ADD_LOCAL_TABLE_TO_METADATA)
|
if (cascadeOperationType == CASCADE_USER_ADD_LOCAL_TABLE_TO_METADATA ||
|
||||||
|
cascadeOperationType == CASCADE_AUTO_ADD_LOCAL_TABLE_TO_METADATA)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* In CreateCitusLocalTable function, this check would never error out,
|
* In CreateCitusLocalTable function, this check would never error out,
|
||||||
|
@ -474,11 +475,25 @@ ExecuteCascadeOperationForRelationIdList(List *relationIdList,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case CASCADE_ADD_LOCAL_TABLE_TO_METADATA:
|
case CASCADE_USER_ADD_LOCAL_TABLE_TO_METADATA:
|
||||||
{
|
{
|
||||||
if (!IsCitusTable(relationId))
|
if (!IsCitusTable(relationId))
|
||||||
{
|
{
|
||||||
CreateCitusLocalTable(relationId, cascadeViaForeignKeys, true);
|
bool autoConverted = false;
|
||||||
|
CreateCitusLocalTable(relationId, cascadeViaForeignKeys,
|
||||||
|
autoConverted);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case CASCADE_AUTO_ADD_LOCAL_TABLE_TO_METADATA:
|
||||||
|
{
|
||||||
|
if (!IsCitusTable(relationId))
|
||||||
|
{
|
||||||
|
bool autoConverted = true;
|
||||||
|
CreateCitusLocalTable(relationId, cascadeViaForeignKeys,
|
||||||
|
autoConverted);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -52,6 +52,7 @@ static void ErrorIfAddingPartitionTableToMetadata(Oid relationId);
|
||||||
static void ErrorIfUnsupportedCreateCitusLocalTable(Relation relation);
|
static void ErrorIfUnsupportedCreateCitusLocalTable(Relation relation);
|
||||||
static void ErrorIfUnsupportedCitusLocalTableKind(Oid relationId);
|
static void ErrorIfUnsupportedCitusLocalTableKind(Oid relationId);
|
||||||
static void ErrorIfUnsupportedCitusLocalColumnDefinition(Relation relation);
|
static void ErrorIfUnsupportedCitusLocalColumnDefinition(Relation relation);
|
||||||
|
static CascadeOperationType GetCascadeTypeForCitusLocalTables(bool autoConverted);
|
||||||
static List * GetShellTableDDLEventsForCitusLocalTable(Oid relationId);
|
static List * GetShellTableDDLEventsForCitusLocalTable(Oid relationId);
|
||||||
static uint64 ConvertLocalTableToShard(Oid relationId);
|
static uint64 ConvertLocalTableToShard(Oid relationId);
|
||||||
static void RenameRelationToShardRelation(Oid shellRelationId, uint64 shardId);
|
static void RenameRelationToShardRelation(Oid shellRelationId, uint64 shardId);
|
||||||
|
@ -260,20 +261,14 @@ CreateCitusLocalTable(Oid relationId, bool cascadeViaForeignKeys, bool autoConve
|
||||||
qualifiedRelationName, qualifiedRelationName)));
|
qualifiedRelationName, qualifiedRelationName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* save the relation name, to obtain the shell relation id later */
|
CascadeOperationType cascadeType =
|
||||||
char *relationName = get_rel_name(relationId);
|
GetCascadeTypeForCitusLocalTables(autoConverted);
|
||||||
Oid relationSchemaId = get_rel_namespace(relationId);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* By acquiring AccessExclusiveLock, make sure that no modifications happen
|
* By acquiring AccessExclusiveLock, make sure that no modifications happen
|
||||||
* on the relations.
|
* on the relations.
|
||||||
*/
|
*/
|
||||||
CascadeOperationForFkeyConnectedRelations(relationId, lockMode,
|
CascadeOperationForFkeyConnectedRelations(relationId, lockMode, cascadeType);
|
||||||
CASCADE_ADD_LOCAL_TABLE_TO_METADATA);
|
|
||||||
|
|
||||||
Oid shellRelationId = get_relname_relid(relationName, relationSchemaId);
|
|
||||||
|
|
||||||
UpdatePartitionAutoConverted(shellRelationId, autoConverted);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We converted every foreign key connected table in our subgraph
|
* We converted every foreign key connected table in our subgraph
|
||||||
|
@ -289,8 +284,11 @@ CreateCitusLocalTable(Oid relationId, bool cascadeViaForeignKeys, bool autoConve
|
||||||
{
|
{
|
||||||
relationList = lappend_oid(relationList, relationId);
|
relationList = lappend_oid(relationList, relationId);
|
||||||
|
|
||||||
|
CascadeOperationType cascadeType =
|
||||||
|
GetCascadeTypeForCitusLocalTables(autoConverted);
|
||||||
|
|
||||||
CascadeOperationForRelationIdList(relationList, AccessExclusiveLock,
|
CascadeOperationForRelationIdList(relationList, AccessExclusiveLock,
|
||||||
CASCADE_ADD_LOCAL_TABLE_TO_METADATA);
|
cascadeType);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -549,6 +547,22 @@ ErrorIfUnsupportedCitusLocalColumnDefinition(Relation relation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GetCascadeTypeForCitusLocalTables returns CASCADE_AUTO_ADD_LOCAL_TABLE_TO_METADATA
|
||||||
|
* if autoConverted is true. Returns CASCADE_USER_ADD_LOCAL_TABLE_TO_METADATA otherwise.
|
||||||
|
*/
|
||||||
|
static CascadeOperationType
|
||||||
|
GetCascadeTypeForCitusLocalTables(bool autoConverted)
|
||||||
|
{
|
||||||
|
if (autoConverted)
|
||||||
|
{
|
||||||
|
return CASCADE_AUTO_ADD_LOCAL_TABLE_TO_METADATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CASCADE_USER_ADD_LOCAL_TABLE_TO_METADATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GetShellTableDDLEventsForCitusLocalTable returns a list of DDL commands
|
* GetShellTableDDLEventsForCitusLocalTable returns a list of DDL commands
|
||||||
* to create the shell table from scratch.
|
* to create the shell table from scratch.
|
||||||
|
|
|
@ -512,8 +512,11 @@ typedef enum CascadeOperationType
|
||||||
/* execute UndistributeTable on each relation */
|
/* execute UndistributeTable on each relation */
|
||||||
CASCADE_FKEY_UNDISTRIBUTE_TABLE = 1 << 1,
|
CASCADE_FKEY_UNDISTRIBUTE_TABLE = 1 << 1,
|
||||||
|
|
||||||
/* execute CreateCitusLocalTable on each relation */
|
/* execute CreateCitusLocalTable on each relation, with autoConverted = false */
|
||||||
CASCADE_ADD_LOCAL_TABLE_TO_METADATA = 1 << 2,
|
CASCADE_USER_ADD_LOCAL_TABLE_TO_METADATA = 1 << 2,
|
||||||
|
|
||||||
|
/* execute CreateCitusLocalTable on each relation, with autoConverted = true */
|
||||||
|
CASCADE_AUTO_ADD_LOCAL_TABLE_TO_METADATA = 1 << 3,
|
||||||
} CascadeOperationType;
|
} CascadeOperationType;
|
||||||
|
|
||||||
extern void CascadeOperationForFkeyConnectedRelations(Oid relationId,
|
extern void CascadeOperationForFkeyConnectedRelations(Oid relationId,
|
||||||
|
|
|
@ -476,7 +476,7 @@ SELECT logicalrelid, autoconverted FROM pg_dist_partition
|
||||||
logicalrelid | autoconverted
|
logicalrelid | autoconverted
|
||||||
---------------------------------------------------------------------
|
---------------------------------------------------------------------
|
||||||
citus_local_table_1 | f
|
citus_local_table_1 | f
|
||||||
citus_local_table_2 | t
|
citus_local_table_2 | f
|
||||||
citus_local_table_3 | f
|
citus_local_table_3 | f
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
|
@ -489,8 +489,9 @@ SELECT logicalrelid, autoconverted FROM pg_dist_partition
|
||||||
logicalrelid | autoconverted
|
logicalrelid | autoconverted
|
||||||
---------------------------------------------------------------------
|
---------------------------------------------------------------------
|
||||||
citus_local_table_1 | f
|
citus_local_table_1 | f
|
||||||
|
citus_local_table_2 | f
|
||||||
citus_local_table_3 | f
|
citus_local_table_3 | f
|
||||||
(2 rows)
|
(3 rows)
|
||||||
|
|
||||||
-- a single drop table cascades into multiple undistributes
|
-- a single drop table cascades into multiple undistributes
|
||||||
DROP TABLE IF EXISTS citus_local_table_1, citus_local_table_2, citus_local_table_3, citus_local_table_2, reference_table_1;
|
DROP TABLE IF EXISTS citus_local_table_1, citus_local_table_2, citus_local_table_3, citus_local_table_2, reference_table_1;
|
||||||
|
|
Loading…
Reference in New Issue