int SimpleStringSetInt32(SimpStringPtr str, int32_t value) { static char valuestr[8]; Assert(str != NULL); sprintf(valuestr, "%d", value); setSimpleStringNoLen(str, valuestr); return FUNC_RETURN_OK; }
int SimpleStringSetFloat(SimpStringPtr str, float value) { static char valuestr[32]; Assert(str != NULL); sprintf(valuestr, "%f", value); setSimpleStringNoLen(str, valuestr); return FUNC_RETURN_OK; }
int SimpleStringSetOid(SimpStringPtr str, Oid value) { static char valuestr[64]; Assert(str != NULL); int64_t val = value; sprintf(valuestr, INT64_FORMAT, val); setSimpleStringNoLen(str, valuestr); return FUNC_RETURN_OK; }
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 }
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; }
int SimpleStringSetBool(SimpStringPtr str, bool value) { Assert(str != NULL); setSimpleStringNoLen(str, value?"true":"false"); return FUNC_RETURN_OK; }
int SimpleStringSetName(SimpStringPtr str, Name value) { Assert(str != NULL); setSimpleStringNoLen(str, value->data); return FUNC_RETURN_OK; }
/** * 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); }
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; }