19 #include <ndb_global.h>
29 int scanReadRecords(
Ndb*,
40 static const char* _dbname =
"TEST_DB";
41 static const char* _delimiter =
"\t";
42 static int _header, _parallelism, _useHexFormat, _lock,
45 const char *load_default_groups[]= {
"mysql_cluster",0 };
48 static int _dumpDisk = 0;
49 static int use_rowid = 0;
50 static int nodata = 0;
51 static int use_gci = 0;
52 static int use_gci64 = 0;
53 static int use_author = 0;
55 static struct my_option my_long_options[] =
57 NDB_STD_OPTS(
"ndb_select_all"),
58 {
"database",
'd',
"Name of database table is in",
59 (uchar**) &_dbname, (uchar**) &_dbname, 0,
60 GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
61 {
"parallelism",
'p',
"parallelism",
62 (uchar**) &_parallelism, (uchar**) &_parallelism, 0,
63 GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
64 {
"lock",
'l',
"Read(0), Read-hold(1), Exclusive(2)",
65 (uchar**) &_lock, (uchar**) &_lock, 0,
66 GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
67 {
"order",
'o',
"Sort resultset according to index",
68 (uchar**) &_order, (uchar**) &_order, 0,
69 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
70 {
"descending",
'z',
"Sort descending (requires order flag)",
71 (uchar**) &_descending, (uchar**) &_descending, 0,
72 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
73 {
"header",
'h',
"Print header",
74 (uchar**) &_header, (uchar**) &_header, 0,
75 GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0 },
76 {
"useHexFormat",
'x',
"Output numbers in hexadecimal format",
77 (uchar**) &_useHexFormat, (uchar**) &_useHexFormat, 0,
78 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
79 {
"delimiter",
'D',
"Column delimiter",
80 (uchar**) &_delimiter, (uchar**) &_delimiter, 0,
81 GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
82 {
"disk", NDB_OPT_NOSHORT,
"Dump disk ref",
83 (uchar**) &_dumpDisk, (uchar**) &_dumpDisk, 0,
84 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
85 {
"rowid", NDB_OPT_NOSHORT,
"Dump rowid",
86 (uchar**) &use_rowid, (uchar**) &use_rowid, 0,
87 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
88 {
"gci", NDB_OPT_NOSHORT,
"Dump gci",
89 (uchar**) &use_gci, (uchar**) &use_gci, 0,
90 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
91 {
"gci64", NDB_OPT_NOSHORT,
"Dump ROW$GCI64",
92 (uchar**) &use_gci64, (uchar**) &use_gci64, 0,
93 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
94 {
"author", NDB_OPT_NOSHORT,
"Dump ROW$AUTHOR",
95 (uchar**) &use_author, (uchar**) &use_author, 0,
96 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
97 {
"tupscan",
't',
"Scan in tup order",
98 (uchar**) &_tup, (uchar**) &_tup, 0,
99 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
100 {
"nodata", NDB_OPT_NOSHORT,
"Dont print data",
101 (uchar**) &nodata, (uchar**) &nodata, 0,
102 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
103 { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
107 static void short_usage_sub(
void)
109 ndb_short_usage_sub(NULL);
114 ndb_usage(short_usage_sub, load_default_groups, my_long_options);
117 int main(
int argc,
char** argv){
119 ndb_opt_set_usage_funcs(short_usage_sub, usage);
120 load_defaults(
"my",load_default_groups,&argc,&argv);
121 const char* _tabname;
124 opt_debug=
"d:t:O,/tmp/ndb_select_all.trace";
126 if ((ho_error=handle_options(&argc, &argv, my_long_options,
127 ndb_std_get_one_option)))
128 return NDBT_ProgramExit(NDBT_WRONGARGS);
129 if ((_tabname = argv[0]) == 0) {
131 return NDBT_ProgramExit(NDBT_WRONGARGS);
138 ndbout <<
"Unable to connect to management server." << endl;
139 return NDBT_ProgramExit(NDBT_FAILED);
143 ndbout <<
"Cluster nodes not ready in 30 seconds." << endl;
144 return NDBT_ProgramExit(NDBT_FAILED);
147 Ndb MyNdb(&con, _dbname );
148 if(MyNdb.init() != 0){
149 ERR(MyNdb.getNdbError());
150 return NDBT_ProgramExit(NDBT_FAILED);
157 pIdx = MyNdb.getDictionary()->getIndex(argv[1], _tabname);
161 ndbout <<
" Table " << _tabname <<
" does not exist!" << endl;
162 return NDBT_ProgramExit(NDBT_WRONGARGS);
165 if(argc > 1 && pIdx == 0)
167 ndbout <<
" Index " << argv[1] <<
" does not exists" << endl;
170 if(_order && pIdx == NULL){
171 ndbout <<
" Order flag given without an index" << endl;
172 return NDBT_ProgramExit(NDBT_WRONGARGS);
175 if (_descending && ! _order) {
176 ndbout <<
" Descending flag given without order flag" << endl;
177 return NDBT_ProgramExit(NDBT_WRONGARGS);
180 if (scanReadRecords(&MyNdb,
187 (
char)*_delimiter, _order, _descending) != 0){
188 return NDBT_ProgramExit(NDBT_FAILED);
191 return NDBT_ProgramExit(NDBT_OK);
195 int scanReadRecords(
Ndb* pNdb,
202 char delimiter,
bool order,
bool descending){
204 int retryAttempt = 0;
205 const int retryMax = 100;
215 if (retryAttempt >= retryMax){
216 ndbout <<
"ERROR: has retried this operation " << retryAttempt
217 <<
" times, failing!" << endl;
222 if (pTrans == NULL) {
226 NdbSleep_MilliSleep(50);
245 unsigned scan_flags = 0;
246 if (_tup) scan_flags |= NdbScanOperation::SF_TupScan;
247 switch(_lock + (3 * order)){
279 sf.le(0, (Uint32)10);
285 sf.ge(0, (Uint32)10);
286 sf.lt(0, (Uint32)20);
289 sf.ge(0, (Uint32)30);
290 sf.lt(0, (Uint32)40);
297 sf.ge(0, (Uint32)10);
298 sf.lt(0, (Uint32)20);
301 sf.ge(0, (Uint32)30);
302 sf.lt(0, (Uint32)40);
308 sf.lt(0, (Uint32)50);
311 sf.ge(0, (Uint32)100);
312 sf.lt(0, (Uint32)200);
323 if(col->getStorageType() == NdbDictionary::Column::StorageTypeDisk)
327 if((row->attributeStore(a) = pOp->
getValue(col)) == 0)
336 if(_dumpDisk && disk)
337 disk_ref = pOp->
getValue(NdbDictionary::Column::DISK_REF);
339 NdbRecAttr * rowid= 0, *frag = 0, *gci = 0, *gci64 = 0, *author = 0;
342 frag = pOp->
getValue(NdbDictionary::Column::FRAGMENT);
343 rowid = pOp->
getValue(NdbDictionary::Column::ROWID);
348 gci = pOp->
getValue(NdbDictionary::Column::ROW_GCI);
353 gci64 = pOp->
getValue(NdbDictionary::Column::ROW_GCI64);
358 author = pOp->
getValue(NdbDictionary::Column::ROW_AUTHOR);
367 NdbSleep_MilliSleep(50);
376 bool do_delimiter=
false;
377 char delimiter_string[2];
378 delimiter_string[0]= delimiter;
379 delimiter_string[1]=
'\0';
380 #define DELIMITER if (do_delimiter) ndbout << delimiter_string; else do_delimiter= true
404 ndbout <<
"DISK_REF";
410 ndbout <<
"ROW$GCI64";
416 ndbout <<
"ROW$AUTHOR";
431 ndbout.setHexFormat(1);
435 ndbout <<
"[ fragment: " << frag->u_32_value()
437 <<
" m_page_idx: " << *(Uint32*)(rowid->
aRef() + 4) <<
" ]";
446 ndbout << gci->u_64_value() <<
"\t";
455 ndbout <<
"[ m_file_no: " << *(Uint16*)(disk_ref->
aRef()+6)
457 <<
" m_page_idx: " << *(Uint16*)(disk_ref->
aRef() + 4) <<
" ]";
466 Uint64 tmp = gci64->u_64_value();
467 ndbout <<
"\t" << Uint32(tmp >> 32) <<
"/" << Uint32(tmp);
473 if (author->isNULL())
477 ndbout <<
"\t" << author->u_32_value();
482 if (rowid || disk_ref || gci || !nodata || gci64 || author)
491 NdbSleep_MilliSleep(50);
502 ndbout << rows <<
" rows returned" << endl;