incubator-hawq git commit: HAWQ-666. Restore to correct memory context after free query resource in ExecutorEnd

2016-04-12 Thread huor
Repository: incubator-hawq
Updated Branches:
  refs/heads/master 17389e39a -> c71e20cee


HAWQ-666. Restore to correct memory context after free query resource in 
ExecutorEnd


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

Branch: refs/heads/master
Commit: c71e20ceee2ee02d4af0b48a4679e0ff8fd7de72
Parents: 17389e3
Author: Ruilong Huo 
Authored: Tue Apr 12 20:12:37 2016 -0700
Committer: Ruilong Huo 
Committed: Tue Apr 12 20:12:37 2016 -0700

--
 src/backend/executor/execMain.c | 23 ---
 1 file changed, 12 insertions(+), 11 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c71e20ce/src/backend/executor/execMain.c
--
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index d9830f3..5e8c6b1 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -1302,6 +1302,7 @@ ExecutorEnd(QueryDesc *queryDesc)
 {
EState *estate;
MemoryContext oldcontext;
+   MemoryContext tmpcontext;
 
/* sanity checks */
Assert(queryDesc != NULL);
@@ -1360,14 +1361,14 @@ ExecutorEnd(QueryDesc *queryDesc)
}
PG_CATCH();
{
- /* Cleanup the global resource reference for spi/function resource 
inheritate. */
-if (Gp_role == GP_ROLE_DISPATCH) {
-  // we need to free resource in old memory-context.
-  MemoryContextSwitchTo(oldcontext);
-  AutoFreeResource(queryDesc->resource);
-  queryDesc->resource = NULL;
-  oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
-}
+   /* Cleanup the global resource reference for spi/function 
resource inheritate. */
+   if (Gp_role == GP_ROLE_DISPATCH) {
+   /* we need to free resource in old memory-context. */
+   tmpcontext = MemoryContextSwitchTo(oldcontext);
+   AutoFreeResource(queryDesc->resource);
+   queryDesc->resource = NULL;
+   oldcontext = MemoryContextSwitchTo(tmpcontext);
+   }
 
/*
 * we got an error. do all the necessary cleanup.
@@ -1391,11 +1392,11 @@ ExecutorEnd(QueryDesc *queryDesc)
 
/* Cleanup the global resource reference for spi/function resource 
inheritate. */
if ( Gp_role == GP_ROLE_DISPATCH ) {
- // we need to free resource in old memory-context.
- MemoryContextSwitchTo(oldcontext);
+   /* we need to free resource in old memory-context. */
+   tmpcontext = MemoryContextSwitchTo(oldcontext);
AutoFreeResource(queryDesc->resource);
queryDesc->resource = NULL;
-   oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
+   oldcontext = MemoryContextSwitchTo(tmpcontext);
}
 
/*



incubator-hawq git commit: HAWQ-664. The return value of registering fd is not checked for asynchronous connection

2016-04-12 Thread yjin
Repository: incubator-hawq
Updated Branches:
  refs/heads/master 5553271a6 -> 17389e39a


HAWQ-664. The return value of registering fd is not checked for asynchronous 
connection


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

Branch: refs/heads/master
Commit: 17389e39a6d5cc1f40b18694779d5228dc749de8
Parents: 5553271
Author: YI JIN 
Authored: Wed Apr 13 11:36:22 2016 +1000
Committer: YI JIN 
Committed: Wed Apr 13 11:36:22 2016 +1000

--
 .../communication/rmcomm_AsyncComm.c| 74 +++-
 1 file changed, 41 insertions(+), 33 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/17389e39/src/backend/resourcemanager/communication/rmcomm_AsyncComm.c
--
diff --git a/src/backend/resourcemanager/communication/rmcomm_AsyncComm.c 
b/src/backend/resourcemanager/communication/rmcomm_AsyncComm.c
index ee005bf..f2203db 100644
--- a/src/backend/resourcemanager/communication/rmcomm_AsyncComm.c
+++ b/src/backend/resourcemanager/communication/rmcomm_AsyncComm.c
@@ -691,7 +691,7 @@ int registerAsyncConnectionFileDesc(const char  
*address,
   methods,
   userdata,
   newcommbuffer);
-   goto exit;
+   return res;
}
 
/* Create socket FD */
@@ -725,27 +725,30 @@ int registerAsyncConnectionFileDesc(const char
*address,
if ( setConnectionLongTermNoDelay(fd) != FUNC_RETURN_OK )
{
close(fd);
-   res = UTIL_NETWORK_FAIL_CONNECT;
-   goto exit;
+   return UTIL_NETWORK_FAIL_CONNECT;
}
/*
 * New connection is created. Suppose domain socket and local 
socket
 * connection can be done now. Register a normal client FD in 
poll() to
 * perform content sending and receiving.
 */
-   res = registerFileDesc(fd,
-  actionmask,
-  methods,
-  userdata,
-  newcommbuffer);
-
-   /* Assign connection address. */
-   assignFileDescClientAddressInfo(*newcommbuffer,
-   
address,
-   
port,
-   
&server_addr,
-   
sizeof(server_addr));
-   goto exit;
+   res = registerFileDesc(fd, actionmask, methods, userdata, 
newcommbuffer);
+   if ( res == FUNC_RETURN_OK )
+   {
+   /* Assign connection address. */
+   assignFileDescClientAddressInfo(*newcommbuffer,
+   
address,
+   
port,
+   
&server_addr,
+   
sizeof(server_addr));
+   }
+   else
+   {
+   write_log("registerAsyncCommectionFileDesc failed 
registering fd %d.",
+ fd);
+   close(fd);
+   res = UTIL_NETWORK_FAIL_CONNECT;
+   }
}
else if ( sockres < 0 && errno == EINPROGRESS )
{
@@ -758,27 +761,32 @@ int registerAsyncConnectionFileDesc(const char
*address,

   methods,

   userdata,

   newcommbuffer);
-
-   /* Assign connection address. */
-   assignFileDescClientAddressInfo(*newcommbuffer,
-

incubator-hawq git commit: HAWQ-663. Wrongly count total allocated resource in resource queue manager

2016-04-12 Thread yjin
Repository: incubator-hawq
Updated Branches:
  refs/heads/master 1ba3686a6 -> 5553271a6


HAWQ-663. Wrongly count total allocated resource in resource queue manager


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

Branch: refs/heads/master
Commit: 5553271a6e52f18bf447e39c06bfe70defcd4f13
Parents: 1ba3686
Author: YI JIN 
Authored: Wed Apr 13 11:35:23 2016 +1000
Committer: YI JIN 
Committed: Wed Apr 13 11:35:23 2016 +1000

--
 src/backend/resourcemanager/communication/rmcomm_RM2RMSEG.c | 2 +-
 src/backend/resourcemanager/resourcepool.c  | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/5553271a/src/backend/resourcemanager/communication/rmcomm_RM2RMSEG.c
--
diff --git a/src/backend/resourcemanager/communication/rmcomm_RM2RMSEG.c 
b/src/backend/resourcemanager/communication/rmcomm_RM2RMSEG.c
index 50038b1..95bc194 100644
--- a/src/backend/resourcemanager/communication/rmcomm_RM2RMSEG.c
+++ b/src/backend/resourcemanager/communication/rmcomm_RM2RMSEG.c
@@ -204,7 +204,7 @@ void receivedRUAliveResponse(AsyncCommMessageHandlerContext 
 context,
/* Set the host down. */
elog(WARNING, "Resource manager sets host %s from up to 
down "
  "due to not getting valid 
RUAlive response.",
- GET_SEGRESOURCE_HOSTNAME(segres));
+ 
GET_SEGRESOURCE_HOSTNAME(segres));
 
refreshResourceQueueCapacity(false);
refreshActualMinGRMContainerPerSeg();

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/5553271a/src/backend/resourcemanager/resourcepool.c
--
diff --git a/src/backend/resourcemanager/resourcepool.c 
b/src/backend/resourcemanager/resourcepool.c
index 9ed243e..f6beee0 100644
--- a/src/backend/resourcemanager/resourcepool.c
+++ b/src/backend/resourcemanager/resourcepool.c
@@ -3210,6 +3210,8 @@ void returnAllGRMResourceFromSegment(SegResource segres)
GRMContainerSet ctns  = NULL;
uint32_tcount = 0;
 
+   minusResourceFromResourceManagerByBundle(&(segres->Allocated));
+
for ( int i = 0 ; i < PQUEMGR->RatioCount ; ++i )
{
ctns = segres->ContainerSets[i];
@@ -3262,7 +3264,6 @@ void returnAllGRMResourceFromUnavailableSegments(void)
{
continue;
}
-   minusResourceFromResourceManagerByBundle(&(segres->Allocated));
returnAllGRMResourceFromSegment(segres);
}
freePAIRRefList(&(PRESPOOL->Segments), &allsegres);



[incubator-hawq] Git Push Summary

2016-04-12 Thread odiachenko
Repository: incubator-hawq
Updated Branches:
  refs/heads/HAWQ-628 [deleted] c30af7e98


incubator-hawq git commit: HAWQ-628. Return -1 instead of error.

2016-04-12 Thread odiachenko
Repository: incubator-hawq
Updated Branches:
  refs/heads/master 2850d757c -> 1ba3686a6


HAWQ-628. Return -1 instead of error.


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

Branch: refs/heads/master
Commit: 1ba3686a676e44704af73a2dc833c8665477e112
Parents: 2850d75
Author: Oleksandr Diachenko 
Authored: Mon Apr 11 12:24:37 2016 -0700
Committer: Oleksandr Diachenko 
Committed: Tue Apr 12 15:09:06 2016 -0700

--
 src/backend/utils/adt/dbsize.c |  5 ++---
 src/test/regress/input/hcatalog_lookup.source  |  2 +-
 src/test/regress/output/hcatalog_lookup.source | 14 +++---
 3 files changed, 14 insertions(+), 7 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1ba3686a/src/backend/utils/adt/dbsize.c
--
diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c
index 12f70b9..a997cac 100644
--- a/src/backend/utils/adt/dbsize.c
+++ b/src/backend/utils/adt/dbsize.c
@@ -179,10 +179,9 @@ calculate_database_size(Oid dbOid)
 
Assert(Gp_role != GP_ROLE_EXECUTE);
 
+/* Do not error out because it would break some existing client calls*/
if (dbOid == HcatalogDbOid)
-   ereport(ERROR,
-   (ERRCODE_UNDEFINED_DATABASE,
-   errmsg("database hcatalog (OID 6120) is reserved")));
+   return -1;
 
/* User must have connect privilege for target database */
aclresult = pg_database_aclcheck(dbOid, GetUserId(), ACL_CONNECT);

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1ba3686a/src/test/regress/input/hcatalog_lookup.source
--
diff --git a/src/test/regress/input/hcatalog_lookup.source 
b/src/test/regress/input/hcatalog_lookup.source
index 239494a..2e3b5ea 100644
--- a/src/test/regress/input/hcatalog_lookup.source
+++ b/src/test/regress/input/hcatalog_lookup.source
@@ -142,7 +142,7 @@ select r1.*, r2.* from hcatalog.test_schema.r r1, 
test_schema.r r2;
 -- negative test: partitioned tables and hcatalog
 alter table test_schema.p exchange partition p1 with table 
hcatalog.test_schema.r;
 
--- negative test: cannot run pg_database_size on hcatalog
+-- negative test: return -1 as a size for hcatalog
 select pg_catalog.pg_database_size('hcatalog');
 select pg_catalog.pg_database_size(6120);
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1ba3686a/src/test/regress/output/hcatalog_lookup.source
--
diff --git a/src/test/regress/output/hcatalog_lookup.source 
b/src/test/regress/output/hcatalog_lookup.source
index 609c6d8..8eefb49 100644
--- a/src/test/regress/output/hcatalog_lookup.source
+++ b/src/test/regress/output/hcatalog_lookup.source
@@ -275,11 +275,19 @@ select r1.*, r2.* from hcatalog.test_schema.r r1, 
test_schema.r r2;
 -- negative test: partitioned tables and hcatalog
 alter table test_schema.p exchange partition p1 with table 
hcatalog.test_schema.r;
 ERROR:  reference to hcatalog table "hcatalog.test_schema.r" is not allowed in 
this context
--- negative test: cannot run pg_database_size on hcatalog
+-- negative test: return -1 as a size for hcatalog
 select pg_catalog.pg_database_size('hcatalog');
-ERROR:  database hcatalog (OID 6120) is reserved (SOMEFILE:SOMEFUNC)
+ pg_database_size 
+--
+   -1
+(1 row)
+
 select pg_catalog.pg_database_size(6120);
-ERROR:  database hcatalog (OID 6120) is reserved (SOMEFILE:SOMEFUNC)
+ pg_database_size 
+--
+   -1
+(1 row)
+
 --positive test: should be able to create table named "hcatalog"
 CREATE TABLE hcatalog(a int);
 --negative test: cannot create database named "hcatalog"



incubator-hawq git commit: HAWQ-628. Return -1 instead of error. [Forced Update!]

2016-04-12 Thread odiachenko
Repository: incubator-hawq
Updated Branches:
  refs/heads/HAWQ-628 1a8d51fee -> c30af7e98 (forced update)


HAWQ-628. Return -1 instead of error.


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

Branch: refs/heads/HAWQ-628
Commit: c30af7e989ea858769d1c33a262a571054f7f2b6
Parents: 3ab82d7
Author: Oleksandr Diachenko 
Authored: Mon Apr 11 12:24:37 2016 -0700
Committer: Oleksandr Diachenko 
Committed: Tue Apr 12 15:07:36 2016 -0700

--
 src/backend/utils/adt/dbsize.c |  5 ++---
 src/test/regress/input/hcatalog_lookup.source  |  2 +-
 src/test/regress/output/hcatalog_lookup.source | 14 +++---
 3 files changed, 14 insertions(+), 7 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c30af7e9/src/backend/utils/adt/dbsize.c
--
diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c
index 12f70b9..a997cac 100644
--- a/src/backend/utils/adt/dbsize.c
+++ b/src/backend/utils/adt/dbsize.c
@@ -179,10 +179,9 @@ calculate_database_size(Oid dbOid)
 
Assert(Gp_role != GP_ROLE_EXECUTE);
 
+/* Do not error out because it would break some existing client calls*/
if (dbOid == HcatalogDbOid)
-   ereport(ERROR,
-   (ERRCODE_UNDEFINED_DATABASE,
-   errmsg("database hcatalog (OID 6120) is reserved")));
+   return -1;
 
/* User must have connect privilege for target database */
aclresult = pg_database_aclcheck(dbOid, GetUserId(), ACL_CONNECT);

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c30af7e9/src/test/regress/input/hcatalog_lookup.source
--
diff --git a/src/test/regress/input/hcatalog_lookup.source 
b/src/test/regress/input/hcatalog_lookup.source
index 239494a..2e3b5ea 100644
--- a/src/test/regress/input/hcatalog_lookup.source
+++ b/src/test/regress/input/hcatalog_lookup.source
@@ -142,7 +142,7 @@ select r1.*, r2.* from hcatalog.test_schema.r r1, 
test_schema.r r2;
 -- negative test: partitioned tables and hcatalog
 alter table test_schema.p exchange partition p1 with table 
hcatalog.test_schema.r;
 
--- negative test: cannot run pg_database_size on hcatalog
+-- negative test: return -1 as a size for hcatalog
 select pg_catalog.pg_database_size('hcatalog');
 select pg_catalog.pg_database_size(6120);
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c30af7e9/src/test/regress/output/hcatalog_lookup.source
--
diff --git a/src/test/regress/output/hcatalog_lookup.source 
b/src/test/regress/output/hcatalog_lookup.source
index 609c6d8..8eefb49 100644
--- a/src/test/regress/output/hcatalog_lookup.source
+++ b/src/test/regress/output/hcatalog_lookup.source
@@ -275,11 +275,19 @@ select r1.*, r2.* from hcatalog.test_schema.r r1, 
test_schema.r r2;
 -- negative test: partitioned tables and hcatalog
 alter table test_schema.p exchange partition p1 with table 
hcatalog.test_schema.r;
 ERROR:  reference to hcatalog table "hcatalog.test_schema.r" is not allowed in 
this context
--- negative test: cannot run pg_database_size on hcatalog
+-- negative test: return -1 as a size for hcatalog
 select pg_catalog.pg_database_size('hcatalog');
-ERROR:  database hcatalog (OID 6120) is reserved (SOMEFILE:SOMEFUNC)
+ pg_database_size 
+--
+   -1
+(1 row)
+
 select pg_catalog.pg_database_size(6120);
-ERROR:  database hcatalog (OID 6120) is reserved (SOMEFILE:SOMEFUNC)
+ pg_database_size 
+--
+   -1
+(1 row)
+
 --positive test: should be able to create table named "hcatalog"
 CREATE TABLE hcatalog(a int);
 --negative test: cannot create database named "hcatalog"



incubator-hawq git commit: HAWQ-628. Return -1 instead of error. [Forced Update!]

2016-04-12 Thread odiachenko
Repository: incubator-hawq
Updated Branches:
  refs/heads/HAWQ-628 c2e19b725 -> 1a8d51fee (forced update)


HAWQ-628. Return -1 instead of error.


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

Branch: refs/heads/HAWQ-628
Commit: 1a8d51feec54c71f6a09907472f81b8280070597
Parents: 3ab82d7
Author: Oleksandr Diachenko 
Authored: Mon Apr 11 12:24:37 2016 -0700
Committer: Oleksandr Diachenko 
Committed: Tue Apr 12 15:03:47 2016 -0700

--
 src/backend/utils/adt/dbsize.c |  4 +---
 src/test/regress/input/hcatalog_lookup.source  |  2 +-
 src/test/regress/output/hcatalog_lookup.source | 14 +++---
 3 files changed, 13 insertions(+), 7 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1a8d51fe/src/backend/utils/adt/dbsize.c
--
diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c
index 12f70b9..82ff1a8 100644
--- a/src/backend/utils/adt/dbsize.c
+++ b/src/backend/utils/adt/dbsize.c
@@ -180,9 +180,7 @@ calculate_database_size(Oid dbOid)
Assert(Gp_role != GP_ROLE_EXECUTE);
 
if (dbOid == HcatalogDbOid)
-   ereport(ERROR,
-   (ERRCODE_UNDEFINED_DATABASE,
-   errmsg("database hcatalog (OID 6120) is reserved")));
+   return -1;
 
/* User must have connect privilege for target database */
aclresult = pg_database_aclcheck(dbOid, GetUserId(), ACL_CONNECT);

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1a8d51fe/src/test/regress/input/hcatalog_lookup.source
--
diff --git a/src/test/regress/input/hcatalog_lookup.source 
b/src/test/regress/input/hcatalog_lookup.source
index 239494a..2e3b5ea 100644
--- a/src/test/regress/input/hcatalog_lookup.source
+++ b/src/test/regress/input/hcatalog_lookup.source
@@ -142,7 +142,7 @@ select r1.*, r2.* from hcatalog.test_schema.r r1, 
test_schema.r r2;
 -- negative test: partitioned tables and hcatalog
 alter table test_schema.p exchange partition p1 with table 
hcatalog.test_schema.r;
 
--- negative test: cannot run pg_database_size on hcatalog
+-- negative test: return -1 as a size for hcatalog
 select pg_catalog.pg_database_size('hcatalog');
 select pg_catalog.pg_database_size(6120);
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1a8d51fe/src/test/regress/output/hcatalog_lookup.source
--
diff --git a/src/test/regress/output/hcatalog_lookup.source 
b/src/test/regress/output/hcatalog_lookup.source
index 609c6d8..8eefb49 100644
--- a/src/test/regress/output/hcatalog_lookup.source
+++ b/src/test/regress/output/hcatalog_lookup.source
@@ -275,11 +275,19 @@ select r1.*, r2.* from hcatalog.test_schema.r r1, 
test_schema.r r2;
 -- negative test: partitioned tables and hcatalog
 alter table test_schema.p exchange partition p1 with table 
hcatalog.test_schema.r;
 ERROR:  reference to hcatalog table "hcatalog.test_schema.r" is not allowed in 
this context
--- negative test: cannot run pg_database_size on hcatalog
+-- negative test: return -1 as a size for hcatalog
 select pg_catalog.pg_database_size('hcatalog');
-ERROR:  database hcatalog (OID 6120) is reserved (SOMEFILE:SOMEFUNC)
+ pg_database_size 
+--
+   -1
+(1 row)
+
 select pg_catalog.pg_database_size(6120);
-ERROR:  database hcatalog (OID 6120) is reserved (SOMEFILE:SOMEFUNC)
+ pg_database_size 
+--
+   -1
+(1 row)
+
 --positive test: should be able to create table named "hcatalog"
 CREATE TABLE hcatalog(a int);
 --negative test: cannot create database named "hcatalog"



incubator-hawq git commit: HAWQ-662. Fix memory leak when mppExecutorCleanup throws error.

2016-04-12 Thread hubertzhang
Repository: incubator-hawq
Updated Branches:
  refs/heads/master 3db63cf3c -> 2850d757c


HAWQ-662. Fix memory leak when mppExecutorCleanup throws error.


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

Branch: refs/heads/master
Commit: 2850d757c4ddb81873c027dc7f1fc77719b5ea65
Parents: 3db63cf
Author: hzhang2 
Authored: Tue Apr 12 18:48:31 2016 +0800
Committer: hzhang2 
Committed: Tue Apr 12 18:48:31 2016 +0800

--
 src/backend/executor/execMain.c | 6 ++
 1 file changed, 6 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/2850d757/src/backend/executor/execMain.c
--
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index bb2e8b9..d9830f3 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -1362,8 +1362,11 @@ ExecutorEnd(QueryDesc *queryDesc)
{
  /* Cleanup the global resource reference for spi/function resource 
inheritate. */
 if (Gp_role == GP_ROLE_DISPATCH) {
+  // we need to free resource in old memory-context.
+  MemoryContextSwitchTo(oldcontext);
   AutoFreeResource(queryDesc->resource);
   queryDesc->resource = NULL;
+  oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
 }
 
/*
@@ -1388,8 +1391,11 @@ ExecutorEnd(QueryDesc *queryDesc)
 
/* Cleanup the global resource reference for spi/function resource 
inheritate. */
if ( Gp_role == GP_ROLE_DISPATCH ) {
+ // we need to free resource in old memory-context.
+ MemoryContextSwitchTo(oldcontext);
AutoFreeResource(queryDesc->resource);
queryDesc->resource = NULL;
+   oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
}
 
/*



incubator-hawq git commit: HAWQ-662. Fix memory leak when mppExecutorCleanup throws error.

2016-04-12 Thread hubertzhang
Repository: incubator-hawq
Updated Branches:
  refs/heads/master 3ab82d76a -> 3db63cf3c


HAWQ-662. Fix memory leak when mppExecutorCleanup throws error.


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

Branch: refs/heads/master
Commit: 3db63cf3c46822f2522d5bcf180353e1bd6edd81
Parents: 3ab82d7
Author: hzhang2 
Authored: Tue Apr 12 17:49:32 2016 +0800
Committer: hzhang2 
Committed: Tue Apr 12 17:49:32 2016 +0800

--
 src/backend/executor/execMain.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3db63cf3/src/backend/executor/execMain.c
--
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 58d8d9b..bb2e8b9 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -1360,6 +1360,12 @@ ExecutorEnd(QueryDesc *queryDesc)
}
PG_CATCH();
{
+ /* Cleanup the global resource reference for spi/function resource 
inheritate. */
+if (Gp_role == GP_ROLE_DISPATCH) {
+  AutoFreeResource(queryDesc->resource);
+  queryDesc->resource = NULL;
+}
+
/*
 * we got an error. do all the necessary cleanup.
 */
@@ -1376,11 +1382,6 @@ ExecutorEnd(QueryDesc *queryDesc)
 */
FreeExecutorState(estate);
 
-   /* Cleanup the global resource reference for spi/function 
resource inheritate. */
-   if (Gp_role == GP_ROLE_DISPATCH) {
- AutoFreeResource(queryDesc->resource);
- queryDesc->resource = NULL;
-   }
PG_RE_THROW();
}
PG_END_TRY();