Пример #1
0
/*static*/ mutation_ptr mutation::read_from(binary_reader& reader, dsn_message_t from)
{
    mutation_ptr mu(new mutation());
    unmarshall(reader, mu->data);
    unmarshall(reader, mu->rpc_code);

    // it is possible this is an emtpy mutation due to new primaries inserts empty mutations for holes
    dassert(mu->data.updates.size() == 1 || mu->rpc_code == RPC_REPLICATION_WRITE_EMPTY,
        "batch is not supported now");

    if (nullptr != from)
    {
        mu->_prepare_request = from;
        dsn_msg_add_ref(from); // released on dctor
    }
    else if (mu->data.updates.size() > 0)
    {
        dassert(mu->data.updates.at(0).has_holder(), 
            "the buffer must has ownership");
    }
    else
    {
        dassert(mu->rpc_code == RPC_REPLICATION_WRITE_EMPTY, "must be RPC_REPLICATION_WRITE_EMPTY");
    }
    
    sprintf(mu->_name, "%lld.%lld",
        static_cast<long long int>(mu->data.header.ballot),
        static_cast<long long int>(mu->data.header.decree));

    return mu;
}
Пример #2
0
void unmarshall(binary_reader& reader, /*out*/ app_state& val)
{
    unmarshall(reader, val.app_type);
    unmarshall(reader, val.app_name);
    unmarshall(reader, val.app_id);
    unmarshall(reader, val.partition_count);
    unmarshall(reader, val.partitions);
}
Пример #3
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);
}
Пример #4
0
void meta_service::replay_log(const char* log)
{
    FILE* fp = ::fopen(log, "rb");
    dassert (fp != nullptr, "open operation log %s failed, err = %d", log, errno);

    char buffer[4096]; // enough for holding configuration_update_request
    while (true)
    {
        int32_t len;
        if (1 != ::fread((void*)&len, sizeof(int32_t), 1, fp))
            break;

        dassert(len <= 4096, "");
        auto r = ::fread((void*)buffer, len, 1, fp);
        dassert(r == 1, "log is corrupted");

        blob bb(buffer, 0, len);
        binary_reader reader(bb);

        configuration_update_request request;
        configuration_update_response response;
        unmarshall(reader, request);

        node_states state;
        state.push_back(std::make_pair(request.node, true));

        _state->set_node_state(state, nullptr);
        _state->update_configuration(request, response);
        response.err.end_tracking();
    }

    ::fclose(fp);
}
Пример #5
0
/*static*/ mutation_ptr mutation::read_from(binary_reader& reader, dsn_message_t from)
{
    mutation_ptr mu(new mutation());
    unmarshall(reader, mu->data, DSF_THRIFT_BINARY);

    for (const mutation_update& update : mu->data.updates)
    {
        dassert(update.code != TASK_CODE_INVALID, "invalid mutation task code");
    }

    mu->client_requests.resize(mu->data.updates.size());

    if (nullptr != from)
    {
        mu->_prepare_request = from;
        dsn_msg_add_ref(from); // released on dctor
    }
    
    snprintf_p(mu->_name, sizeof(mu->_name),
        "%" PRId32 ".%" PRId32 ".%" PRId64 ".%" PRId64,
        mu->data.header.pid.get_app_id(),
        mu->data.header.pid.get_partition_index(),
        mu->data.header.ballot,
        mu->data.header.decree);

    return mu;
}
Пример #6
0
    void command_manager::on_remote_cli(message_ptr& request)
    {
        std::string cmd;
        unmarshall(request->reader(), cmd);

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

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

        auto resp = request->create_response();
        marshall(resp->writer(), result);

        ::dsn::service::rpc::reply(resp);
    }
Пример #7
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);
    }
