~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/test/tools/hugoLoad.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
 
 
17
#include <NdbOut.hpp>
 
18
#include <NdbApi.hpp>
 
19
#include <NdbSleep.h>
 
20
#include <NDBT.hpp>
 
21
#include <HugoTransactions.hpp>
 
22
#include <getarg.h>
 
23
 
 
24
 
 
25
int main(int argc, const char** argv){
 
26
  ndb_init();
 
27
 
 
28
  int _records = 0;
 
29
  int _help = 0;
 
30
  int _batch = 512;
 
31
  int _loops = -1;
 
32
  int _rand = 0;
 
33
  int _onetrans = 0;
 
34
  int _abort = 0;
 
35
  const char* db = 0;
 
36
 
 
37
  struct getargs args[] = {
 
38
    { "records", 'r', arg_integer, &_records, "Number of records", "recs" },
 
39
    { "batch", 'b', arg_integer, &_batch, "Number of operations in each transaction", "batch" },
 
40
    { "loops", 'l', arg_integer, &_loops, "Number of loops", "" },
 
41
    { "database", 'd', arg_string, &db, "Database", "" },
 
42
    { "usage", '?', arg_flag, &_help, "Print help", "" },
 
43
    { "rnd-rows", 0, arg_flag, &_rand, "Rand number of records", "recs" },
 
44
    { "one-trans", 0, arg_flag, &_onetrans, "Insert as 1 trans", "" },
 
45
    { "abort", 0, arg_integer, &_abort, "Abort probability", "" }
 
46
  };
 
47
  int num_args = sizeof(args) / sizeof(args[0]);
 
48
  int optind = 0;
 
49
  char desc[] = 
 
50
    "tabname\n"\
 
51
    "This program will load one table in Ndb with calculated data. \n"\
 
52
    "This means that it is possible to check the validity of the data \n"\
 
53
    "at a later time. The last column in each table is used as an update \n"\
 
54
    "counter, it's initialised to zero and should be incremented for each \n"\
 
55
    "update of the record. \n";
 
56
  
 
57
  if(getarg(args, num_args, argc, argv, &optind) ||
 
58
     argv[optind] == NULL || _records == 0 || _help) {
 
59
    arg_printusage(args, num_args, argv[0], desc);
 
60
    return NDBT_ProgramExit(NDBT_WRONGARGS);
 
61
  }
 
62
  
 
63
  
 
64
  // Connect to Ndb
 
65
  Ndb_cluster_connection con;
 
66
  if(con.connect(12, 5, 1) != 0)
 
67
  {
 
68
    return NDBT_ProgramExit(NDBT_FAILED);
 
69
  }
 
70
 
 
71
  if (con.wait_until_ready(30,0) < 0)
 
72
  {
 
73
    ndbout << "Cluster nodes not ready in 30 seconds." << endl;
 
74
    return NDBT_ProgramExit(NDBT_FAILED);
 
75
  }
 
76
  
 
77
  Ndb MyNdb( &con, db ? db : "TEST_DB" );
 
78
 
 
79
  if(MyNdb.init() != 0){
 
80
    ERR(MyNdb.getNdbError());
 
81
    return NDBT_ProgramExit(NDBT_FAILED);
 
82
  }
 
83
 
 
84
  for(Uint32 i = optind; i<argc; i++)
 
85
  {
 
86
    const char* _tabname = argv[i];
 
87
    // Check if table exists in db
 
88
    const NdbDictionary::Table* pTab = 
 
89
      NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
 
90
    if(pTab == NULL){
 
91
      ndbout << " Table " << _tabname << " does not exist!" << endl;
 
92
      return NDBT_ProgramExit(NDBT_WRONGARGS);
 
93
    }
 
94
    
 
95
    HugoTransactions hugoTrans(*pTab);
 
96
loop:    
 
97
    int rows = (_rand ? rand() % _records : _records);
 
98
    int abort = (rand() % 100) < _abort ? 1 : 0;
 
99
    if (abort)
 
100
      ndbout << "load+abort" << endl;
 
101
    if (hugoTrans.loadTable(&MyNdb, 
 
102
                            rows,
 
103
                            _batch,
 
104
                            true, 0, _onetrans, _loops, abort) != 0){
 
105
      return NDBT_ProgramExit(NDBT_FAILED);
 
106
    }
 
107
    
 
108
    if(_loops > 0)
 
109
    {
 
110
      ndbout << "clearing..." << endl;
 
111
      hugoTrans.clearTable(&MyNdb);
 
112
      //hugoTrans.pkDelRecords(&MyNdb, _records);
 
113
      _loops--;
 
114
      goto loop;
 
115
    }
 
116
  }
 
117
 
 
118
  return NDBT_ProgramExit(NDBT_OK);
 
119
}