Repository: incubator-hawq Updated Branches: refs/heads/master b65815a3c -> 323f265aa
HAWQ-573. Refix the bug as last fix has imported more warning messages. Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/323f265a Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/323f265a Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/323f265a Branch: refs/heads/master Commit: 323f265aa28cfb49d29311cc1626e7bd2048e4bf Parents: b65815a Author: doli <d...@pivotal.io> Authored: Thu Mar 31 13:59:29 2016 +0800 Committer: hzhang2 <zhanghuan...@163.com> Committed: Thu Mar 31 17:36:12 2016 +0800 ---------------------------------------------------------------------- src/backend/tcop/pquery.c | 81 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/323f265a/src/backend/tcop/pquery.c ---------------------------------------------------------------------- diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c index 23b59a1..04420c3 100644 --- a/src/backend/tcop/pquery.c +++ b/src/backend/tcop/pquery.c @@ -85,6 +85,7 @@ static List *ActiveRelsType =NULL; typedef struct QueryResourceItem { bool alive; int resource_id; + bool allocateSucceed; } QueryResourceItem; static List *GlobalQueryResources = NIL; @@ -111,7 +112,8 @@ static int64 DoPortalRunFetch(Portal portal, static void DoPortalRewind(Portal portal); static void AddToGlobalQueryResources(int resourceId, QueryResourceLife life); - +static void RemoveFromGlobalQueryResources(int resourceId, QueryResourceLife life); +static void SetResourcesAllocatedSucceed(int resourceId, QueryResourceLife life); static int compare_segment(const void *e1, const void *e2); /* * CreateQueryDesc @@ -805,7 +807,10 @@ AllocateResource(QueryResourceLife life, errorbuf, sizeof(errorbuf)); if (ret != FUNC_RETURN_OK) { + RemoveFromGlobalQueryResources(resourceId, life); ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("%s",errorbuf))); + } else { + SetResourcesAllocatedSucceed(resourceId, life); } elog(DEBUG3, "Acquired resource from resource manager."); @@ -948,10 +953,73 @@ AddToGlobalQueryResources(int resourceId, QueryResourceLife life) newItem = palloc(sizeof(QueryResourceItem)); newItem->alive = true; newItem->resource_id = resourceId; + /* + * Only if the allocate resource RPC returns OK, + * the allocateSucceed can be set true by using SetResourcesAllocatedSucceed() + */ + newItem->allocateSucceed = false; GlobalQueryResources = lappend(GlobalQueryResources, newItem); MemoryContextSwitchTo(old); } +static void +RemoveFromGlobalQueryResources(int resourceId, QueryResourceLife life) +{ + ListCell *lc; + QueryResourceItem *newItem; + MemoryContext old; + + if (life == QRL_NONE) + { + return; + } + + foreach(lc, GlobalQueryResources) + { + QueryResourceItem *qri = lfirst(lc); + if(qri->resource_id == resourceId) + { + /* + * found, delete it. + */ + break; + } + } + + /* + * remove from the global query resource. + */ + old = MemoryContextSwitchTo(TopMemoryContext); + GlobalQueryResources = list_delete_ptr(GlobalQueryResources,lfirst(lc)); + MemoryContextSwitchTo(old); +} + +static void +SetResourcesAllocatedSucceed(int resourceId, QueryResourceLife life) +{ + ListCell *lc; + QueryResourceItem *newItem; + MemoryContext old; + + if (life == QRL_NONE) + { + return; + } + + foreach(lc, GlobalQueryResources) + { + QueryResourceItem *qri = lfirst(lc); + if(qri->resource_id == resourceId) + { + /* + * found, set it succeed. + */ + qri->allocateSucceed = true; + return; + } + } +} + void FreeResource(QueryResource *resource) { @@ -1068,17 +1136,22 @@ CleanupGlobalQueryResources(void) if (qri->alive) { ret = returnResource(qri->resource_id, errorbuf, sizeof(errorbuf)); - if (ret != FUNC_RETURN_OK) + /* + * If qri->allocateSucceed == false, that means it interrupts during acquireResourceFromRM(). + * And we don't know if it has been allocated succeed. + * It also means it may return resource failed as if the resource hasn't been allocated yet. + * So don't report warning message in this situation. + */ + if (ret != FUNC_RETURN_OK && qri->allocateSucceed) { ereport(WARNING, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("%s",errorbuf))); } ret = unregisterConnectionInRM(qri->resource_id, errorbuf, sizeof(errorbuf)); - if (ret != FUNC_RETURN_OK) + if (ret != FUNC_RETURN_OK && qri->allocateSucceed) { ereport(WARNING, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("%s",errorbuf))); } - releaseResourceContext(qri->resource_id); qri->alive = false; }