Пример #8
0
/*static*/ mutation_ptr mutation::read_from(message_ptr& reader)
{
    mutation_ptr mu(new mutation());
    unmarshall(reader, mu->data);
    unmarshall(reader, mu->rpc_code);

    dassert(mu->data.updates.size() == 1, "batch is not supported now");
    message_ptr msg(new message(mu->data.updates[0], false));
    mu->client_request = msg;

    mu->_from_message = reader;

    sprintf(mu->_name, "%lld.%lld",
        static_cast<long long int>(mu->data.header.ballot),
        static_cast<long long int>(mu->data.header.decree));

    return mu;
}
void UserIdCache::restore()
{
	qDebug() << "EEEE UserIdCache::restore()" << endl;
    QVariant userIdCacheData = _settings->getQvariantValueFor(SETTINGS_KEY_CACHE_USERID, "UNSET");
    if (userIdCacheData.toString().compare("UNSET") != 0) {
    	unmarshall(userIdCacheData.toByteArray());
    } else {
    	qWarning() << "EEEE UserIdCache::restore() - no data to restore" << endl;
    }
    LOGIT("restore()");
}
void EntitlementCache::restore()
{
	qDebug() << "EEEE EntitlementCache::restore()" << endl;
    QVariant entitlement = _settings->getQvariantValueFor(SETTINGS_KEY_CACHE_ENTITLEMENT, "UNSET");
    if (entitlement.toString().compare("UNSET") != 0) {
    	unmarshall(entitlement.toByteArray());
    } else {
    	qWarning() << "EEEE EntitlementCache::restore() - no data to restore" << endl;
    }
    LOGIT("restore()");
}
void RollBack::restore()
{
	qDebug() << "EEEE RollBack::restore()" << endl;
    QVariant rollBack = _settings->getQvariantValueFor(SETTINGS_KEY_CACHE_ROLLBACK, "UNSET");
    if (rollBack.toString().compare("UNSET") != 0) {
    	unmarshall(rollBack.toByteArray());
    } else {
    	qWarning() << "EEEE RollBack::restore() - no data to restore" << endl;
    }
    LOGIT("restore()");
}
Пример #12
0
void CRpcMessage::unmarshall(XmlPullParser* xpp, CSoapValue* soapvalue, const char* tagname)
{
    int type;
    StartTag stag;
    EndTag etag;

    while((type = xpp->next()) != XmlPullParser::END_DOCUMENT) 
    {
        if(type == XmlPullParser::END_TAG)
        {
            xpp->readEndTag(etag);
            if(!stricmp(etag.getLocalName(), tagname))
                break;
        }
        else if(type == XmlPullParser::START_TAG)
        {
            xpp->readStartTag(stag);
            StringBuffer ns;
            const char* qname = stag.getQName();
            //DBGLOG("tag qname=%s", qname);
            const char* localname = stag.getLocalName();
            const char* valuetype = stag.getValue("SOAP-ENC:type");
            
            if(strlen(qname) > strlen(localname))
            {
                const char* semcol = strchr(qname, ':');
                if(semcol != NULL)
                {
                    ns.append(qname, 0, semcol - qname);
                }
            }

            CSoapValue* childsoapval = new CSoapValue(ns.str(), localname, valuetype, (const char*)NULL,m_encode_xml);
            soapvalue->add_child(childsoapval);

            // attributes
            for(int i = 0; ; ++i) {
                const char* name = stag.getRawName(i);
                if (!name)
                    break;
                childsoapval->add_attribute(name, stag.getValue(i));    
            }

            unmarshall(xpp, childsoapval, localname);
        }
        else if(type == XmlPullParser::CONTENT) 
        {
            const char* value = xpp->readContent();
            soapvalue->set_value(value);
        }
    }
}
Пример #13
0
/*static*/ mutation_ptr mutation::read_from_log_file(binary_reader& reader, dsn_message_t from)
{
    mutation_ptr mu(new mutation());
    unmarshall(reader, mu->data.header, DSF_THRIFT_BINARY);
    int size;
    unmarshall(reader, size, DSF_THRIFT_BINARY);
    mu->data.updates.resize(size);
    std::vector<int> lengths(size, 0);
    for (int i = 0; i < size; ++i)
    {
        unmarshall(reader, mu->data.updates[i].code, DSF_THRIFT_BINARY);
        unmarshall(reader, lengths[i], DSF_THRIFT_BINARY);
    }
    for (int i = 0; i < size; ++i)
    {
        int len = lengths[i];
        std::shared_ptr<char> holder(new char[len], [](char* ptr){ delete []ptr; });
        reader.read(holder.get(), len);
        mu->data.updates[i].data.assign(holder, 0, len);
    }

    mu->client_requests.resize(mu->data.updates.size());

    if (nullptr != from)
    {
        mu->_prepare_request = from;
        dsn_msg_add_ref(from); // released on dctor
    }

    snprintf_p(mu->_name, sizeof(mu->_name),
        "%" PRId32 ".%" PRId32 ".%" PRId64 ".%" PRId64,
        mu->data.header.pid.get_app_id(),
        mu->data.header.pid.get_partition_index(),
        mu->data.header.ballot,
        mu->data.header.decree);

    return mu;
}
Пример #14
0
void server_state::load(const char* chk_point)
{
    FILE* fp = ::fopen(chk_point, "rb");

    int32_t len;
    ::fread((void*)&len, sizeof(int32_t), 1, fp);

    std::shared_ptr<char> buffer(new char[len]);
    ::fread((void*)buffer.get(), len, 1, fp);

    blob bb(buffer, 0, len);
    binary_reader reader(bb);
    unmarshall(reader, _apps);

    ::fclose(fp);

    dassert(_apps.size() == 1, "");
    auto& app = _apps[0];
    for (int i = 0; i < app.partition_count; i++)
    {
        auto& ps = app.partitions[i];

        if (ps.primary.is_invalid() == false)
        {
            _nodes[ps.primary].primaries.insert(ps.gpid);
            _nodes[ps.primary].partitions.insert(ps.gpid);
        }
        
        for (auto& ep : ps.secondaries)
        {
            dassert(ep.is_invalid() == false, "");
            _nodes[ep].partitions.insert(ps.gpid);
        }
    }

    for (auto& node : _nodes)
    {
        node.second.address = node.first;
        node.second.is_alive = true;
        _node_live_count++;
    }

    for (auto& app : _apps)
    {
        for (auto& par : app.partitions)
        {
            check_consistency(par.gpid);
        }
    }
}
Пример #15
0
    bool command_manager::run_command(const std::string& cmd, const std::vector<std::string>& args, /*out*/ std::string& output)
    {
        command* h = nullptr;
        {
            utils::auto_read_lock l(_lock);
            auto it = _handlers.find(cmd);
            if (it != _handlers.end())
                h = it->second;
        }

        if (h == nullptr)
        {
            output = std::string("unknown command '") + cmd + "'";
            return false;
        }
        else
        {
            if (h->address.is_invalid() || h->address == dsn::task::get_current_rpc()->primary_address())
            {
                output = h->handler(args);
                return true;
            }
            else
            {
                ::dsn::rpc_read_stream response;
                
                dsn_message_t msg = dsn_msg_create_request(RPC_DSN_CLI_CALL, 0, 0);
                ::marshall(msg, cmd);
                ::marshall(msg, args);
                auto resp = dsn_rpc_call_wait(h->address.c_addr(), msg);
                if (resp != nullptr)
                {
                    response.set_read_msg(resp);
                    unmarshall(response, output);
                    return true;
                }
                else
                {
                    dwarn("cli run for %s is too long, timeout", cmd.c_str());
                    return false;
                }
            }
        }
    }
