mirror of https://github.com/citusdata/citus.git
Attempt to fix windows crash on intermediate_results
parent
71209054dc
commit
c271c2350e
|
@ -148,6 +148,7 @@ ReadFileIntoTupleStore(char *fileName, char *copyFormat, TupleDesc tupleDescript
|
||||||
EState *executorState = CreateExecutorState();
|
EState *executorState = CreateExecutorState();
|
||||||
MemoryContext executorTupleContext = GetPerTupleMemoryContext(executorState);
|
MemoryContext executorTupleContext = GetPerTupleMemoryContext(executorState);
|
||||||
ExprContext *executorExpressionContext = GetPerTupleExprContext(executorState);
|
ExprContext *executorExpressionContext = GetPerTupleExprContext(executorState);
|
||||||
|
MemoryContext oldContext = NULL;
|
||||||
|
|
||||||
int columnCount = tupleDescriptor->natts;
|
int columnCount = tupleDescriptor->natts;
|
||||||
Datum *columnValues = palloc0(columnCount * sizeof(Datum));
|
Datum *columnValues = palloc0(columnCount * sizeof(Datum));
|
||||||
|
@ -172,25 +173,43 @@ ReadFileIntoTupleStore(char *fileName, char *copyFormat, TupleDesc tupleDescript
|
||||||
copyOptions);
|
copyOptions);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (true)
|
PG_TRY();
|
||||||
{
|
{
|
||||||
MemoryContext oldContext = NULL;
|
while (true)
|
||||||
bool nextRowFound = false;
|
{
|
||||||
|
bool nextRowFound = false;
|
||||||
|
|
||||||
ResetPerTupleExprContext(executorState);
|
ResetPerTupleExprContext(executorState);
|
||||||
oldContext = MemoryContextSwitchTo(executorTupleContext);
|
oldContext = MemoryContextSwitchTo(executorTupleContext);
|
||||||
|
|
||||||
nextRowFound = NextCopyFrom(copyState, executorExpressionContext,
|
nextRowFound = NextCopyFrom(copyState, executorExpressionContext,
|
||||||
columnValues, columnNulls, NULL);
|
columnValues, columnNulls, NULL);
|
||||||
if (!nextRowFound)
|
if (!nextRowFound)
|
||||||
|
{
|
||||||
|
MemoryContextSwitchTo(oldContext);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
tuplestore_putvalues(tupstore, tupleDescriptor, columnValues, columnNulls);
|
||||||
|
MemoryContextSwitchTo(oldContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PG_CATCH();
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* This is only necessary on windows, in the abort handler we might try to remove
|
||||||
|
* the file being COPY'd (if it was an intermediate result), but on Windows that's
|
||||||
|
* not possible unless we first close our handle to the file.
|
||||||
|
*/
|
||||||
|
if (oldContext != NULL)
|
||||||
{
|
{
|
||||||
MemoryContextSwitchTo(oldContext);
|
MemoryContextSwitchTo(oldContext);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tuplestore_putvalues(tupstore, tupleDescriptor, columnValues, columnNulls);
|
EndCopyFrom(copyState);
|
||||||
MemoryContextSwitchTo(oldContext);
|
PG_RE_THROW();
|
||||||
}
|
}
|
||||||
|
PG_END_TRY();
|
||||||
|
|
||||||
EndCopyFrom(copyState);
|
EndCopyFrom(copyState);
|
||||||
pfree(columnValues);
|
pfree(columnValues);
|
||||||
|
|
Loading…
Reference in New Issue