1
/* Copyright (C) 2003 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; either version 2 of the License, or
6
(at your option) any later version.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
#ifndef ARBIT_SIGNAL_DATA_H
18
#define ARBIT_SIGNAL_DATA_H
21
#include <NodeBitmask.hpp>
24
#include "SignalData.hpp"
25
#include "SignalDataPrint.hpp"
35
STATIC_CONST( DataLength = 2 );
36
STATIC_CONST( TextLength = DataLength * 8 ); // hex digits
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 {
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));
68
* Result codes. Part of signal data. Each signal uses only
69
* a subset but a common namespace is convenient.
73
STATIC_CONST( ErrTextLength = 80 );
79
CfgRank1 = 1, // these have to be 1 and 2
82
// QMGR continueB thread state
83
ThreadStart = 11, // continueB thread started
86
PrepPart1 = 21, // zero old ticket
87
PrepPart2 = 22, // get new ticket
88
PrepAtrun = 23, // late joiner gets ticket at RUN time
91
ApiStart = 31, // arbitrator thread started
92
ApiFail = 32, // arbitrator died
93
ApiExit = 33, // arbitrator reported it will exit
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) {
117
BaseString::snprintf(buf, buf_len, "invalid arbitrator-ticket");
120
BaseString::snprintf(buf, buf_len, "too many requests");
123
BaseString::snprintf(buf, buf_len, "invalid state");
126
BaseString::snprintf(buf, buf_len, "timeout");
129
BaseString::snprintf(buf, buf_len, "unknown error [code=%u]", code);
136
* Common class for arbitration signal data.
138
class ArbitSignalData {
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
STATIC_CONST( SignalLength = 3 + ArbitTicket::DataLength + NodeBitmask::Size );
148
inline bool match(ArbitSignalData& aData) const {
150
node == aData.node &&
151
ticket.match(aData.ticket);