~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/haildb/haildb_engine.cc

  • Committer: Lee Bieber
  • Date: 2010-11-07 19:34:48 UTC
  • mfrom: (1910.1.2 build)
  • Revision ID: kalebral@gmail.com-20101107193448-64kdu912qej354sh
Merge Stewart - including adapting and expanding the "differences from mysql" page from the wiki.
Merge Stewart - fix bug 668143: drizzleslap with --commit runs second iteration data load in a transaction

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
/*****************************************************************************
23
23
 
24
 
Copyright (C) 2000, 2009, MySQL AB & Innobase Oy. All Rights Reserved.
25
 
Copyright (C) 2008, 2009 Google Inc.
 
24
Copyright (c) 2000, 2009, MySQL AB & Innobase Oy. All Rights Reserved.
 
25
Copyright (c) 2008, 2009 Google Inc.
26
26
 
27
27
Portions of this file contain modifications contributed and copyrighted by
28
28
Google, Inc. Those modifications are gratefully acknowledged and are described
45
45
*****************************************************************************/
46
46
/***********************************************************************
47
47
 
48
 
Copyright (C) 1995, 2009, Innobase Oy. All Rights Reserved.
49
 
Copyright (C) 2009, Percona Inc.
 
48
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
 
49
Copyright (c) 2009, Percona Inc.
50
50
 
51
51
Portions of this file contain modifications contributed and copyrighted
52
52
by Percona Inc.. Those modifications are
76
76
#include <drizzled/error.h>
77
77
#include "drizzled/internal/my_pthread.h"
78
78
#include <drizzled/plugin/transactional_storage_engine.h>
79
 
#include <drizzled/plugin/error_message.h>
80
79
 
81
80
#include <fcntl.h>
82
 
#include <stdarg.h>
83
81
 
84
82
#include <string>
85
83
#include <boost/algorithm/string.hpp>
101
99
#include "haildb_engine.h"
102
100
 
103
101
#include <drizzled/field.h>
 
102
#include "drizzled/field/timestamp.h" // needed for UPDATE NOW()
104
103
#include "drizzled/field/blob.h"
105
104
#include "drizzled/field/enum.h"
106
105
#include <drizzled/session.h>
116
115
using namespace google;
117
116
using namespace drizzled;
118
117
 
119
 
int read_row_from_haildb(Session *session, unsigned char* buf, ib_crsr_t cursor, ib_tpl_t tuple, Table* table, bool has_hidden_primary_key, uint64_t *hidden_pkey, drizzled::memory::Root **blobroot= NULL);
 
118
int read_row_from_haildb(unsigned char* buf, ib_crsr_t cursor, ib_tpl_t tuple, Table* table, bool has_hidden_primary_key, uint64_t *hidden_pkey, drizzled::memory::Root **blobroot= NULL);
120
119
static void fill_ib_search_tpl_from_drizzle_key(ib_tpl_t search_tuple,
121
120
                                                const drizzled::KeyInfo *key_info,
122
121
                                                const unsigned char *key_ptr,
165
164
 
166
165
  int doCreateTable(Session&,
167
166
                    Table& table_arg,
168
 
                    const drizzled::identifier::Table &identifier,
 
167
                    const drizzled::TableIdentifier &identifier,
169
168
                    drizzled::message::Table& proto);
170
169
 
171
 
  int doDropTable(Session&, const identifier::Table &identifier);
 
170
  int doDropTable(Session&, const TableIdentifier &identifier);
172
171
 
173
172
  int doRenameTable(drizzled::Session&,
174
 
                    const drizzled::identifier::Table&,
175
 
                    const drizzled::identifier::Table&);
 
173
                    const drizzled::TableIdentifier&,
 
174
                    const drizzled::TableIdentifier&);
176
175
 
177
176
  int doGetTableDefinition(Session& session,
178
 
                           const identifier::Table &identifier,
 
177
                           const TableIdentifier &identifier,
179
178
                           drizzled::message::Table &table_proto);
180
179
 
181
 
  bool doDoesTableExist(Session&, const identifier::Table &identifier);
 
180
  bool doDoesTableExist(Session&, const TableIdentifier &identifier);
182
181
 
183
182
private:
184
 
  void getTableNamesInSchemaFromHailDB(const drizzled::identifier::Schema &schema,
 
183
  void getTableNamesInSchemaFromHailDB(const drizzled::SchemaIdentifier &schema,
185
184
                                       drizzled::plugin::TableNameList *set_of_names,
186
 
                                       drizzled::identifier::Table::vector *identifiers);
 
185
                                       drizzled::TableIdentifiers *identifiers);
187
186
 
188
187
public:
189
188
  void doGetTableIdentifiers(drizzled::CachedDirectory &,
190
 
                             const drizzled::identifier::Schema &schema,
191
 
                             drizzled::identifier::Table::vector &identifiers);
 
189
                             const drizzled::SchemaIdentifier &schema,
 
190
                             drizzled::TableIdentifiers &identifiers);
192
191
 
193
192
  /* The following defines can be increased if necessary */
194
193
  uint32_t max_supported_keys()          const { return 1000; }
239
238
/* This is a superset of the map from innobase plugin.
240
239
   Unlike innobase plugin we don't act on errors here, we just
241
240
   map error codes. */
242
 
static int ib_err_t_to_drizzle_error(Session* session, ib_err_t err)
 
241
static int ib_err_t_to_drizzle_error(ib_err_t err)
243
242
{
244
243
  switch (err)
245
244
  {
269
268
    return HA_ERR_NO_ACTIVE_RECORD;
270
269
 
271
270
  case DB_DEADLOCK:
272
 
    /* HailDB will roll back a transaction itself due to DB_DEADLOCK.
273
 
       This means we have to tell Drizzle about it */
274
 
    session->markTransactionForRollback(true);
275
271
    return HA_ERR_LOCK_DEADLOCK;
276
272
 
277
273
  case DB_LOCK_WAIT_TIMEOUT:
353
349
  (void)options;
354
350
 
355
351
  transaction= get_trx(session);
356
 
  isolation_level= tx_isolation_to_ib_trx_level(session->getTxIsolation());
 
352
  isolation_level= tx_isolation_to_ib_trx_level((enum_tx_isolation)session_tx_isolation(session));
357
353
  *transaction= ib_trx_begin(isolation_level);
358
354
 
359
 
  return *transaction == NULL;
 
355
  return 0;
360
356
}
361
357
 
362
358
void HailDBEngine::doStartStatement(Session *session)
390
386
  err= ib_savepoint_rollback(*transaction, savepoint.getName().c_str(),
391
387
                             savepoint.getName().length());
392
388
 
393
 
  return ib_err_t_to_drizzle_error(session, err);
 
389
  return ib_err_t_to_drizzle_error(err);
394
390
}
395
391
 
396
392
int HailDBEngine::doReleaseSavepoint(Session* session,
402
398
  err= ib_savepoint_release(*transaction, savepoint.getName().c_str(),
403
399
                            savepoint.getName().length());
404
400
  if (err != DB_SUCCESS)
405
 
    return ib_err_t_to_drizzle_error(session, err);
 
401
    return ib_err_t_to_drizzle_error(err);
406
402
 
407
403
  return 0;
408
404
}
412
408
  ib_err_t err;
413
409
  ib_trx_t *transaction= get_trx(session);
414
410
 
415
 
  if (all)
 
411
  if (all || (!session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
416
412
  {
417
413
    err= ib_trx_commit(*transaction);
418
414
 
419
415
    if (err != DB_SUCCESS)
420
 
      return ib_err_t_to_drizzle_error(session, err);
 
416
      return ib_err_t_to_drizzle_error(err);
421
417
 
422
418
    *transaction= NULL;
423
419
  }
430
426
  ib_err_t err;
431
427
  ib_trx_t *transaction= get_trx(session);
432
428
 
433
 
  if (all)
 
429
  if (all || !session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
434
430
  {
435
 
    if (ib_trx_state(*transaction) == IB_TRX_NOT_STARTED)
436
 
      err= ib_trx_release(*transaction);
437
 
    else
438
 
      err= ib_trx_rollback(*transaction);
 
431
    err= ib_trx_rollback(*transaction);
439
432
 
440
433
    if (err != DB_SUCCESS)
441
 
      return ib_err_t_to_drizzle_error(session, err);
 
434
      return ib_err_t_to_drizzle_error(err);
442
435
 
443
436
    *transaction= NULL;
444
437
  }
445
438
  else
446
439
  {
447
 
    if (ib_trx_state(*transaction) == IB_TRX_NOT_STARTED)
448
 
      return 0;
449
 
 
450
440
    err= ib_savepoint_rollback(*transaction, statement_savepoint_name.c_str(),
451
441
                               statement_savepoint_name.length());
452
442
    if (err != DB_SUCCESS)
453
 
      return ib_err_t_to_drizzle_error(session, err);
 
443
      return ib_err_t_to_drizzle_error(err);
454
444
  }
455
445
 
456
446
  return 0;
494
484
  else
495
485
  {
496
486
    assert (err == DB_SUCCESS);
497
 
    err= ib_tuple_read_u64(tuple, getTable()->getShare()->sizeFields(), &nr);
 
487
    err= ib_tuple_read_u64(tuple, getTable()->getShare()->fields, &nr);
498
488
    nr++;
499
489
  }
500
490
  ib_tuple_delete(tuple);
501
 
  tuple= NULL;
502
491
  err= ib_cursor_reset(cursor);
503
492
  assert(err == DB_SUCCESS);
504
493
  return nr;
535
524
  doEndIndexScan();
536
525
  (void) extra(HA_EXTRA_NO_KEYREAD);
537
526
 
538
 
  if (getTable()->getShare()->getTableMessage()->options().auto_increment_value() > nr)
539
 
    nr= getTable()->getShare()->getTableMessage()->options().auto_increment_value();
 
527
  if (getTable()->getShare()->getTableProto()->options().auto_increment_value() > nr)
 
528
    nr= getTable()->getShare()->getTableProto()->options().auto_increment_value();
540
529
 
541
530
  return nr;
542
531
}
649
638
 
650
639
  /* the below is adapted from ha_innodb.cc */
651
640
 
652
 
  const uint32_t sql_command = session->getSqlCommand();
 
641
  const uint32_t sql_command = session_sql_command(session);
653
642
 
654
643
  if (sql_command == SQLCOM_DROP_TABLE) {
655
644
 
680
669
    unexpected if an obsolete consistent read view would be
681
670
    used. */
682
671
 
683
 
    enum_tx_isolation isolation_level= session->getTxIsolation();
 
672
    enum_tx_isolation isolation_level= session_tx_isolation(session);
684
673
 
685
674
    if (isolation_level != ISO_SERIALIZABLE
686
675
        && (lock_type == TL_READ || lock_type == TL_READ_NO_INSERT)
723
712
 
724
713
    if ((lock_type >= TL_WRITE_CONCURRENT_INSERT
725
714
         && lock_type <= TL_WRITE)
726
 
        && ! session->doing_tablespace_operation()
 
715
        && !session_tablespace_op(session)
727
716
        && sql_command != SQLCOM_TRUNCATE
728
717
        && sql_command != SQLCOM_CREATE_TABLE) {
729
718
 
800
789
  return &name[l];
801
790
}
802
791
 
803
 
static void TableIdentifier_to_haildb_name(const identifier::Table &identifier, std::string *str)
 
792
static void TableIdentifier_to_haildb_name(const TableIdentifier &identifier, std::string *str)
804
793
{
805
794
  str->assign(table_path_to_haildb_name(identifier.getPath().c_str()));
806
795
}
829
818
int HailDBCursor::open(const char *name, int, uint32_t)
830
819
{
831
820
  const char* haildb_table_name= table_path_to_haildb_name(name);
832
 
  ib_err_t err= ib_table_get_id(haildb_table_name, &table_id);
 
821
  ib_err_t err= ib_cursor_open_table(haildb_table_name, NULL, &cursor);
833
822
  bool has_hidden_primary_key= false;
834
823
  ib_id_t idx_id;
835
824
 
836
825
  if (err != DB_SUCCESS)
837
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
838
 
 
839
 
  err= ib_cursor_open_table_using_id(table_id, NULL, &cursor);
840
 
  cursor_is_sec_index= false;
841
 
 
842
 
  if (err != DB_SUCCESS)
843
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
826
    return ib_err_t_to_drizzle_error(err);
844
827
 
845
828
  err= ib_index_get_id(haildb_table_name, "HIDDEN_PRIMARY", &idx_id);
846
829
 
871
854
{
872
855
  ib_err_t err= ib_cursor_close(cursor);
873
856
  if (err != DB_SUCCESS)
874
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
857
    return ib_err_t_to_drizzle_error(err);
875
858
 
876
859
  free_share();
877
860
 
904
887
{
905
888
  ib_col_attr_t column_attr= IB_COL_NONE;
906
889
 
907
 
  if (field.has_constraints() && field.constraints().is_notnull())
 
890
  if (field.has_constraints() && ! field.constraints().is_nullable())
908
891
    column_attr= IB_COL_NOT_NULL;
909
892
 
910
893
  switch (field.type())
935
918
    *err= ib_table_schema_add_col(schema, field.name().c_str(), IB_INT,
936
919
                                  column_attr, 0, 4);
937
920
    break;
938
 
  case message::Table::Field::EPOCH:
 
921
  case message::Table::Field::TIMESTAMP:
939
922
    *err= ib_table_schema_add_col(schema, field.name().c_str(), IB_INT,
940
923
                                  column_attr, 0, 8);
941
924
    break;
1035
1018
 
1036
1019
int HailDBEngine::doCreateTable(Session &session,
1037
1020
                                        Table& table_obj,
1038
 
                                        const drizzled::identifier::Table &identifier,
 
1021
                                        const drizzled::TableIdentifier &identifier,
1039
1022
                                        drizzled::message::Table& table_message)
1040
1023
{
1041
1024
  ib_tbl_sch_t haildb_table_schema= NULL;
1079
1062
                        ER_CANT_CREATE_TABLE,
1080
1063
                        _("Cannot create table %s. HailDB Error %d (%s)\n"),
1081
1064
                        haildb_table_name.c_str(), haildb_err, ib_strerror(haildb_err));
1082
 
    return ib_err_t_to_drizzle_error(&session, haildb_err);
 
1065
    return ib_err_t_to_drizzle_error(haildb_err);
1083
1066
  }
1084
1067
 
1085
1068
  for (int colnr= 0; colnr < table_message.field_size() ; colnr++)
1100
1083
                            " HailDB Error %d (%s)\n"),
1101
1084
                          field.name().c_str(), haildb_table_name.c_str(),
1102
1085
                          haildb_err, ib_strerror(haildb_err));
1103
 
      return ib_err_t_to_drizzle_error(&session, haildb_err);
 
1086
      return ib_err_t_to_drizzle_error(haildb_err);
1104
1087
    }
1105
1088
    if (field_err != 0)
1106
1089
      return field_err;
1225
1208
 
1226
1209
  if (table_message.type() == message::Table::TEMPORARY)
1227
1210
  {
1228
 
    session.getMessageCache().storeTableMessage(identifier, table_message);
 
1211
    session.storeTableMessage(identifier, table_message);
1229
1212
    haildb_err= DB_SUCCESS;
1230
1213
  }
1231
1214
  else
1248
1231
                        _("Cannot create table %s. HailDB Error %d (%s)\n"),
1249
1232
                        haildb_table_name.c_str(),
1250
1233
                        haildb_err, ib_strerror(haildb_err));
1251
 
    return ib_err_t_to_drizzle_error(&session, haildb_err);
 
1234
    return ib_err_t_to_drizzle_error(haildb_err);
1252
1235
  }
1253
1236
 
1254
1237
  return 0;
1291
1274
}
1292
1275
 
