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
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
API for compacting DB.
Kishore Nallana6fbd8868c0b
diff --git a/include/core_api.h b/include/core_api.hindex 839b8934..8130434c 100644--- a/include/core_api.h+++ b/include/core_api.h@@ -115,6 +115,8 @@ bool post_config(const std::shared_ptr<http_req>& req, const std::shared_ptr<httbool post_clear_cache(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res);+bool post_compact_db(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res);+// Rate Limitingbool get_rate_limits(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res);diff --git a/include/store.h b/include/store.hindex 84cbf77c..7f7ee9b2 100644--- a/include/store.h+++ b/include/store.h@@ -327,6 +327,11 @@ public:db->Flush(options);}+ rocksdb::Status compact_all() {+ std::shared_lock lock(mutex);+ return db->CompactRange(rocksdb::CompactRangeOptions(), nullptr, nullptr);+ }+rocksdb::Status create_check_point(rocksdb::Checkpoint** checkpoint_ptr, const std::string& db_snapshot_path) {std::shared_lock lock(mutex);rocksdb::Status status = rocksdb::Checkpoint::Create(db, checkpoint_ptr);diff --git a/src/core_api.cpp b/src/core_api.cppindex fc817a97..6d815582 100644--- a/src/core_api.cpp+++ b/src/core_api.cpp@@ -1476,6 +1476,23 @@ bool post_clear_cache(const std::shared_ptr<http_req>& req, const std::shared_ptreturn true;}+bool post_compact_db(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res) {+ CollectionManager& collectionManager = CollectionManager::get_instance();+ rocksdb::Status status = collectionManager.get_store()->compact_all();++ nlohmann::json response;+ response["success"] = status.ok();++ if(!status.ok()) {+ response["error"] = "Error code: " + std::to_string(status.code());+ res->set_500(response.dump());+ } else {+ res->set_200(response.dump());+ }++ return true;+}+bool get_synonyms(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res) {CollectionManager & collectionManager = CollectionManager::get_instance();auto collection = collectionManager.get_collection(req->params["collection"]);diff --git a/src/main/typesense_server.cpp b/src/main/typesense_server.cppindex c2c64cd9..33f2c6a0 100644--- a/src/main/typesense_server.cpp+++ b/src/main/typesense_server.cpp@@ -75,7 +75,7 @@ void master_server_routes() {server->post("/operations/snapshot", post_snapshot, false, true);server->post("/operations/vote", post_vote, false, false);server->post("/operations/cache/clear", post_clear_cache, false, false);-+ server->post("/operations/db/compact", post_compact_db, false, false);server->get("/limits", get_rate_limits);server->get("/limits/:id", get_rate_limit);