MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SCI_Transporter.hpp
1 /*
2  Copyright (C) 2003-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 as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef SCI_Transporter_H
20 #define SCI_Transporter_H
21 #include "Transporter.hpp"
22 #include "SHM_Buffer.hpp"
23 
24 
25 #include <sisci_api.h>
26 #include <sisci_error.h>
27 #include <sisci_types.h>
28 
29 #include <ndb_types.h>
30 
70 class SCI_Transporter : public Transporter {
71  friend class TransporterRegistry;
72 public:
73 
78  bool initTransporter();
79 
80 
86  sci_error_t createSequence(Uint32 adapterid);
87 
88 
94  sci_error_t initLocalSegment();
95 
102  Uint32 remoteSegmentId(Uint16 localNodeId, Uint16 remoteNodeId);
103 
104  // Get local segment id (inline)
105  Uint32 hostSegmentId(Uint16 localNodeId, Uint16 remoteNodeId);
106 
110  void closeSCI();
111 
112 
118  bool checkConnected();
119 
126  bool getConnectionStatus();
127 
128 private:
130  const char *local_host,
131  const char *remote_host,
132  int port,
133  bool isMgmConnection,
134  Uint32 packetSize,
135  Uint32 bufferSize,
136  Uint32 nAdapters,
137  Uint16 remoteSciNodeId0,
138  Uint16 remoteSciNodeId1,
139  NodeId localNodeID,
140  NodeId remoteNodeID,
141  NodeId serverNodeId,
142  bool checksum,
143  bool signalId,
144  Uint32 reportFreq = 4096);
145 
149  ~SCI_Transporter();
150 
151  virtual bool configure_derived(const TransporterConfiguration* conf);
152 
153  bool m_mapped;
154  bool m_initLocal;
155  bool m_sciinit;
156  Uint32 m_failCounter;
160 //#ifdef DEBUG_TRANSPORTER
161 #if 1
162  Uint32 i1024;
163  Uint32 i2048;
164  Uint32 i2049;
165  Uint32 i10242048;
166  Uint32 i20484096;
167  Uint32 i4096;
168  Uint32 i4097;
169 #endif
170 
171  volatile Uint32 * m_localStatusFlag;
172  volatile Uint32 * m_remoteStatusFlag;
173  volatile Uint32 * m_remoteStatusFlag2;
174 
175  SHM_Reader * reader;
176  SHM_Writer * writer;
177  SHM_Writer * writer2;
178 
182  Uint32 m_reportFreq;
183 
184  Uint32 m_adapters;
185  Uint32 m_numberOfRemoteNodes;
186 
187  Uint16 m_remoteNodes[2];
188 
189  typedef struct SciAdapter {
190  sci_desc_t scidesc;
191  Uint32 localSciNodeId;
192  bool linkStatus;
193  } SciAdapter;
194 
195  SciAdapter* sciAdapters;
196  Uint32 m_ActiveAdapterId;
197  Uint32 m_StandbyAdapterId;
198 
199  typedef struct sourceSegm {
200  sci_local_segment_t localHandle; // Handle to local segment to be mapped
201  struct localHandleMap {
202  sci_map_t map; // Handle to the new mapped segment.
203  // 2 = max adapters in one node
204  } lhm[2];
205 
206  volatile void *mappedMemory; // Used when reading
207  } sourceSegm;
208 
209  typedef struct targetSegm {
210  struct remoteHandleMap {
211  sci_remote_segment_t remoteHandle; //Handle to local segment to be mapped
212  sci_map_t map; //Handle to the new mapped segment
213  } rhm[2];
214 
215  sci_sequence_status_t m_SequenceStatus; // Used for error checking
216  sci_sequence_t sequence;
217  volatile void * mappedMemory; // Used when writing
218  SHM_Writer * writer;
219  } targetSegm;
220 
221  sci_sequence_status_t m_SequenceStatus; // Used for error checking
222 
223 
224  // Shared between all SCI users active=(either prim or second)
225  sci_desc_t activeSCIDescriptor;
226 
227  sourceSegm* m_SourceSegm; // Local segment reference
228  targetSegm* m_TargetSegm; // Remote segment reference
229 
230  Uint32 m_LocalAdapterId; // Adapter Id
231  Uint16 m_LocalSciNodeId; // The SCI-node Id of this machine (adapter 0)
232  Uint16 m_LocalSciNodeId1; // The SCI-node Id of this machine (adapter 1)
233  Uint16 m_RemoteSciNodeId; // The SCI-node Id of remote machine (adapter 0)
234  Uint16 m_RemoteSciNodeId1; // The SCI-node Id of remote machine (adapter 1)
235 
236  Uint32 m_PacketSize; // The size of each data packet
237  Uint32 m_BufferSize; // Mapped SCI buffer size
238 
248  bool doSend();
249 
254  Uint32 getLocalNodeId(Uint32 adapterNo);
255 
256  bool hasDataToRead() const {
257  return reader->empty() == false;
258  }
259 
264  bool disconnectLocal();
265 
270  bool disconnectRemote();
271 
272  void resetToInitialState();
273 
274  void getReceivePtr(Uint32 ** ptr, Uint32 ** eod){
275  reader->getReadPtr(* ptr, * eod);
276  }
277 
278  void updateReceivePtr(Uint32 *ptr){
279  reader->updateReadPtr(ptr);
280  }
281 
287  void setupLocalSegment();
288 
292  void setupRemoteSegment();
293 
297  void setConnected();
298 
302  void setDisconnect();
303 
310  bool getLinkStatus(Uint32 adapterNo);
311 
316  void failoverShmWriter();
317 
318  bool init_local();
319  bool init_remote();
320 
321  bool send_limit_reached(int bufsize) { return (bufsize > m_PacketSize); }
322  bool send_is_possible(int timeout_millisec) const { return 1; }
323 
324 protected:
325 
332  bool connect_server_impl(NDB_SOCKET_TYPE sockfd);
333  bool connect_client_impl(NDB_SOCKET_TYPE sockfd);
334 
341  void disconnectImpl();
342 
343  static bool initSCI();
344 };
345 
346 
350 inline
351 Uint32
352 SCI_Transporter::hostSegmentId(Uint16 SciLocalNodeId,
353  Uint16 SciRemoteNodeId) {
354 
355  return (SciLocalNodeId << 16) | SciRemoteNodeId;
356 }
357 
361 inline
362 Uint32
363 SCI_Transporter::remoteSegmentId(Uint16 SciLocalNodeId,
364  Uint16 SciRemoteNodeId) {
365 
366  return (SciRemoteNodeId << 16) | SciLocalNodeId;
367 }
368 
369 
370 #endif