index: shorten indexer thread names

`BaseIndex` currently uses the same name for logs, `getindexinfo`, prune locks, and the sync thread.
Linux truncates system thread names to 15 visible bytes after the `b-` prefix, so long indexer names are clipped in system tools.

Pass a separate thread name explicitly at each `BaseIndex` call site and shorten the OS-visible indexer names to `txidx`, `blkfltbscidx`, `coinstatsidx`, and `txospenderidx`.
Add an `Assume` to `ThreadRename()` so future OS-visible thread names keep fitting the same Linux limit.
The public index names, `getindexinfo` keys, command-line options, and on-disk paths stay unchanged.

Co-authored-by: winterrdog <winterrdog@users.noreply.github.com>
Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com>
Co-authored-by: sedited <seb.kung@gmail.com>
Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
This commit is contained in:
Lőrinc
2026-05-20 14:57:19 +03:00
parent d69c46292d
commit d3e40af259
11 changed files with 29 additions and 18 deletions

View File

@@ -708,7 +708,7 @@ and its `cs_KeyStore` lock for example).
- [HTTP worker threads (`b-http.xx`)](https://doxygen.bitcoincore.org/httpserver_8cpp.html#http_pool)
: Threads to service RPC and REST requests.
- [Indexer threads (`b-txindex`, etc)](https://doxygen.bitcoincore.org/class_base_index.html#index_sync)
- [Indexer threads (`b-txidx`, `b-blkfltbscidx`, `b-coinstatsidx`, `b-txospenderidx`)](https://doxygen.bitcoincore.org/class_base_index.html#index_sync)
: One thread per indexer.
- [SchedulerThread (`b-scheduler`)](https://doxygen.bitcoincore.org/class_c_scheduler.html#scheduler)

View File

@@ -92,8 +92,8 @@ void BaseIndex::DB::WriteBestBlock(CDBBatch& batch, const CBlockLocator& locator
batch.Write(DB_BEST_BLOCK, locator);
}
BaseIndex::BaseIndex(std::unique_ptr<interfaces::Chain> chain, std::string name)
: m_chain{std::move(chain)}, m_name{std::move(name)} {}
BaseIndex::BaseIndex(std::unique_ptr<interfaces::Chain> chain, std::string name, std::string thread_name)
: m_chain{std::move(chain)}, m_name{std::move(name)}, m_thread_name{std::move(thread_name)} {}
BaseIndex::~BaseIndex()
{
@@ -460,7 +460,7 @@ bool BaseIndex::StartBackgroundSync()
{
if (!m_init) throw std::logic_error("Error: Cannot start a non-initialized index");
m_thread_sync = std::thread(&util::TraceThread, GetName(), [this] { Sync(); });
m_thread_sync = std::thread(&util::TraceThread, m_thread_name, [this] { Sync(); });
return true;
}

View File

@@ -117,6 +117,7 @@ protected:
std::unique_ptr<interfaces::Chain> m_chain;
Chainstate* m_chainstate{nullptr};
const std::string m_name;
const std::string m_thread_name;
void BlockConnected(const kernel::ChainstateRole& role, const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex) override;
@@ -141,7 +142,7 @@ protected:
void SetBestBlockIndex(const CBlockIndex* block);
public:
BaseIndex(std::unique_ptr<interfaces::Chain> chain, std::string name);
BaseIndex(std::unique_ptr<interfaces::Chain> chain, std::string name, std::string thread_name);
/// Destructor interrupts sync thread if running and blocks until it exits.
virtual ~BaseIndex();

View File

@@ -61,6 +61,15 @@ constexpr size_t CF_HEADERS_CACHE_MAX_SZ{2000};
namespace {
std::string BlockFilterThreadName(BlockFilterType filter_type)
{
switch (filter_type) {
case BlockFilterType::BASIC: return "blkfltbscidx";
case BlockFilterType::INVALID: return "";
} // no default case, so the compiler can warn about missing cases
assert(false);
}
struct DBVal {
uint256 hash;
uint256 header;
@@ -75,7 +84,7 @@ static std::map<BlockFilterType, BlockFilterIndex> g_filter_indexes;
BlockFilterIndex::BlockFilterIndex(std::unique_ptr<interfaces::Chain> chain, BlockFilterType filter_type,
size_t n_cache_size, bool f_memory, bool f_wipe)
: BaseIndex(std::move(chain), BlockFilterTypeName(filter_type) + " block filter index")
: BaseIndex(std::move(chain), BlockFilterTypeName(filter_type) + " block filter index", BlockFilterThreadName(filter_type))
, m_filter_type(filter_type)
{
const std::string& filter_name = BlockFilterTypeName(filter_type);

View File

@@ -87,7 +87,7 @@ struct DBVal {
std::unique_ptr<CoinStatsIndex> g_coin_stats_index;
CoinStatsIndex::CoinStatsIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory, bool f_wipe)
: BaseIndex(std::move(chain), "coinstatsindex")
: BaseIndex(std::move(chain), "coinstatsindex", "coinstatsidx")
{
// An earlier version of the index used "indexes/coinstats" but it contained
// a bug and is superseded by a fixed version at "indexes/coinstatsindex".

View File

@@ -66,7 +66,7 @@ void TxIndex::DB::WriteTxs(const std::vector<std::pair<Txid, CDiskTxPos>>& v_pos
}
TxIndex::TxIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory, bool f_wipe)
: BaseIndex(std::move(chain), "txindex"), m_db(std::make_unique<TxIndex::DB>(n_cache_size, f_memory, f_wipe))
: BaseIndex(std::move(chain), "txindex", "txidx"), m_db(std::make_unique<TxIndex::DB>(n_cache_size, f_memory, f_wipe))
{}
TxIndex::~TxIndex() = default;

View File

@@ -60,7 +60,7 @@ struct DBKey {
};
TxoSpenderIndex::TxoSpenderIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory, bool f_wipe)
: BaseIndex(std::move(chain), "txospenderindex"), m_db{std::make_unique<DB>(gArgs.GetDataDirNet() / "indexes" / "txospenderindex" / "db", n_cache_size, f_memory, f_wipe)}
: BaseIndex(std::move(chain), "txospenderindex", "txospenderidx"), m_db{std::make_unique<DB>(gArgs.GetDataDirNet() / "indexes" / "txospenderindex" / "db", n_cache_size, f_memory, f_wipe)}
{
if (!m_db->Read("siphash_key", m_siphash_key)) {
FastRandomContext rng(false);

View File

@@ -338,9 +338,8 @@ private:
int m_blocking_height;
public:
explicit IndexReorgCrash(std::unique_ptr<interfaces::Chain> chain, std::shared_future<void> blocker,
int blocking_height, FakeNodeClock& clock)
: BaseIndex(std::move(chain), "test index"), m_clock(clock), m_blocker(blocker), m_blocking_height(blocking_height)
explicit IndexReorgCrash(std::unique_ptr<interfaces::Chain> chain, std::shared_future<void> blocker, int blocking_height, FakeNodeClock& clock)
: BaseIndex(std::move(chain), "test index", "testidx"), m_clock(clock), m_blocker(blocker), m_blocking_height(blocking_height)
{
const fs::path path = gArgs.GetDataDirNet() / "index";
fs::create_directories(path);

View File

@@ -17,7 +17,7 @@ using util::ToString;
BOOST_AUTO_TEST_SUITE(util_threadnames_tests)
const std::string TEST_THREAD_NAME_BASE = "test_thread.";
const std::string TEST_THREAD_NAME_BASE = "test_thrd.";
/**
* Run a bunch of threads to all call util::ThreadRename.
@@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE(util_threadnames_test_rename_threaded)
BOOST_CHECK_EQUAL(names.size(), 100U);
// Names "test_thread.[n]" should exist for n = [0, 99]
// Names "test_thrd.[n]" should exist for n = [0, 99]
for (int i = 0; i < 100; ++i) {
BOOST_CHECK(names.contains(TEST_THREAD_NAME_BASE + ToString(i)));
}

View File

@@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <util/threadnames.h>
#include <util/check.h>
#include <algorithm>
#include <cstring>
@@ -53,6 +54,7 @@ static void SetInternalName(const std::string& name)
void util::ThreadRename(const std::string& name)
{
Assume(name.size() <= 13); // Linux keeps 15 bytes
SetThreadName(("b-" + name).c_str());
SetInternalName(name);
}

View File

@@ -77,10 +77,10 @@ class InitTest(BitcoinTestFramework):
b'net thread start',
b'addcon thread start',
b'initload thread start',
b'txindex thread start',
b'block filter index thread start',
b'coinstatsindex thread start',
b'txospenderindex thread start',
b'txidx thread start',
b'blkfltbscidx thread start',
b'coinstatsidx thread start',
b'txospenderidx thread start',
b'msghand thread start',
b'net thread start',
b'addcon thread start',