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

Commit50c8a80

Browse files
committed
Add node hash table
1 parent7c81f05 commit50c8a80

File tree

9 files changed

+61
-17
lines changed

9 files changed

+61
-17
lines changed

‎contrib/pg_dtm/dtmd/include/ddd.h‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
#include<stdbool.h>
44
#include"transaction.h"
55

6-
typedefstructInstance {
6+
typedefstructNode {
7+
structNode*collision;
78
structEdge*edges;/* local subgraph */
8-
}Instance;
9+
nodeid_tnode_id;
10+
}Node;
911

1012
typedefstructEdge {
1113
L2Listnode;/* node of list of outgoing eedges */
@@ -33,9 +35,13 @@ typedef struct Graph
3335
intmin_deadlock_duration;
3436
}Graph;
3537

38+
typedefstructCluster
39+
{
40+
Node*hashtable[MAX_STREAMS];
41+
}Cluster;
3642

3743
externvoidinitGraph(Graph*graph);
38-
externvoidaddSubgraph(Instance*instance,Graph*graph,xid_t*xids,intn_xids);
44+
externvoidaddSubgraph(Graph*graph,nodeid_tnode_id,xid_t*xids,intn_xids);
3945
externbooldetectDeadLock(Graph*graph,xid_troot);
4046

4147
#endif

‎contrib/pg_dtm/dtmd/include/int.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
#defineINT_H
33

44
typedefunsignedxid_t;
5+
typedefunsigned long longnodeid_t;
56

67
#endif

‎contrib/pg_dtm/dtmd/include/server.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,6 @@ bool client_message_finish(client_t client);
9898
*/
9999
boolclient_message_shortcut(client_tclient,xid_targ);
100100

101+
unsignedclient_get_ip_addr(client_tclient);
102+
101103
#endif

‎contrib/pg_dtm/dtmd/src/ddd.c‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
staticboolrecursiveTraverseGraph(Vertex*root,Vertex*v,intmarker);
77

8+
staticClustercluster;
9+
810
voidinitGraph(Graph*graph)
911
{
1012
memset(graph->hashtable,0,sizeof(graph->hashtable));
@@ -74,10 +76,28 @@ static inline Vertex* findVertex(Graph* graph, xid_t xid)
7476
returnv;
7577
}
7678

77-
voidaddSubgraph(Instance*instance,Graph*graph,xid_t*xids,intn_xids)
79+
staticinlineNode*findNode(Cluster*cluster,nodeid_tnode_id)
80+
{
81+
size_th=node_id %MAX_STREAMS;
82+
Node*node;
83+
for (node=cluster->hashtable[h];node!=NULL;node=node->collision) {
84+
if (node->node_id==node_id) {
85+
returnnode;
86+
}
87+
}
88+
node= (Node*)malloc(sizeof(Node));
89+
node->node_id=node_id;
90+
node->edges=NULL;
91+
node->collision=cluster->hashtable[h];
92+
cluster->hashtable[h]=node;
93+
returnnode;
94+
}
95+
96+
voidaddSubgraph(Graph*graph,nodeid_tnode_id,xid_t*xids,intn_xids)
7897
{
7998
xid_t*last=xids+n_xids;
8099
Edge*e,*next,*edges=NULL;
100+
Node*node=findNode(&cluster,node_id);
81101
while (xids!=last) {
82102
Vertex*src=findVertex(graph,*xids++);
83103
xid_txid;
@@ -92,7 +112,7 @@ void addSubgraph(Instance* instance, Graph* graph, xid_t* xids, int n_xids)
92112
l2_list_link(&src->outgoingEdges,&e->node);
93113
}
94114
}
95-
for (e=instance->edges;e!=NULL;e=next) {
115+
for (e=node->edges;e!=NULL;e=next) {
96116
next=e->next;
97117
l2_list_unlink(&e->node);
98118
if (--e->dst->nIncomingEdges==0&&l2_list_is_empty(&e->dst->outgoingEdges)) {
@@ -103,7 +123,7 @@ void addSubgraph(Instance* instance, Graph* graph, xid_t* xids, int n_xids)
103123
}
104124
freeEdge(graph,e);
105125
}
106-
instance->edges=edges;
126+
node->edges=edges;
107127
}
108128

109129
staticboolrecursiveTraverseGraph(Vertex*root,Vertex*v,intmarker)

‎contrib/pg_dtm/dtmd/src/main.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ typedef struct client_userdata_t {
3333
intid;
3434
intsnapshots_sent;
3535
xid_txid;
36-
Instanceinstance;/* It has to be moved somewhere else, because this is per-backend structure */
3736
}client_userdata_t;
3837

3938
clog_tclg;
@@ -536,17 +535,22 @@ static void onnoise(client_t client, int argc, xid_t *argv) {
536535
staticGraphgraph;
537536

538537
staticvoidondeadlock(client_tclient,intargc,xid_t*argv) {
539-
if (argc<3) {
538+
intport;
539+
xid_troot;
540+
nodeid_tnode_id;
541+
542+
if (argc<4) {
540543
shout(
541-
"[%d] DEADLOCK: wrong number of arguments %d, expected >3\n",
544+
"[%d] DEADLOCK: wrong number of arguments %d, expected >4\n",
542545
CLIENT_ID(client),argc
543546
);
544547
client_message_shortcut(client,RES_FAILED);
545548
return;
546549
}
547-
xid_troot=argv[1];
548-
Instance*instance=&CLIENT_USERDATA(client)->instance;
549-
addSubgraph(instance,&graph,argv+2,argc-2);
550+
port=argv[1];
551+
root=argv[2];
552+
node_id= ((nodeid_t)port <<32) |client_get_ip_addr(client);
553+
addSubgraph(&graph,node_id,argv+3,argc-3);
550554
boolhasDeadLock=detectDeadLock(&graph,root);
551555
client_message_shortcut(client,hasDeadLock ?RES_DEADLOCK :RES_OK);
552556
}

‎contrib/pg_dtm/dtmd/src/server.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include<sys/socket.h>
1515
#include<arpa/inet.h>
1616
#include<netinet/tcp.h>
17+
#include<netinet/in.h>
1718

1819
#include"server.h"
1920
#include"limits.h"
@@ -490,6 +491,15 @@ void *client_get_userdata(client_t client) {
490491
returnclient->userdata;
491492
}
492493

494+
unsignedclient_get_ip_addr(client_tclient)
495+
{
496+
structsockaddr_ininet_addr;
497+
socklen_tinet_addr_len=sizeof(inet_addr);
498+
inet_addr.sin_addr.s_addr=0;
499+
getpeername(client->stream->fd, (structsockaddr*)&inet_addr,&inet_addr_len);
500+
returninet_addr.sin_addr.s_addr;
501+
}
502+
493503
#if0
494504
// usage example
495505

‎contrib/pg_dtm/libdtm.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,13 +481,13 @@ int DtmGlobalReserve(TransactionId xid, int nXids, TransactionId *first)
481481
return0;
482482
}
483483

484-
boolDtmGlobalDetectDeadLock(TransactionIdxid,void*data,intsize)
484+
boolDtmGlobalDetectDeadLock(intport,TransactionIdxid,void*data,intsize)
485485
{
486-
intmsg_size=size+sizeof(xid)*2;
486+
intmsg_size=size+sizeof(xid)*3;
487487
intdata_size=sizeof(ShubMessageHdr)+msg_size;
488488
char*buf= (char*)malloc(data_size);
489489
ShubMessageHdr*msg= (ShubMessageHdr*)buf;
490-
xid_t*body= (xid_t*)(msg+1);
490+
xid_t*body= (xid_t*)(msg+2);
491491
intsent;
492492
intreslen;
493493
xid_tresults[RESULTS_SIZE];
@@ -498,6 +498,7 @@ bool DtmGlobalDetectDeadLock(TransactionId xid, void* data, int size)
498498
msg->size=msg_size;
499499

500500
*body++=CMD_DEADLOCK;
501+
*body++=port;
501502
*body++=xid;
502503
memcpy(body,data,size);
503504

‎contrib/pg_dtm/libdtm.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ int DtmGlobalReserve(TransactionId xid, int nXids, TransactionId *first);
6262
* resource graph if a new local graph is received from this cluster node (not
6363
* backend).
6464
*/
65-
boolDtmGlobalDetectDeadLock(TransactionIdxid,void*graph,intsize);
65+
boolDtmGlobalDetectDeadLock(intport,TransactionIdxid,void*graph,intsize);
6666

6767
#endif

‎contrib/pg_dtm/pg_dtm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ bool DtmDetectGlobalDeadLock(PGPROC* proc)
10291029
ByteBufferbuf;
10301030
ByteBufferAlloc(&buf);
10311031
EnumerateLocks(DtmSerializeLock,&buf);
1032-
hasDeadlock=DtmGlobalDetectDeadLock(proc->lxid,buf.data,buf.used);
1032+
hasDeadlock=DtmGlobalDetectDeadLock(PostPortNumber,proc->lxid,buf.data,buf.used);
10331033
ByteBufferFree(&buf);
10341034
returnhasDeadlock;
10351035
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp