Skip to content

Commit

Permalink
add more logs in cluster module
Browse files Browse the repository at this point in the history
  • Loading branch information
raffertyyu committed Mar 9, 2023
1 parent 2d43792 commit 9041b91
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/tendisplus/cluster/cluster_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,15 @@ uint32_t ClusterNode::delAllSlots() {
bool ClusterNode::addSlave(std::shared_ptr<ClusterNode> slave) {
std::lock_guard<myMutex> lk(_mutex);
for (auto v : _slaves) {
if (v == slave)
if (v == slave) {
LOG(ERROR) << "node:" << getNodeName()
<< " already has slave:" << slave->getNodeName();
return false;
}
}

LOG(INFO) << "node:" << getNodeName()
<< " add slave:" << slave->getNodeName();
_slaves.emplace_back(std::move(slave));
_flags |= CLUSTER_NODE_MIGRATE_TO;
_numSlaves++;
Expand All @@ -392,6 +397,8 @@ bool ClusterNode::removeSlave(std::shared_ptr<ClusterNode> slave) {

for (auto iter = _slaves.begin(); iter != _slaves.end();) {
if (*iter == slave) {
LOG(WARNING) << "node:" << getNodeName()
<< " delete slave:" << slave->getNodeName();
iter = _slaves.erase(iter);
_numSlaves--;

Expand Down Expand Up @@ -557,6 +564,8 @@ void ClusterNode::setAsMaster() {
std::lock_guard<myMutex> lk(_mutex);
_flags &= ~CLUSTER_NODE_SLAVE;
_flags |= CLUSTER_NODE_MASTER;
LOG(INFO) << "node:" << getNodeName() << " are master now. old master:"
<< (_slaveOf ? _slaveOf->getNodeName() : "None");
_slaveOf = nullptr;
}

Expand Down Expand Up @@ -597,6 +606,8 @@ bool ClusterNode::clearNodeFailureIfNeeded(uint32_t timeout) {

void ClusterNode::setMaster(std::shared_ptr<ClusterNode> master) {
std::lock_guard<myMutex> lk(_mutex);
LOG(INFO) << "node:" << getNodeName() << " are slave now. old master:"
<< (_slaveOf ? _slaveOf->getNodeName() : "None");
_slaveOf = master;
}

Expand Down

0 comments on commit 9041b91

Please sign in to comment.