コード例 #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
int deserializeToSimpleString(SimpStringPtr str, char *content)
{
	Assert(str != NULL);
	str->Len = *((int32_t *)content);
	str->Str = (char *)rm_palloc0(str->Context, (str->Len+1));
	memcpy(str->Str, content+4, str->Len);
	return __SIZE_ALIGN64(str->Len + sizeof(int32_t));
}
コード例 #3
0
int serializeSizeGSimpString(GSimpStringPtr ssp, int *value)
{
	Assert( ssp );
	Assert( value );

	*value = __SIZE_ALIGN64(ssp->Len + sizeof(int32_t));

	return FUNC_RETURN_OK;
}
コード例 #4
0
int serializeFromGSimpString(GSimpStringPtr ssp, char *content, int *value)
{
	Assert( ssp );
	Assert( content );
	Assert( value );

	*((int32_t *)content) = ssp->Len;
	memcpy(content+4, ssp->Str, ssp->Len);

	*value = __SIZE_ALIGN64(ssp->Len + sizeof(int32_t));

	return FUNC_RETURN_OK;
}
コード例 #5
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;
}
コード例 #6
0
int deserializeToGSimpString(GSimpStringPtr ssp, char *content, int *value)
{
	Assert( ssp );
	Assert( content );
	Assert( value );

	ssp->Len = *((int32_t *)content);
	ssp->Str = (char *)malloc(ssp->Len+1);

	if ( ssp->Str == NULL )
	{
		write_log("Function deserializeToGSimpString out of memory");
		return UTIL_SIMPSTRING_OUT_OF_MEMORY;
	}

	memcpy(ssp->Str, content+4, ssp->Len);

	*value =  __SIZE_ALIGN64(ssp->Len + sizeof(int32_t));

	return FUNC_RETURN_OK;
}
コード例 #7
0
	/*
	 * parse preferred list and
	 * append (hostname, rackname, requested container number) into the message
	 */
	foreach(cell, preferred)
	{
		PAIR pair = (PAIR)lfirst(cell);
		SegResource segres = (SegResource)(pair->Key);
		ResourceBundle resource = (ResourceBundle)(pair->Value);
		int16_t num_containers = resource->Core;
		int16_t flag = 0; /* not used yet */
		char *hostname = GET_SEGINFO_GRMHOSTNAME(&(segres->Stat->Info));
		char *rackname = GET_SEGINFO_GRMRACKNAME(&(segres->Stat->Info));
		uint32_t preferredLen = sizeof(preferredLen) + sizeof(num_containers) + sizeof(flag) +
								__SIZE_ALIGN64((strlen(hostname) + 1 + strlen(rackname) + 1));
		appendSMBVar(&sendBuffer, preferredLen);
		appendSMBVar(&sendBuffer, num_containers);
		appendSMBVar(&sendBuffer, flag);
		appendSMBStr(&sendBuffer, hostname);
		appendSMBStr(&sendBuffer, rackname);
		appendSelfMaintainBufferTill64bitAligned(&sendBuffer);
		elog(LOG, "YARN mode resource broker build a preferred request."
				  "host:%s, rack:%s, container number:%d",
				  hostname, rackname, num_containers);
	}
コード例 #8
0
HostAddress createHostAddressAsStringFromIPV4AddressStr(MCTYPE context, const char *addr)
{
	static uint32_t addrlen = 0;
	HostAddress 	result = NULL;
	int				resultsize = 0;

	result = rm_palloc0(context, sizeof(HostAddressData));
	result->Attribute.Offset  = 0;
	result->Attribute.Mark   |= HOST_ADDRESS_CONTENT_STRING;

	addrlen = strlen(addr);
	resultsize = __SIZE_ALIGN64(offsetof(AddressStringData, Address) +
								addrlen + 1 );
	AddressString straddr = rm_palloc0(context, resultsize);

	straddr->Length = addrlen;
	strcpy(straddr->Address, addr);
	result->Address = (char *)straddr;
	result->AddressSize = resultsize;

	return result;
}
コード例 #9
0
int serializationSize(SimpStringPtr str)
{
	return __SIZE_ALIGN64(str->Len + sizeof(int32_t));
}
コード例 #10
0
int serializeFromSimpleString(SimpStringPtr str, char *content)
{
	*((int32_t *)content) = str->Len;
	memcpy(content+4, str->Str, str->Len);
	return __SIZE_ALIGN64(str->Len + sizeof(int32_t));
}
コード例 #11
0
int getHostIPV4AddressesByHostNameAsString(MCTYPE 	 		context,
										   const char 	   *hostname,
										   SimpStringPtr 	ohostname,
										   List   		  **addresses)
{
	Assert(hostname != NULL);
	Assert(ohostname != NULL);
	Assert(addresses != NULL);

	char ipstr[32];
	struct hostent  *hent = NULL;
	*addresses = NULL;
	/* Try to resolve this host by hostname. */

	for ( int i = 0 ; i < NETWORK_RETRY_TIMES ; ++i )
	{
		hent = gethostbyname(hostname);
		if( hent != NULL )
		{
			break;
		}
		else if ( h_errno != TRY_AGAIN )
		{
			write_log("Failed to call gethostbyname() to get host %s, %s",
					  hostname,
					  hstrerror(h_errno));
			break;
		}
		pg_usleep(NETWORK_RETRY_SLEEP_US);
	}

	if ( hent == NULL )
	{
		write_log("Failed to resolve host %s.", hostname);
		return SYSTEM_CALL_ERROR;
	}

	setSimpleStringNoLen(ohostname, hent->h_name);

	if ( hent->h_addrtype != AF_INET )
	{
		return FUNC_RETURN_OK; /* No IPv4 addresses. addresses is set NULL. */
	}

	/* This switch is to support List operation */
	MEMORY_CONTEXT_SWITCH_TO(context)

	for ( char **paddr = hent->h_addr_list ; *paddr != NULL ; paddr++ )
	{

		inet_ntop(hent->h_addrtype, *paddr, ipstr, sizeof(ipstr));

		int newaddrlen = strlen(ipstr);
		AddressString newaddr = (AddressString)
								rm_palloc0(context,
										   __SIZE_ALIGN64(
											   offsetof(AddressStringData, Address) +
											   newaddrlen + 1));
		newaddr->Length = newaddrlen;
		memcpy(newaddr->Address, ipstr, newaddrlen+1);
		*addresses = lappend(*addresses, (void *)newaddr);
	}

	MEMORY_CONTEXT_SWITCH_BACK

	return FUNC_RETURN_OK;
}