MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ndb_share.h
1 /*
2  Copyright (c) 2011, 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 as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef NDB_SHARE_H
19 #define NDB_SHARE_H
20 
21 #include <my_global.h>
22 #include <my_alloc.h> // MEM_ROOT
23 #include <thr_lock.h> // THR_LOCK
24 #include <my_bitmap.h> // MY_BITMAP
25 
26 #include <ndbapi/Ndb.hpp> // Ndb::TupleIdRange
27 
28 enum NDB_SHARE_STATE {
29  NSS_INITIAL= 0,
30  NSS_DROPPED,
31  NSS_ALTERED
32 };
33 
34 
35 enum enum_conflict_fn_type
36 {
37  CFT_NDB_UNDEF = 0
38  ,CFT_NDB_MAX
39  ,CFT_NDB_OLD
40  ,CFT_NDB_MAX_DEL_WIN
41  ,CFT_NDB_EPOCH
42  ,CFT_NUMBER_OF_CFTS /* End marker */
43 };
44 
45 #ifdef HAVE_NDB_BINLOG
46 static const Uint32 MAX_CONFLICT_ARGS= 8;
47 
48 enum enum_conflict_fn_arg_type
49 {
50  CFAT_END
51  ,CFAT_COLUMN_NAME
52  ,CFAT_EXTRA_GCI_BITS
53 };
54 
55 struct st_conflict_fn_arg
56 {
57  enum_conflict_fn_arg_type type;
58  const char *ptr;
59  uint32 len;
60  union
61  {
62  uint32 fieldno; // CFAT_COLUMN_NAME
63  uint32 extraGciBits; // CFAT_EXTRA_GCI_BITS
64  };
65 };
66 
67 struct st_conflict_fn_arg_def
68 {
69  enum enum_conflict_fn_arg_type arg_type;
70  bool optional;
71 };
72 
73 /* What type of operation was issued */
74 enum enum_conflicting_op_type
75 { /* NdbApi */
76  WRITE_ROW, /* insert (!write) */
77  UPDATE_ROW, /* update */
78  DELETE_ROW /* delete */
79 };
80 
81 /*
82  prepare_detect_func
83 
84  Type of function used to prepare for conflict detection on
85  an NdbApi operation
86 */
87 typedef int (* prepare_detect_func) (struct NDB_CONFLICT_FN_SHARE* cfn_share,
88  enum_conflicting_op_type op_type,
89  const uchar* old_data,
90  const uchar* new_data,
91  const MY_BITMAP* write_set,
92  class NdbInterpretedCode* code);
93 
94 struct st_conflict_fn_def
95 {
96  const char *name;
97  enum_conflict_fn_type type;
98  const st_conflict_fn_arg_def* arg_defs;
99  prepare_detect_func prep_func;
100 };
101 
102 /* What sort of conflict was found */
103 enum enum_conflict_cause
104 {
105  ROW_ALREADY_EXISTS,
106  ROW_DOES_NOT_EXIST,
107  ROW_IN_CONFLICT
108 };
109 
110 /* NdbOperation custom data which points out handler and record. */
111 struct Ndb_exceptions_data {
112  struct NDB_SHARE* share;
113  const NdbRecord* key_rec;
114  const uchar* row;
115  enum_conflicting_op_type op_type;
116 };
117 
118 enum enum_conflict_fn_flags
119 {
120  CFF_NONE = 0,
121  CFF_REFRESH_ROWS = 1
122 };
123 
124 struct NDB_CONFLICT_FN_SHARE {
125  const st_conflict_fn_def* m_conflict_fn;
126 
127  /* info about original table */
128  uint8 m_pk_cols;
129  uint8 m_resolve_column;
130  uint8 m_resolve_size;
131  uint8 m_flags;
132  uint16 m_offset[16];
133  uint16 m_resolve_offset;
134 
135  const NdbDictionary::Table *m_ex_tab;
136  uint32 m_count;
137 };
138 #endif
139 
140 
141 /*
142  Stats that can be retrieved from ndb
143 */
145  Uint64 row_count;
146  Uint64 commit_count;
147  ulong row_size;
148  Uint64 fragment_memory;
149  Uint64 fragment_extent_space;
150  Uint64 fragment_extent_free_space;
151 };
152 
153 
154 struct NDB_SHARE {
155  NDB_SHARE_STATE state;
156  MEM_ROOT mem_root;
157  THR_LOCK lock;
158  pthread_mutex_t mutex;
159  char *key;
160  uint key_length;
161  char *new_key;
162  uint use_count;
163  uint commit_count_lock;
164  ulonglong commit_count;
165  char *db;
166  char *table_name;
167  Ndb::TupleIdRange tuple_id_range;
168  struct Ndb_statistics stat;
169  struct Ndb_index_stat* index_stat_list;
170  bool util_thread; // if opened by util thread
171  uint32 connect_count;
172  uint32 flags;
173 #ifdef HAVE_NDB_BINLOG
174  NDB_CONFLICT_FN_SHARE *m_cfn_share;
175 #endif
176  class Ndb_event_data *event_data; // Place holder before NdbEventOperation is created
177  class NdbEventOperation *op;
178  char *old_names; // for rename table
179  MY_BITMAP *subscriber_bitmap;
180  class NdbEventOperation *new_op;
181 };
182 
183 
184 inline
185 NDB_SHARE_STATE
186 get_ndb_share_state(NDB_SHARE *share)
187 {
188  NDB_SHARE_STATE state;
189  pthread_mutex_lock(&share->mutex);
190  state= share->state;
191  pthread_mutex_unlock(&share->mutex);
192  return state;
193 }
194 
195 
196 inline
197 void
198 set_ndb_share_state(NDB_SHARE *share, NDB_SHARE_STATE state)
199 {
200  pthread_mutex_lock(&share->mutex);
201  share->state= state;
202  pthread_mutex_unlock(&share->mutex);
203 }
204 
205 #endif