mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / include / kernel / signaldata / ArbitSignalData.hpp
blob366afa4b4772d09ab58c5261b43f374edbf0f76a
1 /* Copyright (c) 2003-2007 MySQL AB
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.
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.
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 */
16 #ifndef ARBIT_SIGNAL_DATA_H
17 #define ARBIT_SIGNAL_DATA_H
19 #include <string.h>
20 #include <NodeBitmask.hpp>
21 #include <NdbTick.h>
22 #include <NdbHost.h>
23 #include "SignalData.hpp"
24 #include "SignalDataPrint.hpp"
26 /**
27 * The ticket.
29 class ArbitTicket {
30 private:
31 Uint32 data[2];
33 public:
34 ArbitTicket() {}
35 STATIC_CONST( DataLength = 2 );
36 STATIC_CONST( TextLength = DataLength * 8 ); // hex digits
38 inline void clear() {
39 data[0] = 0;
40 data[1] = 0;
43 inline void update() {
44 Uint16 cnt = data[0] & 0xFFFF; // previous count
45 Uint16 pid = NdbHost_GetProcessId();
46 data[0] = (pid << 16) | (cnt + 1);
47 data[1] = NdbTick_CurrentMillisecond();
50 inline bool match(ArbitTicket& aTicket) const {
51 return
52 data[0] == aTicket.data[0] &&
53 data[1] == aTicket.data[1];
56 inline void getText(char *buf, size_t buf_len) const {
57 BaseString::snprintf(buf, buf_len, "%08x%08x", data[0], data[1]);
60 /* inline char* getText() const {
61 static char buf[TextLength + 1];
62 getText(buf, sizeof(buf));
63 return buf;
64 } */
67 /**
68 * Result codes. Part of signal data. Each signal uses only
69 * a subset but a common namespace is convenient.
71 class ArbitCode {
72 public:
73 STATIC_CONST( ErrTextLength = 80 );
75 enum {
76 NoInfo = 0,
78 // CFG signals
79 CfgRank1 = 1, // these have to be 1 and 2
80 CfgRank2 = 2,
82 // QMGR continueB thread state
83 ThreadStart = 11, // continueB thread started
85 // PREP signals
86 PrepPart1 = 21, // zero old ticket
87 PrepPart2 = 22, // get new ticket
88 PrepAtrun = 23, // late joiner gets ticket at RUN time
90 // arbitrator state
91 ApiStart = 31, // arbitrator thread started
92 ApiFail = 32, // arbitrator died
93 ApiExit = 33, // arbitrator reported it will exit
95 // arbitration result
96 LoseNodes = 41, // lose on ndb node count
97 WinNodes = 42, // win on ndb node count
98 WinGroups = 43, // we win, no need for arbitration
99 LoseGroups = 44, // we lose, missing node group
100 Partitioning = 45, // possible network partitioning
101 WinChoose = 46, // positive reply
102 LoseChoose = 47, // negative reply
103 LoseNorun = 48, // arbitrator required but not running
104 LoseNocfg = 49, // arbitrator required but none configured
106 // general error codes
107 ErrTicket = 91, // invalid arbitrator-ticket
108 ErrToomany = 92, // too many requests
109 ErrState = 93, // invalid state
110 ErrTimeout = 94, // timeout waiting for signals
111 ErrUnknown = 95 // unknown error
114 static inline void getErrText(Uint32 code, char* buf, size_t buf_len) {
115 switch (code) {
116 case ErrTicket:
117 BaseString::snprintf(buf, buf_len, "invalid arbitrator-ticket");
118 break;
119 case ErrToomany:
120 BaseString::snprintf(buf, buf_len, "too many requests");
121 break;
122 case ErrState:
123 BaseString::snprintf(buf, buf_len, "invalid state");
124 break;
125 case ErrTimeout:
126 BaseString::snprintf(buf, buf_len, "timeout");
127 break;
128 default:
129 BaseString::snprintf(buf, buf_len, "unknown error [code=%u]", code);
130 break;
136 * Common class for arbitration signal data.
138 class ArbitSignalData {
139 public:
140 Uint32 sender; // sender's node id (must be word 0)
141 Uint32 code; // result code or other info
142 Uint32 node; // arbitrator node id
143 ArbitTicket ticket; // ticket
144 NodeBitmask mask; // set of nodes
146 ArbitSignalData() {}
147 STATIC_CONST( SignalLength = 3 + ArbitTicket::DataLength + NodeBitmask::Size );
149 inline bool match(ArbitSignalData& aData) const {
150 return
151 node == aData.node &&
152 ticket.match(aData.ticket);
156 #endif