~vlad-lesin/percona-server/mysql-5.0.33-original

« back to all changes in this revision

Viewing changes to ndb/include/kernel/signaldata/ArbitSignalData.hpp

  • Committer: Vlad Lesin
  • Date: 2012-07-31 09:21:34 UTC
  • Revision ID: vladislav.lesin@percona.com-20120731092134-zfodx022b7992wsi
VirginĀ 5.0.33

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 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; either version 2 of the License, or
 
6
   (at your option) any later version.
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
16
 
 
17
#ifndef ARBIT_SIGNAL_DATA_H
 
18
#define ARBIT_SIGNAL_DATA_H
 
19
 
 
20
#include <string.h>
 
21
#include <NodeBitmask.hpp>
 
22
#include <NdbTick.h>
 
23
#include <NdbHost.h>
 
24
#include "SignalData.hpp"
 
25
#include "SignalDataPrint.hpp"
 
26
 
 
27
/**
 
28
 * The ticket.
 
29
 */
 
30
class ArbitTicket {
 
31
private:
 
32
  Uint32 data[2];
 
33
 
 
34
public:
 
35
  STATIC_CONST( DataLength = 2 );
 
36
  STATIC_CONST( TextLength = DataLength * 8 );  // hex digits
 
37
 
 
38
  inline void clear() {
 
39
    data[0] = 0;
 
40
    data[1] = 0;
 
41
  }
 
42
 
 
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();
 
48
  }
 
49
 
 
50
  inline bool match(ArbitTicket& aTicket) const {
 
51
    return
 
52
      data[0] == aTicket.data[0] &&
 
53
      data[1] == aTicket.data[1];
 
54
  }
 
55
 
 
56
  inline void getText(char *buf, size_t buf_len) const {
 
57
    BaseString::snprintf(buf, buf_len, "%08x%08x", data[0], data[1]);
 
58
  }
 
59
 
 
60
/*  inline char* getText() const {
 
61
    static char buf[TextLength + 1];
 
62
    getText(buf, sizeof(buf));
 
63
    return buf;
 
64
  } */
 
65
};
 
66
 
 
67
/**
 
68
 * Result codes.  Part of signal data.  Each signal uses only
 
69
 * a subset but a common namespace is convenient.
 
70
 */
 
71
class ArbitCode {
 
72
public:
 
73
  STATIC_CONST( ErrTextLength = 80 );
 
74
 
 
75
  enum {
 
76
    NoInfo = 0,
 
77
 
 
78
    // CFG signals
 
79
    CfgRank1 = 1,               // these have to be 1 and 2
 
80
    CfgRank2 = 2,
 
81
 
 
82
    // QMGR continueB thread state
 
83
    ThreadStart = 11,           // continueB thread started
 
84
 
 
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
 
89
 
 
90
    // arbitrator state
 
91
    ApiStart = 31,              // arbitrator thread started
 
92
    ApiFail = 32,               // arbitrator died
 
93
    ApiExit = 33,               // arbitrator reported it will exit
 
94
 
 
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
 
105
 
 
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
 
112
  };
 
113
 
 
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;
 
131
    }
 
132
  }
 
133
};
 
134
 
 
135
/**
 
136
 * Common class for arbitration signal data.
 
137
 */
 
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
 
145
 
 
146
  STATIC_CONST( SignalLength = 3 + ArbitTicket::DataLength + NodeBitmask::Size );
 
147
 
 
148
  inline bool match(ArbitSignalData& aData) const {
 
149
    return
 
150
      node == aData.node &&
 
151
      ticket.match(aData.ticket);
 
152
  }
 
153
};
 
154
 
 
155
#endif