Skip to content

Commit

Permalink
Con-currency clean up when ns version mismatch #880
Browse files Browse the repository at this point in the history
  • Loading branch information
lylei committed Mar 28, 2017
1 parent 09abd6d commit 1c69c21
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
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

0 comments on commit 1c69c21

Please sign in to comment.