Пример #1
0
int cleanupRMSEG2RMComm(void)
{
	destroySelfMaintainBuffer(&(RMSEG2RM_Context.SendBuffer));
	destroySelfMaintainBuffer(&(RMSEG2RM_Context.RecvBuffer));

	return FUNC_RETURN_OK;
}
Пример #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
void SimpleStringReplaceFirst(SimpStringPtr str, char *oldstr, char *newstr)
{
	char *pos = strstr(str->Str, oldstr);
	/* If the old string does not exist, no need to do any update. */
	if ( pos == NULL )
		return;

	SelfMaintainBufferData smb;
	initializeSelfMaintainBuffer(&smb, str->Context);
	if ( str->Str != pos ) {
		appendSelfMaintainBuffer(&smb, str->Str, pos - str->Str);
	}
	int oldstrlen = strlen(oldstr);
	appendSelfMaintainBuffer(&smb, newstr, strlen(newstr));
	if ( oldstrlen + (pos - str->Str) < str->Len ) {
		appendSMBStr(&smb, pos + oldstrlen);
	}
	setSimpleStringWithContent(str, smb.Buffer, getSMBContentSize(&smb));
	destroySelfMaintainBuffer(&smb);
}
Пример #4
0
int getLocalHostName(SimpStringPtr hostname)
{
	static int AppendSize = 2;
	/*
	 * Call gethostname() to read hostname, however, the hostname string array
	 * is fixed, therefore there is a possibility that the actual host name is
	 * longer than the pre-created array.
	 *
	 * gethostname() does not return -1 and does not set errno to ENAMETOOLONG
	 * in MACOS ( I did not test in linux yet ). So the logic here to judge if
	 * complete hostname string is returned is to check if we have more than 2
	 * \0 values at the very end of the array.
	 */
	SelfMaintainBufferData  buffer;
	int						sysres  = 0;
	int						res		= FUNC_RETURN_OK;

	initializeSelfMaintainBuffer(&buffer, hostname->Context);

	for ( int i = 0 ; i < 4096/AppendSize ; ++i ) {
		prepareSelfMaintainBuffer(&buffer, AppendSize, true);
		sysres = gethostname(buffer.Buffer, buffer.Size);
		if ( sysres == 0 && buffer.Buffer[buffer.Size-2] == '\0')
			break;
		jumpforwardSelfMaintainBuffer(&buffer, AppendSize);
	}

	if ( sysres != 0 ) {
		res = UTIL_NETWORK_TOOLONG_HOSTNAME;
	}
	else {
		/* Copy out the hostname string. */
		setSimpleStringNoLen(hostname, buffer.Buffer);
	}
	destroySelfMaintainBuffer(&buffer);
	return res;
}
Пример #5
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;
}
Пример #6
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;
}
Пример #7
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;
}