Пример #16
0
TEST(core, rpc)
{
    int req = 0;
    std::string result;
    ::dsn::rpc_address server("localhost", 20101);

    ::dsn::rpc_read_stream response;
    auto err = ::dsn::rpc::call_typed_wait(
        &response,
        server,
        RPC_TEST_HASH,
        req,
        1,
        0
        );
    EXPECT_TRUE(err == ERR_OK);

    unmarshall(response, result);
    EXPECT_TRUE(result.substr(0, result.length() - 2) == "server.THREAD_POOL_TEST_SERVER");
}
Пример #17
0
void meta_service::on_log_completed(error_code err, int size, char* buffer, message_ptr req, message_ptr resp)
{
    free(buffer);
    dassert(err == ERR_SUCCESS, "log operation failed, cannot proceed, err = %s", err.to_string());

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

    update_configuration(request, response);

    meta_response_header rhdr;
    rhdr.err = err;
    rhdr.primary_address = primary_address();

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

    rpc::reply(resp);
}
Пример #18
0
void meta_service::update_configuration(message_ptr req, message_ptr resp)
{
    if (_state->freezed())
    {
        meta_response_header rhdr;
        rhdr.err = 0;
        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);

        rpc::reply(resp);
        return;
    }

    auto bb = req->reader().get_remaining_buffer();
    uint64_t offset;
    int len = bb.length() + sizeof(int32_t);
    
    char* buffer = (char*)malloc(len);
    *(int32_t*)buffer = bb.length();
    memcpy(buffer + sizeof(int32_t), bb.data(), bb.length());

    {

        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, buffer, req, resp));
    }
}
Пример #19
0
void replication_app_client_base::query_partition_configuration_reply(error_code err, message_ptr& request, message_ptr& response, int pidx)
{
    if (!err)
    {
        configuration_query_by_index_response resp;
        unmarshall(response->reader(), resp);
        if (resp.err == ERR_SUCCESS)
        {
            zauto_write_lock l(_config_lock);
            _last_contact_point = response->header().from_address;

            if (resp.partitions.size() > 0)
            {
                if (_app_id != -1 && _app_id != resp.partitions[0].gpid.app_id)
                {
                    dassert(false, "app id is changed (mostly the app was removed and created with the same name), local Vs remote: %u vs %u ",
                            _app_id, resp.partitions[0].gpid.app_id);
                }

                _app_id = resp.partitions[0].gpid.app_id;
                _app_partition_count = resp.partition_count;
            }

            for (auto it = resp.partitions.begin(); it != resp.partitions.end(); it++)
            {
                partition_configuration& new_config = *it;
                auto it2 = _config_cache.find(new_config.gpid.pidx);
                if (it2 == _config_cache.end())
                {
                    _config_cache[new_config.gpid.pidx] = new_config;
                }
                else if (it2->second.ballot < new_config.ballot)
                {
                    it2->second = new_config;
                }
            }
        }
    }

    // send pending client msgs
    partition_context* pc = nullptr;
    {
        zauto_lock l(_requests_lock);
        auto it = _pending_requests.find(pidx);
        if (it != _pending_requests.end())
        {
            pc = it->second;
            _pending_requests.erase(pidx);
        }
    }

    if (pc != nullptr)
    {
        for (auto& req : pc->requests)
        {
            call(req, false);
        }
        pc->requests.clear();
        delete pc;
    }
}
Пример #20
0
void CRpcMessage::unmarshall(XmlPullParser* xpp, CMimeMultiPart* multipart)
{
    unmarshall(xpp, m_params, m_name, multipart);
}
Пример #21
0
void CRpcMessage::unmarshall(XmlPullParser* xpp)
{
    unmarshall(xpp, m_params, m_name);
}
Пример #22
0
	inline void NumberMarshaller::setFieldValue(JNIEnv * const env, const jobject obj, const jfieldID fieldID, const double & value) const
	{
		env->SetDoubleField(obj, fieldID, unmarshall(env, value));
	}
