Fix missing files

This commit is contained in:
Kishore Nallan 2023-10-31 10:33:54 +05:30
parent ae597f40ba
commit 9b7518e7ac
2 changed files with 86 additions and 0 deletions

35
include/housekeeper.h Normal file
View File

@ -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();
};

51
src/housekeeper.cpp Normal file
View File

@ -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;
}