1 /*
2    Copyright (c) 2003, 2021, Oracle and/or its affiliates.
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, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #ifndef FAIL_REP_HPP
26 #define FAIL_REP_HPP
27 
28 #include "SignalData.hpp"
29 #include <NodeBitmask.hpp>
30 
31 #define JAM_FILE_ID 24
32 
33 
34 /**
35  *
36  */
37 class FailRep {
38   /**
39    * Sender(s) & Reciver(s)
40    */
41   friend class Qmgr;
42   friend class Ndbcntr;
43 
44   /**
45    * For printing
46    */
47   friend bool printFAIL_REP(FILE *, const Uint32 *, Uint32, Uint16);
48 
49 public:
50   STATIC_CONST( OrigSignalLength = 2 );
51   STATIC_CONST( PartitionedExtraLength = 1 + NdbNodeBitmask::Size );
52   STATIC_CONST( SourceExtraLength = 1 );
53   STATIC_CONST( SignalLength = OrigSignalLength + SourceExtraLength );
54 
55   enum FailCause {
56     ZOWN_FAILURE=0,
57     ZOTHER_NODE_WHEN_WE_START=1,
58     ZIN_PREP_FAIL_REQ=2,
59     ZSTART_IN_REGREQ=3,
60     ZHEARTBEAT_FAILURE=4,
61     ZLINK_FAILURE=5,
62     ZOTHERNODE_FAILED_DURING_START=6,
63     ZMULTI_NODE_SHUTDOWN = 7,
64     ZPARTITIONED_CLUSTER = 8,
65     ZCONNECT_CHECK_FAILURE = 9,
66     ZFORCED_ISOLATION = 10
67   };
68 
getFailSourceNodeId(Uint32 sigLen) const69   Uint32 getFailSourceNodeId(Uint32 sigLen) const
70   {
71     /* Get failSourceNodeId from signal given length
72      * 2 cases of 2 existing cases :
73      *   1) Old node, no source id
74      *   2) New node, source id
75      *   a) ZPARTITIONED_CLUSTER, extra info
76      *   b) Other error, no extra info
77      */
78     if (failCause == ZPARTITIONED_CLUSTER)
79     {
80       return (sigLen == (SignalLength + PartitionedExtraLength)) ?
81         partitioned.partitionFailSourceNodeId :
82         0;
83     }
84 
85     return (sigLen == SignalLength) ? failSourceNodeId :
86       0;
87   }
88 
89 private:
90 
91   Uint32 failNodeId;
92   Uint32 failCause;
93   /**
94    * Used when failCause == ZPARTITIONED_CLUSTER
95    */
96   union {
97     struct
98     {
99       Uint32 president;
100       Uint32 partition[NdbNodeBitmask::Size];
101       Uint32 partitionFailSourceNodeId;
102     } partitioned;
103     Uint32 failSourceNodeId;
104   };
105 };
106 
107 
108 
109 #undef JAM_FILE_ID
110 
111 #endif
112