Пример #23
0
void replica::on_prepare(dsn_message_t request)
{
    check_hashed_access();

    replica_configuration rconfig;
    mutation_ptr mu;

    {
        rpc_read_stream reader(request);
        unmarshall(reader, rconfig);
        mu = mutation::read_from(reader, request);
    }

    decree decree = mu->data.header.decree;

    dinfo("%s: mutation %s on_prepare", name(), mu->name());

    dassert(mu->data.header.ballot == rconfig.ballot, "");

    if (mu->data.header.ballot < get_ballot())
    {
        derror("%s: mutation %s on_prepare skipped due to old view", name(), mu->name());
        // no need response because the rpc should have been cancelled on primary in this case
        return;
    }

    // update configuration when necessary
    else if (rconfig.ballot > get_ballot())
    {
        if (!update_local_configuration(rconfig))
        {
            derror(
                "%s: mutation %s on_prepare failed as update local configuration failed, state = %s",
                name(), mu->name(),
                enum_to_string(status())
                );
            ack_prepare_message(ERR_INVALID_STATE, mu);
            return;
        }
    }

    if (PS_INACTIVE == status() || PS_ERROR == status())
    {
        derror(
            "%s: mutation %s on_prepare failed as invalid replica state, state = %s",
            name(), mu->name(),
            enum_to_string(status())
            );
        ack_prepare_message(
            (PS_INACTIVE == status() && _inactive_is_transient) ? ERR_INACTIVE_STATE : ERR_INVALID_STATE,
            mu
            );
        return;
    }
    else if (PS_POTENTIAL_SECONDARY == status())
    {
        // new learning process
        if (rconfig.learner_signature != _potential_secondary_states.learning_signature)
        {
            init_learn(rconfig.learner_signature);
            // no need response as rpc is already gone
            return;
        }

        if (!(_potential_secondary_states.learning_status == LearningWithPrepare
            || _potential_secondary_states.learning_status == LearningSucceeded))
        {
            derror(
                "%s: mutation %s on_prepare skipped as invalid learning status, state = %s, learning_status = %s",
                name(), mu->name(),
                enum_to_string(status()),
                enum_to_string(_potential_secondary_states.learning_status)
                );

            // no need response as rpc is already gone
            return;
        }
    }

    dassert (rconfig.status == status(), "");    
    if (decree <= last_committed_decree())
    {
        ack_prepare_message(ERR_OK, mu);
        return;
    }
    
    // real prepare start
    auto mu2 = _prepare_list->get_mutation_by_decree(decree);
    if (mu2 != nullptr && mu2->data.header.ballot == mu->data.header.ballot)
    {
        if (mu2->is_logged())
        {
            ack_prepare_message(ERR_OK, mu);
        }
        else
        {
            derror("%s: mutation %s on_prepare skipped as it is duplicate", name(), mu->name());
            // response will be unnecessary when we add retry logic in rpc engine.
            // the retried rpc will use the same id therefore it will be considered responsed
            // even the response is for a previous try.
        }
        return;
    }

    error_code err = _prepare_list->prepare(mu, status());
    dassert (err == ERR_OK, "");

    if (PS_POTENTIAL_SECONDARY == status())
    {
        dassert (mu->data.header.decree <= last_committed_decree() + _options->max_mutation_count_in_prepare_list, "");
    }
    else
    {
        dassert (PS_SECONDARY == status(), "");
        dassert (mu->data.header.decree <= last_committed_decree() + _options->staleness_for_commit, "");
    }

    dassert(mu->log_task() == nullptr, "");
    mu->log_task() = _stub->_log->append(mu,
        LPC_WRITE_REPLICATION_LOG,
        this,
        std::bind(&replica::on_append_log_completed, this, mu,
                  std::placeholders::_1,
                  std::placeholders::_2),
        gpid_to_hash(get_gpid())
        );
}
int main(int argc,char** argv){

	int flagRegistrazione = 0;
	int skt;
	int maxConnessioni = 10;
	hdata_t *user = (hdata_t*)malloc(sizeof(hdata_t));
	char* s = (char*)malloc((strlen(*argv)+1)*sizeof(char));;
	msg_t login;
	bzero(&login,sizeof(msg_t));
	
	if (argc == 1 || argc > 6) {
		printf("Parametri di accesso invalidi.\n");
		return(-1);
	}

	short comando = parser(argc,argv);
	switch (comando) {
		case -1:
			exit(-1);
		break;

		case 1:
			printf("Guida all'uso chat-client (!)\n");
			exit(1);
		break;

		case 2:
			sprintf(s,"%s %s",argv[2],argv[3]);
			user->fullname = (char*)malloc((strlen(s)+1)*sizeof(char));
			strcpy(user->fullname,s);
			user->email = (char*)malloc((strlen(argv[4])+1)*sizeof(char));
			strcpy(user->email,argv[4]);
			user->uname = (char*)malloc((strlen(argv[5])+1)*sizeof(char));
			strcpy(user->uname,argv[5]);
			flagRegistrazione = 1;	
			printf("Reg_log: %s\t%s\t%s\n",user->uname,user->fullname,user->email);
		break;

		case 3:
			user->uname = (char*)malloc((strlen(argv[1])+1)*sizeof(char));
			strcpy(user->uname,argv[1]);
		break;
	}

	struct sockaddr_in server_info;
	bzero(&server_info,sizeof(struct sockaddr_in));

	skt = socket(AF_INET,SOCK_STREAM,0);

	server_info.sin_family = AF_INET;
	server_info.sin_port = htons(3117);
	server_info.sin_addr.s_addr = inet_addr("127.0.0.1");
	//server_info.sin_addr.s_addr = inet_addr("192.168.0.112");

	while (maxConnessioni != 0) {
		if (connect(skt,(struct sockaddr*)&server_info,sizeof(server_info)) == 0) {
				printf("CONNESSIONE EFFETTUATA!\n");		
				break;
		} else {
				maxConnessioni--;
				sleep(1);
		}
	}
	if (maxConnessioni == 0) {
		perror("Numero massimo di connessioni fallite raggiunto.Riprova più tardi.\n");
		exit(1);
	}
	if (flagRegistrazione) {
		bzero(&login,sizeof(msg_t));
		login.type = MSG_REGLOG;
		login.msg = (char*)malloc((strlen(user->fullname)+strlen(user->email)+strlen(user->uname)+4)*sizeof(char));
		sprintf(login.msg,"%s:%s:%s",user->uname,user->fullname,user->email);
		login.msglen = strlen(login.msg)+1;
	} else {
		bzero(&login,sizeof(msg_t));
		login.type = MSG_LOGIN;
		login.msg = (char*)malloc((strlen(user->uname)+1)*sizeof(char));
		strcpy(login.msg,user->uname);
		login.msglen = strlen(login.msg)+1;
	}
	char* mail = (char*)malloc((strlen(login.msg)+3)*sizeof(char));
	mail = marshall(login);
	write(skt,mail,(strlen(mail)+1)*sizeof(char));
	
	msg_t* unpacked = (msg_t*)malloc(sizeof(msg_t));
	unmarshall(skt,unpacked);
	printf("%c\t%s\t%s\t%s\t%d\n",unpacked->type,unpacked->sender,unpacked->receiver,unpacked->msg,unpacked->msglen);

	close(skt);

	// Avvio i 2 thread e pa-pa-pa...

	return 0;
}
Пример #25
0
	inline jvalue NumberMarshaller::unmarshallToValue(JNIEnv * env, const double & in) const
	{
		jvalue value{};
		value.d = unmarshall(env, in);
		return value;
	}