1293
1276
int HailDBEngine::doDropTable(Session &session,
1294
 
                                      const identifier::Table &identifier)
 
1277
                                      const TableIdentifier &identifier)
1295
1278
{
1296
1279
  ib_trx_t haildb_schema_transaction;
1297
1280
  ib_err_t haildb_err;
1317
1300
 
1318
1301
  if (identifier.getType() == message::Table::TEMPORARY)
1319
1302
  {
1320
 
      session.getMessageCache().removeTableMessage(identifier);
 
1303
      session.removeTableMessage(identifier);
1321
1304
      delete_table_message_from_haildb(haildb_schema_transaction,
1322
1305
                                       haildb_table_name.c_str());
1323
1306
  }
1373
1356
  return 0;
1374
1357
}
1375
1358
 
1376
 
static ib_err_t rename_table_message(ib_trx_t transaction, const identifier::Table &from_identifier, const identifier::Table &to_identifier)
 
1359
static ib_err_t rename_table_message(ib_trx_t transaction, const TableIdentifier &from_identifier, const TableIdentifier &to_identifier)
1377
1360
{
1378
1361
  ib_crsr_t cursor;
1379
1362
  ib_tpl_t search_tuple;
1464
1447
}
1465
1448
 
1466
1449
int HailDBEngine::doRenameTable(drizzled::Session &session,
1467
 
                                        const drizzled::identifier::Table &from,
1468
 
                                        const drizzled::identifier::Table &to)
 
1450
                                        const drizzled::TableIdentifier &from,
 
1451
                                        const drizzled::TableIdentifier &to)
1469
1452
{
1470
1453
  ib_trx_t haildb_schema_transaction;
1471
1454
  ib_err_t err;
1475
1458
  if (to.getType() == message::Table::TEMPORARY
1476
1459
      && from.getType() == message::Table::TEMPORARY)
1477
1460
  {
1478
 
    session.getMessageCache().renameTableMessage(from, to);
 
1461
    session.renameTableMessage(from, to);
1479
1462
    return 0;
1480
1463
  }
1481
1464
 
1515
1498
  assert(rollback_err == DB_SUCCESS);
1516
1499
  rollback_err= ib_trx_rollback(haildb_schema_transaction);
1517
1500
  assert(rollback_err == DB_SUCCESS);
1518
 
  return ib_err_t_to_drizzle_error(&session, err);
 
1501
  return ib_err_t_to_drizzle_error(err);
1519
1502
}
1520
1503
 
1521
1504
void HailDBEngine::getTableNamesInSchemaFromHailDB(
1522
 
                                 const drizzled::identifier::Schema &schema,
 
1505
                                 const drizzled::SchemaIdentifier &schema,
1523
1506
                                 drizzled::plugin::TableNameList *set_of_names,
1524
 
                                 drizzled::identifier::Table::vector *identifiers)
 
1507
                                 drizzled::TableIdentifiers *identifiers)
1525
1508
{
1526
1509
  ib_trx_t   transaction;
1527
1510
  ib_crsr_t  cursor;
1551
1534
    {
1552
1535
      BOOST_FOREACH(std::string table_name, haildb_system_table_names)
1553
1536
      {
1554
 
        identifiers->push_back(identifier::Table(schema.getSchemaName(),
 
1537
        identifiers->push_back(TableIdentifier(schema.getSchemaName(),
1555
1538
                                               table_name));
1556
1539
      }
1557
1540
    }
1594
1577
      if (set_of_names)
1595
1578
        set_of_names->insert(just_table_name);
1596
1579
      if (identifiers)
1597
 
        identifiers->push_back(identifier::Table(schema.getSchemaName(), just_table_name));
 
1580
        identifiers->push_back(TableIdentifier(schema.getSchemaName(), just_table_name));
1598
1581
    }
1599
1582
 
1600
1583
 
1613
1596
}
1614
1597
 
1615
1598
void HailDBEngine::doGetTableIdentifiers(drizzled::CachedDirectory &,
1616
 
                                                 const drizzled::identifier::Schema &schema,
1617
 
                                                 drizzled::identifier::Table::vector &identifiers)
 
1599
                                                 const drizzled::SchemaIdentifier &schema,
 
1600
                                                 drizzled::TableIdentifiers &identifiers)
1618
1601
{
1619
1602
  getTableNamesInSchemaFromHailDB(schema, NULL, &identifiers);
1620
1603
}
1739
1722
}
1740
1723
 
1741
1724
int HailDBEngine::doGetTableDefinition(Session &session,
1742
 
                                               const identifier::Table &identifier,
 
1725
                                               const TableIdentifier &identifier,
1743
1726
                                               drizzled::message::Table &table)
1744
1727
{
1745
1728
  ib_crsr_t haildb_cursor= NULL;
1746
1729
  string haildb_table_name;
1747
1730
 
1748
1731
  /* Check temporary tables!? */
1749
 
  if (session.getMessageCache().getTableMessage(identifier, table))
 
1732
  if (session.getTableMessage(identifier, table))
1750
1733
    return EEXIST;
1751
1734
 
1752
1735
  TableIdentifier_to_haildb_name(identifier, &haildb_table_name);
1768
1751
}
1769
1752
 
1770
1753
bool HailDBEngine::doDoesTableExist(Session &,
1771
 
                                    const identifier::Table& identifier)
 
1754
                                    const TableIdentifier& identifier)
1772
1755
{
1773
1756
  ib_crsr_t haildb_cursor;
1774
1757
  string haildb_table_name;
1793
1776
  return("BTREE");
1794
1777
}
1795
1778
 
1796
 
static ib_err_t write_row_to_haildb_tuple(const unsigned char* buf,
1797
 
                                          Field **fields, ib_tpl_t tuple)
 
1779
static ib_err_t write_row_to_haildb_tuple(Field **fields, ib_tpl_t tuple)
1798
1780
{
1799
1781
  int colnr= 0;
1800
1782
  ib_err_t err= DB_ERROR;
1801
 
  ptrdiff_t row_offset= buf - (*fields)->getTable()->getInsertRecord();
1802
1783
 
1803
1784
  for (Field **field= fields; *field; field++, colnr++)
1804
1785
  {
1805
 
    (**field).move_field_offset(row_offset);
1806
 
 
1807
1786
    if (! (**field).isWriteSet() && (**field).is_null())
1808
 
    {
1809
 
      (**field).move_field_offset(-row_offset);
1810
1787
      continue;
1811
 
    }
1812
1788
 
1813
1789
    if ((**field).is_null())
1814
1790
    {
1815
1791
      err= ib_col_set_value(tuple, colnr, NULL, IB_SQL_NULL);
1816
1792
      assert(err == DB_SUCCESS);
1817
 
      (**field).move_field_offset(-row_offset);
1818
1793
      continue;
1819
1794
    }
1820
1795
 
1826
1801
      */
1827
1802
      String str;
1828
1803
      (**field).setReadSet();
1829
 
      (**field).val_str_internal(&str);
 
1804
      (**field).val_str(&str);
1830
1805
      err= ib_col_set_value(tuple, colnr, str.ptr(), str.length());
1831
1806
    }
1832
1807
    else if ((**field).type() == DRIZZLE_TYPE_ENUM)
1852
1827
    }
1853
1828
 
1854
1829
    assert (err == DB_SUCCESS);
1855
 
 
1856
 
    (**field).move_field_offset(-row_offset);
1857
1830
  }
1858
1831
 
1859
1832
  return err;
1902
1875
 
1903
1876
  tuple= ib_clust_read_tuple_create(cursor);
1904
1877
 
1905
 
  if (cursor_is_sec_index)
1906
 
  {
1907
 
    err= ib_cursor_close(cursor);
1908
 
    assert(err == DB_SUCCESS);
1909
 
 
1910
 
    err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
1911
 
 
1912
 
    if (err != DB_SUCCESS)
1913
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
1914
 
 
1915
 
    cursor_is_sec_index= false;
1916
 
  }
1917
 
  else
1918
 
  {
1919
 
    ib_cursor_attach_trx(cursor, transaction);
1920
 
  }
 
1878
  ib_cursor_attach_trx(cursor, transaction);
1921
1879
 
1922
1880
  err= ib_cursor_first(cursor);
1923
1881
  if (current_session->lex->sql_command == SQLCOM_CREATE_TABLE
1976
1934
 
1977
1935
  }
1978
1936
 
1979
 
  write_row_to_haildb_tuple(record, getTable()->getFields(), tuple);
 
1937
  write_row_to_haildb_tuple(getTable()->getFields(), tuple);
1980
1938
 
1981
1939
  if (share->has_hidden_primary_key)
1982
1940
  {
1983
 
    err= ib_tuple_write_u64(tuple, getTable()->getShare()->sizeFields(),
1984
 
                            share->hidden_pkey_auto_increment_value.fetch_and_increment());
 
1941
    err= ib_tuple_write_u64(tuple, getTable()->getShare()->fields, share->hidden_pkey_auto_increment_value.fetch_and_increment());
1985
1942
  }
