1 /*
2    Copyright (c) 2009, 2019, 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, 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 KERNEL_NDBINFO_HPP
26 #define KERNEL_NDBINFO_HPP
27 
28 #include <signaldata/DbinfoScan.hpp>
29 
30 #define JAM_FILE_ID 230
31 
32 
33 class Ndbinfo {
34 public:
35 
36   enum ColumnType {
37     String = 1,
38     Number = 2,
39     Number64 = 3
40   };
41 
42   struct Column {
43     const char* name;
44     ColumnType coltype;
45     const char* comment;
46   };
47 
48   enum TableId {
49     TABLES_TABLEID =             0,
50     COLUMNS_TABLEID =            1,
51     TEST_TABLEID =               2,
52     POOLS_TABLEID =              3,
53     TRANSPORTERS_TABLEID =       4,
54     LOGSPACES_TABLEID =          5,
55     LOGBUFFERS_TABLEID =         6,
56     RESOURCES_TABLEID =          7,
57     COUNTERS_TABLEID =           8,
58     NODES_TABLEID =              9,
59     DISKPAGEBUFFER_TABLEID =     10,
60     THREADBLOCKS_TABLEID =       11,
61     THREADSTAT_TABLEID =         12,
62     TRANSACTIONS_TABLEID =       13,
63     OPERATIONS_TABLEID =         14,
64     MEMBERSHIP_TABLEID =         15,
65     DICT_OBJ_INFO_TABLEID =      16,
66     FRAG_MEM_USE_TABLEID =       17,
67     DISK_WRITE_SPEED_BASE_TABLEID = 18,
68     DISK_WRITE_SPEED_AGGREGATE_TABLEID = 19,
69     FRAG_OPERATIONS_TABLEID =    20,
70     RESTART_INFO_TABLEID =       21,
71     TC_TIME_TRACK_STATS_TABLEID = 22,
72     CONFIG_VALUES_TABLEID =      23,
73     THREADS_TABLEID =            24,
74     CPUSTAT_50MS_TABLEID =       25,
75     CPUSTAT_1SEC_TABLEID =       26,
76     CPUSTAT_20SEC_TABLEID =      27,
77     CPUSTAT_TABLEID =            28,
78     FRAG_LOCKS_TABLEID =         29,
79     ACC_OPERATIONS_TABLEID =     30,
80     TABLE_DIST_STATUS_TABLEID =  31,
81     TABLE_FRAGMENTS_TABLEID =    32,
82     TABLE_REPLICAS_TABLEID =     33,
83     TABLE_DIST_STATUS_ALL_TABLEID =34,
84     TABLE_FRAGMENTS_ALL_TABLEID =35,
85     TABLE_REPLICAS_ALL_TABLEID = 36,
86     STORED_TABLES_TABLEID =      37,
87     PROCESSES_TABLEID =          38,
88     CONFIG_NODES_TABLEID =       39,
89     PGMAN_TIME_TRACK_STATS_TABLEID = 40,
90     DISKSTAT_TABLEID =           41,
91     DISKSTATS_1SEC_TABLEID =     42
92   };
93 
94   enum BufferId {
95     REDO = 0,
96     DD_UNDO = 1,
97     BACKUP_DATA_BUFFER = 2,
98     BACKUP_LOG_BUFFER = 3
99   };
100 
101   struct Table {
102     struct Members {
103       const char* name;
104       int ncols;
105       int flags;
106       const char* comment;
107     } m;
108     Column col[1];
109 
columnsNdbinfo::Table110     int columns(void) const {
111       return m.ncols;
112     }
113   };
114   static int getNumTables();
115   static const Table& getTable(int i);
116   static const Table& getTable(Uint32 i);
117 
118   class Row {
119     friend class SimulatedBlock;
120     Uint32* start;      // Start of row buffer
121     Uint32* curr;       // Current position in row buffer
122     Uint32* end;        // End of buffer
123     int col_counter;    // Current column counter
124     DbinfoScan& m_req;  // The scan parameters
125     Row();              // Not impl
126     Row(const Row&);    // Not impl
127   public:
128 
129     Row(class Signal* signal, DbinfoScanReq& req);
130 
getLength(void) const131     Uint32 getLength(void) const {
132       return (Uint32)(curr - start);
133     }
134 
getDataPtr() const135     Uint32* getDataPtr() const {
136       return start;
137     }
138 
139     void write_string(const char* col);
140     void write_uint32(Uint32 value);
141     void write_uint64(Uint64 value);
142 
columns(void) const143     int columns(void) const {
144       return col_counter;
145     }
146 
147   private:
148     bool check_buffer_space(class AttributeHeader& ah) const;
149     void check_attribute_type(class AttributeHeader& ah, ColumnType) const;
150   };
151 
152   struct ScanCursor
153   {
154     Uint32 senderRef;
155     Uint32 saveSenderRef;
156     Uint32 currRef; // The current node, block and instance
157     Uint32 saveCurrRef;
158     /**
159      * Flags
160      *
161      m = More data         - 1  Bit 1
162 
163                1111111111222222222233
164      01234567890123456789012345678901
165      m
166     */
167     Uint32 flags;
168     Uint32 data[4];  // Cursor data
169 
170     Uint32 totalRows;
171     Uint32 totalBytes;
172     STATIC_CONST( Length = 10 );
173 
174     STATIC_CONST( MOREDATA_SHIFT = 0 );
175     STATIC_CONST( MOREDATA_MASK = 1 );
176 
getHasMoreDataNdbinfo::ScanCursor177     static bool getHasMoreData(const UintR & flags){
178       return (bool)((flags >> MOREDATA_SHIFT) & MOREDATA_MASK);
179     }
setHasMoreDataNdbinfo::ScanCursor180     static void setHasMoreData(UintR & flags, bool value){
181       flags = (flags & ~(MOREDATA_MASK << MOREDATA_SHIFT)) |
182               ((value & MOREDATA_MASK) << MOREDATA_SHIFT);
183     }
184   };
185 
186   class Ratelimit {
187     friend class SimulatedBlock;
188     Uint32 rows;
189     Uint32 bytes;
190     Ratelimit(const Ratelimit&);// Not impl
191   public:
Ratelimit()192     Ratelimit() :
193       rows(0),
194       bytes(0){
195     }
196 
need_break(const DbinfoScan & scan) const197     bool need_break(const DbinfoScan& scan) const
198     {
199       const Uint32 MAX_ROWS = 256;
200 
201       // Upgrade zero to MAX_ROWS
202       Uint32 maxRows = scan.maxRows ? scan.maxRows : MAX_ROWS;
203 
204       // Limit maxRows to MAX_ROWS
205       if (maxRows > MAX_ROWS)
206         maxRows = MAX_ROWS;
207 
208       if (maxRows != 0 && rows >= maxRows)
209         return true; // More than max rows already sent
210       if (scan.maxBytes != 0 &&  bytes >= scan.maxBytes)
211         return true; // More than max bytes already sent
212       return false;
213     }
214   };
215 
216   struct pool_entry {
217     const char* poolname;
218     Uint64 used;
219     Uint64 total;
220     Uint64 entry_size;
221     Uint64 used_hi;
222     Uint32 config_params[4];
223     Uint32 record_type;
224   };
225 
226   enum counter_id {
227     ATTRINFO_COUNTER = 1,
228     TRANSACTIONS_COUNTER = 2,
229     COMMITS_COUNTER = 3,
230     READS_COUNTER = 4,
231     SIMPLE_READS_COUNTER = 5,
232     WRITES_COUNTER = 6,
233     ABORTS_COUNTER = 7,
234     TABLE_SCANS_COUNTER = 8,
235     RANGE_SCANS_COUNTER = 9,
236     OPERATIONS_COUNTER = 10,
237     /* Counters fetched from the SPJ block.*/
238     SPJ_READS_RECEIVED_COUNTER = 11,
239     SPJ_LOCAL_READS_SENT_COUNTER = 12,
240     SPJ_REMOTE_READS_SENT_COUNTER = 13,
241     SPJ_READS_NOT_FOUND_COUNTER = 14,
242     SPJ_TABLE_SCANS_RECEIVED_COUNTER = 15,
243     SPJ_LOCAL_TABLE_SCANS_SENT_COUNTER = 16,
244     SPJ_RANGE_SCANS_RECEIVED_COUNTER = 17,
245     SPJ_LOCAL_RANGE_SCANS_SENT_COUNTER = 18,
246     SPJ_REMOTE_RANGE_SCANS_SENT_COUNTER = 19,
247     SPJ_SCAN_BATCHES_RETURNED_COUNTER = 20,
248     SPJ_SCAN_ROWS_RETURNED_COUNTER = 21,
249     SPJ_PRUNED_RANGE_SCANS_RECEIVED_COUNTER = 22,
250     SPJ_CONST_PRUNED_RANGE_SCANS_RECEIVED_COUNTER = 23,
251     LOCAL_READ_COUNTER = 24,
252     LOCAL_WRITE_COUNTER = 25,
253     LQHKEY_OVERLOAD = 26,
254     LQHKEY_OVERLOAD_TC = 27,
255     LQHKEY_OVERLOAD_READER = 28,
256     LQHKEY_OVERLOAD_NODE_PEER = 29,
257     LQHKEY_OVERLOAD_SUBSCRIBER = 30,
258     LQHSCAN_SLOWDOWN = 31
259   };
260 
261   struct counter_entry {
262     counter_id id;
263     Uint64 val;
264   };
265 };
266 
267 
268 #undef JAM_FILE_ID
269 
270 #endif
271