Пример #26
0
        void partition_resolver_simple::query_config_reply(error_code err, dsn_message_t request, dsn_message_t response, int partition_index)
        {
            auto client_err = ERR_OK;

            if (err == ERR_OK)
            {
                configuration_query_by_index_response resp;
                unmarshall(response, resp);
                if (resp.err == ERR_OK)
                {
                    zauto_write_lock l(_config_lock);

                    if (_app_id != -1 && _app_id != resp.app_id)
                    {
                        dassert(false, "app id is changed (mostly the app was removed and created with the same name), local Vs remote: %u vs %u ",
                            _app_id, resp.app_id);
                    }
                    if (_app_partition_count != -1 && _app_partition_count != resp.partition_count)
                    {
                        dassert(false, "partition count is changed (mostly the app was removed and created with the same name), local Vs remote: %u vs %u ",
                            _app_partition_count, resp.partition_count);
                    }
                    _app_id = resp.app_id;
                    _app_partition_count = resp.partition_count;
                    _app_is_stateful = resp.is_stateful;

                    for (auto it = resp.partitions.begin(); it != resp.partitions.end(); ++it)
                    {
                        auto& new_config = *it;

                        dinfo("%s.client: query config reply, gpid = %d.%d, ballot = %" PRId64 ", primary = %s",
                            _app_path.c_str(),
                            new_config.pid.get_app_id(),
                            new_config.pid.get_partition_index(),
                            new_config.ballot,
                            new_config.primary.to_string()
                            );

                        auto it2 = _config_cache.find(new_config.pid.get_partition_index());
                        if (it2 == _config_cache.end())
                        {
                            std::unique_ptr<partition_info> pi(new partition_info);
                            pi->timeout_count = 0;
                            pi->config = new_config;
                            _config_cache.emplace(new_config.pid.get_partition_index(), std::move(pi));
                        }
                        else if (_app_is_stateful && it2->second->config.ballot < new_config.ballot)
                        {
                            it2->second->timeout_count = 0;
                            it2->second->config = new_config;
                        }
                        else if (!_app_is_stateful)
                        {
                            it2->second->timeout_count = 0;
                            it2->second->config = new_config;
                        }
                        else
                        {
                            // nothing to do
                        }
                    }
                }
                else if (resp.err == ERR_OBJECT_NOT_FOUND)
                {
                    derror("%s.client: query config reply, gpid = %d.%d, err = %s",
                        _app_path.c_str(),
                        _app_id,
                        partition_index,
                        resp.err.to_string()
                        );

                    client_err = ERR_APP_NOT_EXIST;
                }
                else
                {
                    derror("%s.client: query config reply, gpid = %d.%d, err = %s",
                        _app_path.c_str(),
                        _app_id,
                        partition_index,
                        resp.err.to_string()
                        );

                    client_err = resp.err;
                }
            }
            else
            {
                derror("%s.client: query config reply, gpid = %d.%d, err = %s",
                    _app_path.c_str(),
                    _app_id,
                    partition_index,
                    err.to_string()
                    );
            }

            // get specific or all partition update
            if (partition_index != -1)
            {
                partition_context* pc = nullptr;
                {
                    zauto_lock l(_requests_lock);
                    auto it = _pending_requests.find(partition_index);
                    if (it != _pending_requests.end())
                    {
                        pc = it->second;
                        _pending_requests.erase(partition_index);
                    }
                }

                if (pc)
                {
                    handle_pending_requests(pc->requests, client_err);
                    delete pc;
                }
            }

            // get all partition update
            else
            {
                pending_replica_requests reqs;
                std::deque<request_context_ptr> reqs2;
                {
                    zauto_lock l(_requests_lock);
                    reqs.swap(_pending_requests);
                    reqs2.swap(_pending_requests_before_partition_count_unknown);
                }
             
                if (!reqs2.empty())
                {
                    if (_app_partition_count != -1)
                    {
                        for (auto& req : reqs2)
                        {
                            dassert(req->partition_index == -1, "");
                            req->partition_index = get_partition_index(_app_partition_count, req->partition_hash);
                        }
                    }
                    handle_pending_requests(reqs2, client_err);
                }

                for (auto& r : reqs)
                {
                    if (r.second)
                    {
                        handle_pending_requests(r.second->requests, client_err);
                        delete r.second;
                    }
                }
            }
        }
