1 /* 2 Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License, version 2.0, 6 as published by the Free Software Foundation. 7 8 This program is also distributed with certain software (including 9 but not limited to OpenSSL) that is licensed under separate terms, 10 as designated in a particular file or component or in included license 11 documentation. The authors of MySQL hereby grant you an additional 12 permission to link the program and your derivative works with the 13 separately licensed software that they have included with MySQL. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License, version 2.0, for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 */ 24 25 #ifndef NDB_THD_NDB_H 26 #define NDB_THD_NDB_H 27 28 #include <my_global.h> 29 #include <my_base.h> // ha_rows 30 #include <sql_list.h> // List<> 31 #include <hash.h> // HASH 32 33 #include "ndb_share.h" 34 35 #include <kernel/ndb_limits.h> // MAX_NDB_NODES 36 37 /* 38 Place holder for ha_ndbcluster thread specific data 39 */ 40 41 enum THD_NDB_OPTIONS 42 { 43 TNO_NO_LOG_SCHEMA_OP= 1 << 0, 44 /* 45 In participating mysqld, do not try to acquire global schema 46 lock, as one other mysqld already has the lock. 47 */ 48 TNO_NO_LOCK_SCHEMA_OP= 1 << 1 49 }; 50 51 enum THD_NDB_TRANS_OPTIONS 52 { 53 TNTO_INJECTED_APPLY_STATUS= 1 << 0 54 ,TNTO_NO_LOGGING= 1 << 1 55 ,TNTO_TRANSACTIONS_OFF= 1 << 2 56 }; 57 58 class Thd_ndb 59 { 60 THD* m_thd; 61 62 Thd_ndb(THD*); 63 ~Thd_ndb(); 64 const bool m_slave_thread; // cached value of thd->slave_thread 65 66 /* Skip binlog setup in ndbcluster_find_files() */ 67 bool m_skip_binlog_setup_in_find_files; 68 69 public: 70 static Thd_ndb* seize(THD*); 71 static void release(Thd_ndb* thd_ndb); 72 73 void init_open_tables(); 74 75 class Ndb_cluster_connection *connection; 76 class Ndb *ndb; 77 class ha_ndbcluster *m_handler; 78 ulong count; 79 uint lock_count; 80 uint start_stmt_count; 81 uint save_point_count; 82 class NdbTransaction *trans; 83 bool m_error; 84 bool m_slow_path; 85 bool m_force_send; 86 87 uint32 options; 88 uint32 trans_options; 89 void transaction_checks(void); 90 List<NDB_SHARE> changed_tables; 91 HASH open_tables; 92 /* 93 This is a memroot used to buffer rows for batched execution. 94 It is reset after every execute(). 95 */ 96 MEM_ROOT m_batch_mem_root; 97 /* 98 Estimated pending batched execution bytes, once this is > BATCH_FLUSH_SIZE 99 we execute() to flush the rows buffered in m_batch_mem_root. 100 */ 101 uint m_unsent_bytes; 102 uint m_batch_size; 103 bool add_row_check_if_batch_full(uint size); 104 105 uint m_execute_count; 106 107 uint m_scan_count; 108 uint m_pruned_scan_count; 109 110 /** This is the number of sorted scans (via ordered indexes).*/ 111 uint m_sorted_scan_count; 112 113 /** This is the number of NdbQueryDef objects that the handler has created.*/ 114 uint m_pushed_queries_defined; 115 /** 116 This is the number of cases where the handler decided not to use an 117 NdbQuery object that it previously created for executing a particular 118 instance of a query fragment. This may happen if for examle the optimizer 119 decides to use another type of access operation than originally assumed. 120 */ 121 uint m_pushed_queries_dropped; 122 /** 123 This is the number of times that the handler instantiated an NdbQuery object 124 from a NdbQueryDef object and used the former for executing an instance 125 of a query fragment. 126 */ 127 uint m_pushed_queries_executed; 128 /** 129 This is the number of lookup operations (via unique index or primary key) 130 that were eliminated by pushing linked operations (NdbQuery) to the data 131 nodes. 132 */ 133 uint m_pushed_reads; 134 135 uint m_transaction_no_hint_count[MAX_NDB_NODES]; 136 uint m_transaction_hint_count[MAX_NDB_NODES]; 137 138 NdbTransaction *global_schema_lock_trans; 139 uint global_schema_lock_count; 140 uint global_schema_lock_error; 141 uint schema_locks_count; // Number of global schema locks taken by thread 142 bool has_required_global_schema_lock(const char* func); 143 144 /** 145 Epoch of last committed transaction in this session, 0 if none so far 146 */ 147 Uint64 m_last_commit_epoch_session; 148 149 unsigned m_connect_count; 150 bool valid_ndb(void) const; 151 bool recycle_ndb(void); 152 is_slave_thread(void)153 bool is_slave_thread(void) const { return m_slave_thread; } 154 set_skip_binlog_setup_in_find_files(bool value)155 void set_skip_binlog_setup_in_find_files(bool value) 156 { 157 // Only alloow toggeling the value 158 assert(m_skip_binlog_setup_in_find_files != value); 159 160 m_skip_binlog_setup_in_find_files = value; 161 } 162 skip_binlog_setup_in_find_files(void)163 bool skip_binlog_setup_in_find_files(void) const 164 { 165 return m_skip_binlog_setup_in_find_files; 166 } 167 }; 168 169 #endif 170