MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ArbitSignalData.hpp
1 /*
2  Copyright (c) 2003, 2010, 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 ARBIT_SIGNAL_DATA_H
19 #define ARBIT_SIGNAL_DATA_H
20 
21 #include <string.h>
22 #include <NodeBitmask.hpp>
23 #include <NdbTick.h>
24 #include <NdbHost.h>
25 #include "SignalData.hpp"
26 #include "SignalDataPrint.hpp"
27 
31 class ArbitTicket {
32 private:
33  Uint32 data[2];
34 
35 public:
36  STATIC_CONST( DataLength = 2 );
37  STATIC_CONST( TextLength = DataLength * 8 ); // hex digits
38 
39  inline void clear() {
40  data[0] = 0;
41  data[1] = 0;
42  }
43 
44  inline void update() {
45  Uint16 cnt = data[0] & 0xFFFF; // previous count
46  Uint16 pid = NdbHost_GetProcessId();
47  data[0] = (pid << 16) | (cnt + 1);
48  data[1] = (Uint32)NdbTick_CurrentMillisecond();
49  }
50 
51  inline bool match(ArbitTicket& aTicket) const {
52  return
53  data[0] == aTicket.data[0] &&
54  data[1] == aTicket.data[1];
55  }
56 
57  inline void getText(char *buf, size_t buf_len) const {
58  BaseString::snprintf(buf, buf_len, "%08x%08x", data[0], data[1]);
59  }
60 
61 /* inline char* getText() const {
62  static char buf[TextLength + 1];
63  getText(buf, sizeof(buf));
64  return buf;
65  } */
66 };
67 
72 class ArbitCode {
73 public:
74  STATIC_CONST( ErrTextLength = 80 );
75 
76  enum {
77  NoInfo = 0,
78 
79  // CFG signals
80  CfgRank1 = 1, // these have to be 1 and 2
81  CfgRank2 = 2,
82 
83  // QMGR continueB thread state
84  ThreadStart = 11, // continueB thread started
85 
86  // PREP signals
87  PrepPart1 = 21, // zero old ticket
88  PrepPart2 = 22, // get new ticket
89  PrepAtrun = 23, // late joiner gets ticket at RUN time
90 
91  // arbitrator state
92  ApiStart = 31, // arbitrator thread started
93  ApiFail = 32, // arbitrator died
94  ApiExit = 33, // arbitrator reported it will exit
95 
96  // arbitration result
97  LoseNodes = 41, // lose on ndb node count
98  WinNodes = 42, // win on ndb node count
99  WinGroups = 43, // we win, no need for arbitration
100  LoseGroups = 44, // we lose, missing node group
101  Partitioning = 45, // possible network partitioning
102  WinChoose = 46, // positive reply
103  LoseChoose = 47, // negative reply
104  LoseNorun = 48, // arbitrator required but not running
105  LoseNocfg = 49, // arbitrator required but none configured
106  WinWaitExternal = 50, // continue after external arbitration wait
107 
108  // general error codes
109  ErrTicket = 91, // invalid arbitrator-ticket
110  ErrToomany = 92, // too many requests
111  ErrState = 93, // invalid state
112  ErrTimeout = 94, // timeout waiting for signals
113  ErrUnknown = 95 // unknown error
114  };
115 
116  static inline void getErrText(Uint32 code, char* buf, size_t buf_len) {
117  switch (code) {
118  case ErrTicket:
119  BaseString::snprintf(buf, buf_len, "invalid arbitrator-ticket");
120  break;
121  case ErrToomany:
122  BaseString::snprintf(buf, buf_len, "too many requests");
123  break;
124  case ErrState:
125  BaseString::snprintf(buf, buf_len, "invalid state");
126  break;
127  case ErrTimeout:
128  BaseString::snprintf(buf, buf_len, "timeout");
129  break;
130  default:
131  BaseString::snprintf(buf, buf_len, "unknown error [code=%u]", code);
132  break;
133  }
134  }
135 };
136 
141 public:
142  Uint32 sender; // sender's node id (must be word 0)
143  Uint32 code; // result code or other info
144  Uint32 node; // arbitrator node id
145  ArbitTicket ticket; // ticket
146  NodeBitmaskPOD mask; // set of nodes
147 
148  STATIC_CONST( SignalLength = 3 + ArbitTicket::DataLength + NodeBitmask::Size );
149 
150  inline bool match(ArbitSignalData& aData) const {
151  return
152  node == aData.node &&
153  ticket.match(aData.ticket);
154  }
155 };
156 
157 #endif