Refactor memory context reset

pull/366/head
Metin Doslu 2016-03-18 14:46:46 -07:00
parent 71f8dd28b8
commit eb41a249c9
2 changed files with 6 additions and 12 deletions

View File

@ -156,7 +156,6 @@ CitusCopyFrom(CopyStmt *copyStatement, char *completionTag)
HTAB *shardConnectionHash = NULL; HTAB *shardConnectionHash = NULL;
List *connectionList = NIL; List *connectionList = NIL;
MemoryContext tupleContext = NULL; MemoryContext tupleContext = NULL;
MemoryContext outputRowContext = NULL;
CopyState copyState = NULL; CopyState copyState = NULL;
TupleDesc tupleDescriptor = NULL; TupleDesc tupleDescriptor = NULL;
uint32 columnCount = 0; uint32 columnCount = 0;
@ -290,22 +289,15 @@ CitusCopyFrom(CopyStmt *copyStatement, char *completionTag)
* files. * files.
*/ */
tupleContext = AllocSetContextCreate(CurrentMemoryContext, tupleContext = AllocSetContextCreate(CurrentMemoryContext,
"COPY FROM Row Memory Context", "COPY Row Memory Context",
ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE); ALLOCSET_DEFAULT_MAXSIZE);
/* we use outputRowContext to serialize row to send to workers */
outputRowContext = AllocSetContextCreate(CurrentMemoryContext,
"COPY TO Row Memory Context",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
rowOutputState = (OutputCopyState) palloc0(sizeof(OutputCopyStateData)); rowOutputState = (OutputCopyState) palloc0(sizeof(OutputCopyStateData));
rowOutputState->binary = true; rowOutputState->binary = true;
rowOutputState->fe_msgbuf = makeStringInfo(); rowOutputState->fe_msgbuf = makeStringInfo();
rowOutputState->rowcontext = outputRowContext; rowOutputState->rowcontext = tupleContext;
columnOutputFunctions = ColumnOutputFunctions(tupleDescriptor, columnOutputFunctions = ColumnOutputFunctions(tupleDescriptor,
rowOutputState->binary); rowOutputState->binary);
@ -919,6 +911,8 @@ ColumnOutputFunctions(TupleDesc rowDescriptor, bool binaryFormat)
* and appends the data to the row output state object's message buffer. * and appends the data to the row output state object's message buffer.
* This function is modeled after the CopyOneRowTo() function in * This function is modeled after the CopyOneRowTo() function in
* commands/copy.c, but only implements a subset of that functionality. * commands/copy.c, but only implements a subset of that functionality.
* Note that the caller of this function should reset row memory context
* to not bloat memory usage.
*/ */
void void
OutputRow(Datum *valueArray, bool *isNullArray, TupleDesc rowDescriptor, OutputRow(Datum *valueArray, bool *isNullArray, TupleDesc rowDescriptor,
@ -928,9 +922,8 @@ OutputRow(Datum *valueArray, bool *isNullArray, TupleDesc rowDescriptor,
uint32 columnIndex = 0; uint32 columnIndex = 0;
uint32 columnCount = 0; uint32 columnCount = 0;
/* reset previous tuple's output data, and the temporary memory context */ /* reset previous tuple's output data */
resetStringInfo(rowOutputState->fe_msgbuf); resetStringInfo(rowOutputState->fe_msgbuf);
MemoryContextReset(rowOutputState->rowcontext);
oldContext = MemoryContextSwitchTo(rowOutputState->rowcontext); oldContext = MemoryContextSwitchTo(rowOutputState->rowcontext);

View File

@ -823,6 +823,7 @@ FilterAndPartitionTable(const char *filterQuery,
FileOutputStreamWrite(partitionFile, rowText); FileOutputStreamWrite(partitionFile, rowText);
resetStringInfo(rowText); resetStringInfo(rowText);
MemoryContextReset(rowOutputState->rowcontext);
} }
SPI_freetuptable(SPI_tuptable); SPI_freetuptable(SPI_tuptable);