hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject incubator-hawq git commit: HAWQ-1438. Support resource owner beyond transaction boundary
Date Fri, 21 Apr 2017 08:37:46 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/master e889fc6d7 -> b8e6afd12


HAWQ-1438. Support resource owner beyond transaction boundary

(1) Add TopResourceOwner to trace resource used beyond the transaction boundary.
(2) When to auto alloc a new TopResourceOwner for each process?
    Generate a singleton TopResourceOwner when setting CurrentResourceOwner to NULL.
(3) If crashed at some code beyond the transaction boundary, we should manually create
    a new resource owner, because we don't manually create TopResourceOwner for each process.
(4) When to call ResourceOwnerDelete(TopResourceOwner) automatically for each process?
    Register it at on_proc_exit().


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

Branch: refs/heads/master
Commit: b8e6afd12c170830c5fbb03ef8405fe71154c367
Parents: e889fc6
Author: Ming LI <mli@apache.org>
Authored: Thu Apr 20 17:04:51 2017 +0800
Committer: Ming LI <mli@apache.org>
Committed: Fri Apr 21 15:24:27 2017 +0800

----------------------------------------------------------------------
 src/backend/access/transam/xact.c     |  6 +--
 src/backend/access/transam/xlog.c     |  4 +-
 src/backend/utils/init/flatfiles.c    |  2 +-
 src/backend/utils/resowner/resowner.c | 66 ++++++++++++++++++++++++++----
 src/include/utils/resowner.h          |  2 +
 5 files changed, 65 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b8e6afd1/src/backend/access/transam/xact.c
----------------------------------------------------------------------
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 440b2ca..3a408c7 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -2458,7 +2458,7 @@ CommitTransaction(void)
 	//AtEOXact_Snapshot(true);
 	pgstat_report_xact_timestamp(0);
 
-	CurrentResourceOwner = NULL;
+	CurrentResourceOwner = GetTopResourceOwner();
 	ResourceOwnerDelete(TopTransactionResourceOwner);
 	s->curTransactionOwner = NULL;
 	CurTransactionResourceOwner = NULL;
@@ -2687,7 +2687,7 @@ PrepareTransaction(void)
 	AtEOXact_HashTables(true);
 	/* don't call AtEOXact_PgStat here */
 
-	CurrentResourceOwner = NULL;
+	CurrentResourceOwner = GetTopResourceOwner();
 	ResourceOwnerDelete(TopTransactionResourceOwner);
 	s->curTransactionOwner = NULL;
 	CurTransactionResourceOwner = NULL;
@@ -2933,7 +2933,7 @@ CleanupTransaction(void)
 	 */
 	AtCleanup_Portals();		/* now safe to release portal memory */
 
-	CurrentResourceOwner = NULL;	/* and resource owner */
+	CurrentResourceOwner = GetTopResourceOwner();	/* and resource owner */
 	if (TopTransactionResourceOwner)
 		ResourceOwnerDelete(TopTransactionResourceOwner);
 	s->curTransactionOwner = NULL;

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b8e6afd1/src/backend/access/transam/xlog.c
----------------------------------------------------------------------
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index eeef04e..0a0f73c 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -6561,7 +6561,7 @@ StartupXLOG(void)
 					(errmsg("redo done at %X/%X",
 							ReadRecPtr.xlogid, ReadRecPtr.xrecoff)));
 
-			CurrentResourceOwner = NULL;
+			CurrentResourceOwner = GetTopResourceOwner();
 
 			InRedo = false;
 
@@ -7574,7 +7574,7 @@ XLogStandbyRecoverRange(XLogRecPtr *redoCheckpointLoc, CheckPoint *redoCheckPoin
 	 */
 	FlushBufferPool();
 
-	CurrentResourceOwner = NULL;
+	CurrentResourceOwner = GetTopResourceOwner();
 
 	InRedo = false;
 	InRecovery = false;

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b8e6afd1/src/backend/utils/init/flatfiles.c
----------------------------------------------------------------------
diff --git a/src/backend/utils/init/flatfiles.c b/src/backend/utils/init/flatfiles.c
index 79f5ec3..d916293 100644
--- a/src/backend/utils/init/flatfiles.c
+++ b/src/backend/utils/init/flatfiles.c
@@ -1107,7 +1107,7 @@ BuildFlatFiles(bool database_only)
 		write_auth_time_file(rel_authid, rel_authtime);
 	}
 
-	CurrentResourceOwner = NULL;
+	CurrentResourceOwner = GetTopResourceOwner();
 	ResourceOwnerDelete(owner);
 
 	XLogCloseRelationCache();

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b8e6afd1/src/backend/utils/resowner/resowner.c
----------------------------------------------------------------------
diff --git a/src/backend/utils/resowner/resowner.c b/src/backend/utils/resowner/resowner.c
index b45c92c..055280d 100644
--- a/src/backend/utils/resowner/resowner.c
+++ b/src/backend/utils/resowner/resowner.c
@@ -70,6 +70,7 @@ typedef struct ResourceOwnerData
  *	  GLOBAL MEMORY															 *
  *****************************************************************************/
 
+static ResourceOwner TopResourceOwner = NULL;
 ResourceOwner CurrentResourceOwner = NULL;
 ResourceOwner CurTransactionResourceOwner = NULL;
 ResourceOwner TopTransactionResourceOwner = NULL;
