Esempio n. 1
0
void meta_service::on_request(message_ptr& msg)
{
    meta_request_header hdr;
    unmarshall(msg, hdr);

    meta_response_header rhdr;
    bool is_primary = _state->get_meta_server_primary(rhdr.primary_address);
    if (is_primary) is_primary = (primary_address() == rhdr.primary_address);
    rhdr.err = ERR_SUCCESS;

    message_ptr resp = msg->create_response();
    if (!is_primary)
    {
        rhdr.err = ERR_TALK_TO_OTHERS;
        
        marshall(resp, rhdr);
    }
    else if (hdr.rpc_tag == RPC_CM_QUERY_NODE_PARTITIONS)
    {
        configuration_query_by_node_request request;
        configuration_query_by_node_response response;
        unmarshall(msg, request);

        query_configuration_by_node(request, response);

        marshall(resp, rhdr);
        marshall(resp, response);
    }

    else if (hdr.rpc_tag == RPC_CM_QUERY_PARTITION_CONFIG_BY_INDEX)
    {
        configuration_query_by_index_request request;
        configuration_query_by_index_response response;
        unmarshall(msg, request);

        query_configuration_by_index(request, response);
        
        marshall(resp, rhdr);
        marshall(resp, response);
    }

    else  if (hdr.rpc_tag == RPC_CM_UPDATE_PARTITION_CONFIGURATION)
    {
        update_configuration(msg, resp);
        return;
    }
    
    else
    {
        dassert(false, "unknown rpc tag %x (%s)", hdr.rpc_tag, task_code(hdr.rpc_tag).to_string());
    }

    rpc::reply(resp);
}
Esempio n. 2
0
void meta_service::on_request(dsn_message_t msg)
{
    meta_request_header hdr;
    ::unmarshall(msg, hdr);

    meta_response_header rhdr;
    bool is_primary = _state->get_meta_server_primary(rhdr.primary_address);
    if (is_primary) is_primary = (primary_address() == rhdr.primary_address);
    rhdr.err = ERR_OK;

    ::dsn::rpc_address faddr;
    dsn_msg_from_address(msg, faddr.c_addr_ptr());
    dinfo("recv meta request %s from %s:%hu", 
        dsn_task_code_to_string(hdr.rpc_tag),
        faddr.name(),
        faddr.port()
        );

    dsn_message_t resp = dsn_msg_create_response(msg);
    if (!is_primary)
    {
        rhdr.err = ERR_TALK_TO_OTHERS;        
        ::marshall(resp, rhdr);
    }
    else if (!_started)
    {
        rhdr.err = ERR_SERVICE_NOT_ACTIVE;
        ::marshall(resp, rhdr);
    }
    else if (hdr.rpc_tag == RPC_CM_QUERY_NODE_PARTITIONS)
    {
        configuration_query_by_node_request request;
        configuration_query_by_node_response response;
        ::unmarshall(msg, request);

        query_configuration_by_node(request, response);

        ::marshall(resp, rhdr);
        ::marshall(resp, response);
    }

    else if (hdr.rpc_tag == RPC_CM_QUERY_PARTITION_CONFIG_BY_INDEX)
    {
        configuration_query_by_index_request request;
        configuration_query_by_index_response response;
        unmarshall(msg, request);

        query_configuration_by_index(request, response);
        
        ::marshall(resp, rhdr);
        ::marshall(resp, response);
    }

    else  if (hdr.rpc_tag == RPC_CM_UPDATE_PARTITION_CONFIGURATION)
    {
        update_configuration(msg, resp);
        rhdr.err.end_tracking();
        return;
    }
    
    else
    {
        dassert(false, "unknown rpc tag %x (%s)", hdr.rpc_tag, dsn_task_code_to_string(hdr.rpc_tag));
    }

    dsn_rpc_reply(resp);
}