~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzleslap.cc

  • Committer: Brian Aker
  • Date: 2010-11-09 03:47:39 UTC
  • Revision ID: brian@tangent.org-20101109034739-y8ezwzxl6yut5gat
Merge in change to handle update follbacks in slap.

Show diffs side-by-side

added added

removed removed

Lines of Context:
105
105
#include <boost/program_options.hpp>
106
106
#include <drizzled/atomics.h>
107
107
 
 
108
#define SLAP_NAME "drizzleslap"
108
109
#define SLAP_VERSION "1.5"
109
110
 
110
111
#define HUGE_STRING_LENGTH 8196
129
130
std::vector < std::string > primary_keys;
130
131
 
131
132
drizzled::atomic<size_t> connection_count;
 
133
drizzled::atomic<uint64_t> failed_update_for_transaction;
132
134
 
133
135
static string host, 
134
136
  opt_password, 
299
301
    /*
300
302
      We have to execute differently based on query type. This should become a function.
301
303
    */
 
304
    bool is_failed_update= false;
302
305
    if ((ptr->getType() == UPDATE_TYPE_REQUIRES_PREFIX) ||
303
306
        (ptr->getType() == SELECT_TYPE_REQUIRES_PREFIX))
304
307
    {
327
330
 
328
331
        if (run_query(con, &result, buffer, length))
329
332
        {
 
333
          if ((ptr->getType() == UPDATE_TYPE_REQUIRES_PREFIX) and commit_rate)
 
334
          {
 
335
            // Expand to check to see if Innodb, if so we should restart the
 
336
            // transaction.  
 
337
 
 
338
            is_failed_update= true;
 
339
            failed_update_for_transaction.fetch_and_increment();
 
340
          }
 
341
          else
 
342
          {
 
343
            fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
 
344
                    SLAP_NAME, (uint32_t)length, buffer, drizzle_con_error(&con));
 
345
            abort();
 
346
          }
 
347
        }
 
348
      }
 
349
    }
 
350
    else
 
351
    {
 
352
      if (run_query(con, &result, ptr->getString(), ptr->getLength()))
 
353
      {
 
354
        if ((ptr->getType() == UPDATE_TYPE_REQUIRES_PREFIX) and commit_rate)
 
355
        {
 
356
          // Expand to check to see if Innodb, if so we should restart the
 
357
          // transaction.
 
358
 
 
359
          is_failed_update= true;
 
360
          failed_update_for_transaction.fetch_and_increment();
 
361
        }
 
362
        else
 
363
        {
330
364
          fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
331
 
                  internal::my_progname, (uint32_t)length, buffer, drizzle_con_error(&con));
 
365
                  SLAP_NAME, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
332
366
          abort();
333
367
        }
334
368
      }
335
369
    }
336
 
    else
337
 
    {
338
 
      if (run_query(con, &result, ptr->getString(), ptr->getLength()))
339
 
      {
340
 
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
341
 
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
342
 
        abort();
343
 
      }
344
 
    }
345
370
 
346
 
    if (not opt_only_print)
 
371
    if (not opt_only_print and not is_failed_update)
347
372
    {
348
373
      while ((row = drizzle_row_next(&result)))
349
374
        counter++;
351
376
    }
352
377
    queries++;
353
378
 
354
 
    if (commit_rate && (++commit_counter == commit_rate))
 
379
    if (commit_rate && (++commit_counter == commit_rate) and not is_failed_update)
355
380
    {
356
381
      commit_counter= 0;
357
382
      run_query(con, NULL, "COMMIT", strlen("COMMIT"));
560
585
 
561
586
    if ( vm.count("help") || vm.count("info"))
562
587
    {
563
 
      printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname, SLAP_VERSION,
 
588
      printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",SLAP_NAME, SLAP_VERSION,
564
589
          drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
565
590
      puts("Copyright (C) 2008 Sun Microsystems");
566
591
      puts("This software comes with ABSOLUTELY NO WARRANTY. "
625
650
 
626
651
    if ( vm.count("version") )
627
652
    {
628
 
      printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname, SLAP_VERSION,
 
653
      printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",SLAP_NAME, SLAP_VERSION,
629
654
          drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
630
655
      abort();
631
656
    }
1244
1269
  {
1245
1270
    fprintf(stderr,
1246
1271
            "%s: Can't use --auto-generate-sql when create and query strings are specified!\n",
1247
 
            internal::my_progname);
 
1272
            SLAP_NAME);
1248
1273
    abort();
1249
1274
  }
1250
1275
 
1253
1278
  {
1254
1279
    fprintf(stderr,
1255
1280
            "%s: Either auto-generate-sql-guid-primary or auto-generate-sql-add-autoincrement can be used!\n",
1256
 
            internal::my_progname);
 
1281
            SLAP_NAME);
1257
1282
    abort();
1258
1283
  }
1259
1284
 
1261
1286
  {
1262
1287
    fprintf(stderr,
1263
1288
            "%s: Either auto-generate-sql-execute-number or number-of-queries can be used!\n",
1264
 
            internal::my_progname);
 
1289
            SLAP_NAME);
1265
1290
    abort();
1266
1291
  }
