Skip to content

Commit

Permalink
Merge pull request #515 from yvxiang/write
Browse files Browse the repository at this point in the history
Hold lock in Block::Write
  • Loading branch information
lylei committed Oct 14, 2016
2 parents 6335dd2 + 374d83b commit 492e788
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/chunkserver/data_block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,16 @@ int64_t Block::Read(char* buf, int64_t len, int64_t offset) {
/// Write operation.
bool Block::Write(int32_t seq, int64_t offset, const char* data,
int64_t len, int64_t* add_use) {
if (finished_) {
LOG(INFO, "Write a finish block #%ld V%ld %ld, seq: %d, offset: %ld",
meta_.block_id(), meta_.version(), meta_.block_size(), seq, offset);
MutexLock lock(&mu_, "BlockWrite", 1000);
if (finished_ || deleted_) {
LOG(INFO, "Write a finish block #%ld V%ld %ld, seq: %d, offset: %ld, finished: %d, deleted: %d",
meta_.block_id(), meta_.version(), meta_.block_size(), seq, offset, finished_, deleted_);
return false;
}
if (offset < meta_.block_size()) {
assert (offset + len <= meta_.block_size());
LOG(INFO, "Write #%ld size %ld, seq: %d, wrong offset: %ld",
meta_.block_id(), meta_.block_size(), seq, offset);
assert (offset + len <= meta_.block_size());
return true;
}
char* buf = NULL;
Expand Down Expand Up @@ -394,12 +395,7 @@ bool Block::IsRecover() {
}
/// Append to block buffer
StatusCode Block::Append(int32_t seq, const char* buf, int64_t len) {
MutexLock lock(&mu_, "BlockAppend", 1000);
if (finished_ || deleted_) {
LOG(INFO, "[Append] block #%ld closed, do not append to blockbuf_. finished_=%d, deleted_=%d",
meta_.block_id(), finished_, deleted_);
return kBlockClosed;
}
mu_.AssertHeld();
if (blockbuf_ == NULL) {
buflen_ = FLAGS_write_buf_size;
blockbuf_ = new char[buflen_];
Expand Down

0 comments on commit 492e788

Please sign in to comment.