1 /*
2    Copyright (C) 2003, 2005-2008 MySQL AB, 2008 Sun Microsystems, Inc.
3     All rights reserved. Use is subject to license terms.
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License, version 2.0,
7    as published by the Free Software Foundation.
8 
9    This program is also distributed with certain software (including
10    but not limited to OpenSSL) that is licensed under separate terms,
11    as designated in a particular file or component or in included license
12    documentation.  The authors of MySQL hereby grant you an additional
13    permission to link the program and your derivative works with the
14    separately licensed software that they have included with MySQL.
15 
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19    GNU General Public License, version 2.0, for more details.
20 
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
24 */
25 
26 #ifndef LQH_TRANS_CONF_H
27 #define LQH_TRANS_CONF_H
28 
29 #include "SignalData.hpp"
30 
31 /**
32  * This signal is sent as response to a LQH_TRANSREQ
33  * which is sent as by a take-over TC
34  */
35 class LqhTransConf {
36   /**
37    * Reciver(s)
38    */
39   friend class Dbtc;
40 
41   /**
42    * Sender(s)
43    */
44   friend class Dblqh;
45   friend class DblqhProxy;
46 
47   friend bool printLQH_TRANSCONF(FILE *, const Uint32 *, Uint32, Uint16);
48 public:
49   STATIC_CONST( SignalLength = 17 );
50 
51   /**
52    * Upgrade
53    */
54   STATIC_CONST( SignalLength_GCI_LO = 16 );
55   STATIC_CONST( SignalLength_FRAG_ID = 17 );
56 private:
57 
58   /**
59    * This type describes the state of the operation returned in this signal
60    */
61   enum OperationStatus {
62     InvalidStatus = 0, /**< This status should never be sent in a signal
63 			  it is only used for initializing variables so that
64 			  you can easily later check if they have changed */
65     LastTransConf = 4, /**< This status indicates that LQH has finished the scan
66 			  of operations belonging to the died TC.
67 			  Data 0 - 2 is valid */
68 
69     Prepared  = 2,
70     Committed = 3,
71     Aborted   = 1,
72     Marker    = 5 /**< This means that the only thing left is a marker,
73 		     Data 0 - 6 is valid */
74   };
75 
76   /**
77    * DATA VARIABLES
78    */
79   Uint32 tcRef;           // 0
80   Uint32 lqhNodeId;       // 1
81   Uint32 operationStatus; // 2 See enum OperationStatus
82   Uint32 transId1;        // 3
83   Uint32 transId2;        // 4
84   Uint32 apiRef;          // 5
85   Uint32 apiOpRec;        // 6
86   Uint32 lqhConnectPtr;
87   Uint32 oldTcOpRec;
88   Uint32 requestInfo;
89   Uint32 gci_hi;
90   Uint32 nextNodeId1;
91   Uint32 nextNodeId2;
92   Uint32 nextNodeId3;
93   Uint32 tableId;
94   Uint32 gci_lo;
95   Uint32 fragId;
96 
97   /**
98    * Getters
99    */
100   static Uint32 getReplicaNo(Uint32 & requestInfo);
101   static Uint32 getReplicaType(Uint32 & requestInfo);
102   static Uint32 getLastReplicaNo(Uint32 & requestInfo);
103   static Uint32 getSimpleFlag(Uint32 & requestInfo);
104   static Uint32 getDirtyFlag(Uint32 & requestInfo);
105   static Uint32 getOperation(Uint32 & requestInfo);
106   static Uint32 getMarkerFlag(Uint32 & requestInfo);
107 
108   static void setReplicaNo(UintR & requestInfo, UintR val);
109   static void setReplicaType(UintR & requestInfo, UintR val);
110   static void setLastReplicaNo(UintR & requestInfo, UintR val);
111   static void setSimpleFlag(UintR & requestInfo, UintR val);
112   static void setDirtyFlag(UintR & requestInfo, UintR val);
113   static void setOperation(UintR & requestInfo, UintR val);
114   static void setMarkerFlag(Uint32 & requestInfo, Uint32 val);
115 };
116 
117 /**
118  * Request Info
119  *
120  * t = replica type           - 2  Bits (0-1)
121  * r = Replica No             - 2  Bits (2-3)
122  * l = Last Replica No        - 2  Bits (4-5)
123  * s = Simple                 - 1  Bits (6)
124  * d = Dirty                  - 1  Bit  (7)
125  * o = Operation              - 3  Bit  (8-9)
126  * m = Marker present         - 1  Bit  (10)
127  *
128  *           1111111111222222222233
129  * 01234567890123456789012345678901
130  * ttrrllsdooom
131  */
132 #define LTC_REPLICA_TYPE_SHIFT    (0)
133 #define LTC_REPLICA_TYPE_MASK     (3)
134 #define LTC_REPLICA_NO_SHIFT      (2)
135 #define LTC_REPLICA_NO_MASK       (3)
136 #define LTC_LAST_REPLICA_SHIFT    (4)
137 #define LTC_LAST_REPLICA_MASK     (3)
138 #define LTC_SIMPLE_SHIFT          (6)
139 #define LTC_DIRTY_SHIFT           (7)
140 #define LTC_OPERATION_SHIFT       (8)
141 #define LTC_OPERATION_MASK        (7)
142 #define LTC_MARKER_SHIFT          (10)
143 
144 inline
145 Uint32
getReplicaType(Uint32 & requestInfo)146 LqhTransConf::getReplicaType(Uint32 & requestInfo){
147   return (requestInfo >> LTC_REPLICA_TYPE_SHIFT) & LTC_REPLICA_TYPE_MASK;
148 }
149 
150 inline
151 Uint32
getReplicaNo(Uint32 & requestInfo)152 LqhTransConf::getReplicaNo(Uint32 & requestInfo){
153   return (requestInfo >> LTC_REPLICA_NO_SHIFT) & LTC_REPLICA_NO_MASK;
154 }
155 
156 inline
157 Uint32
getLastReplicaNo(Uint32 & requestInfo)158 LqhTransConf::getLastReplicaNo(Uint32 & requestInfo){
159   return (requestInfo >> LTC_LAST_REPLICA_SHIFT) & LTC_LAST_REPLICA_MASK;
160 }
161 
162 inline
163 Uint32
getSimpleFlag(Uint32 & requestInfo)164 LqhTransConf::getSimpleFlag(Uint32 & requestInfo){
165   return (requestInfo >> LTC_SIMPLE_SHIFT) & 1;
166 }
167 
168 inline
169 Uint32
getDirtyFlag(Uint32 & requestInfo)170 LqhTransConf::getDirtyFlag(Uint32 & requestInfo){
171   return (requestInfo >> LTC_DIRTY_SHIFT) & 1;
172 }
173 
174 inline
175 Uint32
getOperation(Uint32 & requestInfo)176 LqhTransConf::getOperation(Uint32 & requestInfo){
177   return (requestInfo >> LTC_OPERATION_SHIFT) & LTC_OPERATION_MASK;
178 }
179 
180 inline
181 Uint32
getMarkerFlag(Uint32 & requestInfo)182 LqhTransConf::getMarkerFlag(Uint32 & requestInfo){
183   return (requestInfo >> LTC_MARKER_SHIFT) & 1;
184 }
185 
186 
187 inline
188 void
setReplicaNo(UintR & requestInfo,UintR val)189 LqhTransConf::setReplicaNo(UintR & requestInfo, UintR val){
190   ASSERT_MAX(val, LTC_REPLICA_NO_MASK, "LqhTransConf::setReplicaNo");
191   requestInfo |= (val << LTC_REPLICA_NO_SHIFT);
192 }
193 
194 inline
195 void
setReplicaType(UintR & requestInfo,UintR val)196 LqhTransConf::setReplicaType(UintR & requestInfo, UintR val){
197   ASSERT_MAX(val, LTC_REPLICA_TYPE_MASK, "LqhTransConf::setReplicaType");
198   requestInfo |= (val << LTC_REPLICA_TYPE_SHIFT);
199 }
200 
201 inline
202 void
setLastReplicaNo(UintR & requestInfo,UintR val)203 LqhTransConf::setLastReplicaNo(UintR & requestInfo, UintR val){
204   ASSERT_MAX(val, LTC_LAST_REPLICA_MASK, "LqhTransConf::setLastReplicaNo");
205   requestInfo |= (val << LTC_LAST_REPLICA_SHIFT);
206 }
207 
208 inline
209 void
setSimpleFlag(UintR & requestInfo,UintR val)210 LqhTransConf::setSimpleFlag(UintR & requestInfo, UintR val){
211   ASSERT_BOOL(val, "LqhTransConf::setSimpleFlag");
212   requestInfo |= (val << LTC_SIMPLE_SHIFT);
213 }
214 
215 inline
216 void
setDirtyFlag(UintR & requestInfo,UintR val)217 LqhTransConf::setDirtyFlag(UintR & requestInfo, UintR val){
218   ASSERT_BOOL(val, "LqhTransConf::setDirtyFlag");
219   requestInfo |= (val << LTC_DIRTY_SHIFT);
220 }
221 
222 inline
223 void
setOperation(UintR & requestInfo,UintR val)224 LqhTransConf::setOperation(UintR & requestInfo, UintR val){
225   ASSERT_MAX(val, LTC_OPERATION_MASK, "LqhTransConf::setOperation");
226   requestInfo |= (val << LTC_OPERATION_SHIFT);
227 }
228 
229 inline
230 void
setMarkerFlag(UintR & requestInfo,UintR val)231 LqhTransConf::setMarkerFlag(UintR & requestInfo, UintR val){
232   ASSERT_BOOL(val, "LqhTransConf::setMarkerFlag");
233   requestInfo |= (val << LTC_MARKER_SHIFT);
234 }
235 
236 #endif
237