@@ -1289,14 +1289,22 @@ void redis_local_scheduler_table_subscribe_callback(redisAsyncContext *c,
12891289 DBClientID client_id = from_flatbuf (message->db_client_id ());
12901290 /* Extract the fields of the local scheduler info struct. */
12911291 LocalSchedulerInfo info;
1292- info.total_num_workers = message->total_num_workers ();
1293- info.task_queue_length = message->task_queue_length ();
1294- info.available_workers = message->available_workers ();
1295- for (int i = 0 ; i < ResourceIndex_MAX; ++i) {
1296- info.static_resources [i] = message->static_resources ()->Get (i);
1297- }
1298- for (int i = 0 ; i < ResourceIndex_MAX; ++i) {
1299- info.dynamic_resources [i] = message->dynamic_resources ()->Get (i);
1292+ memset (&info, 0 , sizeof (info));
1293+ if (message->is_dead ()) {
1294+ /* If the local scheduler is dead, then ignore all other fields in the
1295+ * message. */
1296+ info.is_dead = true ;
1297+ } else {
1298+ /* If the local scheduler is alive, collect load information. */
1299+ info.total_num_workers = message->total_num_workers ();
1300+ info.task_queue_length = message->task_queue_length ();
1301+ info.available_workers = message->available_workers ();
1302+ for (int i = 0 ; i < ResourceIndex_MAX; ++i) {
1303+ info.static_resources [i] = message->static_resources ()->Get (i);
1304+ }
1305+ for (int i = 0 ; i < ResourceIndex_MAX; ++i) {
1306+ info.dynamic_resources [i] = message->dynamic_resources ()->Get (i);
1307+ }
13001308 }
13011309
13021310 /* Call the subscribe callback. */
@@ -1355,7 +1363,7 @@ void redis_local_scheduler_table_send_info(TableCallbackData *callback_data) {
13551363 fbb, to_flatbuf (fbb, db->client ), info.total_num_workers ,
13561364 info.task_queue_length , info.available_workers ,
13571365 fbb.CreateVector (info.static_resources , ResourceIndex_MAX),
1358- fbb.CreateVector (info.dynamic_resources , ResourceIndex_MAX));
1366+ fbb.CreateVector (info.dynamic_resources , ResourceIndex_MAX), false );
13591367 fbb.Finish (message);
13601368
13611369 int status = redisAsyncCommand (
@@ -1368,6 +1376,22 @@ void redis_local_scheduler_table_send_info(TableCallbackData *callback_data) {
13681376 }
13691377}
13701378
1379+ void redis_local_scheduler_table_disconnect (DBHandle *db) {
1380+ flatbuffers::FlatBufferBuilder fbb;
1381+ LocalSchedulerInfoMessageBuilder builder (fbb);
1382+ builder.add_db_client_id (to_flatbuf (fbb, db->client ));
1383+ builder.add_is_dead (true );
1384+ auto message = builder.Finish ();
1385+ fbb.Finish (message);
1386+ redisReply *reply = (redisReply *) redisCommand (
1387+ db->sync_context , " PUBLISH local_schedulers %b" , fbb.GetBufferPointer (),
1388+ fbb.GetSize ());
1389+ CHECK (reply->type != REDIS_REPLY_ERROR);
1390+ CHECK (reply->type == REDIS_REPLY_INTEGER);
1391+ LOG_DEBUG (" %" PRId64 " subscribers received this publish.\n " , reply->integer );
1392+ freeReplyObject (reply);
1393+ }
1394+
13711395void redis_driver_table_subscribe_callback (redisAsyncContext *c,
13721396 void *r,
13731397 void *privdata) {
0 commit comments