projecteru / redis-cerberus

Redis Cluster Proxy
MIT License
352 stars 82 forks source link

Client::_push_awaitings_to_ready()代码是不是错了? #36

Closed zkmn73 closed 7 years ago

zkmn73 commented 7 years ago

在core/client.cpp里面的Client::_push_awaitings_to_ready()

void Client::_push_awaitings_to_ready()
{
    if (this->_awaiting_count != 0 || (
            !this->_ready_groups.empty() &&
            this->_awaiting_groups.size() + this->_ready_groups.empty() > MAX_RESPONSES
        ))
    {
        return;
    }
    for (util::sptr<CommandGroup>& g: this->_awaiting_groups) {
        g->append_buffer_to(this->_output_buffer_set);
        this->_ready_groups.push_back(std::move(g));
    }
    this->_awaiting_groups.clear();
    if (!this->_output_buffer_set.empty()) {
        this->_proxy->set_conn_poll_rw(this);
    }
}

这个函数把_awaiting_groups里面的命令放到_ready_groups里面,第一个if, 当_awaiting_count的数量不为0的时候不做操作, 或者 _ready_groups不为空,并且 this->_awaiting_groups.size() + this->_ready_groups.empty() > MAX_RESPONSES _ready_groups.empty()->false->0这个是不是错了?应该是 this->_awaiting_groups.size() + this->_ready_groups.size() > MAX_RESPONSES 这里的意思应该是一次写到output_buffer的数量最大为MAX_RESPONSES, 当_awaiting_groups的数量+_ready_groups的数量大于MAX_RESPONSES的时候就先等reay的处理完再处理awaiting_groups的。

zkmn73 commented 7 years ago

PR: https://github.com/HunanTV/redis-cerberus/pull/37