1 /* Copyright (C) 2015-2019 Codership Oy <info@codership.com> 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License as published by 5 the Free Software Foundation; version 2 of the License. 6 7 This program is distributed in the hope that it will be useful, 8 but WITHOUT ANY WARRANTY; without even the implied warranty of 9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 GNU General Public License for more details. 11 12 You should have received a copy of the GNU General Public License along 13 with this program; if not, write to the Free Software Foundation, Inc., 14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ 15 16 17 #ifndef WSREP_SCHEMA_H 18 #define WSREP_SCHEMA_H 19 20 /* wsrep-lib */ 21 #include "wsrep_types.h" 22 23 #include "mysqld.h" 24 #include "wsrep_mysqld.h" 25 26 /* 27 Forward decls 28 */ 29 class THD; 30 class Relay_log_info; 31 struct TABLE; 32 struct TABLE_LIST; 33 struct st_mysql_lex_string; 34 typedef struct st_mysql_lex_string LEX_STRING; 35 36 /** Name of the table in `wsrep_schema_str` used for storing streaming 37 replication data. In an InnoDB full format, e.g. "database/tablename". */ 38 extern const char* wsrep_sr_table_name_full; 39 40 class Wsrep_schema 41 { 42 public: 43 44 Wsrep_schema(); 45 ~Wsrep_schema(); 46 47 /* 48 Initialize wsrep schema. Storage engines must be running before 49 calling this function. 50 */ 51 int init(); 52 53 /* 54 Store wsrep view info into wsrep schema. 55 */ 56 int store_view(THD*, const Wsrep_view& view); 57 58 /* 59 Restore view info from stable storage. 60 */ 61 Wsrep_view restore_view(THD* thd, const Wsrep_id& own_id) const; 62 63 /** 64 Append transaction fragment to fragment storage. 65 Transaction must have been started for THD before this call. 66 In order to make changes durable, transaction must be committed 67 separately after this call. 68 69 @param thd THD object 70 @param server_id Wsrep server identifier 71 @param transaction_id Transaction identifier 72 @param flags Flags for the fragment 73 @param data Fragment data buffer 74 75 @return Zero in case of success, non-zero on failure. 76 */ 77 int append_fragment(THD* thd, 78 const wsrep::id& server_id, 79 wsrep::transaction_id transaction_id, 80 wsrep::seqno seqno, 81 int flags, 82 const wsrep::const_buffer& data); 83 /** 84 Update existing fragment meta data. The fragment must have been 85 inserted before using append_fragment(). 86 87 @param thd THD object 88 @param ws_meta Wsrep meta data 89 90 @return Zero in case of success, non-zero on failure. 91 */ 92 int update_fragment_meta(THD* thd, 93 const wsrep::ws_meta& ws_meta); 94 95 /** 96 Remove fragments from storage. This method must be called 97 inside active transaction. Fragment removal will be committed 98 once the transaction commits. 99 100 @param thd Pointer to THD object 101 @param server_id Identifier of the running server 102 @param transaction_id Identifier of the current transaction 103 @param fragments Vector of fragment seqnos to be removed 104 */ 105 int remove_fragments(THD* thd, 106 const wsrep::id& server_id, 107 wsrep::transaction_id transaction_id, 108 const std::vector<wsrep::seqno>& fragments); 109 110 /** 111 Replay a transaction from stored fragments. The caller must have 112 started a transaction for a thd. 113 114 @param thd Pointer to THD object 115 @param ws_meta Write set meta data for commit fragment. 116 @param fragments Vector of fragments to be replayed 117 118 @return Zero on success, non-zero on failure. 119 */ 120 int replay_transaction(THD* thd, 121 Relay_log_info* rli, 122 const wsrep::ws_meta& ws_meta, 123 const std::vector<wsrep::seqno>& fragments); 124 125 /** 126 Recover streaming transactions from SR table. 127 This method should be called after storage enignes are initialized. 128 It will scan SR table and replay found streaming transactions. 129 130 @param orig_thd The THD object of the calling thread. 131 132 @return Zero on success, non-zero on failure. 133 */ 134 int recover_sr_transactions(THD* orig_thd); 135 136 private: 137 /* Non-copyable */ 138 Wsrep_schema(const Wsrep_schema&); 139 Wsrep_schema& operator=(const Wsrep_schema&); 140 }; 141 142 extern Wsrep_schema* wsrep_schema; 143 144 #endif /* !WSREP_SCHEMA_H */ 145