Skip to content

Commit

Permalink
issue=baidu#607 fix naming style in bfs_wrapper
Browse files Browse the repository at this point in the history
move the underscore to the end of membership variables
  • Loading branch information
yvxiang committed Nov 16, 2016
1 parent 1138f5d commit 960c7ed
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
66 changes: 33 additions & 33 deletions tera/bfs_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,98 +25,98 @@ namespace bfs {

int32_t BfsFile::Write(const char* buf, int32_t len) {
common::timer::AutoTimer ac;
int ret = _file->Write(buf, len);
int ret = file_->Write(buf, len);
LOG(INFO, "Write(%s, len: %d) return %d use %.3f ms",
_name.c_str(), len, ret, ac.TimeUsed() / 1000.0);
name_.c_str(), len, ret, ac.TimeUsed() / 1000.0);
if (ret != len) {
LOG(INFO, "Write(%s, len: %d) return %d",
_name.c_str(), len, ret);
name_.c_str(), len, ret);
}
return ret;
}

int32_t BfsFile::Flush() {
common::timer::AutoTimer ac;
int ret = _file->Flush();
int ret = file_->Flush();
LOG(INFO, "Flush(%s) return %d use %.3f ms",
_name.c_str(), ret, ac.TimeUsed() / 1000.0);
name_.c_str(), ret, ac.TimeUsed() / 1000.0);
return ret;
}
int32_t BfsFile::Sync() {
LOG(INFO, "Sync(%s) start", _name.c_str());
LOG(INFO, "Sync(%s) start", name_.c_str());
common::timer::AutoTimer ac;
int ret = _file->Sync();
int ret = file_->Sync();
LOG(INFO, "Sync(%s) return %d usd %.3f ms",
_name.c_str(), ret, ac.TimeUsed() / 1000.0);
name_.c_str(), ret, ac.TimeUsed() / 1000.0);
return ret;
}
int32_t BfsFile::Read(char* buf, int32_t len) {
common::timer::AutoTimer ac;
int32_t ret = _file->Read(buf, len);
int32_t ret = file_->Read(buf, len);
LOG(INFO, "Read(%s, len: %d) return %d use %.3f ms",
_name.c_str(), len, ret, ac.TimeUsed() / 1000.0);
name_.c_str(), len, ret, ac.TimeUsed() / 1000.0);
if (ret != len) {
//LOG(INFO, "Read(%s, len: %d) return %d",
// _name.c_str(), len, ret);
// name_.c_str(), len, ret);
}
return ret;
}
int32_t BfsFile::Pread(int64_t offset, char* buf, int32_t len) {
common::timer::AutoTimer ac;
int32_t ret = _file->Pread(buf, len, offset, true);
int32_t ret = file_->Pread(buf, len, offset, true);
LOG(INFO, "Pread(%s, offset: %ld, len: %d) return %d use %.3f ms",
_name.c_str(), offset, len, ret, ac.TimeUsed() / 1000.0);
name_.c_str(), offset, len, ret, ac.TimeUsed() / 1000.0);
return ret;
}
int64_t BfsFile::Tell() {
common::timer::AutoTimer ac;
int64_t ret = _file->Seek(0, SEEK_CUR);
int64_t ret = file_->Seek(0, SEEK_CUR);
LOG(INFO, "Tell(%s) return %ld use %.3f ms",
_name.c_str(), ret, ac.TimeUsed() / 1000.0);
name_.c_str(), ret, ac.TimeUsed() / 1000.0);
return ret;
}
int32_t BfsFile::Seek(int64_t offset) {
common::timer::AutoTimer ac;
int64_t ret = _file->Seek(offset, SEEK_SET);
int64_t ret = file_->Seek(offset, SEEK_SET);
if (ret >= 0) {
ret = 0;
}
LOG(INFO, "Seek(%s, %ld) return %ld use %.3f ms",
_name.c_str(), offset, ret, ac.TimeUsed() / 1000.0);
name_.c_str(), offset, ret, ac.TimeUsed() / 1000.0);
return ret;
}
int32_t BfsFile::CloseFile() {
LOG(INFO, "CloseFile(%s)", _name.c_str());
LOG(INFO, "CloseFile(%s)", name_.c_str());
common::timer::AutoTimer ac;
int32_t ret = _file->Close();
delete _file;
_file = NULL;
int32_t ret = file_->Close();
delete file_;
file_ = NULL;
if (ret != 0) {
LOG(INFO, "CloseFile(%s) fail", _name.c_str());
LOG(INFO, "CloseFile(%s) fail", name_.c_str());
return -1;
}
LOG(INFO, "CloseFile(%s) succeed use %.3f ms",
_name.c_str(), ac.TimeUsed() / 1000.0);
name_.c_str(), ac.TimeUsed() / 1000.0);
return 0;
}

