1 /* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. 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, version 2.0, 5 as published by the Free Software Foundation. 6 7 This program is also distributed with certain software (including 8 but not limited to OpenSSL) that is licensed under separate terms, 9 as designated in a particular file or component or in included license 10 documentation. The authors of MySQL hereby grant you an additional 11 permission to link the program and your derivative works with the 12 separately licensed software that they have included with MySQL. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License, version 2.0, for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 22 23 #ifndef RPL_TRANSACTION_WRITE_SET_CTX_H 24 #define RPL_TRANSACTION_WRITE_SET_CTX_H 25 26 #include <stddef.h> 27 #include <list> 28 #include <map> 29 #include <string> 30 #include <vector> 31 32 #include "my_inttypes.h" 33 34 /** 35 Server side support to provide a service to plugins to report if 36 a given transaction should continue or be aborted. 37 Its value is reset on Transaction_ctx::cleanup(). 38 Its value is set through service service_rpl_transaction_ctx. 39 */ 40 class Rpl_transaction_write_set_ctx { 41 public: 42 Rpl_transaction_write_set_ctx(); ~Rpl_transaction_write_set_ctx()43 virtual ~Rpl_transaction_write_set_ctx() {} 44 45 /* 46 Function to add the write set of the hash of the PKE in the std::vector 47 in the transaction_ctx object. 48 49 @param[in] hash - the uint64 type hash value of the PKE. 50 */ 51 void add_write_set(uint64 hash); 52 53 /* 54 Function to get the pointer of the write set vector in the 55 transaction_ctx object. 56 */ 57 std::vector<uint64> *get_write_set(); 58 59 /* 60 Cleanup function of the vector which stores the PKE. 61 */ 62 void clear_write_set(); 63 64 /* 65 mark transactions that include tables with no pk 66 */ 67 void set_has_missing_keys(); 68 69 /* 70 check if the transaction was marked as having missing keys. 71 72 @retval true The transaction accesses tables with no PK. 73 @retval false All tables referenced in transaction have PK. 74 */ 75 bool get_has_missing_keys(); 76 77 /* 78 mark transactions that include tables referenced by foreign keys 79 */ 80 void set_has_related_foreign_keys(); 81 82 /* 83 function to check if the transaction was marked as having missing keys. 84 85 @retval true If the transaction was marked as being referenced by a foreign 86 key 87 */ 88 bool get_has_related_foreign_keys(); 89 90 /** 91 Function to add a new SAVEPOINT identifier in the savepoint map in the 92 transaction_ctx object. 93 94 @param[in] name - the identifier name of the SAVEPOINT. 95 */ 96 void add_savepoint(char *name); 97 98 /** 99 Function to delete a SAVEPOINT identifier in the savepoint map in the 100 transaction_ctx object. 101 102 @param[in] name - the identifier name of the SAVEPOINT. 103 */ 104 void del_savepoint(char *name); 105 106 /** 107 Function to delete all data added to write set and savepoint since 108 SAVEPOINT identifier was added to savepoinbt in the transaction_ctx object. 109 110 @param[in] name - the identifier name of the SAVEPOINT. 111 */ 112 void rollback_to_savepoint(char *name); 113 114 /** 115 Function to push savepoint data to a list and clear the savepoint map in 116 order to create another identifier context, needed on functions ant trigger. 117 */ 118 void reset_savepoint_list(); 119 120 /** 121 Restore previous savepoint map context, called after executed trigger or 122 function. 123 */ 124 void restore_savepoint_list(); 125 126 private: 127 std::vector<uint64> write_set; 128 bool m_has_missing_keys; 129 bool m_has_related_foreign_keys; 130 131 /** 132 Contains information related to SAVEPOINTs. The key on map is the 133 identifier and the value is the size of write set when command was 134 executed. 135 */ 136 std::map<std::string, size_t> savepoint; 137 138 /** 139 Create a savepoint context hierarchy to support encapsulation of 140 identifier name when function or trigger are executed. 141 */ 142 std::list<std::map<std::string, size_t>> savepoint_list; 143 }; 144 145 #endif /* RPL_TRANSACTION_WRITE_SET_CTX_H */ 146