@@ -94,22 +95,21 @@ static void ResourceOwnerReleaseInternal(ResourceOwner owner,
 							 bool isTopLevel);
 static void PrintRelCacheLeakWarning(Relation rel);
 static void PrintTupleDescLeakWarning(TupleDesc tupdesc);
-
-
+static ResourceOwner ResourceOwnerCreateInternal(ResourceOwner parent,
+					const char *name);
 /*****************************************************************************
  *	  EXPORTED ROUTINES														 *
  *****************************************************************************/
 
-
 /*
- * ResourceOwnerCreate
- *		Create an empty ResourceOwner.
+ * ResourceOwnerCreateInternal
+ *		Create an empty ResourceOwner. This is only internal usage.
  *
  * All ResourceOwner objects are kept in TopMemoryContext, since they should
  * only be freed explicitly.
  */
-ResourceOwner
-ResourceOwnerCreate(ResourceOwner parent, const char *name)
+static ResourceOwner
+ResourceOwnerCreateInternal(ResourceOwner parent, const char *name)
 {
 	ResourceOwner owner;
 
@@ -126,7 +126,35 @@ ResourceOwnerCreate(ResourceOwner parent, const char *name)
 
 	return owner;
 }
+/*
+ * GetTopResourceOwner
+ *		Get a singleton TopResourceOwner, if it doesn't exist, create a new ResourceOwner.
+ *
+ * It will register callback fucntion to delete it for process exits when it is created,
+ * so that we did not need to call it in every process.
+ */
+ResourceOwner
+GetTopResourceOwner()
+{
+	if(TopResourceOwner == NULL){
+	    TopResourceOwner = ResourceOwnerCreateInternal(NULL, "Default TopResourceOwner");
+	    /* Register to automatically delete TopResourceOwner when process exit */
+	    on_proc_exit(DeleteTopResourceOwner, 0);
+	}
 
+	return TopResourceOwner;
+}
+/*
+ * ResourceOwnerCreate
+ *
+ * If parent is NULL, we will set parent to TopResourceOwner, so that all resource owner
can be
+ * traced by only one TopResourceOwner.
+ */
+ResourceOwner
+ResourceOwnerCreate(ResourceOwner parent, const char *name)
+{
+	return ResourceOwnerCreateInternal(parent == NULL?GetTopResourceOwner():parent, name);
+}
 /*
  * ResourceOwnerRelease
  *		Release all resources owned by a ResourceOwner and its descendants,
@@ -285,7 +313,7 @@ ResourceOwnerReleaseInternal(ResourceOwner owner,
 		{
 			if (isCommit)
 				PrintCatCacheLeakWarning(owner->catrefs[owner->ncatrefs - 1],
-                                         owner->name);
+	                                     owner->name);
 			ReleaseCatCache(owner->catrefs[owner->ncatrefs - 1]);
 		}
 		/* Ditto for catcache lists */
@@ -293,7 +321,7 @@ ResourceOwnerReleaseInternal(ResourceOwner owner,
 		{
 			if (isCommit)
 				PrintCatCacheListLeakWarning(owner->catlistrefs[owner->ncatlistrefs - 1],
-                                             owner->name);
+	                                         owner->name);
 			ReleaseCatCacheList(owner->catlistrefs[owner->ncatlistrefs - 1]);
 		}
 		/* Ditto for tupdesc references */
@@ -364,6 +392,26 @@ ResourceOwnerDelete(ResourceOwner owner)
 }
 
 /*
+ * DeleteTopResourceOwner
+ *		Firstly release all resource, then Delete TopResourceOwner object and its descendants.
+ *
+ * This function can be called serveral times because it need to be registerred in a callback
+ * function, which may occurs serveral times.
+ */
+void
+DeleteTopResourceOwner()
+{
+	if(TopResourceOwner == NULL)
+	    return;
+
+	ResourceOwnerRelease(TopResourceOwner,
+	        RESOURCE_RELEASE_BEFORE_LOCKS,
+	        false, true);
+	CurrentResourceOwner = NULL;
+	ResourceOwnerDelete(TopResourceOwner);
+	TopResourceOwner = NULL;
+}
+/*
  * Fetch parent of a ResourceOwner (returns NULL if top-level owner)
  */
 ResourceOwner

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b8e6afd1/src/include/utils/resowner.h
----------------------------------------------------------------------
diff --git a/src/include/utils/resowner.h b/src/include/utils/resowner.h
index 2cd615c..382cf7d 100644
--- a/src/include/utils/resowner.h
+++ b/src/include/utils/resowner.h
@@ -67,6 +67,7 @@ typedef void (*ResourceReleaseCallback) (ResourceReleasePhase phase,
  */
 
 /* generic routines */
+extern ResourceOwner GetTopResourceOwner();
 extern ResourceOwner ResourceOwnerCreate(ResourceOwner parent,
 					const char *name);
 extern void ResourceOwnerRelease(ResourceOwner owner,
@@ -74,6 +75,7 @@ extern void ResourceOwnerRelease(ResourceOwner owner,
 					 bool isCommit,
 					 bool isTopLevel);
 extern void ResourceOwnerDelete(ResourceOwner owner);
+extern void DeleteTopResourceOwner();
 extern ResourceOwner ResourceOwnerGetParent(ResourceOwner owner);
 extern void ResourceOwnerNewParent(ResourceOwner owner,
 					   ResourceOwner newparent);


Mime
View raw message