Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Fix batch indexer shutdown sequence.

Kishore Nallan0ace552ed73e
diff --git a/src/typesense_server_utils.cpp b/src/typesense_server_utils.cpp
index 832c8d14..e7ab2586 100644
--- a/src/typesense_server_utils.cpp
+++ b/src/typesense_server_utils.cpp
@@ -391,11 +391,11 @@ int run_server(const Config & config, const std::string & version, void (*master
bool ssl_enabled = (!config.get_ssl_cert().empty() && !config.get_ssl_cert_key().empty());
- BatchedIndexer batch_indexer(server, &store, num_threads);
+ BatchedIndexer* batch_indexer = new BatchedIndexer(server, &store, num_threads);
// first we start the peering service
- ReplicationState replication_state(server, &batch_indexer, &store, &meta_store,
+ ReplicationState replication_state(server, batch_indexer, &store, &meta_store,
&app_thread_pool, server->get_message_dispatcher(),
ssl_enabled,
&config,
@@ -403,10 +403,10 @@ int run_server(const Config & config, const std::string & version, void (*master
config.get_num_documents_parallel_load());
std::thread raft_thread([&replication_state, &config, &state_dir,
- &app_thread_pool, &server_thread_pool, &batch_indexer]() {
+ &app_thread_pool, &server_thread_pool, batch_indexer]() {
- std::thread batch_indexing_thread([&batch_indexer]() {
- batch_indexer.run();
+ std::thread batch_indexing_thread([batch_indexer]() {
+ batch_indexer->run();
});
std::string path_to_nodes = config.get_nodes();
@@ -417,7 +417,7 @@ int run_server(const Config & config, const std::string & version, void (*master
config.get_snapshot_interval_seconds());
LOG(INFO) << "Shutting down batch indexer...";
- batch_indexer.stop();
+ batch_indexer->stop();
LOG(INFO) << "Waiting for batch indexing thread to be done...";
batch_indexing_thread.join();
@@ -444,6 +444,10 @@ int run_server(const Config & config, const std::string & version, void (*master
quit_raft_service = true; // we set this once again in case API thread crashes instead of a signal
raft_thread.join();
+ LOG(INFO) << "Deleting batch indexer";
+
+ delete batch_indexer;
+
LOG(INFO) << "CURL clean up";
curl_global_cleanup();