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

Con-currency clean up when ns version mismatch #880 #881

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
16 changes: 11 additions & 5 deletions src/chunkserver/block_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,22 +306,28 @@ StatusCode BlockManager::RemoveBlock(int64_t block_id) {
return kOK;
}

// TODO: concurrent & async cleanup
bool BlockManager::CleanUp(int64_t namespace_version) {
ThreadPool tp(10);
for (auto it = block_map_.begin(); it != block_map_.end();) {
Block* block = it->second;
if (block->CleanUp(namespace_version)) {
file_cache_->EraseFileCache(block->GetFilePath());
block->DecRef();
if (block->GetNamespaceVersion() != namespace_version) {
tp.AddTask(std::bind(&BlockManager::ClenaUpBlockAsync, this, block));
block_map_.erase(it++);
} else {
++it;
}
}
LOG(INFO, "CleanUp done");
tp.Stop(true);
LOG(INFO, "CleanUp done. block_map_ size = %lu", block_map_.size());
return true;
}

void BlockManager::ClenaUpBlockAsync(Block* block) {
file_cache_->EraseFileCache(block->GetFilePath());
block->SetDeleted();
block->DecRef();
}

bool BlockManager::AddBlock(int64_t block_id, Disk* disk, BlockMeta meta) {
Block* block = new Block(meta, disk, file_cache_);
block->AddRef();
Expand Down
1 change: 1 addition & 0 deletions src/chunkserver/block_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class BlockManager {
void Stat(std::string* str);
private:
void CheckStorePath(const std::string& store_path);
void ClenaUpBlockAsync(Block* block);
Disk* PickDisk(int64_t block_id);
int64_t FindSmallest(std::vector<leveldb::Iterator*>& iters, int32_t* idx);
void LogStatus();
Expand Down
8 changes: 2 additions & 6 deletions src/chunkserver/data_block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,8 @@ int64_t Block::DiskUsed() const {
return disk_file_size_;
}

bool Block::CleanUp(int64_t namespace_version) {
if (namespace_version != disk_->NamespaceVersion()) {
SetDeleted();
return true;
}
return false;
int64_t Block::GetNamespaceVersion() {
return disk_->NamespaceVersion();
}

StatusCode Block::SetDeleted() {
Expand Down
2 changes: 1 addition & 1 deletion src/chunkserver/data_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Block {
std::string GetFilePath() const;
BlockMeta GetMeta() const;
int64_t DiskUsed() const;
bool CleanUp(int64_t namespace_version);
int64_t GetNamespaceVersion();
StatusCode SetDeleted();
void SetVersion(int64_t version);
int GetVersion() const;
Expand Down