Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lock #490

Merged
merged 2 commits into from
Sep 26, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/nameserver/chunkserver_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -627,15 +627,18 @@ void ChunkServerManager::LogStats() {
int32_t w_qps = 0, r_qps = 0;
int64_t w_speed = 0, r_speed = 0, recover_speed = 0;
int32_t overload = 0;
for (ServerMap::iterator it = chunkservers_.begin(); it != chunkservers_.end(); ++it) {
ChunkServerInfo* cs = it->second;
w_qps += cs->w_qps();
w_speed += cs->w_speed();
r_qps += cs->r_qps();
r_speed += cs->r_speed();
recover_speed += cs->recover_speed();
if (cs->load() > kChunkServerLoadMax) {
++overload;
{
MutexLock lock(&mu_);
for (ServerMap::iterator it = chunkservers_.begin(); it != chunkservers_.end(); ++it) {
ChunkServerInfo* cs = it->second;
w_qps += cs->w_qps();
w_speed += cs->w_speed();
r_qps += cs->r_qps();
r_speed += cs->r_speed();
recover_speed += cs->recover_speed();
if (cs->load() > kChunkServerLoadMax) {
++overload;
}
}
}
stats_.w_qps = w_qps;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里有必要锁么?读的时候是没加锁的,整数读/写也应该是原子的,最多导致读出来的stats_结构里多个数据间不一致

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是啊。。有必要加锁么?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上面有必要,下面感觉可以不加

Expand Down