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 build.

Kishore Nallan862437620a44
diff --git a/include/housekeeper.h b/include/housekeeper.h
new file mode 100644
index 00000000..41243cbd
--- /dev/null
+++ b/include/housekeeper.h
@@ -0,0 +1,35 @@
+#pragma once
+#include <mutex>
+#include <atomic>
+#include <condition_variable>
+
+class HouseKeeper {
+private:
+ mutable std::mutex mutex;
+ std::condition_variable cv;
+
+ std::atomic<bool> quit = false;
+ std::atomic<uint32_t> interval_seconds = 1800;
+
+ HouseKeeper() {}
+
+ ~HouseKeeper() {}
+
+
+public:
+
+ static HouseKeeper &get_instance() {
+ static HouseKeeper instance;
+ return instance;
+ }
+
+ HouseKeeper(HouseKeeper const &) = delete;
+
+ void operator=(HouseKeeper const &) = delete;
+
+ void init(uint32_t interval_seconds);
+
+ void run();
+
+ void stop();
+};
diff --git a/src/housekeeper.cpp b/src/housekeeper.cpp
new file mode 100644
index 00000000..07150e11
--- /dev/null
+++ b/src/housekeeper.cpp
@@ -0,0 +1,51 @@
+#include <collection_manager.h>
+#include "housekeeper.h"
+
+void HouseKeeper::run() {
+ uint64_t prev_persistence_s = std::chrono::duration_cast<std::chrono::seconds>(
+ std::chrono::system_clock::now().time_since_epoch()).count();
+
+ while(!quit) {
+ std::unique_lock lk(mutex);
+ cv.wait_for(lk, std::chrono::seconds(60), [&] { return quit.load(); });
+
+ if(quit) {
+ lk.unlock();
+ break;
+ }
+
+ auto now_ts_seconds = std::chrono::duration_cast<std::chrono::seconds>(
+ std::chrono::system_clock::now().time_since_epoch()).count();
+
+ if(now_ts_seconds - prev_persistence_s < interval_seconds) {
+ continue;
+ }
+
+ // iterate through all collections and repair all hnsw graphs
+ auto coll_names = CollectionManager::get_instance().get_collection_names();
+
+ for(auto& coll_name: coll_names) {
+ auto coll = CollectionManager::get_instance().get_collection(coll_name);
+ if(coll == nullptr) {
+ continue;
+ }
+
+ coll->do_housekeeping();
+ LOG(INFO) << "Ran housekeeping.";
+ }
+
+ prev_persistence_s = std::chrono::duration_cast<std::chrono::seconds>(
+ std::chrono::system_clock::now().time_since_epoch()).count();
+
+ lk.unlock();
+ }
+}
+
+void HouseKeeper::stop() {
+ quit = true;
+ cv.notify_all();
+}
+
+void HouseKeeper::init(uint32_t interval_seconds) {
+ this->interval_seconds = interval_seconds;
+}