Skip to content

Commit 3828f76

Browse files
committed
fix kill and revive
1 parent 34d6982 commit 3828f76

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

src/cli/user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void send_kill(struct data_id *data, unsigned short leader) {
149149

150150
void send_revive(struct data_id *data, unsigned short leader) {
151151
struct message *m = generate_message(USER_NODE, leader, data->id, 0, 0, OP_REVIVE);
152-
MPI_Send(m, sizeof(struct message), MPI_BYTE, leader, TAG_REVIVE, MPI_COMM_WORLD);
152+
MPI_Send(m, sizeof(struct message), MPI_BYTE, leader, TAG_MSG, MPI_COMM_WORLD);
153153
free(m);
154154
}
155155

src/network/leader.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ void get_command(struct leader_resources *l_r, unsigned short user) {
208208
case OP_REVIVE: {
209209
debug("Leader recv OP KILL from User", l_r->id);
210210
n_command->command = m->op;
211-
struct data_id *id = calloc(1, sizeof(struct data_id));
212-
n_command->data = id;
211+
n_command->data = generate_data_id(m->id_o);
213212
l_r->leader_command_queue = push_command(l_r->leader_command_queue, n_command);
214213
break;
215214
}
@@ -504,8 +503,10 @@ void execute_command(struct leader_resources *l_r, int *die) {
504503
printf("KILL %u\n", id->id);
505504
fflush(0);
506505
add_dead(l_r, id->id);
507-
if (id->id == l_r->id)
506+
if (id->id == l_r->id) {
507+
debug("KILL LEADER __", id->id);
508508
*die = 1;
509+
}
509510
else {
510511
struct message *m_kill = generate_message(l_r->id, id->id, 0, 0, 0, OP_KILL);
511512
MPI_Send(m_kill, sizeof(struct message), MPI_BYTE, id->id, TAG_MSG, MPI_COMM_WORLD);

src/network/node.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,28 @@ void read_on_node(struct node *n, size_t address, char *data, size_t size) {
5151

5252
void wait_if_dead(struct node *n) {
5353
while (n->is_dead) {
54+
debug("WAITING FOR REVIVE", n->id);
5455
struct message m;
5556
MPI_Recv(&m, sizeof(struct message), MPI_BYTE, MPI_ANY_SOURCE, TAG_REVIVE, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
56-
if (m.op == OP_REVIVE)
57+
if (m.op == OP_REVIVE) {
58+
debug("REVIVE __", n->id);
5759
n->is_dead = 0;
60+
int f = 0;
61+
MPI_Request request;
62+
do {
63+
struct message bin;
64+
MPI_Irecv(&bin, sizeof(struct message), MPI_BYTE, MPI_ANY_SOURCE, TAG_MSG, MPI_COMM_WORLD, &request);
65+
MPI_Test(&request, &f, MPI_STATUS_IGNORE);
66+
} while (f);
67+
MPI_Cancel(&request);
68+
f = 0;
69+
do {
70+
struct message bin;
71+
MPI_Irecv(&bin, sizeof(struct message), MPI_BYTE, MPI_ANY_SOURCE, TAG_ELECTION, MPI_COMM_WORLD, &request);
72+
MPI_Test(&request, &f, MPI_STATUS_IGNORE);
73+
} while (f);
74+
MPI_Cancel(&request);
75+
}
5876
}
5977
}
6078

@@ -95,6 +113,7 @@ void node_cycle(struct node *n) {
95113
free(data);
96114
break;
97115
case OP_KILL:
116+
debug("KILLED __", n->id);
98117
n->is_dead = 1;
99118
break;
100119
default:

0 commit comments

Comments
 (0)