1986
1943
 
1987
1944
  err= ib_cursor_insert_row(cursor, tuple);
2010
1967
      err= ib_cursor_first(cursor);
2011
1968
      assert(err == DB_SUCCESS || err == DB_END_OF_INDEX);
2012
1969
 
2013
 
      write_row_to_haildb_tuple(record, getTable()->getFields(), tuple);
 
1970
      write_row_to_haildb_tuple(getTable()->getFields(), tuple);
2014
1971
 
2015
1972
      err= ib_cursor_insert_row(cursor, tuple);
2016
1973
      assert(err==DB_SUCCESS); // probably be nice and process errors
2019
1976
      ret= HA_ERR_FOUND_DUPP_KEY;
2020
1977
  }
2021
1978
  else if (err != DB_SUCCESS)
2022
 
    ret= ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
1979
    ret= ib_err_t_to_drizzle_error(err);
2023
1980
 
2024
1981
  tuple= ib_tuple_clear(tuple);
2025
1982
  ib_tuple_delete(tuple);
2026
 
  tuple= NULL;
2027
1983
  err= ib_cursor_reset(cursor);
2028
1984
 
2029
1985
  return ret;
2030
1986
}
2031
1987
 
2032
 
int HailDBCursor::doUpdateRecord(const unsigned char *old_data,
2033
 
                                 unsigned char *new_data)
 
1988
int HailDBCursor::doUpdateRecord(const unsigned char *,
 
1989
                                         unsigned char *)
2034
1990
{
2035
1991
  ib_tpl_t update_tuple;
2036
1992
  ib_err_t err;
2037
 
  bool created_tuple= false;
2038
1993
 
2039
1994
  update_tuple= ib_clust_read_tuple_create(cursor);
2040
1995
 
2041
 
  if (tuple == NULL)
2042
 
  {
2043
 
    ib_trx_t transaction= *get_trx(getTable()->in_use);
2044
 
 
2045
 
    if (cursor_is_sec_index)
2046
 
    {
2047
 
      err= ib_cursor_close(cursor);
2048
 
      assert(err == DB_SUCCESS);
2049
 
 
2050
 
      err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2051
 
 
2052
 
      if (err != DB_SUCCESS)
2053
 
        return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2054
 
      cursor_is_sec_index= false;
2055
 
    }
2056
 
    else
2057
 
    {
2058
 
      ib_cursor_attach_trx(cursor, transaction);
2059
 
    }
2060
 
 
2061
 
    store_key_value_from_haildb(getTable()->key_info + getTable()->getShare()->getPrimaryKey(),
2062
 
                                  ref, ref_length, old_data);
2063
 
 
2064
 
    ib_tpl_t search_tuple= ib_clust_search_tuple_create(cursor);
2065
 
 
2066
 
    fill_ib_search_tpl_from_drizzle_key(search_tuple,
2067
 
                                        getTable()->key_info + 0,
2068
 
                                        ref, ref_length);
2069
 
 
2070
 
    err= ib_cursor_set_lock_mode(cursor, IB_LOCK_X);
2071
 
    assert(err == DB_SUCCESS);
2072
 
 
2073
 
    int res;
2074
 
    err= ib_cursor_moveto(cursor, search_tuple, IB_CUR_GE, &res);
2075
 
    assert(err == DB_SUCCESS);
2076
 
 
2077
 
    tuple= ib_clust_read_tuple_create(cursor);
2078
 
 
2079
 
    err= ib_cursor_read_row(cursor, tuple);
2080
 
    assert(err == DB_SUCCESS);// FIXME
2081
 
 
2082
 
    created_tuple= true;
2083
 
  }
2084
 
 
2085
1996
  err= ib_tuple_copy(update_tuple, tuple);
2086
1997
  assert(err == DB_SUCCESS);
2087
1998
 
2088
 
  write_row_to_haildb_tuple(new_data, getTable()->getFields(), update_tuple);
 
1999
  write_row_to_haildb_tuple(getTable()->getFields(), update_tuple);
2089
2000
 
2090
2001
  err= ib_cursor_update_row(cursor, tuple, update_tuple);
2091
2002
 
2092
2003
  ib_tuple_delete(update_tuple);
2093
2004
 
2094
 
  if (created_tuple)
2095
 
  {
2096
 
    ib_err_t ib_err= ib_cursor_reset(cursor); //fixme check error
2097
 
    assert(ib_err == DB_SUCCESS);
2098
 
    tuple= ib_tuple_clear(tuple);
2099
 
    ib_tuple_delete(tuple);
2100
 
    tuple= NULL;
2101
 
  }
2102
 
 
2103
2005
  advance_cursor= true;
2104
2006
 
2105
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2007
  if (err == DB_SUCCESS)
 
2008
    return 0;
 
2009
  else if (err == DB_DUPLICATE_KEY)
 
2010
    return HA_ERR_FOUND_DUPP_KEY;
 
2011
  else
 
2012
    return -1;
2106
2013
}
2107
2014
 
2108
2015
int HailDBCursor::doDeleteRecord(const unsigned char *)
2109
2016
{
2110
2017
  ib_err_t err;
2111
2018
 
2112
 
  assert(ib_cursor_is_positioned(cursor) == IB_TRUE);
2113
2019
  err= ib_cursor_delete_row(cursor);
 
2020
  if (err != DB_SUCCESS)
 
2021
    return -1; // FIXME
2114
2022
 
2115
2023
  advance_cursor= true;
2116
 
 
2117
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2024
  return 0;
2118
2025
}
2119
2026
 
2120
2027
int HailDBCursor::delete_all_rows(void)
2121
2028
{
2122
2029
  /* I *think* ib_truncate is non-transactional....
2123
2030
     so only support TRUNCATE and not DELETE FROM t;
2124
 
     (this is what ha_innodb does)
 
2031
     (this is what ha_haildb does)
2125
2032
  */
2126
 
  if (getTable()->in_use->getSqlCommand() != SQLCOM_TRUNCATE)
 
2033
  if (session_sql_command(getTable()->in_use) != SQLCOM_TRUNCATE)
2127
2034
    return HA_ERR_WRONG_COMMAND;
2128
2035
 
2129
2036
  ib_id_t id;
2131
2038
 
2132
2039
  ib_trx_t transaction= ib_trx_begin(IB_TRX_REPEATABLE_READ);
2133
2040
 
2134
 
  if (cursor_is_sec_index)
2135
 
  {
2136
 
    err= ib_cursor_close(cursor);
2137
 
    assert(err == DB_SUCCESS);
2138
 
 
2139
 
    err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2140
 
 
2141
 
    if (err != DB_SUCCESS)
2142
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2143
 
    cursor_is_sec_index= false;
2144
 
  }
2145
 
  else
2146
 
  {
2147
 
    ib_cursor_attach_trx(cursor, transaction);
2148
 
  }
 
2041
  ib_cursor_attach_trx(cursor, transaction);
2149
2042
 
2150
2043
  err= ib_schema_lock_exclusive(transaction);
2151
2044
  if (err != DB_SUCCESS)
2181
2074
  ib_schema_unlock(transaction);
2182
2075
  ib_err_t rollback_err= ib_trx_rollback(transaction);
2183
2076
  assert(rollback_err == DB_SUCCESS);
2184
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2077
  return err;
2185
2078
}
2186
2079
 
2187
2080
int HailDBCursor::doStartTableScan(bool)
2188
2081
{
2189
 
  ib_err_t err= DB_SUCCESS;
 
2082
  ib_err_t err;
2190
2083
  ib_trx_t transaction;
2191
2084
 
2192
2085
  if (in_table_scan)
2197
2090
 
2198
2091
  assert(transaction != NULL);
2199
2092
 
2200
 
  if (cursor_is_sec_index)
2201
 
  {
2202
 
    err= ib_cursor_close(cursor);
2203
 
    assert(err == DB_SUCCESS);
2204
 
 
2205
 
    err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2206
 
    cursor_is_sec_index= false;
2207
 
  }
2208
 
  else
2209
 
  {
2210
 
    ib_cursor_attach_trx(cursor, transaction);
2211
 
  }
2212
 
 
2213
 
  if (err != DB_SUCCESS)
2214
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2093
  ib_cursor_attach_trx(cursor, transaction);
2215
2094
 
2216
2095
  err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
2217
2096
  assert(err == DB_SUCCESS); // FIXME
2221
2100
  err= ib_cursor_first(cursor);
2222
2101
  if (err != DB_SUCCESS && err != DB_END_OF_INDEX)
2223
2102
  {
2224
 
    int reset_err= ib_cursor_reset(cursor);
2225
 
    assert(reset_err == DB_SUCCESS);
2226
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2103
    previous_error= ib_err_t_to_drizzle_error(err);
 
2104
    err= ib_cursor_reset(cursor);
 
2105
    return previous_error;
2227
2106
  }
2228
2107
 
2229
2108
  advance_cursor= false;
2230
2109
 
 
2110
  previous_error= 0;
2231
2111
  return(0);
2232
2112
}
2233
2113
 
2234
 
int read_row_from_haildb(Session *session, unsigned char* buf, ib_crsr_t cursor, ib_tpl_t tuple, Table* table, bool has_hidden_primary_key, uint64_t *hidden_pkey, drizzled::memory::Root **blobroot)
 
2114
int read_row_from_haildb(unsigned char* buf, ib_crsr_t cursor, ib_tpl_t tuple, Table* table, bool has_hidden_primary_key, uint64_t *hidden_pkey, drizzled::memory::Root **blobroot)
2235
2115
{
2236
2116
  ib_err_t err;
2237
2117
  ptrdiff_t row_offset= buf - table->getInsertRecord();
2238
2118
 
2239
2119
  err= ib_cursor_read_row(cursor, tuple);
2240
2120
 
2241
 
  if (err == DB_RECORD_NOT_FOUND)
 
2121
  if (err != DB_SUCCESS) // FIXME
2242
2122
    return HA_ERR_END_OF_FILE;
2243
 
  if (err != DB_SUCCESS)
2244
 
    return ib_err_t_to_drizzle_error(session, err);
2245
2123
 
2246
2124
  int colnr= 0;
2247
2125
 
2252
2130
  for (Field **field= table->getFields() ; *field ; field++, colnr++)
2253
2131
  {
2254
2132
    if (! (**field).isReadSet())
2255
 
      (**field).setReadSet(); /* Fucking broken API screws us royally. */
 
2133
      continue;
2256
2134
 
2257
2135
    (**field).move_field_offset(row_offset);
2258
2136
 
2262
2140
    if (length == IB_SQL_NULL)
2263
2141
    {
2264
2142
      (**field).set_null();
2265
 
      (**field).move_field_offset(-row_offset);
2266
2143
      continue;
2267
2144
    }
2268
2145
    else
2306
2183
 
2307
2184
    (**field).move_field_offset(-row_offset);
2308
2185
 
2309
 
    if (err != DB_SUCCESS)
2310
 
      return ib_err_t_to_drizzle_error(session, err);
2311
2186
  }
2312
2187
 
2313
2188
  if (has_hidden_primary_key)
2315
2190
    err= ib_tuple_read_u64(tuple, colnr, hidden_pkey);
2316
2191
  }
2317
2192
 
2318
 
  return ib_err_t_to_drizzle_error(session, err);
 
2193
  return 0;
2319
2194
}
2320
2195
 
2321
2196
int HailDBCursor::rnd_next(unsigned char *buf)
2323
2198
  ib_err_t err;
2324
2199
  int ret;
2325
2200
 
 
2201
  if (previous_error)
 
2202
    return previous_error;
 
2203
 
2326
2204
  if (advance_cursor)
2327
 
  {
2328
2205
    err= ib_cursor_next(cursor);
2329
 
    if (err != DB_SUCCESS)
2330
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2331
 
  }
2332
2206
 
2333
2207
  tuple= ib_tuple_clear(tuple);
2334
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2335
 
                            getTable(),
 
2208
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2336
2209
                            share->has_hidden_primary_key,
2337
2210
                            &hidden_autoinc_pkey_position);
2338
2211
 
2345
2218
  ib_err_t err;
2346
2219
 
2347
2220
  ib_tuple_delete(tuple);
2348
 
  tuple= NULL;
2349
2221
  err= ib_cursor_reset(cursor);
2350
2222
  assert(err == DB_SUCCESS);