Пример #27
0
	inline jobject NumberMarshaller::unmarshallBoxed(JNIEnv * const env, const double & in) const
	{
		return Utils::boxDouble(env, unmarshall(env, in));
	}
 error_code meta_state_service_simple::initialize()
 {
     _offset = 0;
     std::string log_path = "meta_state_service.log";
     if (utils::filesystem::file_exists(log_path))
     {
         if (FILE* fd = fopen(log_path.c_str(), "rb"))
         {
             for (;;)
             {
                 log_header header;
                 if (fread(&header, sizeof(log_header), 1, fd) != 1)
                 {
                     break;
                 }
                 if (header.magic != log_header::default_magic)
                 {
                     break;
                 }
                 std::shared_ptr<char> buffer(new char[header.size]);
                 if (fread(buffer.get(), header.size, 1, fd) != 1)
                 {
                     break;
                 }
                 _offset += sizeof(header) + header.size;
                 blob blob_wrapper(buffer, header.size);
                 binary_reader reader(blob_wrapper);
                 int op_type;
                 unmarshall(reader, op_type);
                 switch (static_cast<operation_type>(op_type))
                 {
                 case operation_type::create_node:
                 {
                     std::string node;
                     blob data;
                     create_node_log::parse(reader, node, data);
                     create_node_internal(node, data).end_tracking();
                     break;
                 }
                 case operation_type::delete_node:
                 {
                     std::string node;
                     bool recursively_delete;
                     delete_node_log::parse(reader, node, recursively_delete);
                     delete_node_internal(node, recursively_delete).end_tracking();
                     break;
                 }
                 case operation_type::set_data:
                 {
                     std::string node;
                     blob data;
                     set_data_log::parse(reader, node, data);
                     set_data_internal(node, data).end_tracking();
                     break;
                 }
                 default:
                     //The log is complete but its content is modified by cosmic ray. This is unacceptable
                     dassert(false, "meta state server log corrupted");
                 }   
             }
             fclose(fd);
         }
     }
     _log = dsn_file_open(log_path.c_str(), O_RDWR | O_CREAT | O_BINARY, 0666);
     return ERR_OK;
 }
