MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Ndbinfo.cpp
1 /*
2  Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
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 as published by
6  the Free Software Foundation; version 2 of the License.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "Ndbinfo.hpp"
19 #include "SimulatedBlock.hpp"
20 #include <kernel/AttributeHeader.hpp>
21 #include <signaldata/TransIdAI.hpp>
22 
23 Ndbinfo::Row::Row(Signal* signal, DbinfoScanReq& req) :
24  col_counter(0),
25  m_req(req)
26 {
27  // Use the "temporary" part of signal->theData as row buffer
28  start = signal->getDataPtrSend() + DbinfoScanReq::SignalLength;
29  const Uint32 data_sz = sizeof(signal->theData)/sizeof(signal->theData[0]);
30  end = signal->getDataPtrSend() + data_sz;
31  assert(start < end);
32 
33  curr = start;
34 }
35 
36 bool
37 Ndbinfo::Row::check_buffer_space(AttributeHeader& ah) const
38 {
39  const Uint32 needed = ah.getHeaderSize() + ah.getDataSize();
40  const Uint32 avail = (Uint32)(end - curr);
41 
42  if(needed > avail)
43  {
44  ndbout_c("Warning, too small row buffer for attribute: %d, "
45  "needed: %d, avail: %d", ah.getAttributeId(), needed, avail);
46  assert(false);
47  return false; // Not enough room in row buffer
48  }
49  return true;
50 }
51 
52 void
53 Ndbinfo::Row::check_attribute_type(AttributeHeader& ah, ColumnType type) const
54 {
55  const Table& tab = getTable(m_req.tableId);
56  const Uint32 colid = ah.getAttributeId();
57  assert(colid < (Uint32)tab.m.ncols);
58  assert(tab.col[colid].coltype == type);
59 }
60 
61 void
62 Ndbinfo::Row::write_string(const char* str)
63 {
64  const size_t clen = strlen(str) + 1;
65  // Create AttributeHeader
66  AttributeHeader ah(col_counter++, (Uint32)clen);
67  check_attribute_type(ah, Ndbinfo::String);
68  if (!check_buffer_space(ah))
69  return;
70 
71  // Write AttributeHeader to buffer
72  ah.insertHeader(curr);
73  curr += ah.getHeaderSize();
74 
75  // Write data to buffer
76  memcpy(curr, str, clen);
77  curr += ah.getDataSize();
78 
79  assert(curr <= end);
80  return;
81 }
82 
83 void
84 Ndbinfo::Row::write_uint32(Uint32 value)
85 {
86  // Create AttributeHeader
87  AttributeHeader ah(col_counter++, sizeof(Uint32));
88  check_attribute_type(ah, Ndbinfo::Number);
89  if (!check_buffer_space(ah))
90  return;
91 
92  // Write AttributeHeader to buffer
93  ah.insertHeader(curr);
94  curr += ah.getHeaderSize();
95 
96  // Write data to buffer
97  memcpy(curr, &value, sizeof(Uint32));
98  curr += ah.getDataSize();
99 
100  assert(curr <= end);
101  return;
102 }
103 
104 void
105 Ndbinfo::Row::write_uint64(Uint64 value)
106 {
107  // Create AttributeHeader
108  AttributeHeader ah(col_counter++, sizeof(Uint64));
109  check_attribute_type(ah, Ndbinfo::Number64);
110  if (!check_buffer_space(ah))
111  return;
112 
113  // Write AttributeHeader to buffer
114  ah.insertHeader(curr);
115  curr += ah.getHeaderSize();
116 
117  // Write data to buffer
118  memcpy(curr, &value, sizeof(Uint64));
119  curr += ah.getDataSize();
120 
121  assert(curr <= end);
122  return;
123 }
124 
125