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
Handle lag being negative in leader.
Kishore Nallanc4deb38189e7
diff --git a/include/raft_server.h b/include/raft_server.hindex 306f0c4b..7b36b5ef 100644--- a/include/raft_server.h+++ b/include/raft_server.h@@ -91,7 +91,6 @@ private:braft::Node* volatile node;butil::atomic<int64_t> leader_term;- std::set<braft::PeerId> peers;HttpServer* server;@@ -108,8 +107,8 @@ private:const bool api_uses_ssl;- const size_t healthy_read_lag;- const size_t healthy_write_lag;+ const int64_t healthy_read_lag;+ const int64_t healthy_write_lag;const size_t num_collections_parallel_load;const size_t num_documents_parallel_load;@@ -138,7 +137,7 @@ public:ReplicationState(HttpServer* server, Store* store, Store* meta_store,ThreadPool* thread_pool, http_message_dispatcher* message_dispatcher,- bool api_uses_ssl, size_t healthy_read_lag, size_t healthy_write_lag,+ bool api_uses_ssl, int64_t healthy_read_lag, int64_t healthy_write_lag,size_t num_collections_parallel_load, size_t num_documents_parallel_load);// Starts this node@@ -250,7 +249,6 @@ private:void on_configuration_committed(const ::braft::Configuration& conf) {LOG(INFO) << "Configuration of this group is " << conf;- conf.list_peers(&peers);}void on_start_following(const ::braft::LeaderChangeContext& ctx) {diff --git a/src/http_client.cpp b/src/http_client.cppindex 257b29bf..9634b6c8 100644--- a/src/http_client.cpp+++ b/src/http_client.cpp@@ -162,9 +162,9 @@ size_t HttpClient::curl_req_send_callback(char* buffer, size_t size, size_t nitereq_res->req->body_index += bytes_to_read;- //LOG(INFO) << "Wrote " << bytes_to_read << " bytes to request body (max_buffer_bytes=" << max_req_bytes << ")";- //LOG(INFO) << "req_res->req->body_index: " << req_res->req->body_index;- //LOG(INFO) << "req_res->req->body.size(): " << req_res->req->body.size();+ /*LOG(INFO) << "Wrote " << bytes_to_read << " bytes to request body (max_buffer_bytes=" << max_req_bytes << ")";+ LOG(INFO) << "req_res->req->body_index: " << req_res->req->body_index+ << ", req_res->req->body.size(): " << req_res->req->body.size();*/if(req_res->req->body_index == req_res->req->body.size()) {//LOG(INFO) << "Current body buffer has been consumed fully.";@@ -270,7 +270,9 @@ CURL *HttpClient::init_curl_async(const std::string& url, deferred_req_res_t* rechunk = curl_slist_append(chunk, content_length_header.c_str());curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);- curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE);++ // Enabling this causes issues in mixed mode: client using http/1 but follower -> leader using http/2+ //curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE);// callback called every time request body is neededcurl_easy_setopt(curl, CURLOPT_READFUNCTION, HttpClient::curl_req_send_callback);diff --git a/src/raft_server.cpp b/src/raft_server.cppindex 31818ef3..fe48b241 100644--- a/src/raft_server.cpp+++ b/src/raft_server.cpp@@ -297,7 +297,7 @@ void ReplicationState::on_apply(braft::Iterator& iter) {continue;}- //LOG(INFO) << "Init use count: " << dynamic_cast<ReplicationClosure*>(iter.done())->get_request().use_count();+ //LOG(INFO) << "Apply entry";const std::shared_ptr<http_req>& request_generated = iter.done() ?dynamic_cast<ReplicationClosure*>(iter.done())->get_request() : std::make_shared<http_req>();@@ -562,21 +562,21 @@ void ReplicationState::refresh_catchup_status(bool log_msg) {lock.unlock();// work around for: https://github.com/baidu/braft/issues/277#issuecomment-823080171- size_t current_index = (n_status.applying_index == 0) ? n_status.known_applied_index : n_status.applying_index;- size_t apply_lag = size_t(n_status.last_index - current_index);+ int64_t current_index = (n_status.applying_index == 0) ? n_status.known_applied_index : n_status.applying_index;+ int64_t apply_lag = n_status.last_index - current_index;//LOG(INFO) << "last_index: " << n_status.applying_index << ", known_applied_index: " << n_status.known_applied_index;//LOG(INFO) << "apply_lag: " << apply_lag;if (apply_lag > healthy_read_lag) {- LOG_IF(ERROR, log_msg) << apply_lag << " lagging entries > read max lag of " + std::to_string(healthy_read_lag);+ LOG_IF(ERROR, log_msg) << apply_lag << " lagging entries > healthy read lag of " << healthy_read_lag;this->read_caught_up = false;} else {this->read_caught_up = true;}if (apply_lag > healthy_write_lag) {- LOG_IF(ERROR, log_msg) << apply_lag << " lagging entries > write max lag of " + std::to_string(healthy_write_lag);+ LOG_IF(ERROR, log_msg) << apply_lag << " lagging entries > healthy write lag of " << healthy_write_lag;this->write_caught_up = false;} else {this->write_caught_up = true;@@ -586,7 +586,7 @@ void ReplicationState::refresh_catchup_status(bool log_msg) {ReplicationState::ReplicationState(HttpServer* server, Store *store, Store* meta_store, ThreadPool* thread_pool,http_message_dispatcher *message_dispatcher,bool api_uses_ssl,- size_t healthy_read_lag, size_t healthy_write_lag,+ int64_t healthy_read_lag, int64_t healthy_write_lag,size_t num_collections_parallel_load, size_t num_documents_parallel_load):node(nullptr), leader_term(-1), server(server), store(store), meta_store(meta_store),thread_pool(thread_pool), message_dispatcher(message_dispatcher), api_uses_ssl(api_uses_ssl),