Skip to content

Commit

Permalink
wip: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
onurctirtir committed Aug 24, 2023
1 parent 59d1480 commit 056a4b2
Show file tree
Hide file tree
Showing 7 changed files with 931 additions and 12 deletions.
25 changes: 18 additions & 7 deletions src/backend/distributed/commands/create_distributed_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1486,9 +1486,26 @@ ConvertCitusLocalTableToTableType(Oid relationId, CitusTableType tableType,
NoneDistTableReplicateCoordinatorPlacement(relationId, targetNodeList);
}

if (shouldDropLocalPlacement)
{
/*
* We don't yet drop the local placement before handling partitions.
* Otherewise, local shard placements of the partitions will be gone
* before we create them on workers.
*
* However, we need to delete the related entry from pg_dist_placement
* before distributing partitions (if any) because we need a sane metadata
* state before doing so.
*/
NoneDistTableDeleteCoordinatorPlacement(relationId);
}

/* if this table is partitioned table, distribute its partitions too */
if (PartitionedTable(relationId))
{
/* right now we don't allow partitioned reference tables */
Assert(tableType == SINGLE_SHARD_DISTRIBUTED);

List *partitionList = PartitionList(relationId);

char *parentRelationName = generate_qualified_relation_name(relationId);
Expand Down Expand Up @@ -1526,15 +1543,9 @@ ConvertCitusLocalTableToTableType(Oid relationId, CitusTableType tableType,
MemoryContextDelete(citusPartitionContext);
}

/*
* We drop the local placement after handling partitions. Otherewise, local
* shard placements of the partitions will be gone before we recreate them
* on workers.
*/
if (shouldDropLocalPlacement)
{
Assert(tableType == SINGLE_SHARD_DISTRIBUTED);
NoneDistTableDropCoordinatorPlacement(relationId);
NoneDistTableDropCoordinatorPlacementTable(relationId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void SetLocalEnableManualChangesToShard(bool state);
/*
* NoneDistTableReplicateCoordinatorPlacement replicates local (presumably
* coordinator) shard placement of given none-distributed table to given
* target nodes.
* target nodes and inserts records for new placements into pg_dist_placement.
*/
void
NoneDistTableReplicateCoordinatorPlacement(Oid noneDistTableId,
Expand Down Expand Up @@ -100,11 +100,11 @@ NoneDistTableReplicateCoordinatorPlacement(Oid noneDistTableId,


/*
* NoneDistTableDropCoordinatorPlacement drops local (presumably coordinator)
* shard placement of given none-distributed table.
* NoneDistTableDeleteCoordinatorPlacement deletes pg_dist_placement record for
* local (presumably coordinator) shard placement of given none-distributed table.
*/
void
NoneDistTableDropCoordinatorPlacement(Oid noneDistTableId)
NoneDistTableDeleteCoordinatorPlacement(Oid noneDistTableId)
{
EnsureCoordinator();
EnsureNoneDistTableWithCoordinatorPlacement(noneDistTableId);
Expand All @@ -117,6 +117,22 @@ NoneDistTableDropCoordinatorPlacement(Oid noneDistTableId)

/* remove the old placement from metadata of local node, i.e., coordinator */
DeleteShardPlacementRowGlobally(coordinatorPlacement->placementId);
}


/*
* NoneDistTableDropCoordinatorPlacementTable drops local (presumably coordinator)
* shard placement table of given none-distributed table.
*/
void
NoneDistTableDropCoordinatorPlacementTable(Oid noneDistTableId)
{
EnsureCoordinator();

if (HasDistributionKey(noneDistTableId))
{
ereport(ERROR, (errmsg("table is not a none-distributed table")));
}

/*
* We undistribute Citus local tables that are not chained with any reference
Expand All @@ -135,6 +151,7 @@ NoneDistTableDropCoordinatorPlacement(Oid noneDistTableId)
SetLocalEnableManualChangesToShard(true);

StringInfo dropShardCommand = makeStringInfo();
int64 shardId = GetFirstShardId(noneDistTableId);
ShardInterval *shardInterval = LoadShardInterval(shardId);
appendStringInfo(dropShardCommand, DROP_REGULAR_TABLE_COMMAND,
ConstructQualifiedShardName(shardInterval));
Expand Down
3 changes: 2 additions & 1 deletion src/include/distributed/replicate_none_dist_table_shard.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

extern void NoneDistTableReplicateCoordinatorPlacement(Oid noneDistTableId,
List *targetNodeList);
extern void NoneDistTableDropCoordinatorPlacement(Oid noneDistTableId);
extern void NoneDistTableDeleteCoordinatorPlacement(Oid noneDistTableId);
extern void NoneDistTableDropCoordinatorPlacementTable(Oid noneDistTableId);

#endif /* REPLICA_LOCAL_TABLE_SHARD_H */
Loading

0 comments on commit 056a4b2

Please sign in to comment.