Просмотр исходного кода

Controller assigns ID to dpnode.

The controller can assign an ID number to a dpnode (helpful for logging).
Steven Engler 8 лет назад
Родитель
Сommit
df84062032
2 измененных файлов с 20 добавлено и 2 удалено
  1. 6 1
      controller.cc
  2. 14 1
      dpnode.cc

+ 6 - 1
controller.cc

@@ -120,9 +120,10 @@ static struct ControllerState {
     Worklist worklist;
     Worklist worklist;
     struct evconnlistener *listener;
     struct evconnlistener *listener;
     unsigned int problemid;
     unsigned int problemid;
+    unsigned int dpnode_count;
 
 
     ControllerState() : working(false), num_unsolved_subproblems(0),
     ControllerState() : working(false), num_unsolved_subproblems(0),
-	listener(NULL), problemid(0) {}
+	listener(NULL), problemid(0), dpnode_count(0) {}
 
 
     // Reset the state for a new problem with the same modulus
     // Reset the state for a new problem with the same modulus
     void reset(void) {
     void reset(void) {
@@ -784,6 +785,7 @@ static void controller_master_reader(struct bufferevent *bev, void *ctx)
 
 
     if (len < 1) return;
     if (len < 1) return;
 
 
+    char msg_id = 'I';
     char indata[1];
     char indata[1];
     bufferevent_read(bev, indata, 1);
     bufferevent_read(bev, indata, 1);
     switch(indata[0]) {
     switch(indata[0]) {
@@ -793,6 +795,9 @@ static void controller_master_reader(struct bufferevent *bev, void *ctx)
 	    bufferevent_setcb(bev, controller_dpnode_reader, NULL,
 	    bufferevent_setcb(bev, controller_dpnode_reader, NULL,
 		    controller_dpnode_event_cb, ctx);
 		    controller_dpnode_event_cb, ctx);
 	    controller_dpnode_reader(bev, ctx);
 	    controller_dpnode_reader(bev, ctx);
+	    bufferevent_write(bev, &msg_id, sizeof(msg_id));
+	    bufferevent_write(bev, &ctrlstate.dpnode_count, sizeof(ctrlstate.dpnode_count));
+	    ctrlstate.dpnode_count++;
 	    schedule();
 	    schedule();
 	    return;
 	    return;
 	case 'W':
 	case 'W':

+ 14 - 1
dpnode.cc

@@ -44,9 +44,10 @@ static struct DPControllerState {
     std::set<struct bufferevent *> workers;
     std::set<struct bufferevent *> workers;
     DTable table;
     DTable table;
     unsigned long long numdps;
     unsigned long long numdps;
+    unsigned int id;
 
 
     DPControllerState() : controller_bev(NULL), current_problem(NULL),
     DPControllerState() : controller_bev(NULL), current_problem(NULL),
-			    listener(NULL) {}
+			    listener(NULL), id(0) {}
 } dpctrlstate;
 } dpctrlstate;
 
 
 #ifdef LOG_MEM
 #ifdef LOG_MEM
@@ -215,6 +216,7 @@ struct evconnlistener *dpnode_create(struct event_base *evbase,
 
 
 typedef enum {
 typedef enum {
     DPCCSTATE_AWAITCMD,
     DPCCSTATE_AWAITCMD,
+    DPCCSTATE_RDID,
     DPCCSTATE_RDPROBLEM,
     DPCCSTATE_RDPROBLEM,
     DPCCSTATE_END
     DPCCSTATE_END
 } DPCCState;
 } DPCCState;
@@ -304,6 +306,9 @@ static void controllerconn_reader(struct bufferevent *bev, void *ctx)
 		cerr << "Received command " << cmd[0] << "\n";
 		cerr << "Received command " << cmd[0] << "\n";
 #endif
 #endif
 		switch(cmd[0]) {
 		switch(cmd[0]) {
+		    case 'I':
+			info->state = DPCCSTATE_RDID;
+			break;
 		    case 'P':
 		    case 'P':
 			info->state = DPCCSTATE_RDPROBLEM;
 			info->state = DPCCSTATE_RDPROBLEM;
 			break;
 			break;
@@ -319,6 +324,14 @@ static void controllerconn_reader(struct bufferevent *bev, void *ctx)
 		}
 		}
 		break;
 		break;
 
 
+	    case DPCCSTATE_RDID:
+		if (len < sizeof(unsigned int)) return;
+		unsigned int dpnode_id;
+		bufferevent_read(bev, &dpnode_id, sizeof(unsigned int));
+		dpctrlstate.id = dpnode_id;
+		info->state = DPCCSTATE_AWAITCMD;
+		break;
+
 	    case DPCCSTATE_RDPROBLEM:
 	    case DPCCSTATE_RDPROBLEM:
 		if (len < SUBPROBLEM_DESC_LEN) return;
 		if (len < SUBPROBLEM_DESC_LEN) return;
 		bufferevent_read(bev, subproblem, SUBPROBLEM_DESC_LEN);
 		bufferevent_read(bev, subproblem, SUBPROBLEM_DESC_LEN);