MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hugoFill.cpp
1 /*
2  Copyright (C) 2003-2007 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 #include <NdbApi.hpp>
23 #include <NdbSleep.h>
24 #include <NDBT.hpp>
25 #include <HugoTransactions.hpp>
26 #include <getarg.h>
27 
28 
29 int main(int argc, const char** argv){
30  ndb_init();
31 
32  int _records = 0;
33  const char* _tabname = NULL;
34  int _help = 0;
35  int _batch = 512;
36  const char* db = "TEST_DB";
37 
38  struct getargs args[] = {
39  { "batch", 'b', arg_integer, &_batch, "Number of operations in each transaction", "batch" },
40  { "database", 'd', arg_string, &db, "Database", "" },
41  { "usage", '?', arg_flag, &_help, "Print help", "" }
42  };
43  int num_args = sizeof(args) / sizeof(args[0]);
44  int optind = 0;
45  char desc[] =
46  "tabname\n"\
47  "This program will load one table in Ndb with calculated data \n"\
48  "until the database is full. \n";
49 
50  if(getarg(args, num_args, argc, argv, &optind) ||
51  argv[optind] == NULL || _help) {
52  arg_printusage(args, num_args, argv[0], desc);
53  return NDBT_ProgramExit(NDBT_WRONGARGS);
54  }
55  _tabname = argv[optind];
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, 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_WRONGARGS);
79  }
80 
81  HugoTransactions hugoTrans(*pTab);
82  if (hugoTrans.fillTable(&MyNdb,
83  _batch) != 0){
84  return NDBT_ProgramExit(NDBT_FAILED);
85  }
86 
87  return NDBT_ProgramExit(NDBT_OK);
88 }