1267
1292
 
1281
1306
                          S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1)
1282
1307
      {
1283
1308
        fprintf(stderr,"%s: Could not open csv file: %sn\n",
1284
 
                internal::my_progname, opt_csv_str.c_str());
 
1309
                SLAP_NAME, opt_csv_str.c_str());
1285
1310
        abort();
1286
1311
      }
1287
1312
    }
1396
1421
        {
1397
1422
          fprintf(stderr,
1398
1423
                  "%s: Can't perform key test without a primary key!\n",
1399
 
                  internal::my_progname);
 
1424
                  SLAP_NAME);
1400
1425
          abort();
1401
1426
        }
1402
1427
 
1432
1457
        {
1433
1458
          fprintf(stderr,
1434
1459
                  "%s: Can't perform update test without a primary key!\n",
1435
 
                  internal::my_progname);
 
1460
                  SLAP_NAME);
1436
1461
          abort();
1437
1462
        }
1438
1463
 
1481
1506
      if (not S_ISREG(sbuf.st_mode))
1482
1507
      {
1483
1508
        fprintf(stderr,"%s: Create file was not a regular file\n",
1484
 
                internal::my_progname);
 
1509
                SLAP_NAME);
1485
1510
        abort();
1486
1511
      }
1487
1512
      if ((data_file= open(create_string.c_str(), O_RDWR)) == -1)
1488
1513
      {
1489
 
        fprintf(stderr,"%s: Could not open create file\n", internal::my_progname);
 
1514
        fprintf(stderr,"%s: Could not open create file\n", SLAP_NAME);
1490
1515
        abort();
1491
1516
      }
1492
1517
      if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1526
1551
      if (not S_ISREG(sbuf.st_mode))
1527
1552
      {
1528
1553
        fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1529
 
                internal::my_progname);
 
1554
                SLAP_NAME);
1530
1555
        abort();
1531
1556
      }
1532
1557
      if ((data_file= open(user_supplied_query.c_str(), O_RDWR)) == -1)
1533
1558
      {
1534
 
        fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
 
1559
        fprintf(stderr,"%s: Could not open query supplied file\n", SLAP_NAME);
1535
1560
        abort();
1536
1561
      }
1537
1562
      if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1567
1592
    if (not S_ISREG(sbuf.st_mode))
1568
1593
    {
1569
1594
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1570
 
              internal::my_progname);
 
1595
              SLAP_NAME);
1571
1596
      abort();
1572
1597
    }
1573
1598
    if ((data_file= open(user_supplied_pre_statements.c_str(), O_RDWR)) == -1)
1574
1599
    {
1575
 
      fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
 
1600
      fprintf(stderr,"%s: Could not open query supplied file\n", SLAP_NAME);
1576
1601
      abort();
1577
1602
    }
1578
1603
    if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1608
1633
    if (not S_ISREG(sbuf.st_mode))
1609
1634
    {
1610
1635
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1611
 
              internal::my_progname);
 
1636
              SLAP_NAME);
1612
1637
      abort();
1613
1638
    }
1614
1639
    if ((data_file= open(user_supplied_post_statements.c_str(), O_RDWR)) == -1)
1615
1640
    {
1616
 
      fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
 
1641
      fprintf(stderr,"%s: Could not open query supplied file\n", SLAP_NAME);
1617
1642
      abort();
1618
1643
    }
1619
1644
 
