Skip to content

Commit 7c81f05

Browse files
committed
Add min_deadlock_duration
1 parent 6706ba2 commit 7c81f05

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_t xid;
2222
int nIncomingEdges;
2323
int visited;
24+
int deadlock_duration;
2425
} Vertex;
2526

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

3436

3537
extern void initGraph(Graph* graph);
3638
extern void addSubgraph(Instance* instance, Graph* graph, xid_t* xids, int n_xids);
37-
extern bool findCycle(Graph* graph, xid_t root);
39+
extern bool detectDeadLock(Graph* graph, xid_t root);
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
static inline Edge* 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
return v;
5557
}
5658

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

123-
bool findCycle(Graph* graph, xid_t root)
125+
bool detectDeadLock(Graph* graph, xid_t root)
124126
{
125127
Vertex* v;
126128
for (v = graph->hashtable[root % MAX_TRANSACTIONS]; v != NULL; v = v->next) {
127129
if (v->xid == root) {
128-
return recursiveTraverseGraph(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_t root = argv[1];
548548
Instance* instance = &CLIENT_USERDATA(client)->instance;
549549
addSubgraph(instance, &graph, argv+2, argc-2);
550-
bool hasDeadLock = findCycle(&graph, root);
550+
bool hasDeadLock = 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
static void usage(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
bool assassin = false;
689689
int listenport = DEFAULT_LISTENPORT;
690690

691+
initGraph(&graph);
692+
691693
int opt;
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
return EXIT_FAILURE;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy