mirror of https://github.com/citusdata/citus.git
Refactor memory context reset
parent
71f8dd28b8
commit
eb41a249c9
|
@ -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,14 +289,7 @@ 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_INITSIZE,
|
|
||||||
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_MINSIZE,
|
||||||
ALLOCSET_DEFAULT_INITSIZE,
|
ALLOCSET_DEFAULT_INITSIZE,
|
||||||
ALLOCSET_DEFAULT_MAXSIZE);
|
ALLOCSET_DEFAULT_MAXSIZE);
|
||||||
|
@ -305,7 +297,7 @@ CitusCopyFrom(CopyStmt *copyStatement, char *completionTag)
|
||||||
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);
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue