void RB_clearResource(List **ctnl)
{
	while( (*ctnl) != NULL )
	{
		GRMContainer ctn = (GRMContainer)lfirst(list_head(*ctnl));
		MEMORY_CONTEXT_SWITCH_TO(PCONTEXT)
		(*ctnl) = list_delete_first(*ctnl);
		MEMORY_CONTEXT_SWITCH_BACK

		elog(LOG, "Resource broker dropped GRM container "INT64_FORMAT
				  "(%d MB, %d CORE) on host %s",
				  ctn->ID,
				  ctn->MemoryMB,
				  ctn->Core,
				  ctn->HostName == NULL ? "NULL" : ctn->HostName);

		if ( ctn->CalcDecPending )
		{
			minusResourceBundleData(&(ctn->Resource->DecPending), ctn->MemoryMB, ctn->Core);
			Assert( ctn->Resource->DecPending.Core >= 0 );
			Assert( ctn->Resource->DecPending.MemoryMB >= 0 );
		}

		/* Destroy resource container. */
		freeGRMContainer(ctn);
		PRESPOOL->RetPendingContainerCount--;
	}
}
Exemplo n.º 2
0
/* Return connection id. */
int returnConnectionID(int32_t connid)
{
	int value = connid;
	MEMORY_CONTEXT_SWITCH_TO(PCONTEXT)
	PCONTRACK->FreeConnIDs = lappend_int(PCONTRACK->FreeConnIDs, value);
	MEMORY_CONTEXT_SWITCH_BACK
	elog(DEBUG3, "Resource manager returned connection track ID %d", connid);
	return FUNC_RETURN_OK;
}
Exemplo n.º 3
0
void  _rm_pfree(MCTYPE context, void *ptr,
			    const char *filename, int line, const char *function)
{
	if ( context != NULL ) {
		elog(DEBUG5, "RM_PFREE at %lx from %s:%d:%s",
					(unsigned long)(ptr), filename, line, function);

		MEMORY_CONTEXT_SWITCH_TO(context)
		pfree(ptr);
		MEMORY_CONTEXT_SWITCH_BACK
	}
Exemplo n.º 4
0
int SimpleStringSetText(MCTYPE context, SimpStringPtr str, text *value)
{
	Assert(str != NULL);

	if ( value != NULL ) {
		char *tmpvalue = NULL;
		MEMORY_CONTEXT_SWITCH_TO(context)
		tmpvalue = DatumGetCString(DirectFunctionCall1(textout,
													   PointerGetDatum(value)));
		setSimpleStringNoLen(str, tmpvalue);
		pfree(tmpvalue);
		MEMORY_CONTEXT_SWITCH_BACK
	}
Exemplo n.º 5
0
/* Use connection id. */
int useConnectionID(int32_t *connid)
{
	/* Ensure that we have potential enough connection IDs to utilize. */
	if ( PCONTRACK->FreeConnIDs == NULL )
	{
		*connid = INVALID_CONNID;
		return CONNTRACK_CONNID_FULL;
	}
	*connid = lfirst_int(list_head(PCONTRACK->FreeConnIDs));
	MEMORY_CONTEXT_SWITCH_TO(PCONTEXT)
	PCONTRACK->FreeConnIDs = list_delete_first(PCONTRACK->FreeConnIDs);
	MEMORY_CONTEXT_SWITCH_BACK
	elog(DEBUG3, "Resource manager uses connection track ID %d", *connid);
	return FUNC_RETURN_OK;
}
Exemplo n.º 6
0
void *_rm_repalloc(MCTYPE context, void * ptr, uint32_t newsize,
				   const char *filename, int line, const char *function)
{
	void *res = NULL;
	if ( context != NULL ) {
		MEMORY_CONTEXT_SWITCH_TO(context)
		res = repalloc(ptr, newsize);
		MEMORY_CONTEXT_SWITCH_BACK
		elog(DEBUG5, "RM_REPALLOC %d bytes at %lx from %s:%d:%s",
					newsize, (unsigned long)(res), filename, line, function);
	}
	else {
		res = realloc(ptr, newsize);
		if (!res)
		{
			elog(FATAL, "_rm_repalloc realloc failed, out of memory, newsize %d (errno %d)", newsize, errno);
		}
	}
	return res;
}
Exemplo n.º 7
0
void initializeRMSEG2RMComm(void)
{
	/* Ask for new memory context for this postmaster side memory consumption.*/
	MEMORY_CONTEXT_SWITCH_TO(TopMemoryContext)

	RMSEG2RM_CommContext 	= NULL;

	RMSEG2RM_CommContext = AllocSetContextCreate( CurrentMemoryContext,
											      DRMRMSEG2RM_MEMORY_CONTEXT_NAME,
											      ALLOCSET_DEFAULT_MINSIZE,
											      ALLOCSET_DEFAULT_INITSIZE,
											      ALLOCSET_DEFAULT_MAXSIZE );
	Assert( RMSEG2RM_CommContext != NULL );
	MEMORY_CONTEXT_SWITCH_BACK

	/* Create communication context. */
	RMSEG2RM_Context.RMSEG2RM_Conn_FD = -1;

	initializeSelfMaintainBuffer(&(RMSEG2RM_Context.SendBuffer),
								 RMSEG2RM_CommContext);
	initializeSelfMaintainBuffer(&(RMSEG2RM_Context.RecvBuffer),
								 RMSEG2RM_CommContext);
}
Exemplo n.º 8
0
void *_rm_palloc0(MCTYPE context, uint32_t size,
				  const char *filename, int line, const char *function)
{
	void *res = NULL;
	if ( context != NULL ) {
		MEMORY_CONTEXT_SWITCH_TO(context)
		res = palloc0(size);
		MEMORY_CONTEXT_SWITCH_BACK
		elog(DEBUG5, "RM_PALLOC0 %d bytes at %lx from %s:%d:%s",
					size, (unsigned long)(res), filename, line, function);
	}
	else {
		res = malloc(size);
		if (!res)
		{
			elog(FATAL, "_rm_palloc0 malloc failed, out of memory, size %d (errno %d)", size, errno);
		}
		else
		{
			memset(res, 0, size);
		}
	}
	return res;
}
/**
 * HAWQ RM handles the resource queue definition manipulation including CREATE,
 * ALTER and DROP RESOURCE QUEUE statements.
 */
bool handleRMDDLRequestManipulateResourceQueue(void **arg)
{
	int      				res		 		= FUNC_RETURN_OK;
	uint32_t				ddlres   		= FUNC_RETURN_OK;
	ConnectionTrack        *conntrack       = (ConnectionTrack *)arg;
	DynResourceQueueTrack 	newtrack 		= NULL;
	DynResourceQueueTrack   todroptrack		= NULL;
	DynResourceQueueTrack   toupdatetrack	= NULL;
	SelfMaintainBufferData  responsebuff;
	static char 			errorbuf[1024] 	= "";
	bool					exist 			= false;
	List 				   *fineattr		= NULL;
	List 				   *rsqattr			= NULL;
	DynResourceQueue 		newqueue 		= NULL;
	DynResourceQueue        oldqueue        = NULL;

	/* Check context and retrieve the connection track based on connection id.*/
	RPCRequestHeadManipulateResQueue request = (RPCRequestHeadManipulateResQueue)
											   ((*conntrack)->MessageBuff.Buffer);

	elog(LOG, "Resource manager gets a request from ConnID %d to submit resource "
			  "queue DDL statement.",
			  request->ConnID);

	elog(DEBUG3, "With attribute list size %d", request->WithAttrLength);

	if ( (*conntrack)->ConnID == INVALID_CONNID )
	{
		res = retrieveConnectionTrack((*conntrack), request->ConnID);
		if ( res != FUNC_RETURN_OK )
		{
			elog(WARNING, "Not valid resource context with id %d.", request->ConnID);
			goto senderr;
		}

		elog(DEBUG5, "Resource manager fetched existing connection track "
					 "ID=%d, Progress=%d.",
					 (*conntrack)->ConnID,
					 (*conntrack)->Progress);
	}

	/*
	 * Only registered connection can manipulate resource queue, the status
	 * should be CONN_REGISTER_DONE.
	 */
	Assert( (*conntrack)->Progress == CONN_PP_REGISTER_DONE );

	/*
	 * Only the super user can manipulate resource queue. This is already
	 * checked before sending RPC to RM this process.
	 */
	Assert((*conntrack)->User != NULL &&
		   ((UserInfo)((*conntrack)->User))->isSuperUser);

	/* Build property list for the resource queue to be created. */
	request = (RPCRequestHeadManipulateResQueue)((*conntrack)->MessageBuff.Buffer);

	/* Get resource queue name. */
	char *string = (*conntrack)->MessageBuff.Buffer +
				   sizeof(RPCRequestHeadManipulateResQueueData);
	KVProperty nameattr = createPropertyString(PCONTEXT,
											   NULL,
											   getRSQTBLAttributeName(RSQ_TBL_ATTR_NAME),
											   NULL,
											   string);
	{
		MEMORY_CONTEXT_SWITCH_TO(PCONTEXT)
		rsqattr = lappend(rsqattr, nameattr);
		MEMORY_CONTEXT_SWITCH_BACK
	}

	string += nameattr->Val.Len+1;

	/* Get with list. <key>=<value> */
	for ( int i = 0 ; i < request->WithAttrLength ; ++i )
	{
		KVProperty withattr = createPropertyEmpty(PCONTEXT);
		setSimpleStringNoLen(&(withattr->Key), string);
		string += withattr->Key.Len + 1;
		setSimpleStringNoLen(&(withattr->Val), string);
		string += withattr->Val.Len + 1;

		MEMORY_CONTEXT_SWITCH_TO(PCONTEXT)
		rsqattr = lappend(rsqattr, withattr);
		MEMORY_CONTEXT_SWITCH_BACK
	}

	/* Log the received attributes in DDL request. */
	ListCell *cell = NULL;
	foreach(cell, rsqattr)
	{
		KVProperty attribute = lfirst(cell);
		elog(DEBUG3, "Resource manager received DDL Request: %s=%s",
				     attribute->Key.Str, attribute->Val.Str);
	}