2351
2223
  in_table_scan= false;
2352
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2224
  previous_error= 0;
 
2225
  return 0;
2353
2226
}
2354
2227
 
2355
2228
int HailDBCursor::rnd_pos(unsigned char *buf, unsigned char *pos)
2363
2236
  {
2364
2237
    err= ib_col_set_value(search_tuple, 0,
2365
2238
                          ((uint64_t*)(pos)), sizeof(uint64_t));
2366
 
    if (err != DB_SUCCESS)
2367
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2368
2239
  }
2369
2240
  else
2370
2241
  {
2380
2251
  }
2381
2252
 
2382
2253
  err= ib_cursor_moveto(cursor, search_tuple, IB_CUR_GE, &res);
2383
 
  if (err != DB_SUCCESS)
2384
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2254
  assert(err == DB_SUCCESS);
2385
2255
 
2386
2256
  assert(res==0);
2387
2257
  if (res != 0)
2392
2262
  tuple= ib_tuple_clear(tuple);
2393
2263
 
2394
2264
  if (ret == 0)
2395
 
    ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2396
 
                              getTable(),
 
2265
    ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2397
2266
                              share->has_hidden_primary_key,
2398
2267
                              &hidden_autoinc_pkey_position);
2399
2268
 
2431
2300
      }
2432
2301
 
2433
2302
      String str;
2434
 
      field->val_str_internal(&str);
 
2303
      field->val_str(&str);
2435
2304
 
2436
2305
      *ref++= (char)(str.length() & 0x000000ff);
2437
2306
      *ref++= (char)((str.length()>>8) & 0x000000ff);
2510
2379
 
2511
2380
  if (flag & HA_STATUS_AUTO)
2512
2381
    stats.auto_increment_value= 1;
2513
 
 
2514
 
  if (flag & HA_STATUS_ERRKEY) {
2515
 
    const char *err_table_name;
2516
 
    const char *err_index_name;
2517
 
 
2518
 
    ib_trx_t transaction= *get_trx(getTable()->in_use);
2519
 
 
2520
 
    err= ib_get_duplicate_key(transaction, &err_table_name, &err_index_name);
2521
 
 
2522
 
    errkey= UINT32_MAX;
2523
 
 
2524
 
    for (unsigned int i = 0; i < getTable()->getShare()->keys; i++)
2525
 
    {
2526
 
      if (strcmp(err_index_name, getTable()->key_info[i].name) == 0)
2527
 
      {
2528
 
        errkey= i;
2529
 
        break;
2530
 
      }
2531
 
    }
2532
 
 
2533
 
  }
2534
 
 
2535
 
  if (flag & HA_STATUS_CONST)
2536
 
  {
2537
 
    for (unsigned int i = 0; i < getTable()->getShare()->sizeKeys(); i++)
2538
 
    {
2539
 
      const char* index_name= getTable()->key_info[i].name;
2540
 
      uint64_t ncols;
2541
 
      int64_t *n_diff;
2542
 
      ha_rows rec_per_key;
2543
 
 
2544
 
      err= ib_get_index_stat_n_diff_key_vals(cursor, index_name,
2545
 
                                             &ncols, &n_diff);
2546
 
 
2547
 
      if (err != DB_SUCCESS)
2548
 
        return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2549
 
 
2550
 
      for (unsigned int j=0; j < getTable()->key_info[i].key_parts; j++)
2551
 
      {
2552
 
        if (n_diff[j+1] == 0)
2553
 
          rec_per_key= stats.records;
2554
 
        else
2555
 
          rec_per_key= stats.records / n_diff[j+1];
2556
 
 
2557
 
        /* We import this heuristic from ha_innodb, which says
2558
 
           that MySQL favours table scans too much over index searches,
2559
 
           so we pretend our index selectivity is 2 times better. */
2560
 
 
2561
 
        rec_per_key= rec_per_key / 2;
2562
 
 
2563
 
        if (rec_per_key == 0)
2564
 
          rec_per_key= 1;
2565
 
 
2566
 
        getTable()->key_info[i].rec_per_key[j]=
2567
 
          rec_per_key >= ~(ulong) 0 ? ~(ulong) 0 :
2568
 
          (ulong) rec_per_key;
2569
 
      }
2570
 
 
2571
 
      free(n_diff);
2572
 
    }
2573
 
  }
2574
 
 
2575
2382
  return(0);
2576
2383
}
2577
2384
 
2578
2385
int HailDBCursor::doStartIndexScan(uint32_t keynr, bool)
2579
2386
{
2580
 
  ib_err_t err;
2581
2387
  ib_trx_t transaction= *get_trx(getTable()->in_use);
2582
2388
 
2583
2389
  active_index= keynr;
2584
2390
 
 
2391
  ib_cursor_attach_trx(cursor, transaction);
 
2392
 
2585
2393
  if (active_index == 0 && ! share->has_hidden_primary_key)
2586
2394
  {
2587
 
    if (cursor_is_sec_index)
2588
 
    {
2589
 
      err= ib_cursor_close(cursor);
2590
 
      assert(err == DB_SUCCESS);
2591
 
 
2592
 
      err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2593
 
 
2594
 
      if (err != DB_SUCCESS)
2595
 
        return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2596
 
 
2597
 
    }
2598
 
    else
2599
 
    {
2600
 
      ib_cursor_attach_trx(cursor, transaction);
2601
 
    }
2602
 
 
2603
 
    cursor_is_sec_index= false;
2604
2395
    tuple= ib_clust_read_tuple_create(cursor);
2605
2396
  }
2606
2397
  else
2607
2398
  {
 
2399
    ib_err_t err;
2608
2400
    ib_id_t index_id;
2609
2401
    err= ib_index_get_id(table_path_to_haildb_name(getShare()->getPath()),
2610
2402
                         getShare()->getKeyInfo(keynr).name,
2611
2403
                         &index_id);
2612
2404
    if (err != DB_SUCCESS)
2613
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2405
      return -1;
2614
2406
 
2615
2407
    err= ib_cursor_close(cursor);
2616
2408
    assert(err == DB_SUCCESS);
2617
 
 
2618
2409
    err= ib_cursor_open_index_using_id(index_id, transaction, &cursor);
2619
2410
 
2620
2411
    if (err != DB_SUCCESS)
2621
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2622
 
 
2623
 
    cursor_is_sec_index= true;
 
2412
      return -1;
2624
2413
 
2625
2414
    tuple= ib_clust_read_tuple_create(cursor);
2626
2415
    ib_cursor_set_cluster_access(cursor);
2627
2416
  }
2628
2417
 
2629
 
  err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
 
2418
  ib_err_t err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
2630
2419
  assert(err == DB_SUCCESS);
2631
2420
 
2632
2421
  advance_cursor= false;
2771
2560
 
2772
2561
  if (err != DB_SUCCESS)
2773
2562
  {
2774
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2563
    return ib_err_t_to_drizzle_error(err);
2775
2564
  }
2776
2565
 
2777
2566
  tuple= ib_tuple_clear(tuple);
2778
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2779
 
                            getTable(),
 
2567
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2780
2568
                            share->has_hidden_primary_key,
2781
2569
                            &hidden_autoinc_pkey_position,
2782
2570
                            (allocate_blobs)? &blobroot : NULL);
2853
2641
  return 0;
2854
2642
}
2855
2643
 
2856
 
int HailDBCursor::analyze(Session*)
2857
 
{
2858
 
  ib_err_t err;
2859
 
 
2860
 
  err= ib_update_table_statistics(cursor);
2861
 
 
2862
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2863
 
}
2864
 
 
2865
2644
int HailDBCursor::index_next(unsigned char *buf)
2866
2645
{
2867
2646
  int ret= HA_ERR_END_OF_FILE;
2874
2653
  }
2875
2654
 
2876
2655
  tuple= ib_tuple_clear(tuple);
2877
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2878
 
                            getTable(),
 
2656
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2879
2657
                            share->has_hidden_primary_key,
2880
2658
                            &hidden_autoinc_pkey_position);
2881
2659
 
2903
2681
      if (err == DB_END_OF_INDEX)
2904
2682
        return HA_ERR_END_OF_FILE;
2905
2683
      else
2906
 
        return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2684
        return -1; // FIXME
2907
2685
    }
2908
2686
  }
2909
2687
 
2910
2688
  tuple= ib_tuple_clear(tuple);
2911
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2912
 
                            getTable(),
 
2689
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2913
2690
                            share->has_hidden_primary_key,
2914
2691
                            &hidden_autoinc_pkey_position);
2915
2692
 
2926
2703
 
2927
2704
  err= ib_cursor_first(cursor);
2928
2705
  if (err != DB_SUCCESS)
2929
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2706
    return ib_err_t_to_drizzle_error(err);
2930
2707
 
2931
2708
  tuple= ib_tuple_clear(tuple);
2932
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2933
 
                            getTable(),
 
2709
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2934
2710
                            share->has_hidden_primary_key,
2935
2711
                            &hidden_autoinc_pkey_position);
2936
2712
 
2947
2723
 
2948
2724
  err= ib_cursor_last(cursor);
2949
2725
  if (err != DB_SUCCESS)
2950
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2726
    return ib_err_t_to_drizzle_error(err);
2951
2727
 
2952
2728
  tuple= ib_tuple_clear(tuple);
2953
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2954
 
                            getTable(),
 
2729
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2955
2730
                            share->has_hidden_primary_key,
2956
2731
                            &hidden_autoinc_pkey_position);
2957
2732
  advance_cursor= true;
3043
2818
  return err;
3044
2819
}
3045
2820
 
 
2821
static bool  innobase_use_checksums= true;
 
2822
static char*  innobase_data_home_dir      = NULL;
 
2823
static char*  innobase_log_group_home_dir   = NULL;
3046
2824
static bool innobase_use_doublewrite= true;
 
2825
static unsigned long srv_io_capacity= 200;
 
2826
static unsigned long innobase_fast_shutdown= 1;
3047
2827
static bool srv_file_per_table= false;
3048
2828
static bool innobase_adaptive_hash_index;
3049
2829
static bool srv_adaptive_flushing;
3051
2831
static bool innobase_rollback_on_timeout;
3052
2832
static bool innobase_create_status_file;
3053
2833
static bool srv_use_sys_malloc;
3054
 
static string innobase_file_format_name;
 
2834
static char*  innobase_file_format_name   = const_cast<char *>("Barracuda");
 
2835
static char*  innobase_unix_file_flush_method   = NULL;
 
2836
static unsigned long srv_flush_log_at_trx_commit;
 
2837
static unsigned long srv_max_buf_pool_modified_pct;
 
2838
static unsigned long srv_max_purge_lag;
 
2839
static unsigned long innobase_lru_old_blocks_pct;
 
2840
static unsigned long innobase_lru_block_access_recency;
 
2841
static unsigned long innobase_read_io_threads;
 
2842
static unsigned long innobase_write_io_threads;
3055
2843
typedef constrained_check<unsigned int, 1000, 1> autoextend_constraint;
3056
2844
static autoextend_constraint srv_auto_extend_increment;
 
2845
static unsigned long innobase_lock_wait_timeout;
 
2846
static unsigned long srv_n_spin_wait_rounds;
3057
2847
typedef constrained_check<size_t, SIZE_MAX, 5242880, 1048576> buffer_pool_constraint;
3058
2848
static buffer_pool_constraint innobase_buffer_pool_size;
3059
2849
typedef constrained_check<size_t, SIZE_MAX, 512, 1024> additional_mem_pool_constraint;
3060
2850
static additional_mem_pool_constraint innobase_additional_mem_pool_size;
3061
 
static bool  innobase_use_checksums= true;
3062
 
typedef constrained_check<unsigned int, UINT_MAX, 100> io_capacity_constraint;
3063
 
typedef constrained_check<uint32_t, 2, 0> trinary_constraint;
3064
 
static trinary_constraint innobase_fast_shutdown;
3065
 
static trinary_constraint srv_flush_log_at_trx_commit;
3066
 
typedef constrained_check<uint32_t, 6, 0> force_recovery_constraint;
3067
 
static force_recovery_constraint innobase_force_recovery;
3068
 
typedef constrained_check<int64_t, INT64_MAX, 1024*1024, 1024*1024> log_file_constraint;
3069
 
static log_file_constraint haildb_log_file_size;
3070
 
 
3071
 
static io_capacity_constraint srv_io_capacity;
3072
 
