1 /* 2 * Copyright (C) 2018 Codership Oy <info@codership.com> 3 * 4 * This file is part of wsrep-lib. 5 * 6 * Wsrep-lib is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * Wsrep-lib is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with wsrep-lib. If not, see <https://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef WSREP_DB_SERVER_HPP 21 #define WSREP_DB_SERVER_HPP 22 23 #include "wsrep/gtid.hpp" 24 #include "wsrep/client_state.hpp" 25 #include "wsrep/reporter.hpp" 26 27 #include "db_storage_engine.hpp" 28 #include "db_server_state.hpp" 29 #include "db_server_service.hpp" 30 31 #include <boost/thread.hpp> 32 33 #include <string> 34 #include <memory> 35 36 namespace db 37 { 38 class simulator; 39 class client; 40 class server 41 { 42 public: 43 server(simulator& simulator, 44 const std::string& name, 45 const std::string& address); 46 void applier_thread(); 47 void start_applier(); 48 void stop_applier(); 49 void start_clients(); 50 void stop_clients(); 51 void client_thread(const std::shared_ptr<db::client>& client); storage_engine()52 db::storage_engine& storage_engine() { return storage_engine_; } server_state()53 db::server_state& server_state() { return server_state_; } next_transaction_id()54 wsrep::transaction_id next_transaction_id() 55 { 56 return wsrep::transaction_id(last_transaction_id_.fetch_add(1) + 1); 57 } 58 void donate_sst(const std::string&, const wsrep::gtid&, bool); 59 wsrep::client_state* local_client_state(); 60 void release_client_state(wsrep::client_state*); 61 wsrep::high_priority_service* streaming_applier_service(); 62 void log_state_change(enum wsrep::server_state::state, 63 enum wsrep::server_state::state); 64 private: 65 void start_client(size_t id); 66 67 db::simulator& simulator_; 68 db::storage_engine storage_engine_; 69 wsrep::default_mutex mutex_; 70 wsrep::default_condition_variable cond_; 71 db::server_service server_service_; 72 wsrep::reporter reporter_; 73 db::server_state server_state_; 74 std::atomic<size_t> last_client_id_; 75 std::atomic<size_t> last_transaction_id_; 76 std::vector<boost::thread> appliers_; 77 std::vector<std::shared_ptr<db::client>> clients_; 78 std::vector<boost::thread> client_threads_; 79 }; 80 }; 81 82 #endif // WSREP_DB_SERVER_HPP 83