MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
verify_index.cpp
1 /*
2  Copyright (C) 2003-2006 MySQL AB
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 #include <ndb_global.h>
20 
21 #include <NdbOut.hpp>
22 
23 #include <NdbApi.hpp>
24 #include <NdbMain.h>
25 #include <NDBT.hpp>
26 #include <NdbSleep.h>
27 #include <getarg.h>
28 #include <UtilTransactions.hpp>
29 
30 
31 int main(int argc, const char** argv){
32  ndb_init();
33  int _parallelism = 240;
34  const char* _tabname = NULL;
35  const char* _indexname = NULL;
36  int _help = 0;
37 
38  struct getargs args[] = {
39  { "parallelism", 's', arg_integer, &_parallelism, "parallelism", "parallelism" },
40  { "usage", '?', arg_flag, &_help, "Print help", "" }
41  };
42  int num_args = sizeof(args) / sizeof(args[0]);
43  int optind = 0;
44  char desc[] =
45  "tabname indexname\n"\
46  "This program will verify the index [indexname] and compare it to data\n"
47  "in table [tablename]\n";
48 
49  if(getarg(args, num_args, argc, argv, &optind) ||
50  argv[optind] == NULL || argv[optind+1] == NULL || _help) {
51  arg_printusage(args, num_args, argv[0], desc);
52  return NDBT_ProgramExit(NDBT_WRONGARGS);
53  }
54  _tabname = argv[optind];
55  _indexname = argv[optind+1];
56 
57  // Connect to Ndb
59  if(con.connect(12, 5, 1) != 0)
60  {
61  return NDBT_ProgramExit(NDBT_FAILED);
62  }
63  Ndb MyNdb(&con, "TEST_DB" );
64 
65  if(MyNdb.init() != 0){
66  ERR(MyNdb.getNdbError());
67  return NDBT_ProgramExit(NDBT_FAILED);
68  }
69 
70  // Connect to Ndb and wait for it to become ready
71  while(MyNdb.waitUntilReady() != 0)
72  ndbout << "Waiting for ndb to become ready..." << endl;
73 
74  // Check if table exists in db
75  const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
76  if(pTab == NULL){
77  ndbout << " Table " << _tabname << " does not exist!" << endl;
78  return NDBT_ProgramExit(NDBT_FAILED);
79  }
80 
81  UtilTransactions utilTrans(*pTab);
82  if (utilTrans.verifyIndex(&MyNdb,
83  _indexname,
84  _parallelism) != 0){
85  return NDBT_ProgramExit(NDBT_FAILED);
86  }
87 
88  return NDBT_ProgramExit(NDBT_OK);
89 }
90 
91 
92