fix: expore stop_indexer for outside-restarts

This commit is contained in:
erhant 2026-06-23 16:45:03 +03:00
parent 9ef0d453a9
commit 06396d7aec
2 changed files with 23 additions and 6 deletions

View File

@ -21,12 +21,8 @@ namespace {
} // namespace
LezIndexerModuleImpl::~LezIndexerModuleImpl() {
if (indexer_service_ffi) {
OperationStatus operation_result = stop_indexer(handle(indexer_service_ffi));
if (is_error(&operation_result)) {
warn("destructor", "indexer FFI error on stop");
}
indexer_service_ffi = nullptr;
if (stop_indexer() != 0) {
warn("destructor", "indexer FFI error on stop");
}
}
@ -50,6 +46,21 @@ int64_t LezIndexerModuleImpl::start_indexer(const std::string& config_path) {
return 0;
}
int64_t LezIndexerModuleImpl::stop_indexer() {
if (!indexer_service_ffi) {
return 0; // not running
}
// stop_indexer frees the handle; null ours before returning so a later start
// (or the destructor) doesn't double-free or operate on a dead pointer.
OperationStatus operation_result = ::stop_indexer(handle(indexer_service_ffi));
indexer_service_ffi = nullptr;
if (is_error(&operation_result)) {
warn("stop_indexer", "indexer FFI error on stop");
return static_cast<int64_t>(operation_result);
}
return 0;
}
void LezIndexerModuleImpl::init_logger(const std::string& level) {
::init_logger(level.c_str());
}

View File

@ -35,6 +35,12 @@ public:
/// as scalar wire types; a plain `int` return is treated as a JSON payload.
int64_t start_indexer(const std::string& config_path);
/// Stop ingestion and release the FFI handle. No-op (returns 0) when the
/// indexer isn't running. Pair with start_indexer to apply a new config:
/// stop, then start (start_indexer stays idempotent and won't restart on its
/// own). Returns 0 on success, else the FFI OperationStatus code.
int64_t stop_indexer();
/// Account by 32-byte hex id. The returned JSON omits the id; callers inject
/// the queried id themselves.
std::string getAccount(const std::string& account_id);