/* * get list of data nodes' rest servers, * and choose one (based on modulo segment id). * if pxf_isilon is true, there are no PXF instances on the datanodes. * TODO: add locality */ PxfServer* get_pxf_server(GPHDUri* gphd_uri, const Relation rel) { ClientContext client_context; /* holds the communication info */ PxfInputData inputData = {0}; List *rest_servers = NIL; ListCell *rest_server_c = NULL; PxfServer *found_server = NULL; PxfServer *ret_server = (PxfServer*)palloc0(sizeof(PxfServer)); char *server_ip = NULL; int server_index = 0; Assert(gphd_uri); /* init context */ init_client_context(&client_context); client_context.http_headers = churl_headers_init(); /* set HTTP header that guarantees response in JSON format */ churl_headers_append(client_context.http_headers, REST_HEADER_JSON_RESPONSE, NULL); if (!client_context.http_headers) { return NULL; } /* * Enrich the curl HTTP header */ inputData.headers = client_context.http_headers; inputData.gphduri = gphd_uri; inputData.rel = rel; inputData.filterstr = NULL; /* We do not supply filter data to the HTTP header */ add_delegation_token(&inputData); build_http_header(&inputData); int port = atoi(gphd_uri->port); if (!pxf_isilon) { /* send request */ rest_servers = get_datanode_rest_servers(gphd_uri, &client_context); foreach(rest_server_c, rest_servers) { PxfServer *rest_server = (PxfServer*)lfirst(rest_server_c); /* In case there are several rest servers on the same host, we assume * there are multiple DN residing together. * The port is incremented by one, to match singlecluster convention */ if (pxf_service_singlecluster) { if (server_ip == NULL) { server_ip = rest_server->host; } else if (are_ips_equal(server_ip, rest_server->host)) { port++; } } rest_server->port = port; }
/* * Add key/value pairs to connection header. * These values are the context of the query and used * by the remote component. */ void add_querydata_to_http_header(gphadoop_context* context, PG_FUNCTION_ARGS) { PxfInputData inputData = {0}; inputData.headers = context->churl_headers; inputData.gphduri = context->gphd_uri; inputData.rel = EXTPROTOCOL_GET_RELATION(fcinfo); inputData.filterstr = serializePxfFilterQuals(EXTPROTOCOL_GET_SCANQUALS(fcinfo)); add_delegation_token(&inputData); build_http_header(&inputData); free_token_resources(&inputData); }
/* * Add key/value pairs to connection header. * These values are the context of the query and used * by the remote component. */ void add_querydata_to_http_header(gphadoop_context* context, PG_FUNCTION_ARGS) { PxfInputData inputData = {0}; inputData.headers = context->churl_headers; inputData.gphduri = context->gphd_uri; inputData.rel = EXTPROTOCOL_GET_RELATION(fcinfo); inputData.quals = EXTPROTOCOL_GET_SCANQUALS(fcinfo); inputData.filterstr = serializePxfFilterQuals(EXTPROTOCOL_GET_SCANQUALS(fcinfo)); if (EXTPROTOCOL_GET_SELECTDESC(fcinfo)) { inputData.proj_info = EXTPROTOCOL_GET_PROJINFO(fcinfo); int agg_type = EXTPROTOCOL_GET_AGG_TYPE(fcinfo); if (agg_type) { inputData.agg_type = agg_type; } } add_delegation_token(&inputData); build_http_header(&inputData); free_token_resources(&inputData); }