-
Notifications
You must be signed in to change notification settings - Fork 555
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
Concurrent load disk when cs starts #880 #882
Open
lylei
wants to merge
1
commit into
baidu:master
Choose a base branch
from
lylei:start
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,17 +163,47 @@ int64_t BlockManager::DiskQuota() const { | |
return disk_quota_; | ||
} | ||
|
||
// TODO: concurrent load | ||
bool BlockManager::LoadStorage() { | ||
bool ret = true; | ||
// return value from Disk::LoadStorage: | ||
// 0: initial state, 1: done, -1: error occured | ||
std::vector<int> ret_vals; | ||
ret_vals.resize(disks_.size(), 0); | ||
ThreadPool tp(disks_.size()); | ||
int disk_index = 0; | ||
for (auto it = disks_.begin(); it != disks_.end(); ++it) { | ||
Disk* disk = it->second; | ||
ret = ret && disk->LoadStorage(std::bind(&BlockManager::AddBlock, | ||
std::function<bool (int64_t, Disk*, BlockMeta)> callback = std::bind(&BlockManager::AddBlock, | ||
this, std::placeholders::_1, | ||
std::placeholders::_2, | ||
std::placeholders::_3)); | ||
disk_quota_ += disk->GetQuota(); | ||
std::placeholders::_3); | ||
tp.AddTask(std::bind(&Disk::LoadStorage, disk, callback, &(ret_vals[disk_index]))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 用不着这么多层括号吧, &ret_vals[disk_index]应该就是可以的 |
||
++disk_index; | ||
} | ||
bool ret = true; | ||
while (true) { | ||
sleep(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 感觉没必要上来就sleep一秒, 说不定已经完成了呢 |
||
bool done = true; | ||
for (auto it = ret_vals.begin(); it != ret_vals.end(); ++it) { | ||
if (*it < 0) { | ||
ret = false; | ||
break; | ||
} else if (*it == 0) { | ||
done = false; | ||
break; | ||
} | ||
} | ||
if (done || !ret) { | ||
break; | ||
} | ||
} | ||
if (ret) { | ||
for (auto it = disks_.begin(); it != disks_.end(); ++it) { | ||
Disk* disk = it->second; | ||
disk_quota_ += disk->GetQuota(); | ||
} | ||
} | ||
tp.Stop(false); | ||
LOG(INFO, "LoadStorage done. Quota = %ld", disk_quota_); | ||
return ret; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以直接写成
std::vector ret_vals(disks_.size(), 0);