1707
1732
  {
1708
1733
    if (run_query(con, &result, "SELECT id from t1", strlen("SELECT id from t1")))
1709
1734
    {
1710
 
      fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", internal::my_progname,
 
1735
      fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", SLAP_NAME,
1711
1736
              drizzle_con_error(&con));
1712
1737
      abort();
1713
1738
    }
1759
1784
 
1760
1785
  if (run_query(con, NULL, query, len))
1761
1786
  {
1762
 
    fprintf(stderr,"%s: Cannot create schema %s : %s\n", internal::my_progname, db,
 
1787
    fprintf(stderr,"%s: Cannot create schema %s : %s\n", SLAP_NAME, db,
1763
1788
            drizzle_con_error(&con));
1764
1789
    abort();
1765
1790
  }
1785
1810
    if (drizzle_select_db(&con,  &result, db, &ret) == NULL ||
1786
1811
        ret != DRIZZLE_RETURN_OK)
1787
1812
    {
1788
 
      fprintf(stderr,"%s: Cannot select schema '%s': %s\n",internal::my_progname, db,
 
1813
      fprintf(stderr,"%s: Cannot select schema '%s': %s\n",SLAP_NAME, db,
1789
1814
              ret == DRIZZLE_RETURN_ERROR_CODE ?
1790
1815
              drizzle_result_error(&result) : drizzle_con_error(&con));
1791
1816
      abort();
1800
1825
                  engine_stmt->getString());
1801
1826
    if (run_query(con, NULL, query, len))
1802
1827
    {
1803
 
      fprintf(stderr,"%s: Cannot set default engine: %s\n", internal::my_progname,
 
1828
      fprintf(stderr,"%s: Cannot set default engine: %s\n", SLAP_NAME,
1804
1829
              drizzle_con_error(&con));
1805
1830
      abort();
1806
1831
    }
1825
1850
      if (run_query(con, NULL, buffer, strlen(buffer)))
1826
1851
      {
1827
1852
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1828
 
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
 
1853
                SLAP_NAME, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
1829
1854
        if (not opt_ignore_sql_errors)
1830
1855
          abort();
1831
1856
      }
1836
1861
      if (run_query(con, NULL, ptr->getString(), ptr->getLength()))
1837
1862
      {
1838
1863
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1839
 
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
 
1864
                SLAP_NAME, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
1840
1865
        if (not opt_ignore_sql_errors)
1841
1866
          abort();
1842
1867
      }
1866
1891
  if (run_query(con, NULL, query, len))
1867
1892
  {
1868
1893
    fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
1869
 
            internal::my_progname, db, drizzle_con_error(&con));
 
1894
            SLAP_NAME, db, drizzle_con_error(&con));
1870
1895
    abort();
1871
1896
  }
1872
1897
}
1878
1903
    if (run_query(con, NULL, ptr->getString(), ptr->getLength()))
1879
1904
    {
1880
1905
      fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1881
 
              internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
 
1906
              SLAP_NAME, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
1882
1907
      abort();
1883
1908
    }
1884
1909
  }
2187
2212
         con.getUsers(), con.getRealUsers());
2188
2213
  printf("\tNumber of times test was run: %u\n", iterations);
2189
2214
  printf("\tAverage number of queries per client: %"PRIu64"\n", con.getAvgRows());
 
2215
 
 
2216
  uint64_t temp_val= failed_update_for_transaction; 
 
2217
  if (temp_val)
 
2218
    printf("\tFailed number of updates %"PRIu64"\n", temp_val);
 
2219
 
2190
2220
  printf("\n");
2191
2221
}
2192
2222
 
2359
2389
        connect_to_schema ? create_schema_string.c_str() : NULL,
2360
2390
        use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL) == NULL)
2361
2391
  {
2362
 
    fprintf(stderr,"%s: Error creating drizzle object\n", internal::my_progname);
 
2392
    fprintf(stderr,"%s: Error creating drizzle object\n", SLAP_NAME);
2363
2393
    abort();
2364
2394
  }
2365
2395
 
2380
2410
  }
2381
2411
  if (connect_error)
2382
2412
  {
2383
 
    fprintf(stderr,"%s: Error when connecting to server: %d %s\n", internal::my_progname,
 
2413
    fprintf(stderr,"%s: Error when connecting to server: %d %s\n", SLAP_NAME,
2384
2414
            ret, drizzle_con_error(&con));
2385
2415
    abort();
2386
2416
  }