Пример #1
0
/*
 * Acquire resource from hosts in LIBYARN mode.
 *
 * This function use round-robin sequence to select available hosts in HAWQ RM
 * resource pool and choose suitable host to allocate containers.
 */
int RB_LIBYARN_acquireResource(uint32_t memorymb, uint32_t core, List *preferred)
{
	int		 res	   = FUNC_RETURN_OK;
	uint32_t MessageID = RM2RB_ALLOC_RESOURCE;
	ListCell *cell = NULL;

	if ( PipeReceivePending )
	{
		return RESBROK_PIPE_BUSY;
	}

	elog(LOG, "Allocating container request is triggered.");

	/* Write request to pipe */
	SelfMaintainBufferData sendBuffer;
	initializeSelfMaintainBuffer(&sendBuffer, PCONTEXT);
	appendSMBVar(&sendBuffer, MessageID);
	appendSelfMaintainBufferTill64bitAligned(&sendBuffer);

	RPCRequestRBAllocateResourceContainersData request;
	request.ContainerCount = core;
	request.MemoryMB	   = memorymb / core;
	request.Core		   = 1;
	request.PreferredSize  = list_length(preferred);
	request.MsgLength      = 0;
	foreach(cell, preferred)
	{
		PAIR pair = (PAIR)lfirst(cell);
		SegResource segres = (SegResource)(pair->Key);
		char *hostname = GET_SEGINFO_GRMHOSTNAME(&(segres->Stat->Info));
		char *rackname = GET_SEGINFO_GRMRACKNAME(&(segres->Stat->Info));
		uint32_t preferredLen = sizeof(uint32_t)*2 +
								__SIZE_ALIGN64((strlen(hostname) + 1 + strlen(rackname) + 1));
		request.MsgLength += preferredLen;
	}
Пример #2
0
/*
 * Return cluster report including all node status. The response should be
 * handled asynchronously.
 */
int RB_LIBYARN_getClusterReport(const char  *quename,
								List 	   **machines,
								double 	    *maxcapacity)
{
	int		 res		= FUNC_RETURN_OK;
	uint32_t MessageID	= RM2RB_GET_CLUSTERREPORT;
	int		 piperes	= 0;

	if ( PipeReceivePending )
	{
		elog(DEBUG5, "YARN resource broker skip sending cluster report due to "
					 "not getting response of last request.");
		return FUNC_RETURN_OK;
	}

	/* Write request to pipe */
	SelfMaintainBufferData sendBuffer;
	initializeSelfMaintainBuffer(&sendBuffer, PCONTEXT);
	appendSMBVar(&sendBuffer, MessageID);
	appendSelfMaintainBufferTill64bitAligned(&sendBuffer);

	RPCRequestRBGetClusterReportHeadData request;
	request.QueueNameLen = __SIZE_ALIGN64(strlen(quename) + 1);
	request.Reserved     = 0;
	appendSMBVar(&sendBuffer, request);
	appendSMBStr(&sendBuffer, quename);
	appendSelfMaintainBufferTill64bitAligned(&sendBuffer);

	piperes = pipewrite(ResBrokerRequestPipe[1],
						sendBuffer.Buffer,
						sendBuffer.Cursor + 1);
	if ( piperes != sendBuffer.Cursor + 1 )
	{
		elog(WARNING, "YARN mode resource broker failed to generate cluster "
					  "report request to resource broker process through pipe. "
				      "Wrote length %d, expected length %d, errno %d",
				      piperes,
				      sendBuffer.Cursor + 1,
					  errno);
		res = RESBROK_PIPE_ERROR;
	}
	destroySelfMaintainBuffer(&sendBuffer);
	elog(LOG, "YARN mode resource broker generated cluster report request to "
			  "resource broker process.");
	PipeReceivePending = res == FUNC_RETURN_OK;
	return res;
}
Пример #3
0
int decreaseMemoryQuota(char 			*seghostname,
					    GRMContainerSet  rescontainerset)
{
    int             res			= FUNC_RETURN_OK;
    AsyncCommBuffer commbuffer	= NULL;
    GRMContainerSet ctns		= NULL;

    Assert( seghostname != NULL );
    Assert( rescontainerset->Containers != NULL );

    /* Move resource containers that should be returned to communication context.*/
    ctns = createGRMContainerSet();
    moveGRMContainerSetContainerList(ctns, rescontainerset);

    /* Build request */
    SelfMaintainBufferData tosend;
    initializeSelfMaintainBuffer(&tosend, PCONTEXT);

    RPCRequestUpdateMemoryQuotaData request;

    request.MemoryQuotaDelta = ctns->Allocated.MemoryMB;

    GRMContainer firstcont = getGRMContainerSetContainerFirst(ctns);
    Assert( firstcont != NULL );

    request.MemoryQuotaTotalPending = firstcont->Resource->Allocated.MemoryMB +
    								  firstcont->Resource->OldInuse.MemoryMB;

    Assert( request.MemoryQuotaTotalPending >= 0 );

    elog(LOG, "Resource manager decrease host %s memory quota "UINT64_FORMAT" MB, "
    		  "Expected total memory quota after decreasing is " UINT64_FORMAT" MB. "
			  "Include %d MB old in-use memory quota.",
			  seghostname,
    		  request.MemoryQuotaDelta,
			  request.MemoryQuotaTotalPending,
			  firstcont->Resource->OldInuse.MemoryMB);

    appendSMBVar(&tosend, request);

    /* Set content to send and add to AsyncComm framework */
    AsyncCommMessageHandlerContext context =
            (AsyncCommMessageHandlerContext)rm_palloc0(AsyncCommContext,
            sizeof(AsyncCommMessageHandlerContextData));
    context->inMessage               = false;
    context->UserData                = ctns;
    context->MessageRecvReadyHandler = NULL;
    context->MessageRecvedHandler    = recvDecreaseMemoryQuotaResponse;
    context->MessageSendReadyHandler = NULL;
    context->MessageSentHandler      = sentDecreaseMemoryQuota;
    context->MessageErrorHandler     = sentDecreaseMemoryQuotaError;
    context->MessageCleanUpHandler   = sentDecreaseMemoryQuotaCleanup;

	res = registerAsyncConnectionFileDesc(NULL,
										  seghostname,
										  rm_segment_port,
										  ASYNCCOMM_READBYTES | ASYNCCOMM_WRITEBYTES,
										  &AsyncCommBufferHandlersMessage,
										  context,
										  &commbuffer);
    if ( res != FUNC_RETURN_OK )
    {
        elog(LOG, "Resource manager failed to set connection to segment host %s "
        		  "on port %d to decrease memory quota.",
                  seghostname,
				  rm_segment_port);
		processContainersAfterDecreaseMemoryQuota(ctns, false);
		freeGRMContainerSet(ctns);
		rm_pfree(AsyncCommContext, context);
        return res;
    }
    else
    {
    	elog(DEBUG3, "Resource manager succeeded set connection to segment host %s "
    				 "on port %d to decrease memory quota.",
     			     seghostname,
					 rm_segment_port);
    }

    buildMessageToCommBuffer(commbuffer,
                             tosend.Buffer,
                             tosend.Cursor+1,
                             REQUEST_RM_DECREASE_MEMORY_QUOTA,
                             0,
                             0);
    destroySelfMaintainBuffer(&tosend);

    context->AsyncBuffer = commbuffer;

	InitHandler_Message(commbuffer);

    return FUNC_RETURN_OK;
}
Пример #4
0
int sendRUAlive(char *seghostname)
{
	int 			res 			= FUNC_RETURN_OK;
	AsyncCommBuffer	newcommbuffer 	= NULL;
	SegResource 	segres			= NULL;
	int32_t 		segid 			= SEGSTAT_ID_INVALID;

	Assert(seghostname != NULL);

	res = getSegIDByHostName(seghostname, strlen(seghostname), &segid);
	if ( res != FUNC_RETURN_OK )
	{
		elog(WARNING, "Resource manager cannot get registered host %s when send RUAlive message, "
					  "error code: %d",
					  seghostname,
					  res);
		return res;
	}

	segres = getSegResource(segid);
	Assert(segres != NULL);

	bool oldstat = setSegResRUAlivePending(segres, true);
	if( oldstat != false )
	{
		Assert(false);
	}

	/* Build request. */
	SelfMaintainBufferData tosend;
	initializeSelfMaintainBuffer(&tosend, PCONTEXT);

	RPCRequestRUAliveData request;
	request.Reserved = 0;
	appendSMBVar(&tosend, request);

	AsyncCommMessageHandlerContext context =
			(AsyncCommMessageHandlerContext)
			rm_palloc0(AsyncCommContext,
					   sizeof(AsyncCommMessageHandlerContextData));

	context->inMessage				 = false;
	context->MessageRecvReadyHandler = NULL;
	context->MessageRecvedHandler	 = receivedRUAliveResponse;
	context->MessageSendReadyHandler = NULL;
	context->MessageSentHandler		 = sentRUAlive;
	context->MessageErrorHandler 	 = sentRUAliveError;
	context->MessageCleanUpHandler	 = sentRUAliveCleanUp;
	context->UserData                = (void *)segres;

	/* Connect to HAWQ RM server */
	res = registerAsyncConnectionFileDesc(NULL,
										  seghostname,
										  rm_segment_port,
										  ASYNCCOMM_READBYTES | ASYNCCOMM_WRITEBYTES,
										  &AsyncCommBufferHandlersMessage,
										  context,
										  &newcommbuffer);
	if ( res != FUNC_RETURN_OK )
	{
		rm_pfree(AsyncCommContext, context);
		elog(WARNING, "Fail to register asynchronous connection for sending "
					  "RUAlive message. %d", res);
		return res;
	}

	buildMessageToCommBuffer(newcommbuffer,
							 tosend.Buffer,
							 tosend.Cursor+1,
							 REQUEST_RM_RUALIVE,
							 0,
							 0);
	destroySelfMaintainBuffer(&tosend);
	context->AsyncBuffer = newcommbuffer;
	InitHandler_Message(newcommbuffer);
	return FUNC_RETURN_OK;
}
Пример #5
0
/******************************************************************************
 * I aM Alive.
 *
 * Request:
 *         |<----------- 64 bits (8 bytes) ----------->|
 *         +----------+--------------------------------+
 *         |  TDC     |  BDC     |     Reserved        |
 * 		   +----------+----------+---------------------+
 *         |                                           |
 *         |             Machine ID info               |
 *         |                                           |
 * 		   +-------------------------------------------+     _____ 64bit aligned
 *
 * Response:
 *         |<----------- 64 bits (8 bytes) ----------->|
 *         +---------------------+---------------------+
 *         |  heartbeat result   |    Reserved   	   |
 * 		   +---------------------+---------------------+     _____ 64bit aligned
 *
 ******************************************************************************/
int sendIMAlive(int  *errorcode,
				char *errorbuf,
				int	  errorbufsize)
{
	int 				res 					= FUNC_RETURN_OK;
	AsyncCommBuffer		newcommbuffer			= NULL;

	Assert( DRMGlobalInstance->LocalHostStat != NULL );

	/* Build request. */
	SelfMaintainBufferData tosend;
	initializeSelfMaintainBuffer(&tosend, PCONTEXT);

	RPCRequestHeadIMAliveData requesthead;
	requesthead.TmpDirCount 	  = getDQueueLength(&DRMGlobalInstance->LocalHostTempDirectories);
	requesthead.TmpDirBrokenCount = DRMGlobalInstance->LocalHostStat->FailedTmpDirNum;
	requesthead.Reserved		  = 0;

	appendSMBVar(&tosend, requesthead);
	appendSelfMaintainBuffer(&tosend,
							 (char *)(DRMGlobalInstance->LocalHostStat),
							 offsetof(SegStatData, Info) +
							 DRMGlobalInstance->LocalHostStat->Info.Size);

	/* Set content to send and add to AsyncComm framework. */
	AsyncCommMessageHandlerContext context =
			rm_palloc0(AsyncCommContext,
					   sizeof(AsyncCommMessageHandlerContextData));
	context->inMessage				 = false;
	context->UserData  				 = NULL;
	context->MessageRecvReadyHandler = NULL;
	context->MessageRecvedHandler 	 = receivedIMAliveResponse;
	context->MessageSendReadyHandler = NULL;
	context->MessageSentHandler		 = sentIMAlive;
	context->MessageErrorHandler 	 = sentIMAliveError;
	context->MessageCleanUpHandler	 = sentIMAliveCleanUp;

	/* Connect to HAWQ RM server */

	res = registerAsyncConnectionFileDesc(NULL,
										  DRMGlobalInstance->SendToStandby?
										  standby_addr_host:
										  master_addr_host,
										  rm_master_port,
										  ASYNCCOMM_READBYTES | ASYNCCOMM_WRITEBYTES,
										  &AsyncCommBufferHandlersMessage,
										  context,
										  &newcommbuffer);
	if ( res != FUNC_RETURN_OK )
	{
		rm_pfree(AsyncCommContext, context);
		elog(WARNING, "Fail to register asynchronous connection for sending "
					  "IMAlive message. %d", res);
		return res;
	}

	buildMessageToCommBuffer(newcommbuffer,
							 tosend.Buffer,
							 tosend.Cursor + 1,
							 REQUEST_RM_IMALIVE,
							 0,
							 0);

	destroySelfMaintainBuffer(&tosend);

	context->AsyncBuffer = newcommbuffer;

	InitHandler_Message(newcommbuffer);

	return FUNC_RETURN_OK;
}