~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzleslap.cc

  • Committer: Brian Aker
  • Date: 2011-11-26 23:14:59 UTC
  • mto: This revision was merged to the branch mainline in revision 2465.
  • Revision ID: brian@tangent.org-20111126231459-pa9i3arizevf0vlr
Remove con from being passed object.

Show diffs side-by-side

added added

removed removed

Lines of Context:
233
233
void option_cleanup(OptionString *stmt);
234
234
void concurrency_loop(drizzle_con_st &con, uint32_t current, OptionString *eptr);
235
235
static void run_statements(drizzle_con_st &con, Statement *stmt);
236
 
void slap_connect(drizzle_con_st &con, bool connect_to_schema);
237
 
void slap_close(drizzle_con_st &con);
 
236
drizzle_con_st *slap_connect(bool connect_to_schema);
 
237
void slap_close(drizzle_con_st *con);
238
238
static int run_query(drizzle_con_st &con, drizzle_result_st *result, const char *query, int len);
239
239
void standard_deviation(Conclusions &con, Stats *sptr);
240
240
 
273
273
  uint64_t counter= 0, queries;
274
274
  uint64_t detach_counter;
275
275
  uint32_t commit_counter;
276
 
  boost::scoped_ptr<drizzle_con_st> con_ap(new drizzle_con_st);
277
 
  drizzle_con_st &con= *con_ap.get();
278
276
  drizzle_result_st result;
279
277
  drizzle_row_t row;
280
278
  Statement *ptr;
281
279
 
282
280
  master_wakeup.wait();
283
281
 
284
 
  slap_connect(con, true);
 
282
  drizzle_con_st *con= slap_connect(true);
285
283
 
286
284
  if (verbose >= 3)
 
285
  {
287
286
    printf("connected!\n");
 
287
  }
288
288
  queries= 0;
289
289
 
290
290
  commit_counter= 0;
291
291
  if (commit_rate)
292
 
    run_query(con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
 
292
  {
 
293
    run_query(*con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
 
294
  }
293
295
 
294
296
limit_not_met:
295
297
  for (ptr= ctx->getStmt(), detach_counter= 0;
299
301
    if (not opt_only_print && detach_rate && !(detach_counter % detach_rate))
300
302
    {
301
303
      slap_close(con);
302
 
      slap_connect(con, true);
 
304
      con= slap_connect(true);
303
305
    }
304
306
 
305
307
    /*
329
331
 
330
332
        int length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'", (int)ptr->getLength(), ptr->getString(), key);
331
333
 
332
 
        if (run_query(con, &result, buffer, length))
 
334
        if (run_query(*con, &result, buffer, length))
333
335
        {
334
336
          if ((ptr->getType() == UPDATE_TYPE_REQUIRES_PREFIX) and commit_rate)
335
337
          {
342
344
          else
343
345
          {
344
346
            fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
345
 
                    SLAP_NAME, (uint32_t)length, buffer, drizzle_con_error(&con));
 
347
                    SLAP_NAME, (uint32_t)length, buffer, drizzle_con_error(con));
346
348
            abort();
347
349
          }
348
350
        }
350
352
    }
351
353
    else
352
354
    {
353
 
      if (run_query(con, &result, ptr->getString(), ptr->getLength()))
 
355
      if (run_query(*con, &result, ptr->getString(), ptr->getLength()))
354
356
      {
355
357
        if ((ptr->getType() == UPDATE_TYPE_REQUIRES_PREFIX) and commit_rate)
356
358
        {
363
365
        else
364
366
        {
365
367
          fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
366
 
                  SLAP_NAME, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
 
368
                  SLAP_NAME, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(con));
367
369
          abort();
368
370
        }
369
371
      }
380
382
    if (commit_rate && (++commit_counter == commit_rate) and not is_failed_update)
381
383
    {
382
384
      commit_counter= 0;
383
 
      run_query(con, NULL, "COMMIT", strlen("COMMIT"));
 
385
      run_query(*con, NULL, "COMMIT", strlen("COMMIT"));
384
386
    }
385
387
 
386
388
    /* If the timer is set, and the alarm is not active then end */
401
403
 
402
404
end:
403
405
  if (commit_rate)
404
 
    run_query(con, NULL, "COMMIT", strlen("COMMIT"));
 
406
  {
 
407
    run_query(*con, NULL, "COMMIT", strlen("COMMIT"));
 
408
  }
405
409
 
406
410
  slap_close(con);
 
411
  con= NULL;
407
412
 
408
413
  delete ctx;
409
414
}
560
565
 
561
566
    uint64_t temp_drizzle_port= 0;
562
567
    boost::scoped_ptr<drizzle_con_st> con_ap(new drizzle_con_st);
563
 
    drizzle_con_st &con= *con_ap.get();
564
568
    OptionString *eptr;
565
569
 
566
570
    // Disable allow_guessing
674
678
    /* globals? Yes, so we only have to run strlen once */
675
679
    delimiter_length= delimiter.length();
676
680
 
677
 
    slap_connect(con, false);
 
681
    drizzle_con_st *con= slap_connect(false);
678
682
 
679
683
    /* Main iterations loop */
680
684
burnin:
690
694
      if (concurrency.size())
691
695
      {
692
696
        for (current= &concurrency[0]; current && *current; current++)
693
 
          concurrency_loop(con, *current, eptr);
 
697
          concurrency_loop(*con, *current, eptr);
694
698
      }
695
699
      else
696
700
      {
697
701
        uint32_t infinite= 1;
698
702
        do {
699
 
          concurrency_loop(con, infinite, eptr);
 
703
          concurrency_loop(*con, infinite, eptr);
700
704
        }
701
705
        while (infinite++);
702
706
      }
703
707
 
704
708
      if (not opt_preserve)
705
 
        drop_schema(con, create_schema_string.c_str());
 
709
        drop_schema(*con, create_schema_string.c_str());
706
710
 
707
711
    } while (eptr ? (eptr= eptr->getNext()) : 0);
708
712
 
709
713
    if (opt_burnin)
 
714
    {
710
715
      goto burnin;
 
716
    }
711
717
 
712
718
    slap_close(con);
713
719
 
2372
2378
  }
