~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzleslap.cc

  • Committer: Brian Aker
  • Date: 2011-11-04 21:06:16 UTC
  • mto: This revision was merged to the branch mainline in revision 2450.
  • Revision ID: brian@tangent.org-20111104210616-2at42agch94dkwb0
Additional fixes for libdrizzle.

Show diffs side-by-side

added added

removed removed

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