Exemple #1
0
int main(int argc, const char** argv){
  ndb_init();
  int _help = 0;
  char * _database = "BANK";
  
  struct getargs args[] = {
    { "usage", '?', arg_flag, &_help, "Print help", "" },
    { "database", 'd', arg_string, &_database, "Database name", ""} 
  };
  int num_args = sizeof(args) / sizeof(args[0]);
  int optind = 0;
  char desc[] = 
    "This program will make GL records in the bank\n";
  
  if(getarg(args, num_args, argc, argv, &optind) ||  _help) {
    arg_printusage(args, num_args, argv[0], desc);
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }

  Ndb_cluster_connection con;
  if(con.connect(12, 5, 1) != 0)
  {
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  Bank bank(con,_database);

  if (bank.performMakeGLs() != 0)
    return NDBT_ProgramExit(NDBT_FAILED);
  
  return NDBT_ProgramExit(NDBT_OK);

}
Exemple #2
0
int main(int argc, const char** argv){
  ndb_init();
  int _parallelism = 240;
  const char* _tabname = NULL;
  const char* _indexname = NULL;
  int _help = 0;
  
  struct getargs args[] = {
    { "parallelism", 's', arg_integer, &_parallelism, "parallelism", "parallelism" },
    { "usage", '?', arg_flag, &_help, "Print help", "" }
  };
  int num_args = sizeof(args) / sizeof(args[0]);
  int optind = 0;
  char desc[] = 
    "tabname indexname\n"\
    "This program will verify the index [indexname] and compare it to data\n"
    "in table [tablename]\n";
  
  if(getarg(args, num_args, argc, argv, &optind) || 
     argv[optind] == NULL || argv[optind+1] == NULL || _help) {
    arg_printusage(args, num_args, argv[0], desc);
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }
  _tabname = argv[optind];
  _indexname = argv[optind+1];

  // Connect to Ndb
  Ndb_cluster_connection con;
  if(con.connect(12, 5, 1) != 0)
  {
    return NDBT_ProgramExit(NDBT_FAILED);
  }
  Ndb MyNdb(&con, "TEST_DB" );

  if(MyNdb.init() != 0){
    ERR(MyNdb.getNdbError());
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  // Connect to Ndb and wait for it to become ready
  while(MyNdb.waitUntilReady() != 0)
    ndbout << "Waiting for ndb to become ready..." << endl;
   
  // Check if table exists in db
  const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
  if(pTab == NULL){
    ndbout << " Table " << _tabname << " does not exist!" << endl;
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  int rows = 0;
  UtilTransactions utilTrans(*pTab);
  if (utilTrans.verifyIndex(&MyNdb, 
			    _indexname, 
			    _parallelism) != 0){
    return NDBT_ProgramExit(NDBT_FAILED);
  }
    
  return NDBT_ProgramExit(NDBT_OK);
}
Exemple #3
0
int desc_datafile(Ndb_cluster_connection &con, Ndb *myndb, char* name)
{
  unsigned id;
  NdbDictionary::Dictionary *dict= myndb->getDictionary();
  assert(dict);
  Ndb_cluster_connection_node_iter iter;

  con.init_get_next_node(iter);

  while ((id= con.get_next_node(iter)))
  {
    NdbDictionary::Datafile df= dict->getDatafile(id, name);
    NdbError err= dict->getNdbError();
    if ((int) err.classification != (int) ndberror_cl_none)
      return 0;

    ndbout << "Type: Datafile" << endl;
    ndbout << "Name: " << name << endl;
    ndbout << "Node: " << id << endl;
    ndbout << "Path: " << df.getPath() << endl;
    ndbout << "Size: " << df.getSize() << endl;
    ndbout << "Free: " << df.getFree() << endl;

    ndbout << "Tablespace: " << df.getTablespace() << endl;

    /** We probably don't need to display this ever...
	ndbout << "Number: " << uf.getFileNo() << endl;
    */

    ndbout << endl;
  }

  return 1;
}
int runSetup(NDBT_Context* ctx, NDBT_Step* step, int waitGroupSize){

  int records = ctx->getNumRecords();
  int batchSize = ctx->getProperty("BatchSize", 1);
  int transactions = (records / 100) + 1;
  int operations = (records / transactions) + 1;
  Ndb* pNdb = GETNDB(step);

  HugoAsynchTransactions hugoTrans(*ctx->getTab());
  if (hugoTrans.loadTableAsynch(pNdb, records, batchSize,
				transactions, operations) != 0){
    return NDBT_FAILED;
  }

  Ndb_cluster_connection* conn = &pNdb->get_ndb_cluster_connection();

  /* The first call to create_multi_ndb_wait_group() should succeed ... */
  global_poll_group = conn->create_ndb_wait_group(waitGroupSize);
  if(global_poll_group == 0) {
    return NDBT_FAILED;
  }

  /* and subsequent calls should fail */
  if(conn->create_ndb_wait_group(waitGroupSize) != 0) {
    return NDBT_FAILED;
  }

  return NDBT_OK;
}
Exemple #5
0
int main(int argc, const char** argv){
  ndb_init();

  int _records = 0;
  const char* _tabname = NULL;
  int _help = 0;
  int _batch = 512;
  const char* db = "TEST_DB";
  
  struct getargs args[] = {
    { "batch", 'b', arg_integer, &_batch, "Number of operations in each transaction", "batch" },
    { "database", 'd', arg_string, &db, "Database", "" },
    { "usage", '?', arg_flag, &_help, "Print help", "" }
  };
  int num_args = sizeof(args) / sizeof(args[0]);
  int optind = 0;
  char desc[] = 
    "tabname\n"\
    "This program will load one table in Ndb with calculated data \n"\
    "until the database is full. \n";
  
  if(getarg(args, num_args, argc, argv, &optind) ||
     argv[optind] == NULL  || _help) {
    arg_printusage(args, num_args, argv[0], desc);
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }
  _tabname = argv[optind];
  
  // Connect to Ndb
  Ndb_cluster_connection con;
  if(con.connect(12, 5, 1) != 0)
  {
    return NDBT_ProgramExit(NDBT_FAILED);
  }
  Ndb MyNdb(&con, db);

  if(MyNdb.init() != 0){
    ERR(MyNdb.getNdbError());
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  // Connect to Ndb and wait for it to become ready
  while(MyNdb.waitUntilReady() != 0)
    ndbout << "Waiting for ndb to become ready..." << endl;
   
  // Check if table exists in db
  const NdbDictionary::Table* pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
  if(pTab == NULL){
    ndbout << " Table " << _tabname << " does not exist!" << endl;
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }

  HugoTransactions hugoTrans(*pTab);
  if (hugoTrans.fillTable(&MyNdb, 
			  _batch) != 0){
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  return NDBT_ProgramExit(NDBT_OK);
}
Exemple #6
0
int main(int argc, const char** argv){
  ndb_init();
  int _help = 0;
  int _wait = 30;
  char * _database="BANK";
  
  struct getargs args[] = {
    { "wait", 'w', arg_integer, &_wait, "Max time to wait between days", "secs" },
    { "database", 'd', arg_string, &_database, "Database name", ""}, 
    { "usage", '?', arg_flag, &_help, "Print help", "" }
  };
  int num_args = sizeof(args) / sizeof(args[0]);
  int optind = 0;
  char desc[] = 
    "This program will increase time in the bank\n";
  
  if(getarg(args, num_args, argc, argv, &optind) ||  _help) {
    arg_printusage(args, num_args, argv[0], desc);
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }

  Ndb_cluster_connection con;
  if(con.connect(12, 5, 1) != 0)
  {
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  Bank bank(con,_database);

  if (bank.performIncreaseTime(_wait) != 0)
    return NDBT_ProgramExit(NDBT_FAILED);
  
  return NDBT_ProgramExit(NDBT_OK);

}
/*  Ndb_cluster_connection(const char * connectstring = 0);
*/
Handle<Value> Ndb_cluster_connection_new_wrapper(const Arguments &args) {
  DEBUG_MARKER(UDEB_DETAIL);
  HandleScope scope;
  
  REQUIRE_CONSTRUCTOR_CALL();
  REQUIRE_ARGS_LENGTH(1);

  JsValueConverter<const char *> arg0(args[0]);
  
  Ndb_cluster_connection * c = new Ndb_cluster_connection(arg0.toC());

  /* We do not expose set_max_adaptive_send_time() to JavaScript nor even
     consider using the default value of 10 ms.
  */
  c->set_max_adaptive_send_time(1);
  
  wrapPointerInObject(c, NdbccEnvelope, args.This());
  freeFromGC(c, args.This());
  return args.This();
}
int main(int argc, const char** argv){
  ndb_init();

  int _temp = false;
  int _help = 0;
  
  struct getargs args[] = {
    { "temp", 't', arg_flag, &_temp, "Temporary table", "temp" },
    { "usage", '?', arg_flag, &_help, "Print help", "" }
  };
  int num_args = sizeof(args) / sizeof(args[0]);
  int optind = 0;
  char desc[] = 
    "This program will create all standard tables in Ndb.\n"\
    "The tables is  selected from a fixed list of tables\n"\
    "defined in NDBT_Tables class\n";
  
  if(getarg(args, num_args, argc, argv, &optind) || _help) {
    arg_printusage(args, num_args, argv[0], desc);
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }

  // Connect to Ndb
  Ndb_cluster_connection con;
  if(con.connect(12, 5, 1) != 0)
  {
    return NDBT_ProgramExit(NDBT_FAILED);
  }
  Ndb MyNdb(&con, "TEST_DB" );
  
  if(MyNdb.init() != 0){
    ERR(MyNdb.getNdbError());
    return NDBT_ProgramExit(NDBT_FAILED);
  }
  
  while(MyNdb.waitUntilReady() != 0)
    ndbout << "Waiting for ndb to become ready..." << endl;

  return NDBT_Tables::createAllTables(&MyNdb, _temp);

 }
Ndb_cluster_connection* JniNdbEventStreamingImp::connect_to_cluster(const char *connection_string) {
    Ndb_cluster_connection* c;

    if (ndb_init())
        exit(EXIT_FAILURE);

    c = new Ndb_cluster_connection(connection_string);

    if (c->connect(RETRIES, DELAY_BETWEEN_RETRIES, VERBOSE)) {
        fprintf(stderr, "Unable to connect to cluster.\n\n");
        exit(EXIT_FAILURE);
    }

    if (c->wait_until_ready(WAIT_UNTIL_READY, WAIT_UNTIL_READY) < 0) {

        fprintf(stderr, "Cluster was not ready.\n\n");
        exit(EXIT_FAILURE);
    }

    return c;
}
/*  Ndb_cluster_connection(const char * connectstring = 0);
*/
void Ndb_cluster_connection_new_wrapper(const Arguments &args) {
  DEBUG_MARKER(UDEB_DETAIL);
  EscapableHandleScope scope(args.GetIsolate());
  
  REQUIRE_CONSTRUCTOR_CALL();
  REQUIRE_ARGS_LENGTH(1);

  JsValueConverter<const char *> arg0(args[0]);
  
  Ndb_cluster_connection * c = new Ndb_cluster_connection(arg0.toC());

  /* We do not expose set_max_adaptive_send_time() to JavaScript nor even
     consider using the default value of 10 ms.
  */
  c->set_max_adaptive_send_time(1);

  Local<Value> wrapper = NdbccEnvelope.wrap(c);
  NdbccEnvelope.freeFromGC(c, wrapper);

  args.GetReturnValue().Set(wrapper);
}
Exemple #11
0
// Init the connection to an NDB cluster.
Ndb_cluster_connection* connect_to_cluster(char* conn_string)
{
  Ndb_cluster_connection* c;

  if(ndb_init())
    exit(EXIT_FAILURE);

  c= new Ndb_cluster_connection(conn_string);

  if(c->connect(4, 5, 1))
  {
    fprintf(stderr, "Unable to connect to cluster within 30 seconds.\n\n");
    exit(EXIT_FAILURE);
  }

  if(c->wait_until_ready(30, 0) < 0)
  {
    fprintf(stderr, "Cluster was not ready within 30 seconds.\n\n");
    exit(EXIT_FAILURE);
  }

  return c; 
}
Exemple #12
0
int desc_undofile(Ndb_cluster_connection &con, Ndb *myndb, char* name)
{
  unsigned id;
  NdbDictionary::Dictionary *dict= myndb->getDictionary();
  Ndb_cluster_connection_node_iter iter;

  assert(dict);

  con.init_get_next_node(iter);

  while ((id= con.get_next_node(iter)))
  {
    NdbDictionary::Undofile uf= dict->getUndofile(0, name);
    NdbError err= dict->getNdbError();
    if ((int) err.classification != (int) ndberror_cl_none)
      return 0;

    ndbout << "Type: Undofile" << endl;
    ndbout << "Name: " << name << endl;
    ndbout << "Node: " << id << endl;
    ndbout << "Path: " << uf.getPath() << endl;
    ndbout << "Size: " << uf.getSize() << endl;

    ndbout << "Logfile Group: " << uf.getLogfileGroup() << endl;

    /** FIXME: are these needed, the functions aren't there
	but the prototypes are...

	ndbout << "Number: " << uf.getFileNo() << endl;
    */

    ndbout << endl;
  }

  return 1;
}
Exemple #13
0
int main(int argc, const char** argv){
  ndb_init();

  int _records = 0;
  int _loops = 1;
  int _parallelism = 1;
  int _ver2 = 0;
  const char* _tabname = NULL, *db = 0;
  int _help = 0;
  
  struct getargs args[] = {
    { "loops", 'l', arg_integer, &_loops, "number of times to run this program(0=infinite loop)", "loops" },
    { "parallelism", 'p', arg_integer, &_parallelism, "parallelism(1-240)", "para" },
    { "records", 'r', arg_integer, &_records, "Number of records", "recs" },
    { "ver2", '2', arg_flag, &_ver2, "Use version 2 of scanUpdateRecords", "" },
    { "ver2", '1', arg_negative_flag, &_ver2, "Use version 1 of scanUpdateRecords (default)", "" },
    { "usage", '?', arg_flag, &_help, "Print help", "" },
    { "database", 'd', arg_string, &db, "Database", "" }
  };
  int num_args = sizeof(args) / sizeof(args[0]);
  int optind = 0;
  char desc[] = 
    "tabname\n"\
    "This program will scan update all records in one table in Ndb\n";
  
  if(getarg(args, num_args, argc, argv, &optind) ||
     argv[optind] == NULL || _help) {
    arg_printusage(args, num_args, argv[0], desc);
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }
  _tabname = argv[optind];

  // Connect to Ndb
  Ndb_cluster_connection con;
  if(con.connect(12, 5, 1) != 0)
  {
    return NDBT_ProgramExit(NDBT_FAILED);
  }
  Ndb MyNdb( &con, db ? db : "TEST_DB" );

  if(MyNdb.init() != 0){
    ERR(MyNdb.getNdbError());
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  while(MyNdb.waitUntilReady() != 0)
    ndbout << "Waiting for ndb to become ready..." << endl;
   
  // Check if table exists in db
  const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
  if(pTab == NULL){
    ndbout << " Table " << _tabname << " does not exist!" << endl;
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }

  HugoTransactions hugoTrans(*pTab);
  int i = 0;
  int res = NDBT_FAILED;
  while (i<_loops || _loops==0) {
    ndbout << i << ": ";
    if (_ver2 == 0){
      res = hugoTrans.scanUpdateRecords(&MyNdb, 
				      _records,
				      0, 
				      _parallelism);
    } else{
      res = hugoTrans.scanUpdateRecords2(&MyNdb, 
				       _records,
				       0, 
				       _parallelism);
    }
    if (res != NDBT_OK ){
      return NDBT_ProgramExit(NDBT_FAILED);
    }
    i++;
    //NdbSleep_MilliSleep(300);
  }

  return NDBT_ProgramExit(NDBT_OK);
}
int main(int argc, const char** argv){
  ndb_init();

  int _records = 0;
  int _loops = 1;
  int _threads = 1;
  int _stats = 0;
  int _abort = 0;
  int _batch = 1;
  const char* _tabname = NULL, *db = 0;
  int _help = 0;

  struct getargs args[] = {
    { "aborts", 'a', arg_integer, &_abort, "percent of transactions that are aborted", "abort%" },
    { "loops", 'l', arg_integer, &_loops, "number of times to run this program(0=infinite loop)", "loops" },
    { "threads", 't', arg_integer, &_threads, "number of threads (default 1)", "threads" },
    { "stats", 's', arg_flag, &_stats, "report latency per batch", "stats" },
    //    { "batch", 'b', arg_integer, &_batch, "batch value", "batch" },
    { "records", 'r', arg_integer, &_records, "Number of records", "records" },
    { "usage", '?', arg_flag, &_help, "Print help", "" },
    { "database", 'd', arg_string, &db, "Database", "" }
  };
  int num_args = sizeof(args) / sizeof(args[0]);
  int optind = 0;
  char desc[] = 
    "tabname\n"\
    "This program will update all records in a table using PK\n";
  
  if(getarg(args, num_args, argc, argv, &optind) ||
     argv[optind] == NULL || _records == 0 || _help) {
    arg_printusage(args, num_args, argv[0], desc);
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }
  _tabname = argv[optind];

  // Connect to Ndb
  Ndb_cluster_connection con;
  if(con.connect(12, 5, 1) != 0)
  {
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  if (con.wait_until_ready(30,0) < 0)
  {
    ndbout << "Cluster nodes not ready in 30 seconds." << endl;
    return NDBT_ProgramExit(NDBT_FAILED);
  }
  
  Ndb MyNdb( &con, db ? db : "TEST_DB" );

  if(MyNdb.init() != 0){
    ERR(MyNdb.getNdbError());
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  // Check if table exists in db
  const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
  if(pTab == NULL){
    ndbout << " Table " << _tabname << " does not exist!" << endl;
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }

  // threads
  NDBT_ThreadSet ths(_threads);

  // create Ndb object for each thread
  if (ths.connect(&con, db ? db : "TEST_DB") == -1) {
    ndbout << "connect failed: err=" << ths.get_err() << endl;
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  // input is options
  ThrInput input;
  ths.set_input(&input);
  input.pTab = pTab;
  input.records = _records;
  input.batch = _batch;
  input.stats = _stats;

  // output is stats
  ThrOutput output;
  ths.set_output<ThrOutput>();

  int i = 0;
  while (i < _loops || _loops == 0) {
    ndbout << i << ": ";

    ths.set_func(hugoPkUpdate);
    ths.start();
    ths.stop();

    if (ths.get_err())
      NDBT_ProgramExit(NDBT_FAILED);

    if (_stats) {
      NDBT_Stats latency;

      // add stats from each thread
      int n;
      for (n = 0; n < ths.get_count(); n++) {
        NDBT_Thread& thr = ths.get_thread(n);
        ThrOutput* output = (ThrOutput*)thr.get_output();
        latency += output->latency;
      }

      ndbout
        << "latency per batch (us): "
        << " samples=" << latency.getCount()
        << " min=" << (int)latency.getMin()
        << " max=" << (int)latency.getMax()
        << " mean=" << (int)latency.getMean()
        << " stddev=" << (int)latency.getStddev()
        << endl;
    }
    i++;
  }

  return NDBT_ProgramExit(NDBT_OK);
}
int
main(int argc, const char** argv) {
    ndb_init();
    int verbose = 1;
    int optind = 0;

    struct getargs args[1+P_MAX] = {
        { "verbose", 'v', arg_flag, &verbose, "Print verbose status", "verbose" }
    };
    const int num_args = 1 + P_MAX;
    int i;
    for(i = 0; i<P_MAX; i++) {
        args[i+1].long_name = g_paramters[i].name;
        args[i+1].short_name = * g_paramters[i].name;
        args[i+1].type = arg_integer;
        args[i+1].value = &g_paramters[i].value;
        BaseString tmp;
        tmp.assfmt("min: %d max: %d", g_paramters[i].min, g_paramters[i].max);
        args[i+1].help = strdup(tmp.c_str());
        args[i+1].arg_help = 0;
    }

    if(getarg(args, num_args, argc, argv, &optind)) {
        arg_printusage(args, num_args, argv[0], "tabname1 tabname2 ...");
        return NDBT_WRONGARGS;
    }

    myRandom48Init(NdbTick_CurrentMillisecond());
    memset(g_times, 0, sizeof(g_times));

    Ndb_cluster_connection con;
    if(con.connect(12, 5, 1))
    {
        return NDBT_ProgramExit(NDBT_FAILED);
    }

    g_ndb = new Ndb(&con, "TEST_DB");
    if(g_ndb->init() != 0) {
        g_err << "init() failed" << endl;
        goto error;
    }
    if(g_ndb->waitUntilReady() != 0) {
        g_err << "Wait until ready failed" << endl;
        goto error;
    }
    for(i = optind; i<argc; i++) {
        const char * T = argv[i];
        g_info << "Testing " << T << endl;
        BaseString::snprintf(g_table, sizeof(g_table), T);
        BaseString::snprintf(g_ordered, sizeof(g_ordered), "IDX_O_%s", T);
        BaseString::snprintf(g_unique, sizeof(g_unique), "IDX_U_%s", T);
        if(create_table())
            goto error;
        if(load_table())
            goto error;
        for(int l = 0; l<g_paramters[P_LOOPS].value; l++) {
            for(int j = 0; j<P_OP_TYPES; j++) {
                g_paramters[P_OPER].value = j;
                if(run_read())
                    goto error;
            }
        }
        print_result();
    }

    if(g_ndb) delete g_ndb;
    return NDBT_OK;
error:
    if(g_ndb) delete g_ndb;
    return NDBT_FAILED;
}
Exemple #16
0
int main(int argc, const char** argv){
  ndb_init();

  int _records = 0;
  int _loops = 1;
  int _abort = 0;
  int _batch = 0;
  const char* _tabname = NULL, *db = 0;
  int _help = 0;

  struct getargs args[] = {
    { "aborts", 'a', arg_integer, &_abort, "percent of transactions that are aborted", "abort%" },
    { "loops", 'l', arg_integer, &_loops, "number of times to run this program(0=infinite loop)", "loops" },
    //    { "batch", 'b', arg_integer, &_batch, "batch value", "batch" },
    { "records", 'r', arg_integer, &_records, "Number of records", "records" },
    { "usage", '?', arg_flag, &_help, "Print help", "" },
    { "database", 'd', arg_string, &db, "Database", "" }
  };
  int num_args = sizeof(args) / sizeof(args[0]);
  int optind = 0;
  char desc[] = 
    "tabname\n"\
    "This program will update all records in a table using PK\n";
  
  if(getarg(args, num_args, argc, argv, &optind) ||
     argv[optind] == NULL || _records == 0 || _help) {
    arg_printusage(args, num_args, argv[0], desc);
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }
  _tabname = argv[optind];

  // Connect to Ndb
  Ndb_cluster_connection con;
  if(con.connect(12, 5, 1) != 0)
  {
    return NDBT_ProgramExit(NDBT_FAILED);
  }
  Ndb MyNdb( &con, db ? db : "TEST_DB" );

  if(MyNdb.init() != 0){
    ERR(MyNdb.getNdbError());
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  while(MyNdb.waitUntilReady() != 0)
    ndbout << "Waiting for ndb to become ready..." << endl;
   
  // Check if table exists in db
  const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
  if(pTab == NULL){
    ndbout << " Table " << _tabname << " does not exist!" << endl;
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }

  HugoTransactions hugoTrans(*pTab);
  int i = 0;
  while (i<_loops || _loops==0) {
    ndbout << "loop " << i << ": ";
    if (hugoTrans.pkUpdateRecords(&MyNdb, 
				  _records) != 0){
      return NDBT_ProgramExit(NDBT_FAILED);
    }
    i++;
  }

  return NDBT_ProgramExit(NDBT_OK);
}
Exemple #17
0
int main(int argc, const char** argv){
  ndb_init();

  int _records = 0;
  int _help = 0;
  int _batch = 512;
  int _loops = -1;
  int _rand = 0;
  int _onetrans = 0;
  int _abort = 0;
  const char* db = 0;

  struct getargs args[] = {
    { "records", 'r', arg_integer, &_records, "Number of records", "recs" },
    { "batch", 'b', arg_integer, &_batch, "Number of operations in each transaction", "batch" },
    { "loops", 'l', arg_integer, &_loops, "Number of loops", "" },
    { "database", 'd', arg_string, &db, "Database", "" },
    { "usage", '?', arg_flag, &_help, "Print help", "" },
    { "rnd-rows", 0, arg_flag, &_rand, "Rand number of records", "recs" },
    { "one-trans", 0, arg_flag, &_onetrans, "Insert as 1 trans", "" },
    { "abort", 0, arg_integer, &_abort, "Abort probability", "" }
  };
  int num_args = sizeof(args) / sizeof(args[0]);
  int optind = 0;
  char desc[] = 
    "tabname\n"\
    "This program will load one table in Ndb with calculated data. \n"\
    "This means that it is possible to check the validity of the data \n"\
    "at a later time. The last column in each table is used as an update \n"\
    "counter, it's initialised to zero and should be incremented for each \n"\
    "update of the record. \n";
  
  if(getarg(args, num_args, argc, argv, &optind) ||
     argv[optind] == NULL || _records == 0 || _help) {
    arg_printusage(args, num_args, argv[0], desc);
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }
  
  
  // Connect to Ndb
  Ndb_cluster_connection con;
  if(con.connect(12, 5, 1) != 0)
  {
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  if (con.wait_until_ready(30,0) < 0)
  {
    ndbout << "Cluster nodes not ready in 30 seconds." << endl;
    return NDBT_ProgramExit(NDBT_FAILED);
  }
  
  Ndb MyNdb( &con, db ? db : "TEST_DB" );

  if(MyNdb.init() != 0){
    ERR(MyNdb.getNdbError());
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  for(Uint32 i = optind; i<argc; i++)
  {
    const char* _tabname = argv[i];
    // Check if table exists in db
    const NdbDictionary::Table* pTab = 
      NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
    if(pTab == NULL){
      ndbout << " Table " << _tabname << " does not exist!" << endl;
      return NDBT_ProgramExit(NDBT_WRONGARGS);
    }
    
    HugoTransactions hugoTrans(*pTab);
loop:    
    int rows = (_rand ? rand() % _records : _records);
    int abort = (rand() % 100) < _abort ? 1 : 0;
    if (abort)
      ndbout << "load+abort" << endl;
    if (hugoTrans.loadTable(&MyNdb, 
			    rows,
			    _batch,
			    true, 0, _onetrans, _loops, abort) != 0){
      return NDBT_ProgramExit(NDBT_FAILED);
    }
    
    if(_loops > 0)
    {
      ndbout << "clearing..." << endl;
      hugoTrans.clearTable(&MyNdb);
      //hugoTrans.pkDelRecords(&MyNdb, _records);
      _loops--;
      goto loop;
    }
  }

  return NDBT_ProgramExit(NDBT_OK);
}
int main(int argc, const char** argv)
{
  ndb_init();
  int _row = 0;
  int _hex = 0;
  int _primaryKey = 0;
  const char* _tableName = NULL;

  struct getargs args[] = {
    { "row", 'r', 
      arg_integer, &_row, "The row number", "row" },
    { "primarykey", 'p', 
      arg_integer, &_primaryKey, "The primary key", "primarykey" },
    { "hex", 'h', 
      arg_flag, &_hex, "Print hex", "hex" }
  };

  int num_args = sizeof(args) / sizeof(args[0]);
  int optind = 0, i;

  if(getarg(args, num_args, argc, argv, &optind) || argv[optind] == NULL) {
    arg_printusage(args, num_args, argv[0], "table name\n");
    return NDBT_WRONGARGS;
  }
  // Check if table name is supplied
  if (argv[optind] != NULL) 
    _tableName = argv[optind];


  const NdbDictionary::Table* table = NDBT_Tables::getTable(_tableName);
  //  const NDBT_Attribute* attribute = table->getAttribute(_column);

  g_info << "Table " << _tableName << endl
	 << "Row: " << _row << ", PrimaryKey: " << _primaryKey
	 << endl;

  Ndb_cluster_connection con;
  if(con.connect(12, 5, 1) != 0)
  {
    return NDBT_ProgramExit(NDBT_FAILED);
  }
  Ndb* ndb = new Ndb(&con, "TEST_DB");
  if (ndb->init() == 0 && ndb->waitUntilReady(30) == 0)
  {
    NdbConnection* conn = ndb->startTransaction();
    if (conn == NULL)
    {
      g_info << "ERROR: " << ndb->getNdbError() << endl;
      delete ndb;
      return -1;
    }
    NdbOperation* op = conn->getNdbOperation(_tableName);
    if (op == NULL)
    {
      g_info << "ERROR: " << conn->getNdbError() << endl;
      delete ndb;
      return -1;
    }
    op->readTuple();
    NdbRecAttr** data = new NdbRecAttr*[table->getNoOfColumns()];
    for (i = 0; i < table->getNoOfColumns(); i++)
    {
      const NdbDictionary::Column* c = table->getColumn(i);
      if (c->getPrimaryKey())
      {
	op->equal(c->getName(), _primaryKey);
	data[i] = op->getValue(c->getName(), NULL);
      }
      else
      {
	data[i] = op->getValue(c->getName(), NULL);
      }      
    }
    if (conn->execute(Commit) == 0)
    {
      // Print column names
      for (i = 0; i < table->getNoOfColumns(); i++)
      {
	const NdbDictionary::Column* c = table->getColumn(i);
	
	g_info 
	  << c->getName()
	  << "[" << c->getType() << "]   ";	  
      }
      g_info << endl;

      if (_hex)
      {
	g_info << hex;
      }
      for (i = 0; i < table->getNoOfColumns(); i++)
      {
	NdbRecAttr* a = data[i];
	ndbout << (* a) << " ";
      } // for   
      g_info << endl;   
    } // if (conn
    else
    {
      g_info << "Failed to commit read transaction... " 
	     << conn->getNdbError()
	     << ", commitStatus = " << conn->commitStatus()
	     << endl;
    }

    delete[] data;
    
    ndb->closeTransaction(conn);
  } // if (ndb.init
  else
  {
    g_info << "ERROR: Unable to connect to NDB, " 
	   << ndb->getNdbError() << endl;
  }
  delete ndb;

  return 0;
}
int
main(void){
  ndb_init();

  Ndb_cluster_connection con;
  if(con.connect(12, 5, 1) != 0)
  {
    return 1;
  }

  Ndb g_ndb(&con, "test");
  g_ndb.init(1024);

  require(g_ndb.waitUntilReady() == 0);

  while(true){
    g_trans = g_ndb.startTransaction();
    require(g_trans);
  
    size_t i, j;
    const size_t cnt = sizeof(g_scans)/sizeof(g_scans[0]);

    start = NdbTick_CurrentMillisecond();

    for(i = 0; i<cnt; i++){
      ndbout_c("starting scan on: %s %s", 
	       g_scans[i].m_table, g_scans[i].m_index);
      g_scans[i].m_scan = g_trans->getNdbIndexScanOperation(g_scans[i].m_index, 
							    g_scans[i].m_table);
      NdbIndexScanOperation* scan = g_scans[i].m_scan;
      require(scan);
      require(scan->readTuples(NdbScanOperation::LM_CommittedRead, 
			       0, 0, true) == 0);
    }
  
    require(!g_scans[0].m_scan->setBound((Uint32)0, 
					 NdbIndexScanOperation::BoundEQ, 
					 &g_affiliateid, 
					 sizeof(g_affiliateid)));
#if 0
    require(!g_scans[1].m_scan->setBound((Uint32)0, 
					 NdbIndexScanOperation::BoundLE,
					 &g_formatids[0],
					 sizeof(g_formatids[0])));  
#endif

    NdbScanFilter sf(g_scans[1].m_scan);
    sf.begin(NdbScanFilter::OR);
    sf.eq(2, g_formatids[0]);
    sf.eq(2, g_formatids[1]);
    sf.eq(2, g_formatids[2]);
    sf.end();

    // affiliatestometa
    require(g_scans[0].m_scan->getValue("uniquekey"));
    require(g_scans[0].m_scan->getValue("xml"));

    // media
    require(g_scans[1].m_scan->getValue("path"));
    require(g_scans[1].m_scan->getValue("mediaid"));
    require(g_scans[1].m_scan->getValue("formatid"));
  
    // meta
    require(g_scans[2].m_scan->getValue("name"));
    require(g_scans[2].m_scan->getValue("xml"));

    // artiststometamap
    require(g_scans[3].m_scan->getValue("artistid", (char*)&g_artistid));
	  
    // subgenrestometamap
    require(g_scans[4].m_scan->getValue("subgenreid", (char*)&g_subgenreid));
  
    for(i = 0; i<cnt; i++){
      g_scans[i].m_scan->getValue("metaid", (char*)&g_scans[i].metaid);
    }

    g_trans->execute(NoCommit, AbortOnError, 1);

    Uint32 max_val = 0;
    Uint32 match_val = 0;
  
    S_Scan * F [5], * Q [5], * nextF [5];
    Uint32 F_sz = 0, Q_sz = 0;
    for(i = 0; i<cnt; i++){
      F_sz++;
      F[i] = &g_scans[i];
    }

    Uint32 match_count = 0;
    while(F_sz > 0){
      Uint32 prev_F_sz = F_sz;
      F_sz = 0;
      bool found = false;
      //for(i = 0; i<cnt; i++)
      //ndbout_c("%s - %d", g_scans[i].m_table, g_scans[i].metaid);
    
      for(i = 0; i<prev_F_sz; i++){
	int res = F[i]->m_scan->nextResult();
	if(res == -1)
	  abort();

	if(res == 1){
	  continue;
	}

	Uint32 metaid = F[i]->metaid;
	F[i]->row_count++;
      
	if(metaid == match_val){
	  //ndbout_c("flera");
	  nextF[F_sz++] = F[i];
	  require(F_sz >= 0 && F_sz <= cnt);
	  F[i]->match_count++;
	  Uint32 comb = 1;
	  for(j = 0; j<cnt; j++){
	    comb *= (&g_scans[j] == F[i] ? 1 : g_scans[j].match_count);
	  }
	  match_count += comb;
	  found = true;
	  continue;
	}
	if(metaid < max_val){
	  nextF[F_sz++] = F[i];
	  require(F_sz >= 0 && F_sz <= cnt);
	  continue;
	}
	if(metaid > max_val){
	  for(j = 0; j<Q_sz; j++)
	    nextF[F_sz++] = Q[j];
	  require(F_sz >= 0 && F_sz <= cnt);
	  Q_sz = 0;
	  max_val = metaid;
	}
	Q[Q_sz++] = F[i];
	require(Q_sz >= 0 && Q_sz <= cnt);
      }
      if(F_sz == 0 && Q_sz > 0){
	match_val = max_val;
	for(j = 0; j<Q_sz; j++){
	  nextF[F_sz++] = Q[j];
	  Q[j]->match_count = 1;
	}
	require(F_sz >= 0 && F_sz <= cnt);
	require(Q_sz >= 0 && Q_sz <= cnt);
	Q_sz = 0;
	match_count++;
	lookup();
      } else if(!found && F_sz + Q_sz < cnt){
	F_sz = 0;
      }
      require(F_sz >= 0 && F_sz <= cnt);
      for(i = 0; i<F_sz; i++)
	F[i] = nextF[i];
    }
  
    start = NdbTick_CurrentMillisecond() - start;
    ndbout_c("Elapsed: %lldms", start);
  
    ndbout_c("rows: %d", match_count);
    for(i = 0; i<cnt; i++){
      ndbout_c("%s : %d", g_scans[i].m_table, g_scans[i].row_count);
    }
    g_trans->close();
  }
}
Exemple #20
0
int NDBT_TestSuite::execute(int argc, const char** argv){
  int res = NDBT_FAILED;
  /* Arguments:
       Run only a subset of tests
       -n testname Which test to run
       Recommendations to test functions:
       --records Number of records to use(default: 10000)
       --loops Number of loops to execute in the test(default: 100)

       Other parameters should:
       * be calculated from the above two parameters 
       * be divided into different test cases, ex. one testcase runs
         with FragmentType = Single and another perfoms the same 
         test with FragmentType = Large
       * let the test case iterate over all/subset of appropriate parameters
         ex. iterate over FragmentType = Single to FragmentType = AllLarge

       Remeber that the intention is that it should be _easy_ to run 
       a complete test suite without any greater knowledge of what 
       should be tested ie. keep arguments at a minimum
  */

  char **_argv= (char **)argv;

  if (!my_progname)
    my_progname= _argv[0];

  const char *load_default_groups[]= { "mysql_cluster",0 };
  load_defaults("my",load_default_groups,&argc,&_argv);

  int ho_error;
#ifndef DBUG_OFF
  opt_debug= "d:t:i:F:L";
#endif
  if ((ho_error=handle_options(&argc, &_argv, my_long_options,
			       ndb_std_get_one_option)))
  {
    usage();
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }

  if (opt_print == true){
    printExecutionTree();
    return 0;
  }

  if (opt_print_html == true){
    printExecutionTreeHTML();
    return 0;
  }

  if (opt_print_cases == true){
    printCases();
    return 0;
  }

  if (opt_verbose)
    setOutputLevel(2); // Show g_info
  else 
    setOutputLevel(0); // Show only g_err ?

  remote_mgm = opt_remote_mgm;
  records = opt_records;
  loops = opt_loops;
  timer = opt_timer;

  Ndb_cluster_connection con;
  if(con.connect(12, 5, 1))
  {
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  if (opt_seed == 0)
  {
    opt_seed = NdbTick_CurrentMillisecond();
  }
  ndbout_c("random seed: %u", opt_seed);
  srand(opt_seed);
  srandom(opt_seed);

  global_flag_skip_invalidate_cache = 1;
  
  {
    Ndb ndb(&con, "TEST_DB");
    ndb.init(1024);
    if (ndb.waitUntilReady(500)){
      g_err << "Ndb was not ready" << endl;
      return NDBT_ProgramExit(NDBT_FAILED);
    }
    NdbDictionary::Dictionary* pDict = ndb.getDictionary();

    int num_tables= argc;
    if (argc == 0)
      num_tables = NDBT_Tables::getNumTables();

    for(int i = 0; i<num_tables; i++)
    {
      if (argc == 0)
	m_tables_in_test.push_back(NDBT_Tables::getTable(i)->getName());
      else
	m_tables_in_test.push_back(_argv[i]);
      if (createAllTables == true)
      {
	const char *tab_name=  m_tables_in_test[i].c_str();
	const NdbDictionary::Table* pTab = pDict->getTable(tab_name);
	if (pTab && pDict->dropTable(tab_name) != 0)
	{
	  g_err << "ERROR0: Failed to drop table " << tab_name
		<< pDict->getNdbError() << endl;
	  return NDBT_ProgramExit(NDBT_FAILED);
	}
	if(NDBT_Tables::createTable(&ndb, tab_name) != 0)
	{
	  g_err << "ERROR1: Failed to create table " << tab_name
		<< pDict->getNdbError() << endl;
	  return NDBT_ProgramExit(NDBT_FAILED);
	}
      }
    }
  }

  if(argc == 0){
    // No table specified
    res = executeAll(con, opt_testname);
  } else {
    testSuiteTimer.doStart(); 
    for(int i = 0; i<argc; i++){
      executeOne(con, _argv[i], opt_testname);
    }
    testSuiteTimer.doStop();
    res = report(opt_testname);
  }

  if (res == NDBT_OK && createAllTables == true)
  {
    Ndb ndb(&con, "TEST_DB");
    ndb.init(1024);
    if (ndb.waitUntilReady(500)){
      g_err << "Ndb was not ready" << endl;
      return NDBT_ProgramExit(NDBT_FAILED);
    }
    NdbDictionary::Dictionary* pDict = ndb.getDictionary();
    for(unsigned i = 0; i<m_tables_in_test.size(); i++)
    {
      pDict->dropTable(m_tables_in_test[i].c_str());
    }
  }

  return NDBT_ProgramExit(res);
}
Exemple #21
0
int main(int argc, const char** argv){
  ndb_init();

  int _records = 0;
  int _loops = 1;
  int _abort = 0;
  int _parallelism = 1;
  const char* _tabname = NULL, *db = 0;
  int _help = 0;
  int lock = NdbOperation::LM_Read;
  int sorted = 0;

  struct getargs args[] = {
    { "aborts", 'a', arg_integer, &_abort, "percent of transactions that are aborted", "abort%" },
    { "loops", 'l', arg_integer, &_loops, "number of times to run this program(0=infinite loop)", "loops" },
    { "parallelism", 'p', arg_integer, &_parallelism, "parallelism(1-240)", "para" },
    { "records", 'r', arg_integer, &_records, "Number of records", "recs" },
    { "usage", '?', arg_flag, &_help, "Print help", "" },
    { "lock", 'm', arg_integer, &lock, "lock mode", "" },
    { "sorted", 's', arg_flag, &sorted, "sorted", "" },
    { "database", 'd', arg_string, &db, "Database", "" }
  };
  int num_args = sizeof(args) / sizeof(args[0]);
  int optind = 0;
  char desc[] = 
    " tabname\n"\
    "This program will scan read all records in one table in Ndb.\n"\
    "It will verify every column read by calculating the expected value.\n";
  
  if(getarg(args, num_args, argc, argv, &optind) || argv[optind] == NULL || _help) {
    arg_printusage(args, num_args, argv[0], desc);
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }
  _tabname = argv[optind];

  // Connect to Ndb
  Ndb_cluster_connection con;
  if(con.connect(12, 5, 1) != 0)
  {
    return NDBT_ProgramExit(NDBT_FAILED);
  }
  Ndb MyNdb( &con, db ? db : "TEST_DB" );

  if(MyNdb.init() != 0){
    ERR(MyNdb.getNdbError());
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  while(MyNdb.waitUntilReady() != 0)
    ndbout << "Waiting for ndb to become ready..." << endl;
   
  // Check if table exists in db
  const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
  if(pTab == NULL){
    ndbout << " Table " << _tabname << " does not exist!" << endl;
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }

  const NdbDictionary::Index * pIdx = 0;
  if(optind+1 < argc)
  {
    pIdx = MyNdb.getDictionary()->getIndex(argv[optind+1], _tabname);
    if(!pIdx)
      ndbout << " Index " << argv[optind+1] << " not found" << endl;
    else
      if(pIdx->getType() != NdbDictionary::Index::OrderedIndex)
      {
	ndbout << " Index " << argv[optind+1] << " is not scannable" << endl;
	pIdx = 0;
      }
  }
  
  HugoTransactions hugoTrans(*pTab);
  int i = 0;
  while (i<_loops || _loops==0) {
    ndbout << i << ": ";
    if(!pIdx)
    {
      if(hugoTrans.scanReadRecords(&MyNdb, 
				   0,
				   _abort,
				   _parallelism,
				   (NdbOperation::LockMode)lock) != 0)
      {
	return NDBT_ProgramExit(NDBT_FAILED);
      }
    }
    else
    {
      if(hugoTrans.scanReadRecords(&MyNdb, pIdx, 
				   0,
				   _abort,
				   _parallelism,
				   (NdbOperation::LockMode)lock,
				   sorted) != 0)
      {
	return NDBT_ProgramExit(NDBT_FAILED);
      }
    }
    i++;
  }

  return NDBT_ProgramExit(NDBT_OK);
}
Exemple #22
0
int main(int argc, char ** argv)
{
  ndb_init();
  /**
   * define a connect string to the management server
   */
  

  memset( ndbconnectstring,0,255);
  memset( database,0,255);
  memset( tablename,0,255);
  strcpy(ndbconnectstring, "localhost:1186");
  strcpy(database, "");

  option(argc,argv);
  if(strcmp(tablename,"")==0)
    {
      g_analyze_all=true;
    }
  
  char * db;
  if(strcmp(database,"")==0)
    db=0;
  else
    db=database;

  char * table = tablename;

  /**
   * Create a Ndb_cluster_connection object using the connectstring
   */
  Ndb_cluster_connection * conn = new Ndb_cluster_connection(ndbconnectstring);


  /**
   * Connect to the management server
   * try 12 times, wait 5 seconds between each retry,
   * and be verbose (1), if connection attempt failes
   */
  if(conn->connect(12, 5, 1) != 0)
    {
      printf( "Unable to connect to management server." );
      return -1;
    }

  /**
   * Join the cluster
   * wait for 30 seconds for first node to be alive, and 0 seconds
   * for the rest.
   */
  if (conn->wait_until_ready(30,0) <0)
    {
      printf( "Cluster nodes not ready in 30 seconds." );
      return -1;
    }



  /**
   * The first thing we have to do is to instantiate an Ndb object.
   * The Ndb object represents a connection to a database.
   * It is important to note that the Ndb object is not thread safe!!
   * Thus, if it is a multi-threaded application, then typically each thread
   * uses its own Ndb object.
   *
   * Now we create an Ndb object that connects to the test database.
   */

  Ndb * ndb = new Ndb(conn);


  if (ndb->init() != 0)
    {
      /**
       * just exit if we can't initialize the Ndb object
       */
      return -1;
    }
  if(ftScan)
    {
      if(g_analyze_all)
	printf("Analyzing all tables. This may take a while.\n");
      else
	printf("Analyzing entire table. This may take a while.\n");
    }

  if (ignoreData) 
    {
       printf("record in database will be ignored.\n");
    }
 
  memset(g_all_tables,0,sizeof(g_all_tables));
  memset(g_all_dbs,0,sizeof(g_all_dbs));
  char filename[255];  
  if(g_analyze_all)
    {
      if(db!=0)
	sprintf(filename,"%s.csv",db); 
      else
	{
	  strcpy(filename,"all_databases.csv"); 
	  g_multi_db=true;
	}

      list_tables(ndb,db);
    }
  else
    {
      if(db==0)
	{
	  printf("You must specify the database when analyzing only one table\n");
	  exit(1);
	}
      g_count=1;
      sprintf(filename,"%s_%s.csv",db,table); 
      strcpy(g_all_tables[0], table);
    }
  FILE * fh =  fopen(filename,"w+");
  fclose(fh);
  for(int i=0;i<g_count;i++)
    {
      
      if(db!=0)
	{
	  if (supersizeme(ndb, db,  g_all_tables[i], ftScan,ignoreData ) <0)
	    return -1;
	}else
	{
	  if (supersizeme(ndb, g_all_dbs[i],  g_all_tables[i], ftScan,ignoreData) <0)
	    return -1;
	}
      printf("----------------------------------------------------\n");
    }

  return 0;

}
Exemple #23
0
int main(int argc, const char** argv){
  ndb_init();

  int _records = 0;
  int _loops = 1;
  int  _percentVal = 1;
  int _lockTime = 1000;
  const char* _tabname = NULL;
  int _help = 0;
  
  struct getargs args[] = {
    { "loops", 'l', arg_integer, &_loops, "number of times to run this program(0=infinite loop)", "loops" },
    { "records", 'r', arg_integer, &_records, "Number of records", "recs" },
    { "locktime", 't', arg_integer, &_lockTime, "Time in ms to hold lock(default=1000)", "ms" },
    { "percent", 'p', arg_integer, &_percentVal, "Percent of records to lock(default=1%)", "%" },
    { "usage", '?', arg_flag, &_help, "Print help", "" }
  };
  int num_args = sizeof(args) / sizeof(args[0]);
  int optind = 0;
  char desc[] = 
    "tabname\n"\
    "This program will lock p% of the records in the table for x milliseconds\n"\
    "then it will lock the next 1% and continue to do so until it has locked \n"\
    "all records in the table\n";
  
  if(getarg(args, num_args, argc, argv, &optind) ||
     argv[optind] == NULL || _records == 0 || _help) {
    arg_printusage(args, num_args, argv[0], desc);
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }
  _tabname = argv[optind];

  // Connect to Ndb
  Ndb_cluster_connection con;
  if(con.connect(12, 5, 1) != 0)
  {
    return NDBT_ProgramExit(NDBT_FAILED);
  }
  Ndb MyNdb(&con, "TEST_DB" );

  if(MyNdb.init() != 0){
    ERR(MyNdb.getNdbError());
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  while(MyNdb.waitUntilReady() != 0)
    ndbout << "Waiting for ndb to become ready..." << endl;
   
  // Check if table exists in db
  const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
  if(pTab == NULL){
    ndbout << " Table " << _tabname << " does not exist!" << endl;
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }

  HugoTransactions hugoTrans(*pTab);
  int i = 0;
  while (i<_loops || _loops==0) {
    ndbout << i << ": ";
    if (hugoTrans.lockRecords(&MyNdb, _records, _percentVal, _lockTime) != 0){
      return NDBT_ProgramExit(NDBT_FAILED);
    }
    i++;
  }

  return NDBT_ProgramExit(NDBT_OK);
}
int main(int argc, char** argv){
  NDB_INIT(argv[0]);
  ndb_opt_set_usage_funcs(short_usage_sub, usage);
  ndb_load_defaults(NULL, load_default_groups, &argc, &argv);
  int ho_error;
  if ((ho_error=handle_options(&argc, &argv, my_long_options,
			       ndb_std_get_one_option)))
    return -1;


  // Connect to Ndb
  Ndb_cluster_connection con;
  if(con.connect(12, 5, 1) != 0)
  {
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  if (con.wait_until_ready(30,0) < 0)
  {
    ndbout << "Cluster nodes not ready in 30 seconds." << endl;
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  Ndb MyNdb( &con, _db);

  if(MyNdb.init() != 0)
  {
    NDB_ERR(MyNdb.getNdbError());
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  Vector<const NdbDictionary::Table*> tables;
  for(int i = 0; i<argc; i++)
  {
    const char* _tabname = argv[i];
    // Check if table exists in db
    const NdbDictionary::Table* pTab =
      NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
    if(pTab == NULL)
    {
      ndbout << " Table " << _tabname << " does not exist!" << endl;
      return NDBT_ProgramExit(NDBT_WRONGARGS);
    }
    else
    {
      ndbout << " Discovered " << _tabname << endl;
    }
    tables.push_back(pTab);
  }
  tables.push_back(0);

  HugoQueryBuilder::OptionMask mask = 0;
  struct { const char * name; HugoQueryBuilder::QueryOption option; }
  _ops[] = {
    { "lookup", HugoQueryBuilder::O_LOOKUP },
    { "scan", HugoQueryBuilder::O_SCAN },
    { "pk", HugoQueryBuilder::O_PK_INDEX },
    { "uk", HugoQueryBuilder::O_UNIQUE_INDEX },
    { "oi", HugoQueryBuilder::O_ORDERED_INDEX },
    { "ts", HugoQueryBuilder::O_TABLE_SCAN },

    // end-marker
    { 0, HugoQueryBuilder::O_LOOKUP }
  };

  Vector<BaseString> list;
  BaseString tmp(_options);
  tmp.split(list, ",");
  for (unsigned i = 0; i<list.size(); i++)
  {
    bool found = false;
    for (int o = 0; _ops[o].name != 0; o++)
    {
      if (strcasecmp(list[i].c_str(), _ops[o].name) == 0)
      {
        found = true;
        mask |= _ops[o].option;
        break;
      }
    }
    if (!found)
    {
      ndbout << "Unknown option " << list[i].c_str() << ", ignoring" << endl;
    }
  }

  if (_seed == 0)
  {
    _seed = (unsigned)NdbTick_CurrentMillisecond();
  }
  ndbout << "--seed=" << _seed << endl;
  srand(_seed);

  for (int i = 0; (_loops == 0) || (i < _loops);)
  {
    if (_verbose >= 1)
    {
      ndbout << "******\tbuilding new query (mask: 0x" << hex 
             << (Uint64)mask << ")" << endl;
    }
    HugoQueryBuilder builder(&MyNdb, tables.getBase(), mask);
    builder.setJoinLevel(_depth);
    const NdbQueryDef * q = builder.createQuery();
    if (_verbose >= 2)
    {
      q->print(); ndbout << endl;
    }

    for (int j = 0; j < _loops_per_query && ((_loops == 0) || (i < _loops));
         i++, j++)
    {
      int res = 0;
      HugoQueries hq(* q);
      if (q->isScanQuery())
      {
        res = hq.runScanQuery(&MyNdb);
      }
      else
      {
        res = hq.runLookupQuery(&MyNdb, _records/_depth, _batch);
      }
      if (res != 0)
      {
        return NDBT_ProgramExit(NDBT_FAILED);
      }
      if (hq.m_rows_found.size() != 0)
      {
        printf("\tfound: [ ");
        for (unsigned i = 0; i<hq.m_rows_found.size(); i++)
        {
          printf("%u ", (Uint32)hq.m_rows_found[i]);
        }
        ndbout_c("]");
      }
    }
  }

  return NDBT_ProgramExit(NDBT_OK);
}