13
13
#include "util.h"
14
14
#include "transaction.h"
15
15
#include "proto.h"
16
+ #include "ddd.h"
16
17
17
18
#define DEFAULT_DATADIR "/tmp/clog"
18
19
#define DEFAULT_LISTENHOST "0.0.0.0"
@@ -32,6 +33,7 @@ typedef struct client_userdata_t {
32
33
int id ;
33
34
int snapshots_sent ;
34
35
xid_t xid ;
36
+ Instance instance ;/* It has to be moved somewhere else, because this is per-backend structure */
35
37
}client_userdata_t ;
36
38
37
39
clog_t clg ;
@@ -158,6 +160,7 @@ static void debug_cmd(client_t client, int argc, xid_t *argv) {
158
160
case CMD_AGAINST :cmdname = "AGAINST" ;break ;
159
161
case CMD_SNAPSHOT :cmdname = "SNAPSHOT" ;break ;
160
162
case CMD_STATUS :cmdname = "STATUS" ;break ;
163
+ case CMD_DEADLOCK :cmdname = "DEADLOCK" ;break ;
161
164
default :cmdname = "unknown" ;
162
165
}
163
166
debug ("[%d] %s" ,CLIENT_ID (client ),cmdname );
@@ -530,6 +533,25 @@ static void onnoise(client_t client, int argc, xid_t *argv) {
530
533
client_message_shortcut (client ,RES_FAILED );
531
534
}
532
535
536
+ static Graph graph ;
537
+
538
+ static void ondeadlock (client_t client ,int argc ,xid_t * argv ) {
539
+ if (argc < 3 ) {
540
+ shout (
541
+ "[%d] DEADLOCK: wrong number of arguments %d, expected > 3\n" ,
542
+ CLIENT_ID (client ),argc
543
+ );
544
+ client_message_shortcut (client ,RES_FAILED );
545
+ return ;
546
+ }
547
+ xid_t root = argv [1 ];
548
+ Instance * instance = & CLIENT_USERDATA (client )-> instance ;
549
+ addSubgraph (instance ,& graph ,argv + 2 ,argc - 2 );
550
+ bool hasDeadLock = findLoop (& graph ,root );
551
+ client_message_shortcut (client ,hasDeadLock ?RES_DEADLOCK :RES_OK );
552
+ }
553
+
554
+
533
555
static void oncmd (client_t client ,int argc ,xid_t * argv ) {
534
556
debug_cmd (client ,argc ,argv );
535
557
@@ -553,6 +575,9 @@ static void oncmd(client_t client, int argc, xid_t *argv) {
553
575
case CMD_STATUS :
554
576
onstatus (client ,argc ,argv );
555
577
break ;
578
+ case CMD_DEADLOCK :
579
+ ondeadlock (client ,argc ,argv );
580
+ break ;
556
581
default :
557
582
onnoise (client ,argc ,argv );
558
583
}