fix auto & lambda
This commit is contained in:
129
deps/oblib/src/lib/trace/ob_trace.cpp
vendored
129
deps/oblib/src/lib/trace/ob_trace.cpp
vendored
@ -53,67 +53,64 @@ thread_local ObTrace* ObTrace::save_buffer = nullptr;
|
||||
|
||||
void flush_trace()
|
||||
{
|
||||
auto& trace = *OBTRACE;
|
||||
auto& current_span = trace.current_span_;
|
||||
ObTrace& trace = *OBTRACE;
|
||||
common::ObDList<ObSpanCtx>& current_span = trace.current_span_;
|
||||
if (trace.is_inited() && !current_span.is_empty()) {
|
||||
auto func = [&] {
|
||||
auto* span = current_span.get_first();
|
||||
::oceanbase::trace::ObSpanCtx* next = nullptr;
|
||||
while (current_span.get_header() != span) {
|
||||
auto* next = span->get_next();
|
||||
if (nullptr != span->tags_ || 0 != span->end_ts_) {
|
||||
int64_t pos = 0;
|
||||
thread_local char buf[MAX_TRACE_LOG_SIZE];
|
||||
int ret = OB_SUCCESS;
|
||||
auto* tag = span->tags_;
|
||||
bool first = true;
|
||||
INIT_SPAN(span);
|
||||
while (OB_SUCC(ret) && OB_NOT_NULL(tag)) {
|
||||
if (pos + 10 >= MAX_TRACE_LOG_SIZE) {
|
||||
ret = OB_BUF_NOT_ENOUGH;
|
||||
} else {
|
||||
buf[pos++] = ',';
|
||||
if (first) {
|
||||
strcpy(buf + pos, "\"tags\":[");
|
||||
pos += 8;
|
||||
first = false;
|
||||
}
|
||||
ret = tag->tostring(buf, MAX_TRACE_LOG_SIZE, pos);
|
||||
tag = tag->next_;
|
||||
ObSpanCtx* span = current_span.get_first();
|
||||
ObSpanCtx* next = nullptr;
|
||||
while (current_span.get_header() != span) {
|
||||
ObSpanCtx* next = span->get_next();
|
||||
if (nullptr != span->tags_ || 0 != span->end_ts_) {
|
||||
int64_t pos = 0;
|
||||
thread_local char buf[MAX_TRACE_LOG_SIZE];
|
||||
int ret = OB_SUCCESS;
|
||||
ObTagCtxBase* tag = span->tags_;
|
||||
bool first = true;
|
||||
INIT_SPAN(span);
|
||||
while (OB_SUCC(ret) && OB_NOT_NULL(tag)) {
|
||||
if (pos + 10 >= MAX_TRACE_LOG_SIZE) {
|
||||
ret = OB_BUF_NOT_ENOUGH;
|
||||
} else {
|
||||
buf[pos++] = ',';
|
||||
if (first) {
|
||||
strcpy(buf + pos, "\"tags\":[");
|
||||
pos += 8;
|
||||
first = false;
|
||||
}
|
||||
ret = tag->tostring(buf, MAX_TRACE_LOG_SIZE, pos);
|
||||
tag = tag->next_;
|
||||
}
|
||||
if (0 != pos) {
|
||||
if (pos + 1 < MAX_TRACE_LOG_SIZE) {
|
||||
buf[pos++] = ']';
|
||||
buf[pos++] = 0;
|
||||
} else {
|
||||
buf[MAX_TRACE_LOG_SIZE - 2] = ']';
|
||||
buf[MAX_TRACE_LOG_SIZE - 1] = 0;
|
||||
}
|
||||
}
|
||||
INIT_SPAN(span->source_span_);
|
||||
_FLT_LOG(INFO,
|
||||
TRACE_PATTERN "%s}",
|
||||
UUID_TOSTRING(trace.get_trace_id()),
|
||||
__span_type_mapper[span->span_type_],
|
||||
UUID_TOSTRING(span->span_id_),
|
||||
span->start_ts_,
|
||||
span->end_ts_,
|
||||
UUID_TOSTRING(OB_ISNULL(span->source_span_) ? OBTRACE->get_root_span_id() : span->source_span_->span_id_),
|
||||
span->is_follow_ ? "true" : "false",
|
||||
buf);
|
||||
buf[0] = '\0';
|
||||
IGNORE_RETURN sql::handle_span_record(sql::get_flt_span_manager(), buf, pos, span);
|
||||
if (0 != span->end_ts_) {
|
||||
current_span.remove(span);
|
||||
trace.freed_span_.add_first(span);
|
||||
}
|
||||
span->tags_ = nullptr;
|
||||
}
|
||||
span = next;
|
||||
if (0 != pos) {
|
||||
if (pos + 1 < MAX_TRACE_LOG_SIZE) {
|
||||
buf[pos++] = ']';
|
||||
buf[pos++] = 0;
|
||||
} else {
|
||||
buf[MAX_TRACE_LOG_SIZE - 2] = ']';
|
||||
buf[MAX_TRACE_LOG_SIZE - 1] = 0;
|
||||
}
|
||||
}
|
||||
INIT_SPAN(span->source_span_);
|
||||
_FLT_LOG(INFO,
|
||||
TRACE_PATTERN "%s}",
|
||||
UUID_TOSTRING(trace.get_trace_id()),
|
||||
__span_type_mapper[span->span_type_],
|
||||
UUID_TOSTRING(span->span_id_),
|
||||
span->start_ts_,
|
||||
span->end_ts_,
|
||||
UUID_TOSTRING(OB_ISNULL(span->source_span_) ? OBTRACE->get_root_span_id() : span->source_span_->span_id_),
|
||||
span->is_follow_ ? "true" : "false",
|
||||
buf);
|
||||
buf[0] = '\0';
|
||||
IGNORE_RETURN sql::handle_span_record(sql::get_flt_span_manager(), buf, pos, span);
|
||||
if (0 != span->end_ts_) {
|
||||
current_span.remove(span);
|
||||
trace.freed_span_.add_first(span);
|
||||
}
|
||||
span->tags_ = nullptr;
|
||||
}
|
||||
};
|
||||
func();
|
||||
span = next;
|
||||
}
|
||||
trace.offset_ = trace.buffer_size_ / 2;
|
||||
}
|
||||
}
|
||||
@ -136,7 +133,7 @@ UUID UUID::gen()
|
||||
UUID::UUID(const char* uuid)
|
||||
{
|
||||
high_ = low_ = 0;
|
||||
for (auto i = 0; i < 18; ++i) {
|
||||
for (int i = 0; i < 18; ++i) {
|
||||
if (8 == i || 13 == i) {
|
||||
continue;
|
||||
} else if (uuid[i] >= '0' && uuid[i] <= '9') {
|
||||
@ -149,7 +146,7 @@ UUID::UUID(const char* uuid)
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (auto i = 19; i < 36; ++i) {
|
||||
for (int i = 19; i < 36; ++i) {
|
||||
if (23 == i) {
|
||||
continue;
|
||||
} else if (uuid[i] >= '0' && uuid[i] <= '9') {
|
||||
@ -240,9 +237,9 @@ int to_string_and_strip(const char* str, const int64_t length, char* buf, const
|
||||
char from[] = "\"\n\r\\\t";
|
||||
const char* to[] = { "\\\"", "\\n", "\\r", "\\\\", " "};
|
||||
buf[pos++] = '\"';
|
||||
for (auto j = 0; j < length && str[j]; ++j) {
|
||||
for (int j = 0; j < length && str[j]; ++j) {
|
||||
bool conv = false;
|
||||
for (auto i = 0; i < sizeof(from) - 1; ++i) {
|
||||
for (int i = 0; i < sizeof(from) - 1; ++i) {
|
||||
if (from[i] == str[j]) {
|
||||
for (const char* toc = to[i]; *toc; ++toc) {
|
||||
if (pos < buf_len) {
|
||||
@ -368,7 +365,7 @@ ObTrace::ObTrace(int64_t buffer_size)
|
||||
policy_(0),
|
||||
seq_(0)
|
||||
{
|
||||
for (auto i = 0; i < (offset_ / sizeof(ObSpanCtx)); ++i) {
|
||||
for (int i = 0; i < (offset_ / sizeof(ObSpanCtx)); ++i) {
|
||||
IGNORE_RETURN freed_span_.add_last(new(data_ + i * sizeof(ObSpanCtx)) ObSpanCtx);
|
||||
}
|
||||
}
|
||||
@ -475,9 +472,9 @@ void ObTrace::reset_span()
|
||||
#endif
|
||||
// remove all end span
|
||||
if (is_inited() && !current_span_.is_empty()) {
|
||||
auto* span = current_span_.get_first();
|
||||
ObSpanCtx* span = current_span_.get_first();
|
||||
while (current_span_.get_header() != span) {
|
||||
auto* next = span->get_next();
|
||||
ObSpanCtx* next = span->get_next();
|
||||
if (0 != span->end_ts_) {
|
||||
current_span_.remove(span);
|
||||
freed_span_.add_first(span);
|
||||
@ -492,9 +489,9 @@ void ObTrace::reset_span()
|
||||
int ObTrace::serialize(char* buf, const int64_t buf_len, int64_t& pos) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
auto* span = const_cast<ObTrace*>(this)->last_active_span_;
|
||||
ObSpanCtx* span = const_cast<ObTrace*>(this)->last_active_span_;
|
||||
INIT_SPAN(span);
|
||||
auto& span_id = span == nullptr ? root_span_id_ : span->span_id_;
|
||||
const UUID& span_id = span == nullptr ? root_span_id_ : span->span_id_;
|
||||
if (OB_FAIL(trace_id_.serialize(buf, buf_len, pos))) {
|
||||
// LOG_WARN("serialize failed", K(ret), K(buf), K(buf_len), K(pos));
|
||||
} else if (OB_FAIL(span_id.serialize(buf, buf_len, pos))) {
|
||||
@ -557,7 +554,7 @@ void ObTrace::dump_span()
|
||||
char buf[buf_len];
|
||||
int64_t pos = 0;
|
||||
int ret = OB_SUCCESS;
|
||||
auto* span = current_span_.get_first();
|
||||
ObSpanCtx* span = current_span_.get_first();
|
||||
IGNORE_RETURN databuff_printf(buf, buf_len, pos, "active_span: ");
|
||||
while (OB_SUCC(ret) && current_span_.get_header() != span) {
|
||||
if (0 == span->end_ts_) {
|
||||
|
4
deps/oblib/src/lib/trace/ob_trace.h
vendored
4
deps/oblib/src/lib/trace/ob_trace.h
vendored
@ -144,7 +144,7 @@ struct ObTagCtxBase
|
||||
virtual int tostring(char* buf, const int64_t buf_len, int64_t& pos)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const auto l = strlen(__tag_name_mapper[tag_type_]);
|
||||
const size_t l = strlen(__tag_name_mapper[tag_type_]);
|
||||
if (pos + l + 7 >= buf_len) {
|
||||
buf[std::min(pos - 1, buf_len - 1)] = '\0';
|
||||
ret = OB_BUF_NOT_ENOUGH;
|
||||
@ -320,7 +320,7 @@ struct ObTrace
|
||||
} else {
|
||||
v = value;
|
||||
}
|
||||
auto l = v.length();
|
||||
int32_t l = v.length();
|
||||
if (offset_ + sizeof(ObTagCtx<void*>) + l + 1 - sizeof(void*) >= buffer_size_) {
|
||||
// do nothing
|
||||
} else {
|
||||
|
@ -76,22 +76,27 @@ void *ObLuaHandler::realloc_functor(void *userdata, void *ptr, size_t osize, siz
|
||||
int ObLuaHandler::process(const char* lua_code)
|
||||
{
|
||||
bool has_segv = false;
|
||||
auto func = [&, lua_code] {
|
||||
OB_LOG(INFO, "Lua code was executed", K(alloc_count_), K(free_count_), K(alloc_size_), K(free_size_));
|
||||
lua_State* L = lua_newstate(realloc_functor, nullptr);
|
||||
if (OB_ISNULL(L)) {
|
||||
OB_LOG_RET(ERROR, OB_INVALID_ARGUMENT, "luastate is NULL");
|
||||
} else {
|
||||
luaL_openlibs(L);
|
||||
APIRegister::get_instance().register_api(L);
|
||||
try {
|
||||
luaL_dostring(L, lua_code);
|
||||
} catch (std::exception& e) {
|
||||
_OB_LOG_RET(ERROR, OB_ERR_UNEXPECTED, "exception during lua code execution, reason %s", e.what());
|
||||
struct LuaExec {
|
||||
LuaExec(const char* lua_code) : code_(lua_code) {}
|
||||
void operator()() {
|
||||
lua_State* L = lua_newstate(realloc_functor, nullptr);
|
||||
if (OB_ISNULL(L)) {
|
||||
OB_LOG_RET(ERROR, OB_INVALID_ARGUMENT, "luastate is NULL");
|
||||
} else {
|
||||
luaL_openlibs(L);
|
||||
APIRegister::get_instance().register_api(L);
|
||||
try {
|
||||
luaL_dostring(L, code_);
|
||||
} catch (std::exception& e) {
|
||||
_OB_LOG_RET(ERROR, OB_ERR_UNEXPECTED, "exception during lua code execution, reason %s", e.what());
|
||||
}
|
||||
lua_close(L);
|
||||
}
|
||||
lua_close(L);
|
||||
}
|
||||
const char* code_;
|
||||
};
|
||||
OB_LOG(INFO, "Lua code was executed", K(alloc_count_), K(free_count_), K(alloc_size_), K(free_size_));
|
||||
LuaExec func(lua_code);
|
||||
do_with_crash_restore(func, has_segv);
|
||||
if (has_segv) {
|
||||
_OB_LOG(INFO, "restore from sigsegv, coredump during lua code execution at %s\n", crash_restore_buffer);
|
||||
@ -99,12 +104,18 @@ int ObLuaHandler::process(const char* lua_code)
|
||||
OB_LOG(INFO, "Lua code was executed successfully", K(alloc_count_), K(free_count_), K(alloc_size_), K(free_size_));
|
||||
}
|
||||
|
||||
do_with_crash_restore([&] {
|
||||
for (int64_t i = destructors_.size() - 1; i >= 0 ; --i) {
|
||||
destructors_[i]();
|
||||
struct LuaGC {
|
||||
LuaGC(common::ObVector<Function>& destructors) : destructors_(destructors) {}
|
||||
void operator()() {
|
||||
for (int64_t i = destructors_.size() - 1; i >= 0 ; --i) {
|
||||
destructors_[i]();
|
||||
}
|
||||
destructors_.clear();
|
||||
}
|
||||
destructors_.clear();
|
||||
}, has_segv);
|
||||
common::ObVector<Function>& destructors_;
|
||||
};
|
||||
LuaGC gc(destructors_);
|
||||
do_with_crash_restore(gc, has_segv);
|
||||
if (has_segv) {
|
||||
_OB_LOG(INFO, "restore from sigsegv, coredump during lua gc at %s\n", crash_restore_buffer);
|
||||
} else {
|
||||
|
@ -37,7 +37,7 @@ ObRsReentrantThread::~ObRsReentrantThread()
|
||||
|
||||
void ObRsReentrantThread::update_last_run_timestamp()
|
||||
{
|
||||
auto time = ObTimeUtility::current_time();
|
||||
int64_t time = ObTimeUtility::current_time();
|
||||
IGNORE_RETURN lib::Thread::update_loop_ts(time);
|
||||
if (ATOMIC_LOAD(&last_run_timestamp_) != -1) {
|
||||
ATOMIC_STORE(&last_run_timestamp_, time);
|
||||
|
@ -41,7 +41,7 @@ toUType(E enumerator) noexcept
|
||||
// Not support change log rate percentage of each task dynamically.
|
||||
class ObTaskController {
|
||||
using RateLimiter = lib::ObRateLimiter;
|
||||
static constexpr auto MAX_TASK_ID = toUType(ObTaskType::MAX);
|
||||
static constexpr int MAX_TASK_ID = toUType(ObTaskType::MAX);
|
||||
static constexpr int64_t LOG_RATE_LIMIT = 10 << 20;
|
||||
|
||||
public:
|
||||
|
Reference in New Issue
Block a user