BfsImpl::BfsImpl(const std::string& conf) {
if (!FS::OpenFileSystem(conf.c_str(), &_fs, FSOptions())) {
if (!FS::OpenFileSystem(conf.c_str(), &fs_, FSOptions())) {
assert(0);
}
}

int32_t BfsImpl::CreateDirectory(const std::string& path) {
common::timer::AutoTimer ac;
_fs->CreateDirectory(path.c_str());
fs_->CreateDirectory(path.c_str());
LOG(INFO, "CreateDirectory(%s) use %.3f ms",
path.c_str(), ac.TimeUsed() / 1000.0);
return 0;
}
int32_t BfsImpl::DeleteDirectory(const std::string& path) {
common::timer::AutoTimer ac;
LOG(INFO, "DeleteDirectory(%s)", path.c_str());
if (_fs->DeleteDirectory(path.c_str(), true) != 0) {
if (fs_->DeleteDirectory(path.c_str(), true) != 0) {
LOG(INFO, "DeleteDirectory(%s) fail", path.c_str());
return -1;
}
Expand All @@ -127,7 +127,7 @@ int32_t BfsImpl::DeleteDirectory(const std::string& path) {
int32_t BfsImpl::Exists(const std::string& filename) {
common::timer::AutoTimer ac;
LOG(INFO, "Exists(%s)", filename.c_str());
if (_fs->Access(filename.c_str(), 0) != 0) {
if (fs_->Access(filename.c_str(), 0) != 0) {
LOG(INFO, "Exists(%s) return false", filename.c_str());
return -1;
}
Expand All @@ -137,7 +137,7 @@ int32_t BfsImpl::Exists(const std::string& filename) {
}
int32_t BfsImpl::Delete(const std::string& filename) {
common::timer::AutoTimer ac;
if (_fs->DeleteFile(filename.c_str()) != 0) {
if (fs_->DeleteFile(filename.c_str()) != 0) {
LOG(INFO, "Delete(%s) fail", filename.c_str());
return -1;
}
Expand All @@ -148,7 +148,7 @@ int32_t BfsImpl::Delete(const std::string& filename) {
int32_t BfsImpl::GetFileSize(const std::string& filename, uint64_t* size) {
common::timer::AutoTimer ac;
int64_t file_size = 0;
if (_fs->GetFileSize(filename.c_str(), &file_size) != 0) {
if (fs_->GetFileSize(filename.c_str(), &file_size) != 0) {
LOG(INFO, "GetFileSize(%s) fail", filename.c_str());
return -1;
}
Expand All @@ -160,7 +160,7 @@ int32_t BfsImpl::GetFileSize(const std::string& filename, uint64_t* size) {
int32_t BfsImpl::Rename(const std::string& from, const std::string& to) {
common::timer::AutoTimer ac;
Delete(to);
if (_fs->Rename(from.c_str(), to.c_str()) != 0) {
if (fs_->Rename(from.c_str(), to.c_str()) != 0) {
LOG(INFO, "Rename(%s, %s) fail", from.c_str(), to.c_str());
return -1;
}
Expand All @@ -182,7 +182,7 @@ int32_t BfsImpl::ListDirectory(const std::string& path, std::vector<std::string>
}
bfs::BfsFileInfo* files = NULL;
int num = 0;
if (_fs->ListDirectory(path.c_str(), &files, &num) != 0) {
if (fs_->ListDirectory(path.c_str(), &files, &num) != 0) {
return -1;
}
for (int i = 0; i < num; i++) {
Expand All @@ -207,9 +207,9 @@ leveldb::DfsFile* BfsImpl::OpenFile(const std::string& filename, int32_t flags)
bfs::File* file = NULL;
int ret = -1;
if (leveldb::WRONLY == flags) {
ret = _fs->OpenFile(filename.c_str(), O_WRONLY, &file, WriteOptions());
ret = fs_->OpenFile(filename.c_str(), O_WRONLY, &file, WriteOptions());
} else {
ret = _fs->OpenFile(filename.c_str(), O_RDONLY, &file, ReadOptions());
ret = fs_->OpenFile(filename.c_str(), O_RDONLY, &file, ReadOptions());
}
if (ret != 0) {
LOG(WARNING, "OpenFile(%s,%d) fail, ret = %d", filename.c_str(), flags, ret);
Expand Down
8 changes: 4 additions & 4 deletions tera/bfs_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace bfs {

class BfsFile : public leveldb::DfsFile {
public:
BfsFile(const std::string& name, File* file) : _name(name), _file(file) {}
BfsFile(const std::string& name, File* file) : name_(name), file_(file) {}
/// Returns the number of bytes written, -1 on error.
virtual int32_t Write(const char* buf, int32_t len);
/// Returns 0 on success.
Expand All @@ -35,8 +35,8 @@ class BfsFile : public leveldb::DfsFile {
/// Returns 0 on success.
virtual int32_t CloseFile();
private:
std::string _name;
File* _file;
std::string name_;
File* file_;
};

class BfsImpl : public leveldb::Dfs {
Expand All @@ -61,7 +61,7 @@ class BfsImpl : public leveldb::Dfs {
/// Returns DfsFile handler on success, NULL on error.
virtual leveldb::DfsFile* OpenFile(const std::string& filename, int32_t flags);
private:
bfs::FS* _fs;
bfs::FS* fs_;
};

}
Expand Down

0 comments on commit 960c7ed

Please sign in to comment.