My Project
|
00001 /* 00002 Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; version 2 of the License. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00016 */ 00017 00018 #ifndef NDB_SHARE_H 00019 #define NDB_SHARE_H 00020 00021 #include <my_global.h> 00022 #include <my_alloc.h> // MEM_ROOT 00023 #include <thr_lock.h> // THR_LOCK 00024 #include <my_bitmap.h> // MY_BITMAP 00025 00026 #include <ndbapi/Ndb.hpp> // Ndb::TupleIdRange 00027 00028 enum NDB_SHARE_STATE { 00029 NSS_INITIAL= 0, 00030 NSS_DROPPED, 00031 NSS_ALTERED 00032 }; 00033 00034 00035 enum enum_conflict_fn_type 00036 { 00037 CFT_NDB_UNDEF = 0 00038 ,CFT_NDB_MAX 00039 ,CFT_NDB_OLD 00040 ,CFT_NDB_MAX_DEL_WIN 00041 ,CFT_NDB_EPOCH 00042 ,CFT_NUMBER_OF_CFTS /* End marker */ 00043 }; 00044 00045 #ifdef HAVE_NDB_BINLOG 00046 static const Uint32 MAX_CONFLICT_ARGS= 8; 00047 00048 enum enum_conflict_fn_arg_type 00049 { 00050 CFAT_END 00051 ,CFAT_COLUMN_NAME 00052 ,CFAT_EXTRA_GCI_BITS 00053 }; 00054 00055 struct st_conflict_fn_arg 00056 { 00057 enum_conflict_fn_arg_type type; 00058 const char *ptr; 00059 uint32 len; 00060 union 00061 { 00062 uint32 fieldno; // CFAT_COLUMN_NAME 00063 uint32 extraGciBits; // CFAT_EXTRA_GCI_BITS 00064 }; 00065 }; 00066 00067 struct st_conflict_fn_arg_def 00068 { 00069 enum enum_conflict_fn_arg_type arg_type; 00070 bool optional; 00071 }; 00072 00073 /* What type of operation was issued */ 00074 enum enum_conflicting_op_type 00075 { /* NdbApi */ 00076 WRITE_ROW, /* insert (!write) */ 00077 UPDATE_ROW, /* update */ 00078 DELETE_ROW /* delete */ 00079 }; 00080 00081 /* 00082 prepare_detect_func 00083 00084 Type of function used to prepare for conflict detection on 00085 an NdbApi operation 00086 */ 00087 typedef int (* prepare_detect_func) (struct NDB_CONFLICT_FN_SHARE* cfn_share, 00088 enum_conflicting_op_type op_type, 00089 const uchar* old_data, 00090 const uchar* new_data, 00091 const MY_BITMAP* write_set, 00092 class NdbInterpretedCode* code); 00093 00094 struct st_conflict_fn_def 00095 { 00096 const char *name; 00097 enum_conflict_fn_type type; 00098 const st_conflict_fn_arg_def* arg_defs; 00099 prepare_detect_func prep_func; 00100 }; 00101 00102 /* What sort of conflict was found */ 00103 enum enum_conflict_cause 00104 { 00105 ROW_ALREADY_EXISTS, 00106 ROW_DOES_NOT_EXIST, 00107 ROW_IN_CONFLICT 00108 }; 00109 00110 /* NdbOperation custom data which points out handler and record. */ 00111 struct Ndb_exceptions_data { 00112 struct NDB_SHARE* share; 00113 const NdbRecord* key_rec; 00114 const uchar* row; 00115 enum_conflicting_op_type op_type; 00116 }; 00117 00118 enum enum_conflict_fn_flags 00119 { 00120 CFF_NONE = 0, 00121 CFF_REFRESH_ROWS = 1 00122 }; 00123 00124 struct NDB_CONFLICT_FN_SHARE { 00125 const st_conflict_fn_def* m_conflict_fn; 00126 00127 /* info about original table */ 00128 uint8 m_pk_cols; 00129 uint8 m_resolve_column; 00130 uint8 m_resolve_size; 00131 uint8 m_flags; 00132 uint16 m_offset[16]; 00133 uint16 m_resolve_offset; 00134 00135 const NdbDictionary::Table *m_ex_tab; 00136 uint32 m_count; 00137 }; 00138 #endif 00139 00140 00141 /* 00142 Stats that can be retrieved from ndb 00143 */ 00144 struct Ndb_statistics { 00145 Uint64 row_count; 00146 Uint64 commit_count; 00147 ulong row_size; 00148 Uint64 fragment_memory; 00149 Uint64 fragment_extent_space; 00150 Uint64 fragment_extent_free_space; 00151 }; 00152 00153 00154 struct NDB_SHARE { 00155 NDB_SHARE_STATE state; 00156 MEM_ROOT mem_root; 00157 THR_LOCK lock; 00158 pthread_mutex_t mutex; 00159 char *key; 00160 uint key_length; 00161 char *new_key; 00162 uint use_count; 00163 uint commit_count_lock; 00164 ulonglong commit_count; 00165 char *db; 00166 char *table_name; 00167 Ndb::TupleIdRange tuple_id_range; 00168 struct Ndb_statistics stat; 00169 struct Ndb_index_stat* index_stat_list; 00170 bool util_thread; // if opened by util thread 00171 uint32 connect_count; 00172 uint32 flags; 00173 #ifdef HAVE_NDB_BINLOG 00174 NDB_CONFLICT_FN_SHARE *m_cfn_share; 00175 #endif 00176 class Ndb_event_data *event_data; // Place holder before NdbEventOperation is created 00177 class NdbEventOperation *op; 00178 char *old_names; // for rename table 00179 MY_BITMAP *subscriber_bitmap; 00180 class NdbEventOperation *new_op; 00181 }; 00182 00183 00184 inline 00185 NDB_SHARE_STATE 00186 get_ndb_share_state(NDB_SHARE *share) 00187 { 00188 NDB_SHARE_STATE state; 00189 pthread_mutex_lock(&share->mutex); 00190 state= share->state; 00191 pthread_mutex_unlock(&share->mutex); 00192 return state; 00193 } 00194 00195 00196 inline 00197 void 00198 set_ndb_share_state(NDB_SHARE *share, NDB_SHARE_STATE state) 00199 { 00200 pthread_mutex_lock(&share->mutex); 00201 share->state= state; 00202 pthread_mutex_unlock(&share->mutex); 00203 } 00204 00205 #endif