Repository: incubator-hawq
Updated Branches:
  refs/heads/master afcf34c09 -> 50bf9a3e9


HAWQ-1453. Fixed relation_close() error at analyzeStmt(): not owned by resource 
owner TopTransaction (resowner.c:814)

The relation opened at TopResourceOwner, while close at a new transaction 
resource owner.
So when we close these relations, we need to firstly switch back to the 
TopResourceOwner.


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/50bf9a3e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/50bf9a3e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/50bf9a3e

Branch: refs/heads/master
Commit: 50bf9a3e9e5e18ead5167c21fefc48cf9c754179
Parents: afcf34c
Author: Ming LI <[email protected]>
Authored: Wed May 3 17:01:03 2017 +0800
Committer: Ming LI <[email protected]>
Committed: Fri May 5 14:09:29 2017 +0800

----------------------------------------------------------------------
 src/backend/access/heap/heapam.c |  8 ++++++++
 src/backend/commands/analyze.c   | 24 ++++++++++++------------
 src/include/access/heapam.h      |  1 +
 3 files changed, 21 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/50bf9a3e/src/backend/access/heap/heapam.c
----------------------------------------------------------------------
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 78427e9..33e87f4 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -1269,6 +1269,14 @@ relation_close(Relation relation, LOCKMODE lockmode)
 }
 
 
+void
+relation_close_at_resource_owner(Relation relation, LOCKMODE lockmode, 
ResourceOwner resowner)
+{
+       ResourceOwner oldOwner = CurrentResourceOwner;
+       CurrentResourceOwner = resowner;
+       relation_close(relation, lockmode);
+       CurrentResourceOwner = oldOwner;
+}
 /* ----------------
  *             heap_open - open a heap relation by relation OID
  *

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/50bf9a3e/src/backend/commands/analyze.c
----------------------------------------------------------------------
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index c3cf8ac..ddd9677 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -308,7 +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;
+       ResourceOwner asOwner, oldOwner1;  /* asOwner for analyzeStmt resource 
owner */
 
        /**
         * Ensure that an ANALYZE is requested.
@@ -480,9 +480,9 @@ 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;
+       asOwner = ResourceOwnerCreate(CurrentResourceOwner, "analyzeStmt");
+       oldOwner1 = CurrentResourceOwner;
+       CurrentResourceOwner = asOwner;
 
        /**
         *  we use preferred_seg_num as default and
@@ -612,12 +612,12 @@ void analyzeStmt(VacuumStmt *stmt, List *relids, int 
preferred_seg_num)
                                                        (errmsg("skipping 
\"%s\" --- cannot analyze indexes, views, external tables or special system 
tables",
                                                                
RelationGetRelationName(candidateRelation))));
 
-                                               
relation_close(candidateRelation, ShareUpdateExclusiveLock);
+                                               
relation_close_at_resource_owner(candidateRelation, ShareUpdateExclusiveLock, 
asOwner);
                                        }
                                        else if 
(isOtherTempNamespace(RelationGetNamespace(candidateRelation)))
                                        {
                                                /* Silently ignore tables that 
are temp tables of other backends. */
-                                               
relation_close(candidateRelation, ShareUpdateExclusiveLock);
+                                               
relation_close_at_resource_owner(candidateRelation, ShareUpdateExclusiveLock, 
asOwner);
                                        }
                                        else if 
(RelationIsExternalPxfReadOnly(candidateRelation, &ext_uri) &&
                                                 (!pxf_enable_stat_collection))
@@ -627,7 +627,7 @@ void analyzeStmt(VacuumStmt *stmt, List *relids, int 
preferred_seg_num)
                                                        (errmsg("skipping 
\"%s\" --- analyze for PXF tables is turned off by 
'pxf_enable_stat_collection'",
                                                                
RelationGetRelationName(candidateRelation))));
 
-                                               
relation_close(candidateRelation, ShareUpdateExclusiveLock);
+                                               
relation_close_at_resource_owner(candidateRelation, ShareUpdateExclusiveLock, 
asOwner);
                                        }
                                        else
                                        {
@@ -722,7 +722,7 @@ void analyzeStmt(VacuumStmt *stmt, List *relids, int 
preferred_seg_num)
                                                 * releasing the lock before 
commit would expose
                                                 * us to concurrent-update 
failures.)
                                                 */
-                                               
relation_close(candidateRelation, NoLock);
+                                               
relation_close_at_resource_owner(candidateRelation, NoLock, asOwner);
 
                                                /* MPP-6929: metadata tracking 
*/
                                                if (!bTemp && (Gp_role == 
GP_ROLE_DISPATCH))
@@ -753,7 +753,7 @@ void analyzeStmt(VacuumStmt *stmt, List *relids, int 
preferred_seg_num)
                                                (errmsg("Skipping \"%s\" --- 
only table or database owner can analyze it",
                                                        
RelationGetRelationName(candidateRelation))));
 
-                                       relation_close(candidateRelation, 
ShareUpdateExclusiveLock);
+                                       
relation_close_at_resource_owner(candidateRelation, ShareUpdateExclusiveLock, 
asOwner);
                                } /* if 
(analyzePermitted(RelationGetRelid(candidateRelation))) */
                        }
                        else
@@ -795,11 +795,11 @@ void analyzeStmt(VacuumStmt *stmt, List *relids, int 
preferred_seg_num)
        UnsetActiveQueryResource();
        SetActiveQueryResource(savedResource);
 
-       ResourceOwnerRelease(owner,
+       ResourceOwnerRelease(asOwner,
             RESOURCE_RELEASE_BEFORE_LOCKS,
             false, false);
-       CurrentResourceOwner = oldOwner;
-       ResourceOwnerDelete(owner);
+       CurrentResourceOwner = oldOwner1;
+       ResourceOwnerDelete(asOwner);
 
        if (bUseOwnXacts)
        {

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/50bf9a3e/src/include/access/heapam.h
----------------------------------------------------------------------
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index dfec95f..5ec8231 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -211,6 +211,7 @@ extern Relation try_relation_openrv(const RangeVar 
*relation, LOCKMODE lockmode,
                                                                        bool 
noWait);
 
 extern void relation_close(Relation relation, LOCKMODE lockmode);
+extern void relation_close_at_resource_owner(Relation relation, LOCKMODE 
lockmode, ResourceOwner resowner);
 
 extern Relation heap_open(Oid relationId, LOCKMODE lockmode);
 extern Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode);

Reply via email to