Repository: incubator-hawq
Updated Branches:
  refs/heads/master 15c148b35 -> 4d0b99f3b


HAWQ-573. Fix Resource leak when cancel a query during calling a RPC to 
allocate resource.


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

Branch: refs/heads/master
Commit: 4d0b99f3b8e32117a7e974d977fe6b01e863ef7f
Parents: 15c148b
Author: doli <[email protected]>
Authored: Wed Mar 23 10:46:10 2016 +0800
Committer: Ming LI <[email protected]>
Committed: Wed Mar 23 11:06:34 2016 +0800

----------------------------------------------------------------------
 src/backend/tcop/pquery.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/4d0b99f3/src/backend/tcop/pquery.c
----------------------------------------------------------------------
diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c
index 99b6a1d..23b59a1 100644
--- a/src/backend/tcop/pquery.c
+++ b/src/backend/tcop/pquery.c
@@ -110,7 +110,7 @@ static int64 DoPortalRunFetch(Portal portal,
                                 DestReceiver *dest);
 static void DoPortalRewind(Portal portal);
 
-static void AddToGlobalQueryResources(QueryResource *resource);
+static void AddToGlobalQueryResources(int resourceId, QueryResourceLife life);
 
 static int compare_segment(const void *e1, const void *e2);
 /*
@@ -792,6 +792,7 @@ AllocateResource(QueryResourceLife   life,
                elog(ERROR, "%s. (%d)", errorbuf, errorcode);
        }
 
+       AddToGlobalQueryResources(resourceId, life);
        /* Acquire resource. */
        ret = acquireResourceFromRM(resourceId,
                                                                gp_session_id,
@@ -899,7 +900,6 @@ AllocateResource(QueryResourceLife   life,
         * appropriate place.
         */
        gp_segments_for_planner = list_length(resource->segments);
-       AddToGlobalQueryResources(resource);
 
        return resource;
 }
@@ -917,13 +917,13 @@ AutoFreeResource(QueryResource *resource)
 }
 
 static void
-AddToGlobalQueryResources(QueryResource *resource)
+AddToGlobalQueryResources(int resourceId, QueryResourceLife life)
 {
   ListCell *lc;
   QueryResourceItem *newItem;
   MemoryContext old;
 
-  if ((!resource) || (resource->life == QRL_NONE))
+  if (life == QRL_NONE)
   {
     return;
   }
@@ -931,7 +931,7 @@ AddToGlobalQueryResources(QueryResource *resource)
   foreach(lc, GlobalQueryResources)
   {
     QueryResourceItem *qri = lfirst(lc);
-    if(qri->resource_id == resource->resource_id)
+    if(qri->resource_id == resourceId)
     {
       /*
        * found, no need to add.
@@ -947,7 +947,7 @@ AddToGlobalQueryResources(QueryResource *resource)
   old = MemoryContextSwitchTo(TopMemoryContext);
   newItem = palloc(sizeof(QueryResourceItem));
   newItem->alive = true;
-  newItem->resource_id = resource->resource_id;
+  newItem->resource_id = resourceId;
   GlobalQueryResources = lappend(GlobalQueryResources, newItem);
   MemoryContextSwitchTo(old);
 }

Reply via email to