Merge pull request #51993 from azat/symbol-index-cleanup

Cleanup SymbolIndex after reload got removed
This commit is contained in:
Alexey Milovidov 2023-07-10 00:58:16 +03:00 committed by GitHub
commit dd80bdb859
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 16 additions and 29 deletions

View File

@ -208,8 +208,7 @@ void StackTrace::symbolize(
const StackTrace::FramePointers & frame_pointers, [[maybe_unused]] size_t offset, size_t size, StackTrace::Frames & frames)
{
#if defined(__ELF__) && !defined(OS_FREEBSD)
auto symbol_index_ptr = DB::SymbolIndex::instance();
const DB::SymbolIndex & symbol_index = *symbol_index_ptr;
const DB::SymbolIndex & symbol_index = DB::SymbolIndex::instance();
std::unordered_map<std::string, DB::Dwarf> dwarfs;
for (size_t i = 0; i < offset; ++i)
@ -341,8 +340,7 @@ toStringEveryLineImpl([[maybe_unused]] bool fatal, const StackTraceRefTriple & s
using enum DB::Dwarf::LocationInfoMode;
const auto mode = fatal ? FULL_WITH_INLINE : FAST;
auto symbol_index_ptr = DB::SymbolIndex::instance();
const DB::SymbolIndex & symbol_index = *symbol_index_ptr;
const DB::SymbolIndex & symbol_index = DB::SymbolIndex::instance();
std::unordered_map<String, DB::Dwarf> dwarfs;
for (size_t i = stack_trace.offset; i < stack_trace.size; ++i)

View File

@ -509,7 +509,7 @@ const T * find(const void * address, const std::vector<T> & vec)
}
void SymbolIndex::update()
void SymbolIndex::load()
{
dl_iterate_phdr(collectSymbols, &data);
@ -549,17 +549,12 @@ String SymbolIndex::getBuildIDHex() const
return build_id_hex;
}
MultiVersion<SymbolIndex> & SymbolIndex::instanceImpl()
const SymbolIndex & SymbolIndex::instance()
{
static MultiVersion<SymbolIndex> instance(std::unique_ptr<SymbolIndex>(new SymbolIndex));
static SymbolIndex instance;
return instance;
}
MultiVersion<SymbolIndex>::Version SymbolIndex::instance()
{
return instanceImpl().get();
}
}
#endif

View File

@ -8,8 +8,6 @@
#include <Common/Elf.h>
#include <boost/noncopyable.hpp>
#include <Common/MultiVersion.h>
namespace DB
{
@ -20,10 +18,10 @@ namespace DB
class SymbolIndex : private boost::noncopyable
{
protected:
SymbolIndex() { update(); }
SymbolIndex() { load(); }
public:
static MultiVersion<SymbolIndex>::Version instance();
static const SymbolIndex & instance();
struct Symbol
{
@ -89,8 +87,7 @@ public:
private:
Data data;
void update();
static MultiVersion<SymbolIndex> & instanceImpl();
void load();
};
}

View File

@ -22,8 +22,7 @@ int main(int argc, char ** argv)
return 1;
}
auto symbol_index_ptr = SymbolIndex::instance();
const SymbolIndex & symbol_index = *symbol_index_ptr;
const SymbolIndex & symbol_index = SymbolIndex::instance();
for (const auto & elem : symbol_index.symbols())
std::cout << elem.name << ": " << elem.address_begin << " ... " << elem.address_end << "\n";

View File

@ -16,7 +16,7 @@ std::string_view getResource(std::string_view name)
#if defined USE_MUSL
/// If static linking is used, we cannot use dlsym and have to parse ELF symbol table by ourself.
return DB::SymbolIndex::instance()->getResource(name_replaced);
return DB::SymbolIndex::instance().getResource(name_replaced);
#else
// In most `dlsym(3)` APIs, one passes the symbol name as it appears via

View File

@ -986,7 +986,7 @@ void BaseDaemon::initializeTerminationAndSignalProcessing()
signal_listener_thread.start(*signal_listener);
#if defined(__ELF__) && !defined(OS_FREEBSD)
String build_id_hex = SymbolIndex::instance()->getBuildIDHex();
String build_id_hex = SymbolIndex::instance().getBuildIDHex();
if (build_id_hex.empty())
build_id = "";
else

View File

@ -150,7 +150,7 @@ void SentryWriter::onFault(int sig, const std::string & error_message, const Sta
sentry_set_extra("signal_number", sentry_value_new_int32(sig));
#if defined(__ELF__) && !defined(OS_FREEBSD)
const String & build_id_hex = DB::SymbolIndex::instance()->getBuildIDHex();
const String & build_id_hex = DB::SymbolIndex::instance().getBuildIDHex();
sentry_set_tag("build_id", build_id_hex.c_str());
#endif

View File

@ -90,8 +90,7 @@ protected:
ResultT impl(uintptr_t addr) const
{
auto symbol_index_ptr = SymbolIndex::instance();
const SymbolIndex & symbol_index = *symbol_index_ptr;
const SymbolIndex & symbol_index = SymbolIndex::instance();
if (const auto * object = symbol_index.findObject(reinterpret_cast<const void *>(addr)))
{

View File

@ -68,8 +68,7 @@ public:
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override
{
auto symbol_index_ptr = SymbolIndex::instance();
const SymbolIndex & symbol_index = *symbol_index_ptr;
const SymbolIndex & symbol_index = SymbolIndex::instance();
const ColumnPtr & column = arguments[0].column;
const ColumnUInt64 * column_concrete = checkAndGetColumn<ColumnUInt64>(column.get());

View File

@ -27,7 +27,7 @@ namespace
public:
static constexpr auto name = "buildId";
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionBuildId>(context); }
explicit FunctionBuildId(ContextPtr context) : FunctionConstantBase(SymbolIndex::instance()->getBuildIDHex(), context->isDistributed()) {}
explicit FunctionBuildId(ContextPtr context) : FunctionConstantBase(SymbolIndex::instance().getBuildIDHex(), context->isDistributed()) {}
};
#endif

View File

@ -52,7 +52,7 @@ void CrashLogElement::appendToBlock(MutableColumns & columns) const
String build_id_hex;
#if defined(__ELF__) && !defined(OS_FREEBSD)
build_id_hex = SymbolIndex::instance()->getBuildIDHex();
build_id_hex = SymbolIndex::instance().getBuildIDHex();
#endif
columns[i++]->insert(build_id_hex);
}