mirror of
https://github.com/typesense/typesense.git
synced 2025-05-17 20:22:32 +08:00
Fix missing files
This commit is contained in:
parent
ae597f40ba
commit
9b7518e7ac
35
include/housekeeper.h
Normal file
35
include/housekeeper.h
Normal 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
51
src/housekeeper.cpp
Normal 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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user