mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-17 13:13:36 +00:00
Refactor
This commit is contained in:
parent
e6a1124ebe
commit
163a416366
@ -431,16 +431,20 @@ std::string StackTrace::toString(void ** frame_pointers_, size_t offset, size_t
|
||||
return toStringStatic(frame_pointers_copy, offset, size);
|
||||
}
|
||||
|
||||
std::string StackTrace::toStringStatic(const StackTrace::FramePointers & frame_pointers, size_t offset, size_t size, bool reload)
|
||||
static SimpleCache<decltype(toStringImpl), &toStringImpl> & cacheInstance()
|
||||
{
|
||||
static SimpleCache<decltype(toStringImpl), &toStringImpl> cache;
|
||||
return cache;
|
||||
}
|
||||
|
||||
std::string StackTrace::toStringStatic(const StackTrace::FramePointers & frame_pointers, size_t offset, size_t size)
|
||||
{
|
||||
/// Calculation of stack trace text is extremely slow.
|
||||
/// We use simple cache because otherwise the server could be overloaded by trash queries.
|
||||
static SimpleCache<decltype(toStringImpl), &toStringImpl> func_cached;
|
||||
/// Reload cached stacktrace instead.
|
||||
if (reload)
|
||||
{
|
||||
func_cached.drop();
|
||||
return "";
|
||||
}
|
||||
return func_cached(frame_pointers, offset, size);
|
||||
return cacheInstance()(frame_pointers, offset, size);
|
||||
}
|
||||
|
||||
void StackTrace::dropCache()
|
||||
{
|
||||
cacheInstance().drop();
|
||||
}
|
||||
|
@ -61,7 +61,8 @@ public:
|
||||
std::string toString() const;
|
||||
|
||||
static std::string toString(void ** frame_pointers, size_t offset, size_t size);
|
||||
static std::string toStringStatic(const FramePointers & frame_pointers, size_t offset, size_t size, bool reload = false);
|
||||
static std::string toStringStatic(const FramePointers & frame_pointers, size_t offset, size_t size);
|
||||
static void dropCache();
|
||||
static void symbolize(const FramePointers & frame_pointers, size_t offset, size_t size, StackTrace::Frames & frames);
|
||||
|
||||
void toStringEveryLine(std::function<void(const std::string &)> callback) const;
|
||||
|
@ -462,16 +462,22 @@ String SymbolIndex::getBuildIDHex() const
|
||||
return build_id_hex;
|
||||
}
|
||||
|
||||
MultiVersion<SymbolIndex>::Version SymbolIndex::instance(bool reload)
|
||||
MultiVersion<SymbolIndex> & SymbolIndex::instanceImpl()
|
||||
{
|
||||
static MultiVersion<SymbolIndex> instance(std::unique_ptr<SymbolIndex>(new SymbolIndex));
|
||||
if (reload)
|
||||
{
|
||||
instance.set(std::unique_ptr<SymbolIndex>(new SymbolIndex));
|
||||
/// Also reload stacktrace cache.
|
||||
StackTrace::toStringStatic({}, 0, 0, true);
|
||||
}
|
||||
return instance.get();
|
||||
return instance;
|
||||
}
|
||||
|
||||
MultiVersion<SymbolIndex>::Version SymbolIndex::instance()
|
||||
{
|
||||
return instanceImpl().get();
|
||||
}
|
||||
|
||||
void SymbolIndex::reload()
|
||||
{
|
||||
instanceImpl().set(std::unique_ptr<SymbolIndex>(new SymbolIndex));
|
||||
/// Also drop stacktrace cache.
|
||||
StackTrace::dropCache();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,7 +22,8 @@ protected:
|
||||
SymbolIndex() { update(); }
|
||||
|
||||
public:
|
||||
static MultiVersion<SymbolIndex>::Version instance(bool reload = false);
|
||||
static MultiVersion<SymbolIndex>::Version instance();
|
||||
static void reload();
|
||||
|
||||
struct Symbol
|
||||
{
|
||||
@ -60,6 +61,7 @@ private:
|
||||
Data data;
|
||||
|
||||
void update();
|
||||
static MultiVersion<SymbolIndex> & instanceImpl();
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -337,7 +337,7 @@ BlockIO InterpreterSystemQuery::execute()
|
||||
{
|
||||
#if defined(__ELF__) && !defined(__FreeBSD__)
|
||||
getContext()->checkAccess(AccessType::SYSTEM_RELOAD_SYMBOLS);
|
||||
(void)SymbolIndex::instance(true);
|
||||
SymbolIndex::reload();
|
||||
break;
|
||||
#else
|
||||
throw Exception("SYSTEM RELOAD SYMBOLS is not supported on current platform", ErrorCodes::NOT_IMPLEMENTED);
|
||||
|
Loading…
Reference in New Issue
Block a user