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
Use `nodes` instead of `peers` for connection string.
kishorenc9ca493804593
diff --git a/include/config.h b/include/config.hindex a2e35f5b..cf5c6468 100644--- a/include/config.h+++ b/include/config.h@@ -18,7 +18,7 @@ private:std::string peering_address;uint32_t peering_port;- std::string peers;+ std::string nodes;std::string master;@@ -88,14 +88,6 @@ public:this->indices_per_collection = indices_per_collection;}- void set_raft_port(int raft_port) {- this->peering_port = raft_port;- }-- void set_raft_peers(const std::string & raft_peers) {- this->peers = raft_peers;- }-// gettersstd::string get_data_dir() const {@@ -154,8 +146,8 @@ public:return this->peering_port;}- std::string get_peers() const {- return this->peers;+ std::string get_nodes() const {+ return this->nodes;}// loaders@@ -199,7 +191,7 @@ public:this->peering_port = std::stoi(get_env("TYPESENSE_PEERING_PORT"));}- this->peers = get_env("TYPESENSE_PEERS");+ this->nodes = get_env("TYPESENSE_NODES");this->master = get_env("TYPESENSE_MASTER");this->ssl_certificate = get_env("TYPESENSE_SSL_CERTIFICATE");@@ -285,8 +277,8 @@ public:this->peering_port = reader.GetInteger("server", "peering-port", 8107);}- if(reader.Exists("server", "peers")) {- this->peers = reader.Get("server", "peers", "");+ if(reader.Exists("server", "nodes")) {+ this->nodes = reader.Get("server", "nodes", "");}}@@ -347,8 +339,8 @@ public:this->peering_port = options.get<uint32_t>("peering-port");}- if(options.exist("peers")) {- this->peers = options.get<std::string>("peers");+ if(options.exist("nodes")) {+ this->nodes = options.get<std::string>("nodes");}}diff --git a/include/raft_server.h b/include/raft_server.hindex 4075e6bd..d7ce6f33 100644--- a/include/raft_server.h+++ b/include/raft_server.h@@ -39,17 +39,17 @@ public:void Run();};-// Closure that fires when refresh peers operation finishes-class RefreshPeersClosure : public braft::Closure {+// Closure that fires when refresh nodes operation finishes+class RefreshNodesClosure : public braft::Closure {public:- RefreshPeersClosure() {}+ RefreshNodesClosure() {}- ~RefreshPeersClosure() {}+ ~RefreshNodesClosure() {}void Run() {// Auto delete this after Run()- std::unique_ptr<RefreshPeersClosure> self_guard(this);+ std::unique_ptr<RefreshNodesClosure> self_guard(this);if(status().ok()) {LOG(INFO) << "Peer refresh succeeded!";@@ -105,7 +105,7 @@ public:// Starts this nodeint start(const butil::EndPoint & peering_endpoint, int api_port,int election_timeout_ms, int snapshot_interval_s,- const std::string & raft_dir, const std::string & peers);+ const std::string & raft_dir, const std::string & nodes);// Generic write method for synchronizing all writesvoid write(http_req* request, http_res* response);@@ -114,7 +114,7 @@ public:void read(http_res* response);// updates cluster membership- void refresh_peers(const std::string & peers);+ void refresh_nodes(const std::string & nodes);bool is_leader() const {return leader_term.load(butil::memory_order_acquire) > 0;diff --git a/src/raft_server.cpp b/src/raft_server.cppindex 252f9261..f7c90c7c 100644--- a/src/raft_server.cpp+++ b/src/raft_server.cpp@@ -19,19 +19,19 @@ void ReplicationClosure::Run() {int ReplicationState::start(const butil::EndPoint & peering_endpoint, const int api_port,int election_timeout_ms, int snapshot_interval_s,- const std::string & raft_dir, const std::string & peers) {+ const std::string & raft_dir, const std::string & nodes) {braft::NodeOptions node_options;- std::string actual_peers = peers;+ std::string actual_nodes = nodes;- if(actual_peers.empty()) {+ if(actual_nodes.empty()) {std::string ip_str = butil::ip2str(peering_endpoint.ip).c_str();- actual_peers = ip_str + ":" + std::to_string(peering_endpoint.port) + ":" + std::to_string(api_port);+ actual_nodes = ip_str + ":" + std::to_string(peering_endpoint.port) + ":" + std::to_string(api_port);}- if(node_options.initial_conf.parse_from(actual_peers) != 0) {- LOG(ERROR) << "Failed to parse peer configuration `" << peers << "`";+ if(node_options.initial_conf.parse_from(actual_nodes) != 0) {+ LOG(ERROR) << "Failed to parse peer configuration `" << nodes << "`";return -1;}@@ -77,7 +77,7 @@ int ReplicationState::start(const butil::EndPoint & peering_endpoint, const int}std::vector<std::string> peer_vec;- StringUtils::split(actual_peers, peer_vec, ",");+ StringUtils::split(actual_nodes, peer_vec, ",");if(peer_vec.size() == 1) {// NOTE: `reset_peers` is NOT safe to run on a cluster of nodes, but okay for standalone@@ -140,16 +140,16 @@ void ReplicationState::write(http_req* request, http_res* response) {return ;}- // Serialize request to replicated WAL so that all the peers in the group receive it as well.+ // Serialize request to replicated WAL so that all the nodes in the group receive it as well.// NOTE: actual write must be done only on the `on_apply` method to maintain consistency.butil::IOBufBuilder bufBuilder;bufBuilder << request->serialize();- butil::IOBuf log = bufBuilder.buf();// Apply this log as a braft::Task+braft::Task task;- task.data = &log;+ task.data = &bufBuilder.buf();// This callback would be invoked when the task actually executes or failstask.done = new ReplicationClosure(request, response);@@ -314,15 +314,15 @@ int ReplicationState::on_snapshot_load(braft::SnapshotReader* reader) {return init_db();}-void ReplicationState::refresh_peers(const std::string & peers) {+void ReplicationState::refresh_nodes(const std::string & nodes) {if(node && is_leader()) {- LOG(INFO) << "Refreshing peer config";+ LOG(INFO) << "Refreshing node config";braft::Configuration conf;- conf.parse_from(peers);+ conf.parse_from(nodes);- RefreshPeersClosure* refresh_peers_done = new RefreshPeersClosure;- node->change_peers(conf, refresh_peers_done);+ RefreshNodesClosure* refresh_nodes_done = new RefreshNodesClosure;+ node->change_peers(conf, refresh_nodes_done);}}diff --git a/src/typesense_server_utils.cpp b/src/typesense_server_utils.cppindex 5cbe797e..74e92899 100644--- a/src/typesense_server_utils.cpp+++ b/src/typesense_server_utils.cpp@@ -43,7 +43,7 @@ void catch_crash(int sig) {Option<std::string> fetch_file_contents(const std::string & file_path) {if(!file_exists(file_path)) {- return Option<std::string>(404, "Error reading file containing peers.");+ return Option<std::string>(404, "File does not exist.");}std::ifstream infile(file_path);@@ -108,7 +108,7 @@ void init_cmdline_options(cmdline::parser & options, int argc, char **argv) {options.add<std::string>("peering-address", '\0', "Internal IP address to which Typesense peering service binds.", false, "");options.add<uint32_t>("peering-port", '\0', "Port on which Typesense peering service listens.", false, 8107);- options.add<std::string>("peers", '\0', "Path to file containing comma separated string of all nodes in the cluster.", false);+ options.add<std::string>("nodes", '\0', "Path to file containing comma separated string of all nodes in the cluster.", false);options.add<std::string>("ssl-certificate", 'c', "Path to the SSL certificate file.", false, "");options.add<std::string>("ssl-certificate-key", 'k', "Path to the SSL certificate key file.", false, "");@@ -122,7 +122,7 @@ void init_cmdline_options(cmdline::parser & options, int argc, char **argv) {// DEPRECATEDoptions.add<std::string>("listen-address", 'h', "[DEPRECATED: use `api-address`] Address to which Typesense API service binds.", false, "0.0.0.0");options.add<uint32_t>("listen-port", 'p', "[DEPRECATED: use `api-port`] Port on which Typesense API service listens.", false, 8108);- options.add<std::string>("master", 'm', "[DEPRECATED: use clustering via --peers] Master's address in http(s)://<master_address>:<master_port> format "+ options.add<std::string>("master", 'm', "[DEPRECATED: use clustering via --nodes] Master's address in http(s)://<master_address>:<master_port> format ""to start as read-only replica.", false, "");}@@ -173,26 +173,26 @@ bool on_send_response(void *data) {return true;}-int start_raft_server(ReplicationState& replication_state, const std::string& state_dir, const std::string& path_to_peers,+int start_raft_server(ReplicationState& replication_state, const std::string& state_dir, const std::string& path_to_nodes,const std::string& peering_address, uint32_t peering_port, uint32_t api_port) {std::string peer_ips;- if(path_to_peers.empty()) {- LOG(INFO) << "Since no --peers argument is provided, starting a single node Typesense cluster.";+ if(path_to_nodes.empty()) {+ LOG(INFO) << "Since no --nodes argument is provided, starting a single node Typesense cluster.";} else {- const Option<std::string> & peers_op = fetch_file_contents(path_to_peers);+ const Option<std::string> & nodes_op = fetch_file_contents(path_to_nodes);- if(!peers_op.ok()) {- LOG(ERROR) << peers_op.error();+ if(!nodes_op.ok()) {+ LOG(ERROR) << "Error reading file containing nodes configuration: " << nodes_op.error();exit(-1);} else {- peer_ips = peers_op.get();+ peer_ips = nodes_op.get();if(peer_ips.empty()) {- LOG(ERROR) << "File containing peers is empty.";+ LOG(ERROR) << "File containing nodes configuration is empty.";exit(-1);} else {- peer_ips = peers_op.get();+ peer_ips = nodes_op.get();}}}@@ -235,16 +235,16 @@ int start_raft_server(ReplicationState& replication_state, const std::string& st// Wait until 'CTRL-C' is pressed. then Stop() and Join() the servicesize_t raft_counter = 0;while (!brpc::IsAskedToQuit() && !quit_raft_service.load()) {- if(++raft_counter % 10 == 0 && !path_to_peers.empty()) {+ if(++raft_counter % 10 == 0 && !path_to_nodes.empty()) {// reset peer configuration periodically to identify change in cluster membership- const Option<std::string> & refreshed_peers_op = fetch_file_contents(path_to_peers);- if(!refreshed_peers_op.ok()) {- LOG(ERROR) << "Error while refreshing peer configuration: " << refreshed_peers_op.error();+ const Option<std::string> & refreshed_node_op = fetch_file_contents(path_to_nodes);+ if(!refreshed_node_op.ok()) {+ LOG(ERROR) << "Error while refreshing peer configuration: " << refreshed_node_op.error();continue;}- const std::string & refreshed_peer_ips_string = refreshed_peers_op.get();- replication_state.refresh_peers(refreshed_peer_ips_string);+ const std::string & refreshed_node_ips_string = refreshed_node_op.get();+ replication_state.refresh_nodes(refreshed_node_ips_string);}sleep(1);@@ -277,7 +277,7 @@ int run_server(const Config & config, const std::string & version, void (*masterif(!config.get_master().empty()) {LOG(ERROR) << "The --master option has been deprecated. Please use clustering for high availability. "- << "Look for the --peers configuration in the documentation.";+ << "Look for the --nodes configuration in the documentation.";return 1;}@@ -288,9 +288,9 @@ int run_server(const Config & config, const std::string & version, void (*masterbool create_init_db_snapshot = false; // for importing raw DB from earlier versionsif(!directory_exists(db_dir) && file_exists(data_dir+"/CURRENT") && file_exists(data_dir+"/IDENTITY")) {- if(!config.get_peers().empty()) {+ if(!config.get_nodes().empty()) {LOG(ERROR) << "Your data directory needs to be migrated to the new format.";- LOG(ERROR) << "To do that, please start the Typesense server without the --peers argument.";+ LOG(ERROR) << "To do that, please start Typesense server without the --nodes argument.";return 1;}@@ -334,8 +334,8 @@ int run_server(const Config & config, const std::string & version, void (*masterReplicationState replication_state(&store, &thread_pool, server->get_message_dispatcher(), create_init_db_snapshot);std::thread raft_thread([&replication_state, &config, &state_dir]() {- std::string path_to_peers = config.get_peers();- start_raft_server(replication_state, state_dir, path_to_peers,+ std::string path_to_nodes = config.get_nodes();+ start_raft_server(replication_state, state_dir, path_to_nodes,config.get_peering_address(), config.get_peering_port(), config.get_api_port());});