1313#include "util.h"
1414#include "transaction.h"
1515#include "proto.h"
16+ #include "ddd.h"
1617
1718#define DEFAULT_DATADIR "/tmp/clog"
1819#define DEFAULT_LISTENHOST "0.0.0.0"
@@ -32,6 +33,7 @@ typedef struct client_userdata_t {
3233 int id ;
3334 int snapshots_sent ;
3435 xid_t xid ;
36+ Instance instance ; /* It has to be moved somewhere else, because this is per-backend structure */
3537} client_userdata_t ;
3638
3739clog_t clg ;
@@ -158,6 +160,7 @@ static void debug_cmd(client_t client, int argc, xid_t *argv) {
158160 case CMD_AGAINST : cmdname = "AGAINST" ; break ;
159161 case CMD_SNAPSHOT : cmdname = "SNAPSHOT" ; break ;
160162 case CMD_STATUS : cmdname = "STATUS" ; break ;
163+ case CMD_DEADLOCK : cmdname = "DEADLOCK" ; break ;
161164 default : cmdname = "unknown" ;
162165 }
163166 debug ("[%d] %s" , CLIENT_ID (client ), cmdname );
@@ -530,6 +533,25 @@ static void onnoise(client_t client, int argc, xid_t *argv) {
530533 client_message_shortcut (client , RES_FAILED );
531534}
532535
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+
533555static void oncmd (client_t client , int argc , xid_t * argv ) {
534556 debug_cmd (client , argc , argv );
535557
@@ -553,6 +575,9 @@ static void oncmd(client_t client, int argc, xid_t *argv) {
553575 case CMD_STATUS :
554576 onstatus (client , argc , argv );
555577 break ;
578+ case CMD_DEADLOCK :
579+ ondeadlock (client , argc , argv );
580+ break ;
556581 default :
557582 onnoise (client , argc , argv );
558583 }
0 commit comments