1 /*
2    Copyright (c) 2005, 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 SIGNAL_SENDER_HPP
26 #define SIGNAL_SENDER_HPP
27 
28 #include <ndb_global.h>
29 #include "TransporterFacade.hpp"
30 #include "trp_client.hpp"
31 #include "NdbApiSignal.hpp"
32 #include <Vector.hpp>
33 
34 #include <signaldata/TestOrd.hpp>
35 #include <signaldata/TamperOrd.hpp>
36 #include <signaldata/StartOrd.hpp>
37 #include <signaldata/ApiVersion.hpp>
38 #include <signaldata/ResumeReq.hpp>
39 #include <signaldata/SetLogLevelOrd.hpp>
40 #include <signaldata/EventSubscribeReq.hpp>
41 #include <signaldata/EventReport.hpp>
42 #include <signaldata/DumpStateOrd.hpp>
43 #include <signaldata/BackupSignalData.hpp>
44 #include <signaldata/AllocNodeId.hpp>
45 
46 struct SimpleSignal {
47 public:
48   SimpleSignal(bool dealloc = false);
49   SimpleSignal(const SimpleSignal& src);
50   ~SimpleSignal();
51 
52   void set(class SignalSender&,
53 	   Uint8  trace, Uint16 recBlock, Uint16 gsn, Uint32 len);
54 
55   NdbApiSignal header;
56   LinearSectionPtr ptr[3];
57 
readSignalNumberSimpleSignal58   int readSignalNumber() const { return header.readSignalNumber(); };
getDataPtrSendSimpleSignal59   Uint32 *getDataPtrSend() { return header.getDataPtrSend(); }
getDataPtrSimpleSignal60   const Uint32 *getDataPtr() const { return header.getDataPtr(); }
getLengthSimpleSignal61   Uint32 getLength() const { return header.getLength(); }
62 
63   /**
64    * Fragmentation
65    */
isFragmentedSimpleSignal66   bool isFragmented() const { return header.isFragmented(); }
isFirstFragmentSimpleSignal67   bool isFirstFragment() const { return header.isFirstFragment(); }
isLastFragmentSimpleSignal68   bool isLastFragment() const { return header.isLastFragment(); };
getFragmentIdSimpleSignal69   Uint32 getFragmentId() const { return header.getFragmentId(); };
70 
71   void print(FILE * out = stdout) const;
72   SimpleSignal& operator=(const SimpleSignal&);
73 private:
74   bool deallocSections;
75 };
76 
77 class SignalSender  : public trp_client {
78 public:
79   SignalSender(TransporterFacade *facade, int blockNo = -1);
80   SignalSender(Ndb_cluster_connection* connection);
81   virtual ~SignalSender();
82 
83   int lock();
84   int unlock();
85 
86   Uint32 getOwnRef() const;
87 
88   NodeId find_confirmed_node(const NodeBitmask& mask);
89   NodeId find_connected_node(const NodeBitmask& mask);
90   NodeId find_alive_node(const NodeBitmask& mask);
91 
92   SendStatus sendSignal(Uint16 nodeId, const SimpleSignal *);
93   SendStatus sendSignal(Uint16 nodeId, SimpleSignal& sig,
94                         Uint16 recBlock, Uint16 gsn, Uint32 len);
95   int sendFragmentedSignal(Uint16 nodeId, SimpleSignal& sig,
96                            Uint16 recBlock, Uint16 gsn, Uint32 len);
97   NodeBitmask broadcastSignal(NodeBitmask mask, SimpleSignal& sig,
98                               Uint16 recBlock, Uint16 gsn, Uint32 len);
99 
100   SimpleSignal * waitFor(Uint32 timeOutMillis = 0);
101 
get_an_alive_node() const102   Uint32 get_an_alive_node() const { return theFacade->get_an_alive_node(); }
getAliveNode() const103   Uint32 getAliveNode() const { return get_an_alive_node(); }
get_node_alive(Uint32 n) const104   bool get_node_alive(Uint32 n) const { return getNodeInfo(n).m_alive; }
105 
106 private:
107   int m_blockNo;
108   TransporterFacade * theFacade;
109   bool m_locked;
110 
111 public:
112   /**
113    * trp_client interface
114    */
115   virtual void trp_deliver_signal(const NdbApiSignal* signal,
116                                   const struct LinearSectionPtr ptr[3]);
117 
118   Vector<SimpleSignal *> m_jobBuffer;
119   Vector<SimpleSignal *> m_usedBuffer;
120 
121   template<class T>
122   SimpleSignal * waitFor(Uint32 timeOutMillis, T & t);
123 
124   template<class T>
125   NodeId find_node(const NodeBitmask& mask, T & t);
126 };
127 
128 #endif
129