dart/gni/ds_base_gni.c
static int dsrpc_cn_unregister(struct rpc_server *rpc_s, struct rpc_cmd *cmd)
{
	struct dart_server *ds = ds_ref_from_rpc(rpc_s);
	struct hdr_register *hreg = (struct hdr_register *)(cmd->pad);
	struct hdr_register *hr;
	struct msg_buf *msg, *msg_l, *msg_r;
	struct node_id *peer, *cur_peer;
    struct app_info *app;
	int err = -ENOMEM;
	int i;
	int left, right;

	app = app_find(ds, hreg->pm_cp.appid);

	if(ds->rpc_s->ptlmap.id == 0) {
		peer = ds_get_peer(ds, hreg->pm_cp.id);
		peer->f_unreg = 1;

		msg = msg_buf_alloc(rpc_s, peer, 1);
		if (!msg)
			goto err_out;

		msg->msg_rpc->id = ds->self->ptlmap.id;
		msg->msg_rpc->cmd = cn_unregister;

		hr = (struct hdr_register *)(msg->msg_rpc->pad);
		hr->pm_cp.appid = hreg->pm_cp.appid;
		hr->pm_cp.id = hreg->pm_cp.id;
		hr->pm_cp.pid = hreg->pm_cp.pid;
		hr->pm_cp.nid = hreg->pm_cp.nid;
		hr->num_sp = ds->num_sp;

		err = rpc_send(rpc_s, peer, msg);
		if (err < 0) {
			free(msg);
			goto err_out;
		}
	}

    // Propagate unregister notification as a binary tree
    left = (rpc_s->ptlmap.id * 2) + 1;
    right = left + 1;
    if(right < ds->num_sp) {
        peer = ds_get_peer(ds, right);
		msg_r = msg_buf_alloc(rpc_s, peer, 1);
		if (!msg)
			goto err_out;

		msg_r->msg_rpc->id = ds->self->ptlmap.id;
		msg_r->msg_rpc->cmd = cn_unregister;

		hr = (struct hdr_register *)(msg_r->msg_rpc->pad);
		hr->pm_cp.appid = hreg->pm_cp.appid;
		hr->pm_cp.id = hreg->pm_cp.id;
		hr->pm_cp.pid = hreg->pm_cp.pid;
		hr->pm_cp.nid = hreg->pm_cp.nid;
		hr->num_sp = ds->num_sp;

		err = rpc_send(rpc_s, peer, msg_r);
		if (err < 0) 
		{
			free(msg);
			goto err_out;
		}
	}

	if(left < ds->num_sp){
		peer = ds_get_peer(ds, left);

		msg_l = msg_buf_alloc(rpc_s, peer, 1);
		if (!msg)
			goto err_out;

		msg_l->msg_rpc->id = ds->self->ptlmap.id;
		msg_l->msg_rpc->cmd = cn_unregister;

		hr = (struct hdr_register *)(msg_l->msg_rpc->pad);

		hr->pm_cp.appid = hreg->pm_cp.appid;
		hr->pm_cp.id = hreg->pm_cp.id;
		hr->pm_cp.pid = hreg->pm_cp.pid;
		hr->pm_cp.nid = hreg->pm_cp.nid;
		hr->num_sp = ds->num_sp;

		peer = ds_get_peer(ds, left);

		err = rpc_send(rpc_s, peer, msg_l);
		if (err < 0) 
		{
			free(msg);
			goto err_out;
		}

	}

    /* PD - 7/23/18
        Not sure why the following is here. My best guess is that we are trying
        to make sure there are no pending RPC calls that will fail once the app
        is gone. There is a barrier on the client side before sending the
        unregister RPC so this seems less likely...
     */
    for(i = 0; i < 100; i++) {
        err = rpc_process_event(rpc_s);
        if (err!=0)
            printf("'%s()': encountered an error %d, skipping.\n", __func__, err);
    }

	err = ds_free_app(ds, app);
	if (err != 0) 
		goto err_out;

	return 0;

err_out:
	printf("(%s): failed. (%d)\n", __func__, err);
	return err;

}
/*
  RPC routine to unregister a compute peer. 
Master Server: 
	Accept unregister from master client, then bcast to all slave servers. Then send back acknowledge info to master client.
Master and Client Server:
	unlink and delete app info, unlink and delete peer_tab info for this app.
*/
RPC routine to unregister a compute peer.
Master Server:
Accept unregister from master client, then bcast to all slave servers. Then send back acknowledge info to master client.
Master and Client Server:
unlink and delete app info, unlink and delete peer_tab info for this app.
RPC routine to unregister a compute peer . Master Server : Accept unregister from master client then bcast to all slave servers . Then send back acknowledge info to master client . Master and Client Server : unlink and delete app info unlink and delete peer_tab info for this app .
static int dsrpc_cn_unregister(struct rpc_server *rpc_s, struct rpc_cmd *cmd)
{
	struct dart_server *ds = ds_ref_from_rpc(rpc_s);
	struct hdr_register *hreg = (struct hdr_register *)(cmd->pad);
	struct hdr_register *hr;
	struct msg_buf *msg, *msg_l, *msg_r;
	struct node_id *peer, *cur_peer;
    struct app_info *app;
	int err = -ENOMEM;
	int i;
	int left, right;
	app = app_find(ds, hreg->pm_cp.appid);
	if(ds->rpc_s->ptlmap.id == 0) {
		peer = ds_get_peer(ds, hreg->pm_cp.id);
		peer->f_unreg = 1;
		msg = msg_buf_alloc(rpc_s, peer, 1);
		if (!msg)
			goto err_out;
		msg->msg_rpc->id = ds->self->ptlmap.id;
		msg->msg_rpc->cmd = cn_unregister;
		hr = (struct hdr_register *)(msg->msg_rpc->pad);
		hr->pm_cp.appid = hreg->pm_cp.appid;
		hr->pm_cp.id = hreg->pm_cp.id;
		hr->pm_cp.pid = hreg->pm_cp.pid;
		hr->pm_cp.nid = hreg->pm_cp.nid;
		hr->num_sp = ds->num_sp;
		err = rpc_send(rpc_s, peer, msg);
		if (err < 0) {
			free(msg);
			goto err_out;
		}
	}
    left = (rpc_s->ptlmap.id * 2) + 1;
    right = left + 1;
    if(right < ds->num_sp) {
        peer = ds_get_peer(ds, right);
		msg_r = msg_buf_alloc(rpc_s, peer, 1);
		if (!msg)
			goto err_out;
		msg_r->msg_rpc->id = ds->self->ptlmap.id;
		msg_r->msg_rpc->cmd = cn_unregister;
		hr = (struct hdr_register *)(msg_r->msg_rpc->pad);
		hr->pm_cp.appid = hreg->pm_cp.appid;
		hr->pm_cp.id = hreg->pm_cp.id;
		hr->pm_cp.pid = hreg->pm_cp.pid;
		hr->pm_cp.nid = hreg->pm_cp.nid;
		hr->num_sp = ds->num_sp;
		err = rpc_send(rpc_s, peer, msg_r);
		if (err < 0) 
		{
			free(msg);
			goto err_out;
		}
	}
	if(left < ds->num_sp){
		peer = ds_get_peer(ds, left);
		msg_l = msg_buf_alloc(rpc_s, peer, 1);
		if (!msg)
			goto err_out;
		msg_l->msg_rpc->id = ds->self->ptlmap.id;
		msg_l->msg_rpc->cmd = cn_unregister;
		hr = (struct hdr_register *)(msg_l->msg_rpc->pad);
		hr->pm_cp.appid = hreg->pm_cp.appid;
		hr->pm_cp.id = hreg->pm_cp.id;
		hr->pm_cp.pid = hreg->pm_cp.pid;
		hr->pm_cp.nid = hreg->pm_cp.nid;
		hr->num_sp = ds->num_sp;
		peer = ds_get_peer(ds, left);
		err = rpc_send(rpc_s, peer, msg_l);
		if (err < 0) 
		{
			free(msg);
			goto err_out;
		}
	}
    for(i = 0; i < 100; i++) {
        err = rpc_process_event(rpc_s);
        if (err!=0)
            printf("'%s()': encountered an error %d, skipping.\n", __func__, err);
    }
	err = ds_free_app(ds, app);
	if (err != 0) 
		goto err_out;
	return 0;
err_out:
	printf("(%s): failed. (%d)\n", __func__, err);
	return err;
}
static int dsrpc_cn_unregister ( struct rpc_server * rpc_s , struct rpc_cmd * cmd ) { struct dart_server * ds = ds_ref_from_rpc ( rpc_s ) ; struct hdr_register * hreg = ( struct hdr_register * ) ( cmd -> pad ) ; struct hdr_register * hr ; struct msg_buf * msg , * msg_l , * msg_r ; struct node_id * peer , * cur_peer ; struct app_info * app ; int err = - ENOMEM ; int i ; int left , right ; app = app_find ( ds , hreg -> pm_cp . appid ) ; if ( ds -> rpc_s -> ptlmap . id == 0 ) { peer = ds_get_peer ( ds , hreg -> pm_cp . id ) ; peer -> f_unreg = 1 ; msg = msg_buf_alloc ( rpc_s , peer , 1 ) ; if ( ! msg ) goto err_out ; msg -> msg_rpc -> id = ds -> self -> ptlmap . id ; msg -> msg_rpc -> cmd = cn_unregister ; hr = ( struct hdr_register * ) ( msg -> msg_rpc -> pad ) ; hr -> pm_cp . appid = hreg -> pm_cp . appid ; hr -> pm_cp . id = hreg -> pm_cp . id ; hr -> pm_cp . pid = hreg -> pm_cp . pid ; hr -> pm_cp . nid = hreg -> pm_cp . nid ; hr -> num_sp = ds -> num_sp ; err = rpc_send ( rpc_s , peer , msg ) ; if ( err < 0 ) { free ( msg ) ; goto err_out ; } } left = ( rpc_s -> ptlmap . id * 2 ) + 1 ; right = left + 1 ; if ( right < ds -> num_sp ) { peer = ds_get_peer ( ds , right ) ; msg_r = msg_buf_alloc ( rpc_s , peer , 1 ) ; if ( ! msg ) goto err_out ; msg_r -> msg_rpc -> id = ds -> self -> ptlmap . id ; msg_r -> msg_rpc -> cmd = cn_unregister ; hr = ( struct hdr_register * ) ( msg_r -> msg_rpc -> pad ) ; hr -> pm_cp . appid = hreg -> pm_cp . appid ; hr -> pm_cp . id = hreg -> pm_cp . id ; hr -> pm_cp . pid = hreg -> pm_cp . pid ; hr -> pm_cp . nid = hreg -> pm_cp . nid ; hr -> num_sp = ds -> num_sp ; err = rpc_send ( rpc_s , peer , msg_r ) ; if ( err < 0 ) { free ( msg ) ; goto err_out ; } } if ( left < ds -> num_sp ) { peer = ds_get_peer ( ds , left ) ; msg_l = msg_buf_alloc ( rpc_s , peer , 1 ) ; if ( ! msg ) goto err_out ; msg_l -> msg_rpc -> id = ds -> self -> ptlmap . id ; msg_l -> msg_rpc -> cmd = cn_unregister ; hr = ( struct hdr_register * ) ( msg_l -> msg_rpc -> pad ) ; hr -> pm_cp . appid = hreg -> pm_cp . appid ; hr -> pm_cp . id = hreg -> pm_cp . id ; hr -> pm_cp . pid = hreg -> pm_cp . pid ; hr -> pm_cp . nid = hreg -> pm_cp . nid ; hr -> num_sp = ds -> num_sp ; peer = ds_get_peer ( ds , left ) ; err = rpc_send ( rpc_s , peer , msg_l ) ; if ( err < 0 ) { free ( msg ) ; goto err_out ; } } for ( i = 0 ; i < 100 ; i ++ ) { err = rpc_process_event ( rpc_s ) ; if ( err != 0 ) printf ( " \n " , __func__ , err ) ; } err = ds_free_app ( ds , app ) ; if ( err != 0 ) goto err_out ; return 0 ; err_out : printf ( " \n " , __func__ , err ) ; return err ; }
RPC routine to unregister a compute peer.
RPC routine to unregister a compute peer .
// Propagate unregister notification as a binary tree
 /* PD - 7/23/18
        Not sure why the following is here. My best guess is that we are trying
        to make sure there are no pending RPC calls that will fail once the app
        is gone. There is a barrier on the client side before sending the
        unregister RPC so this seems less likely...
     */