Exemplo n.º 1
0
void meta_service::on_log_completed(error_code err, size_t size,
    blob buffer, 
    std::shared_ptr<configuration_update_request> req, dsn_message_t resp)
{
    dassert(err == ERR_OK, "log operation failed, cannot proceed, err = %s", err.to_string());
    dassert(buffer.length() == size, "log size must equal to the specified buffer size");

    configuration_update_response response;    
    update_configuration(*req, response);

    if (resp != nullptr)
    {
        meta_response_header rhdr;
        rhdr.err = err;
        rhdr.primary_address = primary_address();

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

        dsn_rpc_reply(resp);
    }
    else
    {
        err.end_tracking();
    }
}
Exemplo n.º 2
0
void replica::response_client_message(dsn_message_t request, error_code error)
{
    if (nullptr == request)
    {
        error.end_tracking();
        return;
    }   

    ddebug("%s: reply client read/write, err = %s", name(), error.to_string());
    dsn_rpc_reply(dsn_msg_create_response(request), error);
}
Exemplo n.º 3
0
void meta_service::update_configuration(dsn_message_t req, dsn_message_t resp)
{
    if (_state->freezed())
    {
        meta_response_header rhdr;
        rhdr.err = ERR_OK;
        rhdr.primary_address = primary_address();

        configuration_update_request request;
        configuration_update_response response;
        
        ::unmarshall(req, request);

        response.err = ERR_STATE_FREEZED;
        _state->query_configuration_by_gpid(request.config.gpid, response.config);

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

        dsn_rpc_reply(resp);
        return;
    }

    void* ptr;
    size_t sz;
    dsn_msg_read_next(req, &ptr, &sz);
    dsn_msg_read_commit(req, 0); // commit 0 so we can read again

    uint64_t offset;
    int len = (int)sz + sizeof(int32_t);
    
    char* buffer = new char[len];
    *(int32_t*)buffer = (int)sz;
    memcpy(buffer + sizeof(int32_t), ptr, sz);

    auto tmp = std::shared_ptr<char>(buffer);
    blob bb2(tmp, 0, len);

    auto request = std::shared_ptr<configuration_update_request>(new configuration_update_request());
    ::unmarshall(req, *request);

    {

        zauto_lock l(_log_lock);
        offset = _offset;
        _offset += len;

        file::write(_log, buffer, len, offset, LPC_CM_LOG_UPDATE, this,
            std::bind(&meta_service::on_log_completed, this, 
            std::placeholders::_1, std::placeholders::_2, bb2, request, resp));
    }
}
Exemplo n.º 4
0
    void command_manager::on_remote_cli(dsn_message_t req)
    {
        rpc_read_stream reader(req);

        std::string cmd;
        unmarshall(reader, cmd);

        std::vector<std::string> args;
        unmarshall(reader, args);

        std::string result;
        run_command(cmd, args, result);

        auto resp = dsn_msg_create_response(req);
        ::marshall(resp, result);
        dsn_rpc_reply(resp);
    }
Exemplo n.º 5
0
    void command_manager::on_remote_cli(dsn_message_t req)
    {
        ::dsn::command cmd;
        safe_string result;

        ::dsn::unmarshall(req, cmd);

        safe_vector<safe_string> args;
        for (auto& e : cmd.arguments)
        {
            args.emplace_back(e.c_str());
        }

        run_command(cmd.cmd.c_str(), args, result);

        auto resp = dsn_msg_create_response(req);

        std::string r2 = result.c_str();
        ::dsn::marshall(resp, r2);
        dsn_rpc_reply(resp);
    }
Exemplo n.º 6
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);
}