Пример #29
0
void MRmiServerPrivateSocket::invoke(QDataStream& stream)
{
    char* className   = 0;
    char* methodName  = 0;
    quint16 arglength = 0;

    QVariant arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9;

    stream >> arglength >> className >> methodName;
    switch (arglength) {
    case 0:
        QMetaObject::invokeMethod(currentObject(),
                                  methodName);
        break;
    case 1:
        stream >> arg0;
        QMetaObject::invokeMethod(currentObject(),
                                  methodName,
                                  unmarshall(arg0.typeName(),
                                             arg0.data()));

        break;
    case 2:
        stream >> arg0 >> arg1;
        QMetaObject::invokeMethod(currentObject(),
                                  methodName,
                                  unmarshall(arg0.typeName(),
                                             arg0.data()),
                                  unmarshall(arg1.typeName(),
                                             arg1.data()));
        break;
    case 3:
        stream >> arg0 >> arg1 >> arg2;
        QMetaObject::invokeMethod(currentObject(),
                                  methodName,
                                  unmarshall(arg0.typeName(),
                                             arg0.data()),
                                  unmarshall(arg1.typeName(),
                                             arg1.data()),
                                  unmarshall(arg2.typeName(),
                                             arg2.data()));
        break;
    case 4:
        stream >> arg0 >> arg1 >> arg2 >> arg3;
        QMetaObject::invokeMethod(currentObject(),
                                  methodName,
                                  unmarshall(arg0.typeName(),
                                             arg0.data()),
                                  unmarshall(arg1.typeName(),
                                             arg1.data()),
                                  unmarshall(arg2.typeName(),
                                             arg2.data()),
                                  unmarshall(arg3.typeName(),
                                             arg3.data()));
        break;
    case 5:
        stream >> arg0 >> arg1 >> arg2 >> arg3 >> arg4;
        QMetaObject::invokeMethod(currentObject(),
                                  methodName,
                                  unmarshall(arg0.typeName(),
                                             arg0.data()),
                                  unmarshall(arg1.typeName(),
                                             arg1.data()),
                                  unmarshall(arg2.typeName(),
                                             arg2.data()),
                                  unmarshall(arg3.typeName(),
                                             arg3.data()),
                                  unmarshall(arg4.typeName(),
                                             arg4.data()));
        break;
    case 6:
        stream >> arg0 >> arg1 >> arg2 >> arg3 >> arg4 >> arg5;
        QMetaObject::invokeMethod(currentObject(),
                                  methodName,
                                  unmarshall(arg0.typeName(),
                                             arg0.data()),
                                  unmarshall(arg1.typeName(),
                                             arg1.data()),
                                  unmarshall(arg2.typeName(),
                                             arg2.data()),
                                  unmarshall(arg3.typeName(),
                                             arg3.data()),
                                  unmarshall(arg4.typeName(),
                                             arg4.data()),
                                  unmarshall(arg5.typeName(),
                                             arg5.data()));
        break;
    case 7:
        stream >> arg0 >> arg1 >> arg2 >> arg3 >> arg4 >> arg5 >> arg6;
        QMetaObject::invokeMethod(currentObject(),
                                  methodName,
                                  unmarshall(arg0.typeName(),
                                             arg0.data()),
                                  unmarshall(arg1.typeName(),
                                             arg1.data()),
                                  unmarshall(arg2.typeName(),
                                             arg2.data()),
                                  unmarshall(arg3.typeName(),
                                             arg3.data()),
                                  unmarshall(arg4.typeName(),
                                             arg4.data()),
                                  unmarshall(arg5.typeName(),
                                             arg5.data()),
                                  unmarshall(arg6.typeName(),
                                             arg6.data()));
        break;
    case 8:
        stream >> arg0 >> arg1 >> arg2 >> arg3 >> arg4 >> arg5 >> arg6 >> arg7;
        QMetaObject::invokeMethod(currentObject(),
                                  methodName,
                                  unmarshall(arg0.typeName(),
                                             arg0.data()),
                                  unmarshall(arg1.typeName(),
                                             arg1.data()),
                                  unmarshall(arg2.typeName(),
                                             arg2.data()),
                                  unmarshall(arg3.typeName(),
                                             arg3.data()),
                                  unmarshall(arg4.typeName(),
                                             arg4.data()),
                                  unmarshall(arg5.typeName(),
                                             arg5.data()),
                                  unmarshall(arg6.typeName(),
                                             arg6.data()),
                                  unmarshall(arg7.typeName(),
                                             arg7.data()));
        break;
    case 9:
        stream >> arg0 >> arg1 >> arg2 >> arg3 >> arg4 >> arg5 >> arg6 >> arg7
        >> arg8;
        QMetaObject::invokeMethod(currentObject(),
                                  methodName,
                                  unmarshall(arg0.typeName(),
                                             arg0.data()),
                                  unmarshall(arg1.typeName(),
                                             arg1.data()),
                                  unmarshall(arg2.typeName(),
                                             arg2.data()),
                                  unmarshall(arg3.typeName(),
                                             arg3.data()),
                                  unmarshall(arg4.typeName(),
                                             arg4.data()),
                                  unmarshall(arg5.typeName(),
                                             arg5.data()),
                                  unmarshall(arg6.typeName(),
                                             arg6.data()),
                                  unmarshall(arg7.typeName(),
                                             arg7.data()),
                                  unmarshall(arg8.typeName(),
                                             arg8.data()));
        break;
    case 10:
        stream >> arg0 >> arg1 >> arg2 >> arg3 >> arg4 >> arg5 >> arg6 >> arg7
        >> arg8 >> arg9;
        QMetaObject::invokeMethod(currentObject(),
                                  methodName,
                                  unmarshall(arg0.typeName(),
                                             arg0.data()),
                                  unmarshall(arg1.typeName(),
                                             arg1.data()),
                                  unmarshall(arg2.typeName(),
                                             arg2.data()),
                                  unmarshall(arg3.typeName(),
                                             arg3.data()),
                                  unmarshall(arg4.typeName(),
                                             arg4.data()),
                                  unmarshall(arg5.typeName(),
                                             arg5.data()),
                                  unmarshall(arg6.typeName(),
                                             arg6.data()),
                                  unmarshall(arg7.typeName(),
                                             arg7.data()),
                                  unmarshall(arg8.typeName(),
                                             arg8.data()),
                                  unmarshall(arg9.typeName(),
                                             arg9.data()));
        break;
    default:
        break;

    }

    delete[] className;
    delete[] methodName;
    method_size = 0;
}
Пример #30
0
void replica::on_prepare(dsn_message_t request)
{
    check_hashed_access();

    replica_configuration rconfig;
    mutation_ptr mu;

    {
        msg_binary_reader reader(request);
        unmarshall(reader, rconfig);
        mu = mutation::read_from(reader, request);
    }

    decree decree = mu->data.header.decree;

    ddebug( "%s: mutation %s on_prepare", name(), mu->name());

    dassert (mu->data.header.ballot == rconfig.ballot, "");

    if (mu->data.header.ballot < get_ballot())
    {
        ddebug( "%s: mutation %s on_prepare skipped due to old view", name(), mu->name());
        return;
    }

    // update configuration when necessary
    else if (rconfig.ballot > get_ballot())
    {
        if (!update_local_configuration(rconfig))
        {
            ddebug(
                "%s: mutation %s on_prepare  to %s failed as update local configuration failed",
                name(), mu->name(),
                enum_to_string(status())
            );
            ack_prepare_message(ERR_INVALID_STATE, mu);
            return;
        }
    }

    if (PS_INACTIVE == status() || PS_ERROR == status())
    {
        ddebug(
            "%s: mutation %s on_prepare  to %s skipped",
            name(), mu->name(),
            enum_to_string(status())
        );
        ack_prepare_message(
            (PS_INACTIVE == status() && _inactive_is_transient) ? ERR_INACTIVE_STATE : ERR_INVALID_STATE,
            mu
        );
        return;
    }

    else if (PS_POTENTIAL_SECONDARY == status())
    {
        if (_potential_secondary_states.learning_status != LearningWithPrepare && _potential_secondary_states.learning_status != LearningSucceeded)
        {
            ddebug(
                "%s: mutation %s on_prepare to %s skipped, learnings state = %s",
                name(), mu->name(),
                enum_to_string(status()),
                enum_to_string(_potential_secondary_states.learning_status)
            );

            // do not retry as there may retries later
            return;
        }
    }

    dassert (rconfig.status == status(), "");
    if (decree <= last_committed_decree())
    {
        ack_prepare_message(ERR_OK, mu);
        return;
    }

    // real prepare start
    auto mu2 = _prepare_list->get_mutation_by_decree(decree);
    if (mu2 != nullptr && mu2->data.header.ballot == mu->data.header.ballot)
    {
        ddebug( "%s: mutation %s redundant prepare skipped", name(), mu->name());

        if (mu2->is_logged() || _options.prepare_ack_on_secondary_before_logging_allowed)
        {
            ack_prepare_message(ERR_OK, mu);
        }
        return;
    }

    error_code err = _prepare_list->prepare(mu, status());
    dassert (err == ERR_OK, "");

    if (PS_POTENTIAL_SECONDARY == status())
    {
        dassert (mu->data.header.decree <= last_committed_decree() + _options.staleness_for_start_prepare_for_potential_secondary, "");
    }
    else
    {
        dassert (PS_SECONDARY == status(), "");
        dassert (mu->data.header.decree <= last_committed_decree() + _options.staleness_for_commit, "");
    }

    // ack without logging
    if (_options.prepare_ack_on_secondary_before_logging_allowed)
    {
        ack_prepare_message(err, mu);
    }

    // write log
    dassert (mu->log_task() == nullptr, "");

    mu->log_task() = _stub->_log->append(mu,
                                         LPC_WRITE_REPLICATION_LOG,
                                         this,
                                         std::bind(&replica::on_append_log_completed, this, mu, std::placeholders::_1, std::placeholders::_2),
                                         gpid_to_hash(get_gpid())
                                        );

    dassert(mu->log_task() != nullptr, "");
}