Skip to content
Closed
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
6 changes: 3 additions & 3 deletions src/common/io/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ int getFileNum(int64_t &fileNum, const string &path, const string &pattern, bool
return -1;
}

string fullPath;
string fullPath;
struct dirent *entry = NULL;
struct stat fs;
while ((entry = readdir(dirp)) != NULL) {
Expand Down Expand Up @@ -202,7 +202,7 @@ int getFileList(vector<string> &fileList, const string &path, const string &patt
return -1;
}

string fullPath;
string fullPath;
struct dirent *entry = NULL;
struct stat fs;
while ((entry = readdir(dirp)) != NULL) {
Expand Down Expand Up @@ -264,7 +264,7 @@ int getDirList(vector<string> &dirList, const string &path, const string &patter
return -1;
}

string fullPath;
string fullPath;
struct dirent *entry = NULL;
struct stat fs;
while ((entry = readdir(dirp)) != NULL) {
Expand Down
10 changes: 5 additions & 5 deletions src/common/lang/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ See the Mulan PSL v2 for more details. */
#include "common/log/log.h"
namespace common {

map<pthread_mutex_t *, LockTrace::LockID> LockTrace::mLocks;
map<pthread_mutex_t *, int> LockTrace::mWaitTimes;
map<long long, pthread_mutex_t *> LockTrace::mWaitLocks;
map<long long, set<pthread_mutex_t *>> LockTrace::mOwnLocks;
set<pthread_mutex_t *> LockTrace::mEnableRecurisives;
map<pthread_mutex_t *, LockTrace::LockID> LockTrace::mLocks;
map<pthread_mutex_t *, int> LockTrace::mWaitTimes;
map<long long, pthread_mutex_t *> LockTrace::mWaitLocks;
map<long long, set<pthread_mutex_t *>> LockTrace::mOwnLocks;
set<pthread_mutex_t *> LockTrace::mEnableRecurisives;

pthread_rwlock_t LockTrace::mMapMutex = PTHREAD_RWLOCK_INITIALIZER;
int LockTrace::mMaxBlockTids = 8;
Expand Down
2 changes: 1 addition & 1 deletion src/common/lang/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ char *substr(const char *s, int n1, int n2)
*/
string double_to_str(double v)
{
char buf[256];
char buf[256];
double rounded_v = round(v * 100.0) / 100.0;
snprintf(buf, sizeof(buf), "%.2f", rounded_v);
size_t len = strlen(buf);
Expand Down
41 changes: 23 additions & 18 deletions src/common/log/backtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ namespace common {

struct ProcMapSegment
{
uint64_t start_address;
uint64_t end_address;
uint64_t start_address;
uint64_t end_address;
};

class ProcMap
{
public:
ProcMap() = default;
ProcMap() = default;
~ProcMap() = default;

int parse();
Expand Down Expand Up @@ -58,21 +58,29 @@ int ProcMap::parse_file(const char *file_name)
}

ProcMapSegment segment;
char line[1024] = {0};
uint64_t start, end, inode, offset, major, minor;
char perms[8];
char path[257];
char line[1024] = {0};
uint64_t start, end, inode, offset, major, minor;
char perms[8];
char path[257];

while (fgets(line, sizeof(line), fp) != nullptr) {

int ret = sscanf(line, "%" PRIx64 "-%" PRIx64 " %4s %" PRIx64 " %" PRIx64 ":%" PRIx64 "%" PRIu64 "%255s",
&start, &end, perms, &offset, &major, &minor, &inode, path);

int ret = sscanf(line,
"%" PRIx64 "-%" PRIx64 " %4s %" PRIx64 " %" PRIx64 ":%" PRIx64 "%" PRIu64 "%255s",
&start,
&end,
perms,
&offset,
&major,
&minor,
&inode,
path);
if (ret < 8 || perms[2] != 'x') {
continue;
}

segment.start_address = start;
segment.end_address = end;
segment.end_address = end;

segments_.push_back(segment);
}
Expand Down Expand Up @@ -104,10 +112,7 @@ uint64_t ProcMap::get_offset(const uint64_t address) const

//////////////////////////////////////////////////////////////////////////
static ProcMap g_proc_map;
int backtrace_init()
{
return g_proc_map.parse();
}
int backtrace_init() { return g_proc_map.parse(); }

const char *lbt()
{
Expand All @@ -127,8 +132,8 @@ const char *lbt()

int offset = 0;
for (int i = 0; i < size && offset < bt_buffer_size - 1; i++) {
uint64_t address = reinterpret_cast<uint64_t>(buffer[i]);
address = g_proc_map.get_offset(address);
uint64_t address = reinterpret_cast<uint64_t>(buffer[i]);
address = g_proc_map.get_offset(address);
const char *format = (0 == i) ? "0x%lx" : " 0x%lx";
offset += snprintf(backtrace_buffer + offset, sizeof(backtrace_buffer) - offset, format, address);

Expand All @@ -143,4 +148,4 @@ const char *lbt()
return backtrace_buffer;
}

} // namespace common
} // namespace common
4 changes: 2 additions & 2 deletions src/common/log/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ int Log::rename_old_logs()

while (log_index < MAX_LOG_NUM) {
string log_name = log_name_ + "." + size_to_pad_str(log_index, 3);
int result = access(log_name.c_str(), R_OK);
int result = access(log_name.c_str(), R_OK);
if (result) {
break;
}
Expand Down Expand Up @@ -271,7 +271,7 @@ int Log::rotate_by_size()
char log_index_str[4] = {0};
snprintf(log_index_str, sizeof(log_index_str), "%03d", 1);
string log_name_new = log_name_ + "." + log_index_str;
result = rename(log_name_.c_str(), log_name_new.c_str());
result = rename(log_name_.c_str(), log_name_new.c_str());
if (result) {
cerr << "Failed to rename " << log_name_ << " to " << log_name_new << endl;
}
Expand Down
6 changes: 3 additions & 3 deletions src/common/os/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace common {
string getFileName(const string &fullPath)
{
string szRt;
size_t pos;
size_t pos;
try {
pos = fullPath.rfind(FILE_PATH_SPLIT);
if (pos != string::npos && pos < fullPath.size() - 1) {
Expand Down Expand Up @@ -63,7 +63,7 @@ void getFileName(const char *path, string &fileName)
string getDirName(const string &fullPath)
{
string szRt;
size_t pos;
size_t pos;
try {
pos = fullPath.rfind(FILE_PATH_SPLIT);
if (pos != string::npos && pos > 0) {
Expand Down Expand Up @@ -99,7 +99,7 @@ void getDirName(const char *path, string &parent)
string getFilePath(const string &fullPath)
{
string szRt;
size_t pos;
size_t pos;
try {
pos = fullPath.rfind("/");
if (pos != string::npos) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/os/pidfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int writePidFile(const char *progName)
{
assert(progName);
ofstream ostr;
int rv = 1;
int rv = 1;

setPidPath(progName);
string path = getPidPath();
Expand Down
48 changes: 24 additions & 24 deletions src/common/time/datetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ string DateTime::time_t_to_xml_str(time_t timet)
{
string ret_val;
ostringstream oss;
struct tm tmbuf;
tm *tm_info = gmtime_r(&timet, &tmbuf);
struct tm tmbuf;
tm *tm_info = gmtime_r(&timet, &tmbuf);
oss << tm_info->tm_year + 1900 << "-";
if ((tm_info->tm_mon + 1) <= 9)
oss << "0";
Expand All @@ -89,7 +89,7 @@ string DateTime::time_t_to_xml_str(time_t timet)

string DateTime::str_to_time_t_str(string &xml_str)
{
tm tmp;
tm tmp;
ostringstream oss;
sscanf(xml_str.c_str(),
"%04d-%02d-%02dT%02d:%02d:%02dZ",
Expand Down Expand Up @@ -126,7 +126,7 @@ string DateTime::to_xml_date_time()
{

string ret_val;
tm tm_info;
tm tm_info;
ostringstream oss;

tm_info = to_tm();
Expand Down Expand Up @@ -349,26 +349,26 @@ string Now::unique()
uint64_t temp;
static uint64_t last_unique = 0;
#if defined(LINUX)
#if defined(__MUSL__)
#define MUTEX_INITIALIZER(__mutex, __type) \
do { \
static pthread_mutexattr_t __attr; \
static pthread_mutexattr_t *__p_attr = nullptr; \
if (nullptr == __p_attr) { \
__p_attr = &__attr; \
pthread_mutexattr_init(__p_attr); \
pthread_mutexattr_settype(__p_attr, __type); \
pthread_mutex_init(&__mutex, __p_attr); \
} \
} while (0)

static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
MUTEX_INITIALIZER(mutex, PTHREAD_MUTEX_ERRORCHECK);

#undef MUTEX_INITIALIZER
#else
static pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
#endif
#if defined(__MUSL__)
#define MUTEX_INITIALIZER(__mutex, __type) \
do { \
static pthread_mutexattr_t __attr; \
static pthread_mutexattr_t *__p_attr = nullptr; \
if (nullptr == __p_attr) { \
__p_attr = &__attr; \
pthread_mutexattr_init(__p_attr); \
pthread_mutexattr_settype(__p_attr, __type); \
pthread_mutex_init(&__mutex, __p_attr); \
} \
} while (0)

static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
MUTEX_INITIALIZER(mutex, PTHREAD_MUTEX_ERRORCHECK);

#undef MUTEX_INITIALIZER
#else
static pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
#endif
#elif defined(__MACH__)
static pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/memtracer/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

#pragma once
//#include <sys/mman.h> // mmap/munmap
// #include <sys/mman.h> // mmap/munmap

#include "memtracer/common.h"
#include "memtracer/memtracer.h"
Expand Down
6 changes: 3 additions & 3 deletions src/oblsm/memtable/ob_memtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ void ObMemTable::put(uint64_t seq, const string_view &key, const string_view &va
// seq : uint64(sequence)
// value_size : value.size()
// value bytes : char[value.size()]
size_t user_key_size = key.size();
size_t user_key_size = key.size();
size_t val_size = value.size();
size_t internal_key_size = user_key_size + SEQ_SIZE;
const size_t encoded_len = sizeof(size_t) + internal_key_size + sizeof(size_t) + val_size;
char * buf = reinterpret_cast<char *>(arena_.alloc(encoded_len));
char * p = buf;
char *buf = reinterpret_cast<char *>(arena_.alloc(encoded_len));
char *p = buf;
memcpy(p, &internal_key_size, sizeof(size_t));
p += sizeof(size_t);
memcpy(p, key.data(), user_key_size);
Expand Down
13 changes: 5 additions & 8 deletions src/oblsm/table/ob_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ See the Mulan PSL v2 for more details. */

namespace oceanbase {

RC ObBlock::decode(const string &data)
{
return RC::UNIMPLEMENTED;
}
RC ObBlock::decode(const string &data) { return RC::UNIMPLEMENTED; }

string_view ObBlock::get_entry(uint32_t offset) const
{
Expand Down Expand Up @@ -52,7 +49,7 @@ string BlockMeta::encode() const

RC BlockMeta::decode(const string &data)
{
RC rc = RC::SUCCESS;
RC rc = RC::SUCCESS;
const char *data_ptr = data.c_str();
uint32_t first_key_size = get_numeric<uint32_t>(data_ptr);
data_ptr += sizeof(uint32_t);
Expand All @@ -70,13 +67,13 @@ RC BlockMeta::decode(const string &data)

void BlockIterator::seek(const string_view &lookup_key)
{
index_ = 0;
while(valid()) {
index_ = 0;
while (valid()) {
parse_entry();
if (comparator_->compare(extract_user_key(key_), extract_user_key_from_lookup_key(lookup_key)) >= 0) {
break;
}
index_++;
}
}
}
} // namespace oceanbase
4 changes: 2 additions & 2 deletions src/oblsm/table/ob_merger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class ObMergingIterator : public ObLsmIterator
// We might want to use a heap in case there are lots of children.
// For now we use a simple array since we expect a very small number
// of children.
const ObComparator * comparator_;
const ObComparator *comparator_;
vector<unique_ptr<ObLsmIterator>> children_;
ObLsmIterator * current_;
ObLsmIterator *current_;
};

void ObMergingIterator::find_smallest()
Expand Down
3 changes: 2 additions & 1 deletion src/oblsm/table/ob_sstable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ void TableIterator::seek(const string_view &lookup_key)
// TODO: use binary search
for (; curr_block_idx_ < block_cnt_; curr_block_idx_++) {
const auto &block_meta = sst_->block_meta(curr_block_idx_);
if (sst_->comparator()->compare(extract_user_key(block_meta.last_key_), extract_user_key_from_lookup_key(lookup_key)) >= 0) {
if (sst_->comparator()->compare(
extract_user_key(block_meta.last_key_), extract_user_key_from_lookup_key(lookup_key)) >= 0) {
break;
}
}
Expand Down
14 changes: 4 additions & 10 deletions src/oblsm/util/ob_file_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@ string ObFileReader::read_pos(uint32_t pos, uint32_t size)
LOG_WARN("Failed to read file %s, read_size=%ld, size=%ld", filename_.c_str(), read_size, size);
return "";
}

return buf;
}

uint32_t ObFileReader::file_size()
{
return filesystem::file_size(filename_);
}
uint32_t ObFileReader::file_size() { return filesystem::file_size(filename_); }

unique_ptr<ObFileReader> ObFileReader::create_file_reader(const string &filename)
{
Expand All @@ -50,17 +47,14 @@ unique_ptr<ObFileReader> ObFileReader::create_file_reader(const string &filename
RC ObFileReader::open_file()
{
RC rc = RC::SUCCESS;
fd_ = ::open(filename_.c_str(), O_RDONLY);
fd_ = ::open(filename_.c_str(), O_RDONLY);
if (fd_ < 0) {
LOG_WARN("Failed to open file %s", filename_.c_str());
rc = RC::INTERNAL;
}
return rc;
}

void ObFileReader::close_file()
{
::close(fd_);
}
void ObFileReader::close_file() { ::close(fd_); }

} // namespace oceanbase
Loading