2373
2379
}
2374
2380
 
2375
 
void slap_close(drizzle_con_st &con)
 
2381
void slap_close(drizzle_con_st *con)
2376
2382
{
2377
 
  drizzle_free(drizzle_con_drizzle(&con));
 
2383
  drizzle_free(drizzle_con_drizzle(con));
2378
2384
}
2379
2385
 
2380
 
void slap_connect(drizzle_con_st &con, bool connect_to_schema)
 
2386
drizzle_con_st* slap_connect(bool connect_to_schema)
2381
2387
{
2382
2388
  /* Connect to server */
2383
2389
  static uint32_t connection_retry_sleep= 100000; /* Microseconds */
2388
2394
  if (opt_delayed_start)
2389
2395
    usleep(random()%opt_delayed_start);
2390
2396
 
 
2397
  drizzle_con_st* con;
2391
2398
  if ((drizzle= drizzle_create()) == NULL or
2392
 
      drizzle_con_add_tcp(drizzle, &con, host.c_str(), opt_drizzle_port,
2393
 
        user.c_str(),
2394
 
        opt_password.c_str(),
2395
 
        connect_to_schema ? create_schema_string.c_str() : NULL,
2396
 
        use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL) == NULL)
 
2399
      (con= drizzle_con_add_tcp(drizzle,
 
2400
                                host.c_str(), opt_drizzle_port,
 
2401
                                user.c_str(), opt_password.c_str(),
 
2402
                                connect_to_schema ? create_schema_string.c_str() : NULL,
 
2403
                                use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL)) == NULL)
2397
2404
  {
2398
2405
    fprintf(stderr,"%s: Error creating drizzle object\n", SLAP_NAME);
2399
2406
    abort();
2403
2410
 
2404
2411
  if (opt_only_print)
2405
2412
  {
2406
 
    return;
 
2413
    return con;
2407
2414
  }
2408
2415
 
2409
2416
  for (uint32_t x= 0; x < 10; x++)
2410
2417
  {
2411
 
    if ((ret= drizzle_con_connect(&con)) == DRIZZLE_RETURN_OK)
 
2418
    if ((ret= drizzle_con_connect(con)) == DRIZZLE_RETURN_OK)
2412
2419
    {
2413
2420
      /* Connect suceeded */
2414
2421
      connect_error= 0;
2419
2426
  if (connect_error)
2420
2427
  {
2421
2428
    fprintf(stderr,"%s: Error when connecting to server: %d %s\n", SLAP_NAME,
2422
 
            ret, drizzle_con_error(&con));
 
2429
            ret, drizzle_con_error(con));
2423
2430
    abort();
2424
2431
  }
 
2432
 
 
2433
  return con;
2425
2434
}
2426
2435
 
2427
2436
void standard_deviation(Conclusions &con, Stats *sptr)