Repository: incubator-hawq Updated Branches: refs/heads/master 47dd8f6c4 -> db5568488 (forced update)
HAWQ-1417. Fixed crash when ANALYZE after COPY because of invalid resource owner Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/db556848 Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/db556848 Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/db556848 Branch: refs/heads/master Commit: db55684886508c3e5e0ba1b9cd603e797996109b Parents: 8595cdb Author: Ming LI <[email protected]> Authored: Tue Mar 28 15:52:02 2017 +0800 Committer: Ming LI <[email protected]> Committed: Fri Apr 7 11:05:11 2017 +0800 ---------------------------------------------------------------------- src/backend/commands/analyze.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/db556848/src/backend/commands/analyze.c ---------------------------------------------------------------------- diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 65d9bd3..f5e8a47 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -308,6 +308,7 @@ void analyzeStmt(VacuumStmt *stmt, List *relids, int preferred_seg_num) ListCell *le1 = NULL; int successCount = 0, failCount = 0; StringInfoData failNames; + ResourceOwner owner, oldOwner; /** * Ensure that an ANALYZE is requested. @@ -477,6 +478,13 @@ void analyzeStmt(VacuumStmt *stmt, List *relids, int preferred_seg_num) } /** + * Create a resource owner to keep track of our resources even not in trasaction block + */ + owner = ResourceOwnerCreate(CurrentResourceOwner, "analyzeStmt"); + oldOwner = CurrentResourceOwner; + CurrentResourceOwner = owner; + + /** * we use preferred_seg_num as default and * compute target_seg_num based on data size and distributed type * if there is no preferred_seg_num. @@ -808,6 +816,12 @@ void analyzeStmt(VacuumStmt *stmt, List *relids, int preferred_seg_num) elog(failCount > 0 ? INFO : elevel, "ANALYZE completed. Success: %d, Failure: %d %s", successCount, failCount, failNames.data); pfree(failNames.data); + ResourceOwnerRelease(owner, + RESOURCE_RELEASE_BEFORE_LOCKS, + false, true); + ResourceOwnerDelete(owner); + CurrentResourceOwner = oldOwner; + Assert(analyzeStatementContext == CurrentMemoryContext); MemoryContextSwitchTo(callerContext); MemoryContextDelete(analyzeStatementContext);
