MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DictSignal.hpp
1 /* Copyright (C) 2007, 2008 MySQL AB
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
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
15 
16 #ifndef DICT_SIGNAL_HPP
17 #define DICT_SIGNAL_HPP
18 
19 #include <Bitmask.hpp>
20 
21 struct DictSignal
22 {
23  // DICT transaction and operation REQs include Uint32 requestInfo
24  // implementation signals have only requestType
25  // requestInfo format should be as follows
26 
27  // byte 0: requestType (usually enum)
28 
29  static Uint32
30  getRequestType(const Uint32& info) {
31  return BitmaskImpl::getField(1, &info, 0, 8);
32  }
33 
34  static void
35  setRequestType(Uint32& info, Uint32 val) {
36  assert(val < (1 << 8));
37  BitmaskImpl::setField(1, &info, 0, 8, val);
38  }
39 
40  // byte 1: extra case-dependent usage within DICT
41 
42  static Uint32
43  getRequestExtra(const Uint32& info) {
44  return BitmaskImpl::getField(1, &info, 8, 8);
45  }
46 
47  static void
48  setRequestExtra(Uint32& info, Uint32 val) {
49  assert(val < (1 << 8));
50  BitmaskImpl::setField(1, &info, 8, 8, val);
51  }
52 
53  static void
54  addRequestExtra(Uint32& dst_info, const Uint32& src_info) {
55  Uint32 val = getRequestExtra(src_info);
56  setRequestExtra(dst_info, val);
57  }
58 
59  // byte 2: global flags: passed everywhere
60  // byte 3: local flags: consumed by current op
61 
62 private:
63 
64  // flag bits are defined relative to entire requestInfo word
65  enum { RequestFlagsMask = 0xffff0000 };
66  enum { RequestFlagsGlobalMask = 0x00ff0000 };
67 
68 public:
69 
70  enum RequestFlags {
71  // global
72 
73  /*
74  * This node is transaction coordinator and the only participant.
75  * Used by node doing NR to activate each index.
76  */
77  RF_LOCAL_TRANS = (1 << 16),
78 
79  /*
80  * Activate index but do not build it. On SR, the build is done
81  * in a later start phase (for non-logged index). On NR, the build
82  * on this node takes place automatically during data copy.
83  */
84  RF_NO_BUILD = (1 << 17)
85 
86  };
87 
88  static void
89  addRequestFlags(Uint32& dst_info, const Uint32& src_info) {
90  dst_info |= src_info & RequestFlagsMask;
91  }
92 
93  static void
94  addRequestFlagsGlobal(Uint32& dst_info, const Uint32& src_info) {
95  dst_info |= src_info & RequestFlagsGlobalMask;
96  }
97 
98  static const char*
99  getRequestFlagsText(const Uint32& info) {
100  static char buf[100];
101  buf[0] = buf[1] = 0;
102  if (info & RF_LOCAL_TRANS)
103  strcat(buf, " LOCAL_TRANS");
104  if (info & RF_NO_BUILD)
105  strcat(buf, " NO_BUILD");
106  return &buf[1];
107  }
108 
109  static const char*
110  getRequestInfoText(const Uint32& info) {
111  static char buf[100];
112  sprintf(buf, "type: %u extra: %u flags: %s",
113  getRequestType(info), (info >> 8) & 0xff, getRequestFlagsText(info));
114  return buf;
115  }
116 
117  // these match Dbdict.hpp
118 
119  static const char*
120  getTransModeName(Uint32 val) {
121  static const char* name[] = {
122  "Undef", "Normal", "Rollback", "Abort"
123  };
124  Uint32 size = sizeof(name)/sizeof(name[0]);
125  return val < size ? name[val] : "?";
126  }
127 
128  static const char*
129  getTransPhaseName(Uint32 val) {
130  static const char* name[] = {
131  "Undef", "Begin", "Parse", "Prepare", "Commit", "Complete", "End"
132  };
133  Uint32 size = sizeof(name)/sizeof(name[0]);
134  return val < size ? name[val] : "?";
135  }
136 
137  static const char*
138  getTransStateName(Uint32 val) {
139  static const char* name[] = {
140  "Undef", "Ok", "Error", "NodeFail", "NeedTrans", "NoTrans", "NeedOp", "NoOp"
141  };
142  Uint32 size = sizeof(name)/sizeof(name[0]);
143  return val < size ? name[val] : "?";
144  }
145 };
146 
147 #endif