typedef constrained_check<unsigned int, 100, 2> log_files_in_group_constraint;
3073
 
static log_files_in_group_constraint haildb_log_files_in_group;
3074
 
typedef constrained_check<unsigned int, 1024*1024*1024, 1> lock_wait_constraint;
3075
 
static lock_wait_constraint innobase_lock_wait_timeout;
3076
 
typedef constrained_check<long, LONG_MAX, 256*1024, 1024> log_buffer_size_constraint;
3077
 
static log_buffer_size_constraint innobase_log_buffer_size;
3078
 
typedef constrained_check<unsigned int, 97, 5> lru_old_blocks_constraint;
3079
 
static lru_old_blocks_constraint innobase_lru_old_blocks_pct;
3080
 
typedef constrained_check<unsigned int, 99, 0> max_dirty_pages_constraint;
3081
 
static max_dirty_pages_constraint haildb_max_dirty_pages_pct;
3082
 
static uint64_constraint haildb_max_purge_lag;
3083
 
static uint64_constraint haildb_sync_spin_loops;
3084
 
typedef constrained_check<uint32_t, UINT32_MAX, 10> open_files_constraint;
3085
 
static open_files_constraint haildb_open_files;
3086
 
typedef constrained_check<unsigned int, 64, 1> io_threads_constraint;
3087
 
static io_threads_constraint haildb_read_io_threads;
3088
 
static io_threads_constraint haildb_write_io_threads;
3089
 
 
3090
 
 
3091
 
static uint32_t innobase_lru_block_access_recency;
3092
 
 
3093
 
 
3094
 
 
3095
 
static int haildb_file_format_name_validate(Session*, set_var *var)
3096
 
{
3097
 
 
3098
 
  const char *format= var->value->str_value.ptr();
3099
 
  if (format == NULL)
3100
 
    return 1;
3101
 
 
3102
 
  ib_err_t err= ib_cfg_set_text("file_format", format);
3103
 
 
3104
 
  if (err == DB_SUCCESS)
3105
 
  {
3106
 
    innobase_file_format_name= format;
3107
 
    return 0;
3108
 
  }
3109
 
  else
3110
 
    return 1;
3111
 
}
3112
 
 
3113
 
static void haildb_lru_old_blocks_pct_update(Session*, sql_var_t)
3114
 
{
3115
 
  int ret= ib_cfg_set_int("lru_old_blocks_pct", static_cast<uint32_t>(innobase_lru_old_blocks_pct));
3116
 
  (void)ret;
3117
 
}
3118
 
 
3119
 
static void haildb_lru_block_access_recency_update(Session*, sql_var_t)
3120
 
{
3121
 
  int ret= ib_cfg_set_int("lru_block_access_recency", static_cast<uint32_t>(innobase_lru_block_access_recency));
3122
 
  (void)ret;
3123
 
}
3124
 
 
3125
 
static void haildb_status_file_update(Session*, sql_var_t)
3126
 
{
3127
 
  ib_err_t err;
3128
 
 
3129
 
  if (innobase_create_status_file)
3130
 
    err= ib_cfg_set_bool_on("status_file");
3131
 
  else
3132
 
    err= ib_cfg_set_bool_off("status_file");
3133
 
  (void)err;
3134
 
}
3135
 
 
3136
 
extern "C" int haildb_errmsg_callback(ib_msg_stream_t, const char *fmt, ...);
3137
 
namespace drizzled
3138
 
{
3139
 
extern bool volatile shutdown_in_progress;
3140
 
}
3141
 
 
3142
 
extern "C" int haildb_errmsg_callback(ib_msg_stream_t, const char *fmt, ...)
3143
 
{
3144
 
  bool r= false;
3145
 
  va_list args;
3146
 
  va_start(args, fmt);
3147
 
  if (not shutdown_in_progress)
3148
 
  {
3149
 
    r= plugin::ErrorMessage::vprintf(error::WARN, fmt, args);
3150
 
  }
3151
 
  else
3152
 
  {
3153
 
    vfprintf(stderr, fmt, args);
3154
 
  }
3155
 
  va_end(args);
3156
 
 
3157
 
  return (! r==true);
3158
 
}
 
2851
static long innobase_open_files;
 
2852
static long innobase_force_recovery;
 
2853
static long innobase_log_buffer_size;
 
2854
static char  default_haildb_data_file_path[]= "ibdata1:10M:autoextend";
 
2855
static char* haildb_data_file_path= NULL;
 
2856
 
 
2857
static int64_t haildb_log_file_size;
 
2858
static int64_t haildb_log_files_in_group;
3159
2859
 
