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

remove useless fflush and motify lock(&mu_) location at Read method #810

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
36 changes: 15 additions & 21 deletions src/nameserver/logdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ StatusCode LogDB::Write(int64_t index, const std::string& entry) {
}

StatusCode LogDB::Read(int64_t index, std::string* entry) {
MutexLock lock(&mu_);
if (read_log_.empty() || index >= next_index_ || index < smallest_index_) {
return kNsNotFound;
}
Expand All @@ -126,28 +127,22 @@ StatusCode LogDB::Read(int64_t index, std::string* entry) {
int offset = 16 * (index - it->first);
int64_t read_index = -1;
int64_t entry_offset = -1;
{
MutexLock lock(&mu_);
if (fseek(idx_fp, offset, SEEK_SET) != 0) {
LOG(FATAL, "[LogDB] Read cannot find index file %ld ", index);
}
StatusCode s = ReadIndex(idx_fp, index, &read_index, &entry_offset);
if (s != kOK) {
return s;
}
if (fseek(idx_fp, offset, SEEK_SET) != 0) {
LOG(FATAL, "[LogDB] Read cannot find index file %ld ", index);
}
StatusCode s = ReadIndex(idx_fp, index, &read_index, &entry_offset);
if (s != kOK) {
return s;
}
// read log entry
{
MutexLock lock(&mu_);
if(fseek(log_fp, entry_offset, SEEK_SET) != 0) {
LOG(WARNING, "[LogDB] Read %ld with invalid offset %ld ", index, entry_offset);
return kReadError;
}
int ret = ReadOne(log_fp, entry);
if (ret <= 0) {
LOG(WARNING, "[LogDB] Read log error %ld ", index);
return kReadError;
}
if(fseek(log_fp, entry_offset, SEEK_SET) != 0) {
LOG(WARNING, "[LogDB] Read %ld with invalid offset %ld ", index, entry_offset);
return kReadError;
}
int ret = ReadOne(log_fp, entry);
if (ret <= 0) {
LOG(WARNING, "[LogDB] Read log error %ld ", index);
return kReadError;
}
return kOK;
}
Expand All @@ -169,7 +164,6 @@ StatusCode LogDB::WriteMarkerNoLock(const std::string& key, const std::string& v
LOG(WARNING, "[LogDB] WriteMarker failed key = %s value = %s", key.c_str(), value.c_str());
return kWriteError;
}
fflush(marker_log_);
markers_[key] = value;
return kOK;
}
Expand Down