Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteeaf525

Browse files
committed
raw
1 parent5476e85 commiteeaf525

File tree

5 files changed

+62
-55
lines changed

5 files changed

+62
-55
lines changed

‎contrib/pg_exchange/exchange.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ ExchangeCreateCustomPlan(PlannerInfo *root,
710710
private->node.extnodename=EXCHANGE_PRIVATE_NAME;
711711

712712
/* Add stream name into private field*/
713-
GetMyServerName(&host,&port);
713+
host=GetMyServerName(&port);
714714
sprintf(streamName,"%s-%d-%d",host,port,exchange_counter++);
715715
exchange->custom_private=lappend(exchange->custom_private,makeString(streamName));
716716
Assert(altrel->nparts>0);
@@ -777,7 +777,7 @@ create_gather_dfn(EPPNode *epp, RelOptInfo *rel)
777777
/* Foreign relation */
778778
FSExtractServerName(part_rel->serverid,&hostname,&port);
779779
else
780-
GetMyServerName(&hostname,&port);
780+
hostname=GetMyServerName(&port);
781781

782782
createNodeName(epp->nodes[partno],hostname,port);
783783
}
@@ -816,7 +816,7 @@ create_stealth_dfn(EPPNode *epp, RelOptInfo *rel, PlannerInfo *root)
816816
/* Foreign relation */
817817
FSExtractServerName(part_rel->serverid,&hostname,&port);
818818
else
819-
GetMyServerName(&hostname,&port);
819+
hostname=GetMyServerName(&port);
820820

821821
createNodeName(epp->nodes[partno],hostname,port);
822822
}
@@ -845,7 +845,7 @@ create_shuffle_dfn(EPPNode *epp, RelOptInfo *rel, PlannerInfo *root)
845845
/* Foreign relation */
846846
FSExtractServerName(part_rel->serverid,&hostname,&port);
847847
else
848-
GetMyServerName(&hostname,&port);
848+
hostname=GetMyServerName(&port);
849849

850850
createNodeName(epp->nodes[partno],hostname,port);
851851
}
@@ -894,7 +894,7 @@ create_broadcast_dfn(EPPNode *epp, RelOptInfo *rel, PlannerInfo *root)
894894
/* Foreign relation */
895895
FSExtractServerName(part_rel->serverid,&hostname,&port);
896896
else
897-
GetMyServerName(&hostname,&port);
897+
hostname=GetMyServerName(&port);
898898

899899
createNodeName(epp->nodes[partno],hostname,port);
900900
}

‎contrib/pg_exchange/gcp/init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ make -C contrib > /dev/null
2626
make install> /dev/null
2727
make -C contrib install> /dev/null
2828

29-
initdb -D$PGDATA -E UTF8 --locale=C
29+
initdb -D$PGDATA
3030

3131
echo"shared_preload_libraries = 'postgres_fdw, pg_exchange'">>$PGDATA/postgresql.conf
3232
echo"listen_addresses = '*'">>$PGDATA/postgresql.conf

‎contrib/pg_exchange/nodeDistPlanExec.c

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,14 @@ serialize_plan(Plan *plan, const char *sourceText, ParamListInfo params)
143143
rlen1=pg_b64_encode(sparams,sparams_len,params_container);
144144
Assert(rlen >=rlen1);
145145

146-
GetMyServerName(&host,&port);
146+
host=GetMyServerName(&port);
147147
serverName=serializeServer(host,port);
148148
query=palloc0(qlen+plen+rlen+strlen(serverName)+100);
149149
sprintf(query,"SELECT public.pg_exec_plan('%s', '%s', '%s', '%s');",
150150
query_container,plan_container,params_container,
151151
serverName);
152152

153153
pfree(serverName);
154-
pfree(host);
155154
pfree(query_container);
156155
pfree(plan_container);
157156
pfree(sparams);
@@ -239,7 +238,7 @@ EstablishDMQConnections(const lcontext *context, const char *serverName,
239238
char*host;
240239
intport;
241240

242-
GetMyServerName(&host,&port);
241+
host=GetMyServerName(&port);
243242
sprintf(senderName,"%s-%d",host,port);
244243
FSExtractServerName((Oid)sid,&host,&port);
245244
sprintf(receiverName,"%s-%d",host,port);
@@ -689,10 +688,40 @@ localize_plan(Plan *node, lcontext *context)
689688
return false;
690689
}
691690

691+
692+
#include<unistd.h>
693+
#include<sys/types.h>
694+
#include<sys/socket.h>
695+
#include<sys/ioctl.h>
696+
#include<netinet/in.h>
697+
#include<net/if.h>
698+
#include<arpa/inet.h>
699+
#include"common/ip.h"
700+
692701
constchar*LOCALHOST="localhost";
702+
703+
staticchar*
704+
get_hostname(constchar*sipaddr)
705+
{
706+
char*hostname;
707+
structaddrinfohintp;
708+
structaddrinfo*result;
709+
710+
structsockaddr_storagesaddr;
711+
intres;
712+
713+
if ((res=pg_getaddrinfo_all(sipaddr,NULL,&hintp,&result))!=0)
714+
elog(FATAL,"Cannot resolve network address %s, error=%d.",sipaddr,res);
715+
memcpy(&saddr,result->ai_addr,result->ai_addrlen);
716+
hostname= (char*)palloc0(NI_MAXHOST);
717+
if (pg_getnameinfo_all(&saddr,result->ai_addrlen,hostname,NI_MAXHOST,
718+
NULL,0,0)!=0)
719+
elog(FATAL,"Cannot resolve network name");
720+
returnhostname;
721+
}
693722
/*
694723
* fsid - foreign server oid.
695-
* host - returns C-stringwith foreign server host name
724+
* host - returns C-stringcontained foreign server host name
696725
* port - returns foreign server port number.
697726
*/
698727
void
@@ -709,59 +738,31 @@ FSExtractServerName(Oid fsid, char **host, int *port)
709738
DefElem*def= (DefElem*)lfirst(lc);
710739