3160
2860
static int haildb_init(drizzled::module::Context &context)
3161
2861
{
3177
2877
  innobase_print_verbose_log= (vm.count("disable-print-verbose-log")) ? false : true;
3178
2878
  srv_use_sys_malloc= (vm.count("use-internal-malloc")) ? false : true;
3179
2879
 
 
2880
  if (vm.count("io-capacity"))
 
2881
  {
 
2882
    if (srv_io_capacity > (unsigned long)~0L || srv_io_capacity < 100)
 
2883
    {
 
2884
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of io-capacity"));
 
2885
      return 1;
 
2886
    }
 
2887
  }
 
2888
 
 
2889
  if (vm.count("fast-shutdown"))
 
2890
  {
 
2891
    if (innobase_fast_shutdown > 2)
 
2892
    {
 
2893
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of fast-shutdown"));
 
2894
      return 1;
 
2895
    }
 
2896
  }
 
2897
 
 
2898
  if (vm.count("flush-log-at-trx-commit"))
 
2899
  {
 
2900
    if (srv_flush_log_at_trx_commit > 2)
 
2901
    {
 
2902
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of flush-log-at-trx-commit"));
 
2903
      return 1;
 
2904
    }
 
2905
  }
 
2906
 
 
2907
  if (vm.count("force-recovery"))
 
2908
  {
 
2909
    if (innobase_force_recovery > 6)
 
2910
    {
 
2911
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of force-recovery"));
 
2912
      return 1;
 
2913
    }
 
2914
  }
 
2915
 
 
2916
  if (vm.count("log-file-size"))
 
2917
  {
 
2918
    if (haildb_log_file_size > INT64_MAX || haildb_log_file_size < 1*1024*1024L)
 
2919
    {
 
2920
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of log-file-size"));
 
2921
      return 1;
 
2922
    }
 
2923
    haildb_log_file_size/= 1024*1024L;
 
2924
    haildb_log_file_size*= 1024*1024L;
 
2925
  }
 
2926
 
 
2927
  if (vm.count("log-files-in-group"))
 
2928
  {
 
2929
    if (haildb_log_files_in_group > 100 || haildb_log_files_in_group < 2)
 
2930
    {
 
2931
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of log-files-in-group"));
 
2932
      return 1;
 
2933
    }
 
2934
  }
 
2935
 
 
2936
  if (vm.count("lock-wait-timeout"))
 
2937
  {
 
2938
    if (innobase_lock_wait_timeout > 1024*1024*1024 || innobase_lock_wait_timeout < 1)
 
2939
    {
 
2940
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of lock-wait-timeout"));
 
2941
      return 1;
 
2942
    }
 
2943
  }
 
2944
 
 
2945
  if (vm.count("log-buffer-size"))
 
2946
  {
 
2947
    if (innobase_log_buffer_size > LONG_MAX || innobase_log_buffer_size < 256*1024L)
 
2948
    {
 
2949
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of log-buffer-size"));
 
2950
      return 1;
 
2951
    }
 
2952
    innobase_log_buffer_size/= 1024;
 
2953
    innobase_log_buffer_size*= 1024;
 
2954
  }
 
2955
 
 
2956
  if (vm.count("lru-old-blocks-pct"))
 
2957
  {
 
2958
    if (innobase_lru_old_blocks_pct > 95 || innobase_lru_old_blocks_pct < 5)
 
2959
    {
 
2960
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of lru-old-blocks-pct"));
 
2961
      return 1;
 
2962
    }
 
2963
  }
 
2964
 
 
2965
  if (vm.count("lru-block-access-recency"))
 
2966
  {
 
2967
    if (innobase_lru_block_access_recency > ULONG_MAX)
 
2968
    {
 
2969
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of lru-block-access-recency"));
 
2970
      return 1;
 
2971
    }
 
2972
  }
 
2973
 
 
2974
  if (vm.count("max-dirty-pages-pct"))
 
2975
  {
 
2976
    if (srv_max_buf_pool_modified_pct > 99)
 
2977
    {
 
2978
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of max-dirty-pages-pct"));
 
2979
      return 1;
 
2980
    }
 
2981
  }
 
2982
 
 
2983
  if (vm.count("max-purge-lag"))
 
2984
  {
 
2985
    if (srv_max_purge_lag > (unsigned long)~0L)
 
2986
    {
 
2987
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of max-purge-lag"));
 
2988
      return 1;
 
2989
    }
 
2990
  }
 
2991
 
 
2992
  if (vm.count("open-files"))
 
2993
  {
 
2994
    if (innobase_open_files > LONG_MAX || innobase_open_files < 10L)
 
2995
    {
 
2996
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of open-files"));
 
2997
      return 1;
 
2998
    }
 
2999
  }
 
3000
 
 
3001
  if (vm.count("read-io-threads"))
 
3002
  {
 
3003
    if (innobase_read_io_threads > 64 || innobase_read_io_threads < 1)
 
3004
    {
 
3005
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of read-io-threads"));
 
3006
      return 1;
 
3007
    }
 
3008
  }
 
3009
 
 
3010
  if (vm.count("sync-spin-loops"))
 
3011
  {
 
3012
    if (srv_n_spin_wait_rounds > (unsigned long)~0L)
 
3013
    {
 
3014
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of sync_spin_loops"));
 
3015
      return 1;
 
3016
    }
 
3017
  }
 
3018
 
 
3019
  if (vm.count("data-home-dir"))
 
3020
  {
 
3021
    innobase_data_home_dir= const_cast<char *>(vm["data-home-dir"].as<string>().c_str());
 
3022
  }
 
3023
 
 
3024
  if (vm.count("file-format"))
 
3025
  {
 
3026
    innobase_file_format_name= const_cast<char *>(vm["file-format"].as<string>().c_str());
 
3027
  }
 
3028
 
 
3029
  if (vm.count("log-group-home-dir"))
 
3030
  {
 
3031
    innobase_log_group_home_dir= const_cast<char *>(vm["log-group-home-dir"].as<string>().c_str());
 
3032
  }
 
3033
 
 
3034
  if (vm.count("flush-method"))
 
3035
  {
 
3036
    innobase_unix_file_flush_method= const_cast<char *>(vm["flush-method"].as<string>().c_str());
 
3037
  }
 
3038
 
 
3039
  if (vm.count("data-file-path"))
 
3040
  {
 
3041
    haildb_data_file_path= const_cast<char *>(vm["data-file-path"].as<string>().c_str());
 
3042
  }
3180
3043
 
3181
3044
  ib_err_t err;
3182
3045
 
3184
3047
  if (err != DB_SUCCESS)
3185
3048
    goto haildb_error;
3186
3049
 
3187
 
  ib_logger_set(haildb_errmsg_callback, NULL);
3188
 
 
3189
 
  if (not vm["data-home-dir"].as<string>().empty())
3190
 
  {
3191
 
    err= ib_cfg_set_text("data_home_dir", vm["data-home-dir"].as<string>().c_str());
3192
 
    if (err != DB_SUCCESS)
3193
 
      goto haildb_error;
3194
 
  }
3195
 
 
3196
 
  if (vm.count("log-group-home-dir"))
3197
 
  {
3198
 
    err= ib_cfg_set_text("log_group_home_dir", vm["log-group-home-dir"].as<string>().c_str());
3199
 
    if (err != DB_SUCCESS)
3200
 
      goto haildb_error;
3201
 
  }
 
3050
  if (innobase_data_home_dir)
 
3051
  {
 
3052
    err= ib_cfg_set_text("data_home_dir", innobase_data_home_dir);
 
3053
    if (err != DB_SUCCESS)
 
3054
      goto haildb_error;
 
3055
  }
 
3056
 
 
3057
  if (innobase_log_group_home_dir)
 
3058
  {
 
3059
    err= ib_cfg_set_text("log_group_home_dir", innobase_log_group_home_dir);
 
3060
    if (err != DB_SUCCESS)
 
3061
      goto haildb_error;
 
3062
  }
 
3063
 
 
3064
  if (haildb_data_file_path == NULL)
 
3065
    haildb_data_file_path= default_haildb_data_file_path;
3202
3066
 
3203
3067
  if (innobase_print_verbose_log)
3204
3068
    err= ib_cfg_set_bool_on("print_verbose_log");
3240
3104
  if (err != DB_SUCCESS)
3241
3105
    goto haildb_error;
3242
3106
 
3243
 
  err= ib_cfg_set_int("additional_mem_pool_size", innobase_additional_mem_pool_size.get());
3244
 
  if (err != DB_SUCCESS)
3245
 
    goto haildb_error;
3246
 
 
3247
 
  err= ib_cfg_set_int("autoextend_increment", srv_auto_extend_increment.get());
3248
 
  if (err != DB_SUCCESS)
3249
 
    goto haildb_error;
3250
 
 
3251
 
  err= ib_cfg_set_int("buffer_pool_size", innobase_buffer_pool_size.get());
3252
 
  if (err != DB_SUCCESS)
3253
 
    goto haildb_error;
3254
 
 
3255
 
  err= ib_cfg_set_int("io_capacity", srv_io_capacity.get());
 
3107
  err= ib_cfg_set_int("additional_mem_pool_size", static_cast<size_t>(innobase_additional_mem_pool_size));
 
3108
  if (err != DB_SUCCESS)
 
3109
    goto haildb_error;
 
3110
 
 
3111
  err= ib_cfg_set_int("autoextend_increment", static_cast<unsigned int>(srv_auto_extend_increment));
 
3112
  if (err != DB_SUCCESS)
 
3113
    goto haildb_error;
 
3114
 
 
3115
  err= ib_cfg_set_int("buffer_pool_size", static_cast<size_t>(innobase_buffer_pool_size));
 
3116
  if (err != DB_SUCCESS)
 
3117
    goto haildb_error;
 
3118
 
 
3119
  err= ib_cfg_set_int("io_capacity", srv_io_capacity);
3256
3120
  if (err != DB_SUCCESS)
3257
3121
    goto haildb_error;
3258
3122
 
3264
3128
  if (err != DB_SUCCESS)
3265
3129
    goto haildb_error;
3266
3130
 
3267
 
  err= ib_cfg_set_int("flush_log_at_trx_commit",
3268
 
                      srv_flush_log_at_trx_commit.get());
 
3131
  err= ib_cfg_set_int("flush_log_at_trx_commit", srv_flush_log_at_trx_commit);
3269
3132
  if (err != DB_SUCCESS)
3270
3133
    goto haildb_error;
3271
3134
 
3272
 
  if (vm.count("flush-method") != 0)
 
3135
  if (innobase_unix_file_flush_method)
3273
3136
  {
3274
 
    err= ib_cfg_set_text("flush_method", 
3275
 
                         vm["flush-method"].as<string>().c_str());
 
3137
    err= ib_cfg_set_text("flush_method", innobase_unix_file_flush_method);
3276
3138
    if (err != DB_SUCCESS)
3277
3139
      goto haildb_error;
3278
3140
  }
3279
3141
 
3280
 
  err= ib_cfg_set_int("force_recovery",
3281
 
                      innobase_force_recovery.get());
3282
 
  if (err != DB_SUCCESS)
3283
 
    goto haildb_error;
3284
 
 
3285
 
  err= ib_cfg_set_text("data_file_path", vm["data-file-path"].as<string>().c_str());
3286
 
  if (err != DB_SUCCESS)
3287
 
    goto haildb_error;
3288
 
 
3289
 
  err= ib_cfg_set_int("log_file_size", haildb_log_file_size.get());
3290
 
  if (err != DB_SUCCESS)
3291
 
    goto haildb_error;
3292
 
 
3293
 
  err= ib_cfg_set_int("log_buffer_size", innobase_log_buffer_size.get());
3294
 
  if (err != DB_SUCCESS)
3295
 
    goto haildb_error;
3296
 
 
3297
 
  err= ib_cfg_set_int("log_files_in_group", haildb_log_files_in_group.get());
 
3142
  err= ib_cfg_set_int("force_recovery", innobase_force_recovery);
 
3143
  if (err != DB_SUCCESS)
 
3144
    goto haildb_error;
 
3145
 
 
3146
  err= ib_cfg_set_text("data_file_path", haildb_data_file_path);
 
3147
  if (err != DB_SUCCESS)
 
3148
    goto haildb_error;
 
3149
 
 
3150
  err= ib_cfg_set_int("log_file_size", haildb_log_file_size);
 
3151
  if (err != DB_SUCCESS)
 
3152
    goto haildb_error;
 
3153
 
 
3154
  err= ib_cfg_set_int("log_buffer_size", innobase_log_buffer_size);
 
3155
  if (err != DB_SUCCESS)
 
3156
    goto haildb_error;
 
3157
 
 
3158
  err= ib_cfg_set_int("log_files_in_group", haildb_log_files_in_group);
3298
3159
  if (err != DB_SUCCESS)
3299
3160
    goto haildb_error;
3300
3161
 
3302
3163
  if (err != DB_SUCCESS)
3303
3164
    goto haildb_error;
3304
3165
 
3305
 
  err= ib_cfg_set_int("lock_wait_timeout", innobase_lock_wait_timeout.get());
3306
 
  if (err != DB_SUCCESS)
3307
 
    goto haildb_error;
3308
 
 
3309
 
  err= ib_cfg_set_int("max_dirty_pages_pct", haildb_max_dirty_pages_pct.get());
3310
 
  if (err != DB_SUCCESS)
3311
 
    goto haildb_error;
3312
 
 
3313
 
  err= ib_cfg_set_int("max_purge_lag", haildb_max_purge_lag.get());
3314
 
  if (err != DB_SUCCESS)
3315
 
    goto haildb_error;
3316
 
 
3317
 
  err= ib_cfg_set_int("open_files", haildb_open_files.get());
3318
 
  if (err != DB_SUCCESS)
3319
 
    goto haildb_error;
3320
 
 
3321
 
  err= ib_cfg_set_int("read_io_threads", haildb_read_io_threads.get());
3322
 
  if (err != DB_SUCCESS)
3323
 
    goto haildb_error;
3324
 
 
3325
 
  err= ib_cfg_set_int("write_io_threads", haildb_write_io_threads.get());
3326
 
  if (err != DB_SUCCESS)
3327
 
    goto haildb_error;
3328
 
 
3329
 
  err= ib_cfg_set_int("sync_spin_loops", haildb_sync_spin_loops.get());
 
3166
  err= ib_cfg_set_int("lock_wait_timeout", innobase_lock_wait_timeout);
 
3167
  if (err != DB_SUCCESS)
 
3168
    goto haildb_error;
 
3169
 
 
3170
  err= ib_cfg_set_int("max_dirty_pages_pct", srv_max_buf_pool_modified_pct);
 
3171
  if (err != DB_SUCCESS)
 
3172
    goto haildb_error;
 
3173
 
 
3174
  err= ib_cfg_set_int("max_purge_lag", srv_max_purge_lag);
 
3175
  if (err != DB_SUCCESS)
 
3176
    goto haildb_error;
 
3177
 
 
3178
  err= ib_cfg_set_int("open_files", innobase_open_files);
 
3179
  if (err != DB_SUCCESS)
 
3180
    goto haildb_error;
 
3181
 
 
3182
  err= ib_cfg_set_int("read_io_threads", innobase_read_io_threads);
 
3183
  if (err != DB_SUCCESS)
 
3184
    goto haildb_error;
 
3185
 
 
3186
  err= ib_cfg_set_int("write_io_threads", innobase_write_io_threads);
 
3187
  if (err != DB_SUCCESS)
 
3188
    goto haildb_error;
 
3189
 
 
3190
  err= ib_cfg_set_int("sync_spin_loops", srv_n_spin_wait_rounds);
3330
3191
  if (err != DB_SUCCESS)
3331
3192
    goto haildb_error;
3332
3193
 
3338
3199
  if (err != DB_SUCCESS)
3339
3200
    goto haildb_error;
3340
3201
 
3341
 
  err= ib_startup(innobase_file_format_name.c_str());
 
3202
  err= ib_startup(innobase_file_format_name);
3342
3203
  if (err != DB_SUCCESS)
3343
3204
    goto haildb_error;
3344
3205
 
3353
3214
  context.registerVariable(new sys_var_constrained_value_readonly<size_t>("additional_mem_pool_size",innobase_additional_mem_pool_size));
3354
3215
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("autoextend_increment", srv_auto_extend_increment));
3355
3216
  context.registerVariable(new sys_var_constrained_value_readonly<size_t>("buffer_pool_size", innobase_buffer_pool_size));
3356
 
  context.registerVariable(new sys_var_bool_ptr_readonly("checksums",
3357
 
                                                         &innobase_use_checksums));
3358
 
  context.registerVariable(new sys_var_bool_ptr_readonly("doublewrite",
3359
 
                                                         &innobase_use_doublewrite));
3360
 
  context.registerVariable(new sys_var_const_string_val("data_file_path",
3361
 
                                                vm["data-file-path"].as<string>()));
3362
 
  context.registerVariable(new sys_var_const_string_val("data_home_dir",
3363
 
                                                vm["data-home-dir"].as<string>()));
3364
 
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("io_capacity", srv_io_capacity));
3365
 
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("fast_shutdown", innobase_fast_shutdown));
3366
 
  context.registerVariable(new sys_var_bool_ptr_readonly("file_per_table",
3367
 
                                                         &srv_file_per_table));
3368
 
  context.registerVariable(new sys_var_bool_ptr_readonly("rollback_on_timeout",
3369
 
                                                         &innobase_rollback_on_timeout));
3370
 
  context.registerVariable(new sys_var_bool_ptr_readonly("print_verbose_log",
3371
 
                                                         &innobase_print_verbose_log));
3372
 
  context.registerVariable(new sys_var_bool_ptr("status_file",
3373
 
                                                &innobase_create_status_file,
3374
 
                                                haildb_status_file_update));
3375
 
  context.registerVariable(new sys_var_bool_ptr_readonly("use_sys_malloc",
3376
 
                                                         &srv_use_sys_malloc));
3377
 
  context.registerVariable(new sys_var_std_string("file_format",
3378
 
                                                  innobase_file_format_name,
3379
 
                                                  haildb_file_format_name_validate));
3380
 
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("flush_log_at_trx_commit", srv_flush_log_at_trx_commit));
3381
 
  context.registerVariable(new sys_var_const_string_val("flush_method",
3382
 
                                                vm.count("flush-method") ?  vm["flush-method"].as<string>() : ""));
3383
 
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("force_recovery", innobase_force_recovery));
3384
 
  context.registerVariable(new sys_var_const_string_val("log_group_home_dir",
3385
 
                                                vm.count("log-group-home-dir") ?  vm["log-group-home-dir"].as<string>() : ""));
3386
 
  context.registerVariable(new sys_var_constrained_value<int64_t>("log_file_size", haildb_log_file_size));
3387
 
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("log_files_in_group", haildb_log_files_in_group));
3388
 
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("lock_wait_timeout", innobase_lock_wait_timeout));
3389
 
  context.registerVariable(new sys_var_constrained_value_readonly<long>("log_buffer_size", innobase_log_buffer_size));
3390
 
  context.registerVariable(new sys_var_constrained_value<unsigned int>("lru_old_blocks_pct", innobase_lru_old_blocks_pct, haildb_lru_old_blocks_pct_update));
3391
 
  context.registerVariable(new sys_var_uint32_t_ptr("lru_block_access_recency",
3392
 
                                                    &innobase_lru_block_access_recency,
3393
 
                                                    haildb_lru_block_access_recency_update));
3394
 
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("max_dirty_pages_pct", haildb_max_dirty_pages_pct));
3395
 
  context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("max_purge_lag", haildb_max_purge_lag));
3396
 
  context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("sync_spin_loops", haildb_sync_spin_loops));
3397
 
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("open_files", haildb_open_files));
3398
 
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("read_io_threads", haildb_read_io_threads));
3399
 
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("write_io_threads", haildb_write_io_threads));
3400
3217
 
3401
3218
  haildb_datadict_dump_func_initialize(context);
3402
3219
  config_table_function_initialize(context);
3415
3232
  ib_err_t err;
3416
3233
  ib_shutdown_t shutdown_flag= IB_SHUTDOWN_NORMAL;
3417
3234
 
3418
 
  if (innobase_fast_shutdown.get() == 1)
 
3235
  if (innobase_fast_shutdown == 1)
3419
3236
    shutdown_flag= IB_SHUTDOWN_NO_IBUFMERGE_PURGE;
3420
 
  else if (innobase_fast_shutdown.get() == 2)
 
3237
  else if (innobase_fast_shutdown == 2)
3421
3238
    shutdown_flag= IB_SHUTDOWN_NO_BUFPOOL_FLUSH;
3422
3239
 
3423
3240
  err= ib_shutdown(shutdown_flag);
3429
3246
 
3430
3247
}
3431
3248
 
 
3249
static char haildb_file_format_name_storage[100];
 
3250
 
 
3251
static int haildb_file_format_name_validate(Session*, drizzle_sys_var*,
 
3252
                                            void *save,
 
3253
                                            drizzle_value *value)
 
3254
{
 
3255
  ib_err_t err;
 
3256
  char buff[100];
 
3257
  int len= sizeof(buff);
 
3258
  const char *format= value->val_str(value, buff, &len);
 
3259
 
 
3260
  *static_cast<const char**>(save)= NULL;
 
3261
 
 
3262
  if (format == NULL)
 
3263
    return 1;
 
3264
 
 
3265
  err= ib_cfg_set_text("file_format", format);
 
3266
 
 
3267
  if (err == DB_SUCCESS)
 
3268
  {
 
3269
    strncpy(haildb_file_format_name_storage, format, sizeof(haildb_file_format_name_storage));;
 
3270
    haildb_file_format_name_storage[sizeof(haildb_file_format_name_storage)-1]= 0;
 
3271
 
 
3272
    *static_cast<const char**>(save)= haildb_file_format_name_storage;
 
3273
    return 0;
 
3274
  }
 
3275
  else
 
3276
    return 1;
 
3277
}
 
3278
 
 
3279
static void haildb_file_format_name_update(Session*, drizzle_sys_var*,
 
3280
                                           void *var_ptr,
 
3281
                                           const void *save)
 
3282
 
 
3283
{
 
3284
  const char* format;
 
3285
 
 
3286
  assert(var_ptr != NULL);
 
3287
  assert(save != NULL);
 
3288
 
 
3289
  format= *static_cast<const char*const*>(save);
 
3290
 
 
3291
  /* Format is already set in validate */
 
3292
  memmove(haildb_file_format_name_storage, format, sizeof(haildb_file_format_name_storage));;
 
3293
  haildb_file_format_name_storage[sizeof(haildb_file_format_name_storage)-1]= 0;
 
3294
 
 
3295
  *static_cast<const char**>(var_ptr)= haildb_file_format_name_storage;
 
3296
}
 
3297
 
 
3298
static void haildb_lru_old_blocks_pct_update(Session*, drizzle_sys_var*,
 
3299
                                             void *,
 
3300
                                             const void *save)
 
3301
 
 
3302
{
 
3303
  unsigned long pct;
 
3304
 
 
3305
  pct= *static_cast<const unsigned long*>(save);
 
3306
 
 
3307
  ib_err_t err= ib_cfg_set_int("lru_old_blocks_pct", pct);
 
3308
  if (err == DB_SUCCESS)
 
3309
    innobase_lru_old_blocks_pct= pct;
 
3310
}
 
3311
 
 
3312
static void haildb_lru_block_access_recency_update(Session*, drizzle_sys_var*,
 
3313
                                                   void *,
 
3314
                                                   const void *save)
 
3315
 
 
3316
{
 
3317
  unsigned long ms;
 
3318
 
 
3319
  ms= *static_cast<const unsigned long*>(save);
 
3320
 
 
3321
  ib_err_t err= ib_cfg_set_int("lru_block_access_recency", ms);
 
3322
 
 
3323
  if (err == DB_SUCCESS)
 
3324
    innobase_lru_block_access_recency= ms;
 
3325
}
 
3326
 
 
3327
static void haildb_status_file_update(Session*, drizzle_sys_var*,
 
3328
                                      void *,
 
3329
                                      const void *save)
 
3330
 
 
3331
{
 
3332
  bool status_file_enabled;
 
3333
  ib_err_t err;
 
3334
 
 
3335
  status_file_enabled= *static_cast<const bool*>(save);
 
3336
 
 
3337
 
 
3338
  if (status_file_enabled)
 
3339
    err= ib_cfg_set_bool_on("status_file");
 
3340
  else
 
3341
    err= ib_cfg_set_bool_off("status_file");
 
3342
 
 
3343
  if (err == DB_SUCCESS)
 
3344
    innobase_create_status_file= status_file_enabled;
 
3345
}
 
3346
 
 
3347
static DRIZZLE_SYSVAR_BOOL(checksums, innobase_use_checksums,
 
3348
  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
 
3349
  "Enable HailDB checksums validation (enabled by default). "
 
3350
  "Disable with --skip-haildb-checksums.",
 
3351
  NULL, NULL, true);
 
3352
 
 
3353
static DRIZZLE_SYSVAR_STR(data_home_dir, innobase_data_home_dir,
 
3354
  PLUGIN_VAR_READONLY,
 
3355
  "The common part for HailDB table spaces.",
 
3356
  NULL, NULL, NULL);
 
3357
 
 
3358
static DRIZZLE_SYSVAR_BOOL(doublewrite, innobase_use_doublewrite,
 
3359
  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
 
3360
  "Enable HailDB doublewrite buffer (enabled by default). "
 
3361
  "Disable with --skip-haildb-doublewrite.",
 
3362
  NULL, NULL, true);
 
3363
 
 
3364
static DRIZZLE_SYSVAR_ULONG(io_capacity, srv_io_capacity,
 
3365
  PLUGIN_VAR_RQCMDARG,
 
3366
  "Number of IOPs the server can do. Tunes the background IO rate",
 
3367
  NULL, NULL, 200, 100, ~0L, 0);
 
3368
 
 
3369
static DRIZZLE_SYSVAR_ULONG(fast_shutdown, innobase_fast_shutdown,
 
3370
  PLUGIN_VAR_OPCMDARG,
 
3371
  "Speeds up the shutdown process of the HailDB storage engine. Possible "
 
3372
  "values are 0, 1 (faster)"
 
3373
  " or 2 (fastest - crash-like)"
 
3374
  ".",
 
3375
  NULL, NULL, 1, 0, 2, 0);
 
3376
 
 
3377
static DRIZZLE_SYSVAR_BOOL(file_per_table, srv_file_per_table,
 
3378
  PLUGIN_VAR_NOCMDARG,
 
3379
  "Stores each HailDB table to an .ibd file in the database dir.",
 
3380
  NULL, NULL, false);
 
3381
 
 
3382
static DRIZZLE_SYSVAR_STR(file_format, innobase_file_format_name,
 
3383
  PLUGIN_VAR_RQCMDARG,
 
3384
  "File format to use for new tables in .ibd files.",
 
3385
  haildb_file_format_name_validate,
 
3386
  haildb_file_format_name_update, "Barracuda");
 
3387
 
 
3388
static DRIZZLE_SYSVAR_ULONG(flush_log_at_trx_commit, srv_flush_log_at_trx_commit,
 
3389
  PLUGIN_VAR_OPCMDARG,
 
3390
  "Set to 0 (write and flush once per second),"
 
3391
  " 1 (write and flush at each commit)"
 
3392
  " or 2 (write at commit, flush once per second).",
 
3393
  NULL, NULL, 1, 0, 2, 0);
 
3394
 
 
3395
static DRIZZLE_SYSVAR_STR(flush_method, innobase_unix_file_flush_method,
 
3396
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3397
  "With which method to flush data.", NULL, NULL, NULL);
 
3398
 
 
3399
static DRIZZLE_SYSVAR_LONG(force_recovery, innobase_force_recovery,
 
3400
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3401
  "Helps to save your data in case the disk image of the database becomes corrupt.",
 
3402
  NULL, NULL, 0, 0, 6, 0);
 
3403
 
 
3404
static DRIZZLE_SYSVAR_STR(data_file_path, haildb_data_file_path,
 
3405
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3406
  "Path to individual files and their sizes.",
 
3407
  NULL, NULL, NULL);
 
3408
 
 
3409
static DRIZZLE_SYSVAR_STR(log_group_home_dir, innobase_log_group_home_dir,
 
3410
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3411
  "Path to HailDB log files.", NULL, NULL, NULL);
 
3412
 
 
3413
static DRIZZLE_SYSVAR_LONGLONG(log_file_size, haildb_log_file_size,
 
3414
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3415
  "Size of each log file in a log group.",
 
3416
  NULL, NULL, 20*1024*1024L, 1*1024*1024L, INT64_MAX, 1024*1024L);
 
3417
 
 
3418
static DRIZZLE_SYSVAR_LONGLONG(log_files_in_group, haildb_log_files_in_group,
 
3419
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3420
  "Number of log files in the log group. HailDB writes to the files in a circular fashion. Value 3 is recommended here.",
 
3421
  NULL, NULL, 2, 2, 100, 0);
 
3422
 
 
3423
static DRIZZLE_SYSVAR_ULONG(lock_wait_timeout, innobase_lock_wait_timeout,
 
3424
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3425
  "Timeout in seconds an HailDB transaction may wait for a lock before being rolled back. Values above 100000000 disable the timeout.",
 
3426
  NULL, NULL, 5, 1, 1024 * 1024 * 1024, 0);
 
3427
 
 
3428
static DRIZZLE_SYSVAR_LONG(log_buffer_size, innobase_log_buffer_size,
 
3429
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3430
  "The size of the buffer which HailDB uses to write log to the log files on disk.",
 
3431
  NULL, NULL, 8*1024*1024L, 256*1024L, LONG_MAX, 1024);
 
3432
 
 
3433
static DRIZZLE_SYSVAR_ULONG(lru_old_blocks_pct, innobase_lru_old_blocks_pct,
 
3434
  PLUGIN_VAR_RQCMDARG,
 
3435
  "Sets the point in the LRU list from where all pages are classified as "
 
3436
  "old (Advanced users)",
 
3437
  NULL,
 
3438
  haildb_lru_old_blocks_pct_update, 37, 5, 95, 0);
 
3439
 
 
3440
static DRIZZLE_SYSVAR_ULONG(lru_block_access_recency, innobase_lru_block_access_recency,
 
3441
  PLUGIN_VAR_RQCMDARG,
 
3442
  "Milliseconds between accesses to a block at which it is made young. "
 
3443
  "0=disabled (Advanced users)",
 
3444
  NULL,
 
3445
  haildb_lru_block_access_recency_update, 0, 0, ULONG_MAX, 0);
 
3446
 
 
3447
 
 
3448
static DRIZZLE_SYSVAR_ULONG(max_dirty_pages_pct, srv_max_buf_pool_modified_pct,
 
3449
  PLUGIN_VAR_RQCMDARG,
 
3450
  "Percentage of dirty pages allowed in bufferpool.",
 
3451
  NULL, NULL, 75, 0, 99, 0);
 
3452
 
 
3453
static DRIZZLE_SYSVAR_ULONG(max_purge_lag, srv_max_purge_lag,
 
3454
  PLUGIN_VAR_RQCMDARG,
 
3455
  "Desired maximum length of the purge queue (0 = no limit)",
 
3456
  NULL, NULL, 0, 0, ~0L, 0);
 
3457
 
 
3458
static DRIZZLE_SYSVAR_BOOL(rollback_on_timeout, innobase_rollback_on_timeout,
 
3459
  PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
 
3460
  "Roll back the complete transaction on lock wait timeout, for 4.x compatibility (disabled by default)",
 
3461
  NULL, NULL, false);
 
3462
 
 
3463
static DRIZZLE_SYSVAR_LONG(open_files, innobase_open_files,
 
3464
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3465
  "How many files at the maximum HailDB keeps open at the same time.",
 
3466
  NULL, NULL, 300L, 10L, LONG_MAX, 0);
 
3467
 
 
3468
static DRIZZLE_SYSVAR_ULONG(read_io_threads, innobase_read_io_threads,
 
3469
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3470
  "Number of background read I/O threads in HailDB.",
 
3471
  NULL, NULL, 4, 1, 64, 0);
 
3472
 
 
3473
static DRIZZLE_SYSVAR_ULONG(write_io_threads, innobase_write_io_threads,
 
3474
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3475
  "Number of background write I/O threads in HailDB.",
 
3476
  NULL, NULL, 4, 1, 64, 0);
 
3477
 
 
3478
static DRIZZLE_SYSVAR_BOOL(print_verbose_log, innobase_print_verbose_log,
 
3479
  PLUGIN_VAR_NOCMDARG,
 
3480
  "Disable if you want to reduce the number of messages written to the log (default: enabled).",
 
3481
  NULL, NULL, true);
 
3482
 
 
3483
static DRIZZLE_SYSVAR_BOOL(status_file, innobase_create_status_file,
 
3484
  PLUGIN_VAR_OPCMDARG,
 
3485
  "Enable SHOW HAILDB STATUS output in the log",
 
3486
  NULL, haildb_status_file_update, false);
 
3487
 
 
3488
static DRIZZLE_SYSVAR_ULONG(sync_spin_loops, srv_n_spin_wait_rounds,
 
3489
  PLUGIN_VAR_RQCMDARG,
 
3490
  "Count of spin-loop rounds in HailDB mutexes (30 by default)",
 
3491
  NULL, NULL, 30L, 0L, ~0L, 0);
 
3492
 
 
3493
static DRIZZLE_SYSVAR_BOOL(use_sys_malloc, srv_use_sys_malloc,
 
3494
  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
 
3495
  "Use OS memory allocator instead of HailDB's internal memory allocator",
 
3496
  NULL, NULL, true);
3432
3497
 
3433
3498
static void init_options(drizzled::module::option_context &context)
3434
3499
{
3446
3511
          po::value<buffer_pool_constraint>(&innobase_buffer_pool_size)->default_value(128*1024*1024L),
3447
3512
          N_("The size of the memory buffer HailDB uses to cache data and indexes of its tables."));
3448
3513
  context("data-home-dir",
3449
 
          po::value<string>()->default_value(""),
 
3514
          po::value<string>(),
3450
3515
          N_("The common part for HailDB table spaces."));
3451
3516
  context("disable-checksums",
3452
3517
          N_("Disable HailDB checksums validation (enabled by default)."));
3453
3518
  context("disable-doublewrite",
3454
3519
          N_("Disable HailDB doublewrite buffer (enabled by default)."));
3455
3520
  context("io-capacity",
3456
 
          po::value<io_capacity_constraint>(&srv_io_capacity)->default_value(200),
 
3521
          po::value<unsigned long>(&srv_io_capacity)->default_value(200),
3457
3522
          N_("Number of IOPs the server can do. Tunes the background IO rate"));
3458
3523
  context("fast-shutdown",
3459
 
          po::value<trinary_constraint>(&innobase_fast_shutdown)->default_value(1),
 
3524
          po::value<unsigned long>(&innobase_fast_shutdown)->default_value(1),
3460
3525
          N_("Speeds up the shutdown process of the HailDB storage engine. Possible values are 0, 1 (faster) or 2 (fastest - crash-like)."));
3461
3526
  context("file-per-table",
3462
3527
          po::value<bool>(&srv_file_per_table)->default_value(false)->zero_tokens(),
3463
3528
          N_("Stores each HailDB table to an .ibd file in the database dir."));
3464
3529
  context("file-format",
3465
 
          po::value<string>(&innobase_file_format_name)->default_value("Barracuda"),
 
3530
          po::value<string>(),
3466
3531
          N_("File format to use for new tables in .ibd files."));
3467
3532
  context("flush-log-at-trx-commit",
3468
 
          po::value<trinary_constraint>(&srv_flush_log_at_trx_commit)->default_value(1),
 
3533
          po::value<unsigned long>(&srv_flush_log_at_trx_commit)->default_value(1),
3469
3534
          N_("Set to 0 (write and flush once per second),1 (write and flush at each commit) or 2 (write at commit, flush once per second)."));
3470
3535
  context("flush-method",
3471
3536
          po::value<string>(),
3472
3537
          N_("With which method to flush data."));
3473
3538
  context("force-recovery",
3474
 
          po::value<force_recovery_constraint>(&innobase_force_recovery)->default_value(0),
 
3539
          po::value<long>(&innobase_force_recovery)->default_value(0),
3475
3540
          N_("Helps to save your data in case the disk image of the database becomes corrupt."));
3476
3541
  context("data-file-path",
3477
 
          po::value<string>()->default_value("ibdata1:10M:autoextend"),
 
3542
          po::value<string>(),
 
3543
          N_("Path to individual files and their sizes."));
 
3544
  context("log-group-home-dir",
 
3545
          po::value<string>(),
3478
3546
          N_("Path to individual files and their sizes."));
3479
3547
  context("log-group-home-dir",
3480
3548
          po::value<string>(),
3481
3549
          N_("Path to HailDB log files."));
3482
3550
  context("log-file-size",
3483
 
          po::value<log_file_constraint>(&haildb_log_file_size)->default_value(20*1024*1024L),
 
3551
          po::value<int64_t>(&haildb_log_file_size)->default_value(20*1024*1024L),
3484
3552
          N_("Size of each log file in a log group."));
3485
3553
  context("haildb-log-files-in-group",
3486
 
          po::value<log_files_in_group_constraint>(&haildb_log_files_in_group)->default_value(2),
 
3554
          po::value<int64_t>(&haildb_log_files_in_group)->default_value(2),
3487
3555
          N_("Number of log files in the log group. HailDB writes to the files in a circular fashion. Value 3 is recommended here."));
3488
3556
  context("lock-wait-timeout",
3489
 
          po::value<lock_wait_constraint>(&innobase_lock_wait_timeout)->default_value(5),
 
3557
          po::value<unsigned long>(&innobase_lock_wait_timeout)->default_value(5),
3490
3558
          N_("Timeout in seconds an HailDB transaction may wait for a lock before being rolled back. Values above 100000000 disable the timeout."));
3491
3559
  context("log-buffer-size",
3492
 
        po::value<log_buffer_size_constraint>(&innobase_log_buffer_size)->default_value(8*1024*1024L),
 
3560
        po::value<long>(&innobase_log_buffer_size)->default_value(8*1024*1024L),
3493
3561
        N_("The size of the buffer which HailDB uses to write log to the log files on disk."));
3494
3562
  context("lru-old-blocks-pct",
3495
 
          po::value<lru_old_blocks_constraint>(&innobase_lru_old_blocks_pct)->default_value(37),
 
3563
          po::value<unsigned long>(&innobase_lru_old_blocks_pct)->default_value(37),
3496
3564
          N_("Sets the point in the LRU list from where all pages are classified as old (Advanced users)"));
3497
3565
  context("lru-block-access-recency",
3498
 
          po::value<uint32_t>(&innobase_lru_block_access_recency)->default_value(0),
 
3566
          po::value<unsigned long>(&innobase_lru_block_access_recency)->default_value(0),
3499
3567
          N_("Milliseconds between accesses to a block at which it is made young. 0=disabled (Advanced users)"));
3500
3568
  context("max-dirty-pages-pct",
3501
 
          po::value<max_dirty_pages_constraint>(&haildb_max_dirty_pages_pct)->default_value(75),
 
3569
          po::value<unsigned long>(&srv_max_buf_pool_modified_pct)->default_value(75),
3502
3570
          N_("Percentage of dirty pages allowed in bufferpool."));
3503
3571
  context("max-purge-lag",
3504
 
          po::value<uint64_constraint>(&haildb_max_purge_lag)->default_value(0),
 
3572
          po::value<unsigned long>(&srv_max_purge_lag)->default_value(0),
3505
3573
          N_("Desired maximum length of the purge queue (0 = no limit)"));
3506
3574
  context("rollback-on-timeout",
3507
3575
          po::value<bool>(&innobase_rollback_on_timeout)->default_value(false)->zero_tokens(),
3508
3576
          N_("Roll back the complete transaction on lock wait timeout, for 4.x compatibility (disabled by default)"));
3509
3577
  context("open-files",
3510
 
          po::value<open_files_constraint>(&haildb_open_files)->default_value(300),
 
3578
          po::value<long>(&innobase_open_files)->default_value(300),
3511
3579
          N_("How many files at the maximum HailDB keeps open at the same time."));
3512
3580
  context("read-io-threads",
3513
 
          po::value<io_threads_constraint>(&haildb_read_io_threads)->default_value(4),
 
3581
          po::value<unsigned long>(&innobase_read_io_threads)->default_value(4),
3514
3582
          N_("Number of background read I/O threads in HailDB."));
3515
3583
  context("write-io-threads",
3516
 
          po::value<io_threads_constraint>(&haildb_write_io_threads)->default_value(4),
 
3584
          po::value<unsigned long>(&innobase_write_io_threads)->default_value(4),
3517
3585
          N_("Number of background write I/O threads in HailDB."));
3518
3586
  context("disable-print-verbose-log",
3519
3587
          N_("Disable if you want to reduce the number of messages written to the log (default: enabled)."));
3521
3589
          po::value<bool>(&innobase_create_status_file)->default_value(false)->zero_tokens(),
3522
3590
          N_("Enable SHOW HAILDB STATUS output in the log"));
3523
3591
  context("sync-spin-loops",
3524
 
          po::value<uint64_constraint>(&haildb_sync_spin_loops)->default_value(30L),
 
3592
          po::value<unsigned long>(&srv_n_spin_wait_rounds)->default_value(30L),
3525
3593
          N_("Count of spin-loop rounds in HailDB mutexes (30 by default)"));
3526
3594
  context("use-internal-malloc",
3527
3595
          N_("Use HailDB's internal memory allocator instead of the OS memory allocator"));
3528
3596
}
3529
3597
 
 
3598
static drizzle_sys_var* innobase_system_variables[]= {
 
3599
  DRIZZLE_SYSVAR(checksums),
 
3600
  DRIZZLE_SYSVAR(data_home_dir),
 
3601
  DRIZZLE_SYSVAR(doublewrite),
 
3602
  DRIZZLE_SYSVAR(io_capacity),
 
3603
  DRIZZLE_SYSVAR(fast_shutdown),
 
3604
  DRIZZLE_SYSVAR(file_per_table),
 
3605
  DRIZZLE_SYSVAR(file_format),
 
3606
  DRIZZLE_SYSVAR(flush_log_at_trx_commit),
 
3607
  DRIZZLE_SYSVAR(flush_method),
 
3608
  DRIZZLE_SYSVAR(force_recovery),
 
3609
  DRIZZLE_SYSVAR(log_group_home_dir),
 
3610
  DRIZZLE_SYSVAR(data_file_path),
 
3611
  DRIZZLE_SYSVAR(lock_wait_timeout),
 
3612
  DRIZZLE_SYSVAR(log_file_size),
 
3613
  DRIZZLE_SYSVAR(log_files_in_group),
 
3614
  DRIZZLE_SYSVAR(log_buffer_size),
 
3615
  DRIZZLE_SYSVAR(lru_old_blocks_pct),
 
3616
  DRIZZLE_SYSVAR(lru_block_access_recency),
 
3617
  DRIZZLE_SYSVAR(max_dirty_pages_pct),
 
3618
  DRIZZLE_SYSVAR(max_purge_lag),
 
3619
  DRIZZLE_SYSVAR(open_files),
 
3620
  DRIZZLE_SYSVAR(read_io_threads),
 
3621
  DRIZZLE_SYSVAR(rollback_on_timeout),
 
3622
  DRIZZLE_SYSVAR(write_io_threads),
 
3623
  DRIZZLE_SYSVAR(print_verbose_log),
 
3624
  DRIZZLE_SYSVAR(status_file),
 
3625
  DRIZZLE_SYSVAR(sync_spin_loops),
 
3626
  DRIZZLE_SYSVAR(use_sys_malloc),
 
3627
  NULL
 
3628
};
 
3629
 
3530
3630
DRIZZLE_DECLARE_PLUGIN
3531
3631
{
3532
3632
  DRIZZLE_VERSION_ID,
3536
3636
  "Transactional Storage Engine using the HailDB Library",
3537
3637
  PLUGIN_LICENSE_GPL,
3538
3638
  haildb_init,     /* Plugin Init */
3539
 
  NULL, /* depends */
 
3639
  innobase_system_variables, /* system variables */
3540
3640
  init_options                /* config options   */
3541
3641
}
3542
3642
DRIZZLE_DECLARE_PLUGIN_END;