mirror of https://github.com/citusdata/citus.git
prevent memory leak during ConvertTable with a lot of partitions (#6693)
Prevents memory leak during ConvertTable call for a table with a lot of partitions. DESCRIPTION: Fixes memory leak during undistribution and alteration of a table with a lot of partitions.pull/6710/head
parent
3200187757
commit
273911ac7f
|
@ -800,9 +800,21 @@ ConvertTable(TableConversionState *con)
|
||||||
ExecuteQueryViaSPI(tableConstructionSQL, SPI_OK_UTILITY);
|
ExecuteQueryViaSPI(tableConstructionSQL, SPI_OK_UTILITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* when there are many partitions, each call to ProcessUtilityParseTree
|
||||||
|
* accumulates used memory. Free context after each call.
|
||||||
|
*/
|
||||||
|
MemoryContext citusPerPartitionContext =
|
||||||
|
AllocSetContextCreate(CurrentMemoryContext,
|
||||||
|
"citus_per_partition_context",
|
||||||
|
ALLOCSET_DEFAULT_SIZES);
|
||||||
|
MemoryContext oldContext = MemoryContextSwitchTo(citusPerPartitionContext);
|
||||||
|
|
||||||
char *attachPartitionCommand = NULL;
|
char *attachPartitionCommand = NULL;
|
||||||
foreach_ptr(attachPartitionCommand, attachPartitionCommands)
|
foreach_ptr(attachPartitionCommand, attachPartitionCommands)
|
||||||
{
|
{
|
||||||
|
MemoryContextReset(citusPerPartitionContext);
|
||||||
|
|
||||||
Node *parseTree = ParseTreeNode(attachPartitionCommand);
|
Node *parseTree = ParseTreeNode(attachPartitionCommand);
|
||||||
|
|
||||||
ProcessUtilityParseTree(parseTree, attachPartitionCommand,
|
ProcessUtilityParseTree(parseTree, attachPartitionCommand,
|
||||||
|
@ -810,6 +822,9 @@ ConvertTable(TableConversionState *con)
|
||||||
NULL, None_Receiver, NULL);
|
NULL, None_Receiver, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MemoryContextSwitchTo(oldContext);
|
||||||
|
MemoryContextDelete(citusPerPartitionContext);
|
||||||
|
|
||||||
if (isPartitionTable)
|
if (isPartitionTable)
|
||||||
{
|
{
|
||||||
ExecuteQueryViaSPI(attachToParentCommand, SPI_OK_UTILITY);
|
ExecuteQueryViaSPI(attachToParentCommand, SPI_OK_UTILITY);
|
||||||
|
|
Loading…
Reference in New Issue