711740
if (strcmp(def->defname,"host")==0)
712-
hostname=pstrdup(defGetString(def));
741+
hostname=defGetString(def);
713742
elseif (strcmp(def->defname,"port")==0)
714743
*port=strtol(defGetString(def),NULL,10);
715744
}
716745

717746
if (!hostname)
718-
hostname=pstrdup(LOCALHOST);
747+
hostname=GetMyServerName(NULL);
748+
else
749+
{
750+
hostname=get_hostname(hostname);
751+
/* Convert foreign server address to network host name. */
752+
}
719753
*host=hostname;
720754
}
721755

722-
#include<unistd.h>
723-
#include<sys/types.h>
724-
#include<sys/socket.h>
725-
#include<sys/ioctl.h>
726-
#include<netinet/in.h>
727-
#include<net/if.h>
728-
#include<arpa/inet.h>
729-
#include"common/ip.h"
730-
731-
void
732-
GetMyServerName(char**host,int*port)
756+
char*
757+
GetMyServerName(int*port)
733758
{
734-
intfd;
735-
structifreqifr;
736-
structaddrinfohintp;
737-
structaddrinfo*result;
738-
char*sipaddr;
739-
structsockaddr_storagesaddr;
740-
intres;
741-
742-
fd=socket(AF_INET,SOCK_DGRAM,0);
743-
744-
/* I want to get an IPv4 IP address */
745-
ifr.ifr_addr.sa_family=AF_INET;
746-
747-
/* I want IP address attached to "eth0" */
748-
strncpy(ifr.ifr_name,network_interface,IFNAMSIZ-1);
749-
ioctl(fd,SIOCGIFADDR,&ifr);
750-
close(fd);
751-
752-
MemSet(&hintp,0,sizeof(hintp));
753-
hintp.ai_family=AF_INET;
754-
hintp.ai_flags=AI_ALL;
755-
sipaddr=inet_ntoa(((structsockaddr_in*)&ifr.ifr_addr)->sin_addr);
756-
if ((res=pg_getaddrinfo_all(sipaddr,NULL,&hintp,&result))!=0)
757-
elog(FATAL,"Cannot resolve network address %s, error=%d.",sipaddr,res);
758-
memcpy(&saddr,result->ai_addr,result->ai_addrlen);
759-
*host= (char*)palloc0(NI_MAXHOST);
760-
if (pg_getnameinfo_all(&saddr,result->ai_addrlen,*host,NI_MAXHOST,
761-
NULL,0,0)!=0)
762-
elog(FATAL,"Cannot resolve network name");
763-
764-
*port=PostPortNumber;
759+
char*host= (char*)palloc0(HOST_NAME_MAX+1);
760+
761+
if (gethostname(host,HOST_NAME_MAX)!=0)
762+
elog(FATAL,"An error on resolving local hostname was thrown");
763+
if (port!=NULL)
764+
*port=PostPortNumber;
765+
returnhost;
765766
}
766767

767768
char*

‎contrib/pg_exchange/nodeDistPlanExec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extern CustomPath *create_distexec_path(PlannerInfo *root, RelOptInfo *rel,
4141
Path*children,Bitmapset*servers);
4242
externboollocalize_plan(Plan*node,lcontext*context);
4343
externvoidFSExtractServerName(Oidfsid,char**host,int*port);
44-
externvoidGetMyServerName(char**host,int*port);
44+
externchar*GetMyServerName(int*port);
4545
externchar*serializeServer(constchar*host,intport);
4646
externvoidEstablishDMQConnections(constlcontext*context,
4747
constchar*serverName,

‎contrib/pg_execplan/tests/init_shardman.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ initdb -D PGDATA_n2 -E UTF8 --locale=C
4343
echo"shared_preload_libraries = 'postgres_fdw, pg_exchange'">> PGDATA_n0/postgresql.conf
4444
echo"shared_preload_libraries = 'postgres_fdw, pg_exchange'">> PGDATA_n1/postgresql.conf
4545
echo"shared_preload_libraries = 'postgres_fdw, pg_exchange'">> PGDATA_n2/postgresql.conf
46+
echo"listen_addresses = '*'">> PGDATA_n0/postgresql.conf
47+
echo"listen_addresses = '*'">> PGDATA_n1/postgresql.conf
48+
echo"listen_addresses = '*'">> PGDATA_n2/postgresql.conf
49+
echo"host all all 0.0.0.0/0 trust">> PGDATA_n0/pg_hba.conf
50+
echo"host all all 0.0.0.0/0 trust">> PGDATA_n1/pg_hba.conf
51+
echo"host all all 0.0.0.0/0 trust">> PGDATA_n2/pg_hba.conf
4652

4753
#echo "log_min_messages = debug1" >> PGDATA_Slave/postgresql.conf
4854

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp