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

Commit7c81f05

Browse files
committed
Add min_deadlock_duration
1 parent6706ba2 commit7c81f05

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ typedef struct Vertex
2121
xid_txid;
2222
intnIncomingEdges;
2323
intvisited;
24+
intdeadlock_duration;
2425
}Vertex;
2526

2627
typedefstructGraph
@@ -29,11 +30,12 @@ typedef struct Graph
2930
Edge*freeEdges;
3031
Vertex*freeVertexes;
3132
intmarker;
33+
intmin_deadlock_duration;
3234
}Graph;
3335

3436

3537
externvoidinitGraph(Graph*graph);
3638
externvoidaddSubgraph(Instance*instance,Graph*graph,xid_t*xids,intn_xids);
37-
externboolfindCycle(Graph*graph,xid_troot);
39+
externbooldetectDeadLock(Graph*graph,xid_troot);
3840

3941
#endif

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ void initGraph(Graph* graph)
1111
graph->freeEdges=NULL;
1212
graph->freeVertexes=NULL;
1313
graph->marker=0;
14+
graph->min_deadlock_duration=3;
1415
}
1516

1617
staticinlineEdge*newEdge(Graph*graph)
@@ -51,6 +52,7 @@ static inline Vertex* newVertex(Graph* graph)
5152
}else {
5253
graph->freeVertexes=v->next;
5354
}
55+
v->deadlock_duration=0;
5456
returnv;
5557
}
5658

@@ -120,12 +122,15 @@ static bool recursiveTraverseGraph(Vertex* root, Vertex* v, int marker)
120122
return false;
121123
}
122124

123-
boolfindCycle(Graph*graph,xid_troot)
125+
booldetectDeadLock(Graph*graph,xid_troot)
124126
{
125127
Vertex*v;
126128
for (v=graph->hashtable[root %MAX_TRANSACTIONS];v!=NULL;v=v->next) {
127129
if (v->xid==root) {
128-
returnrecursiveTraverseGraph(v,v,++graph->marker);
130+
if (recursiveTraverseGraph(v,v,++graph->marker)) {
131+
return++v->deadlock_duration >=graph->min_deadlock_duration;
132+
}
133+
v->deadlock_duration=0;
129134
}
130135
}
131136
return false;

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ static void ondeadlock(client_t client, int argc, xid_t *argv) {
547547
xid_troot=argv[1];
548548
Instance*instance=&CLIENT_USERDATA(client)->instance;
549549
addSubgraph(instance,&graph,argv+2,argc-2);
550-
boolhasDeadLock=findCycle(&graph,root);
550+
boolhasDeadLock=detectDeadLock(&graph,root);
551551
client_message_shortcut(client,hasDeadLock ?RES_DEADLOCK :RES_OK);
552552
}
553553

@@ -595,7 +595,7 @@ static void onmessage(client_t client, size_t len, char *data) {
595595

596596
staticvoidusage(char*prog) {
597597
printf(
598-
"Usage: %s [-d DATADIR] [-k] [-a HOST] [-p PORT] [-l LOGFILE]\n"
598+
"Usage: %s [-d DATADIR] [-k] [-a HOST] [-p PORT] [-l LOGFILE] [-m MIN_DEADLOCK_DURATION]\n"
599599
" arbiter will try to kill the other one running at\n"
600600
" the same DATADIR.\n"
601601
" -l : Run as a daemon and write output to LOGFILE.\n"
@@ -688,8 +688,10 @@ int main(int argc, char **argv) {
688688
boolassassin= false;
689689
intlistenport=DEFAULT_LISTENPORT;
690690

691+
initGraph(&graph);
692+
691693
intopt;
692-
while ((opt=getopt(argc,argv,"hd:a:p:l:k"))!=-1) {
694+
while ((opt=getopt(argc,argv,"hd:a:p:l:k:m:"))!=-1) {
693695
switch (opt) {
694696
case'd':
695697
datadir=optarg;
@@ -710,6 +712,9 @@ int main(int argc, char **argv) {
710712
case'k':
711713
assassin= true;
712714
break;
715+
case'm':
716+
graph.min_deadlock_duration=atoi(optarg);
717+
break;
713718
default:
714719
usage(argv[0]);
715720
returnEXIT_FAILURE;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp