~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/haildb/haildb_engine.cc

  • Committer: Brian Aker
  • Date: 2010-10-27 21:00:49 UTC
  • mto: This revision was merged to the branch mainline in revision 1886.
  • Revision ID: brian@tangent.org-20101027210049-zfpgx2cfbrh8maq9
A couple of fixes to documentation.

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)
368
364
                    statement_savepoint_name.length());
369
365
}
370
366
 
371
 
void HailDBEngine::doEndStatement(Session *)
 
367
void HailDBEngine::doEndStatement(Session *session)
372
368
{
 
369
  doCommit(session, false);
373
370
}
374
371
 
375
372
int HailDBEngine::doSetSavepoint(Session* session,
390
387
  err= ib_savepoint_rollback(*transaction, savepoint.getName().c_str(),
391
388
                             savepoint.getName().length());
392
389
 
393
 
  return ib_err_t_to_drizzle_error(session, err);
 
390
  return ib_err_t_to_drizzle_error(err);
394
391
}
395
392
 
396
393
int HailDBEngine::doReleaseSavepoint(Session* session,
402
399
  err= ib_savepoint_release(*transaction, savepoint.getName().c_str(),
403
400
                            savepoint.getName().length());
404
401
  if (err != DB_SUCCESS)
405
 
    return ib_err_t_to_drizzle_error(session, err);
 
402
    return ib_err_t_to_drizzle_error(err);
406
403
 
407
404
  return 0;
408
405
}
412
409
  ib_err_t err;
413
410
  ib_trx_t *transaction= get_trx(session);
414
411
 
415
 
  if (all)
 
412
  if (all || (!session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
416
413
  {
417
414
    err= ib_trx_commit(*transaction);
418
415
 
419
416
    if (err != DB_SUCCESS)
420
 
      return ib_err_t_to_drizzle_error(session, err);
 
417
      return ib_err_t_to_drizzle_error(err);
421
418
 
422
419
    *transaction= NULL;
423
420
  }
430
427
  ib_err_t err;
431
428
  ib_trx_t *transaction= get_trx(session);
432
429
 
433
 
  if (all)
 
430
  if (all || !session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
434
431
  {
435
 
    if (ib_trx_state(*transaction) == IB_TRX_NOT_STARTED)
436
 
      err= ib_trx_release(*transaction);
437
 
    else
438
 
      err= ib_trx_rollback(*transaction);
 
432
    err= ib_trx_rollback(*transaction);
439
433
 
440
434
    if (err != DB_SUCCESS)
441
 
      return ib_err_t_to_drizzle_error(session, err);
 
435
      return ib_err_t_to_drizzle_error(err);
442
436
 
443
437
    *transaction= NULL;
444
438
  }
445
439
  else
446
440
  {
447
 
    if (ib_trx_state(*transaction) == IB_TRX_NOT_STARTED)
448
 
      return 0;
449
 
 
450
441
    err= ib_savepoint_rollback(*transaction, statement_savepoint_name.c_str(),
451
442
                               statement_savepoint_name.length());
452
443
    if (err != DB_SUCCESS)
453
 
      return ib_err_t_to_drizzle_error(session, err);
 
444
      return ib_err_t_to_drizzle_error(err);
454
445
  }
455
446
 
456
447
  return 0;
494
485
  else
495
486
  {
496
487
    assert (err == DB_SUCCESS);
497
 
    err= ib_tuple_read_u64(tuple, getTable()->getShare()->sizeFields(), &nr);
 
488
    err= ib_tuple_read_u64(tuple, getTable()->getShare()->fields, &nr);
498
489
    nr++;
499
490
  }
500
491
  ib_tuple_delete(tuple);
501
 
  tuple= NULL;
502
492
  err= ib_cursor_reset(cursor);
503
493
  assert(err == DB_SUCCESS);
504
494
  return nr;
535
525
  doEndIndexScan();
536
526
  (void) extra(HA_EXTRA_NO_KEYREAD);
537
527
 
538
 
  if (getTable()->getShare()->getTableMessage()->options().auto_increment_value() > nr)
539
 
    nr= getTable()->getShare()->getTableMessage()->options().auto_increment_value();
 
528
  if (getTable()->getShare()->getTableProto()->options().auto_increment_value() > nr)
 
529
    nr= getTable()->getShare()->getTableProto()->options().auto_increment_value();
540
530
 
541
531
  return nr;
542
532
}
649
639
 
650
640
  /* the below is adapted from ha_innodb.cc */
651
641
 
652
 
  const uint32_t sql_command = session->getSqlCommand();
 
642
  const uint32_t sql_command = session_sql_command(session);
653
643
 
654
644
  if (sql_command == SQLCOM_DROP_TABLE) {
655
645
 
680
670
    unexpected if an obsolete consistent read view would be
681
671
    used. */
682
672
 
683
 
    enum_tx_isolation isolation_level= session->getTxIsolation();
 
673
    enum_tx_isolation isolation_level= session_tx_isolation(session);
684
674
 
685
675
    if (isolation_level != ISO_SERIALIZABLE
686
676
        && (lock_type == TL_READ || lock_type == TL_READ_NO_INSERT)
723
713
 
724
714
    if ((lock_type >= TL_WRITE_CONCURRENT_INSERT
725
715
         && lock_type <= TL_WRITE)
726
 
        && ! session->doing_tablespace_operation()
 
716
        && !session_tablespace_op(session)
727
717
        && sql_command != SQLCOM_TRUNCATE
728
718
        && sql_command != SQLCOM_CREATE_TABLE) {
729
719
 
800
790
  return &name[l];
801
791
}
802
792
 
803
 
static void TableIdentifier_to_haildb_name(const identifier::Table &identifier, std::string *str)
 
793
static void TableIdentifier_to_haildb_name(const TableIdentifier &identifier, std::string *str)
804
794
{
805
795
  str->assign(table_path_to_haildb_name(identifier.getPath().c_str()));
806
796
}
829
819
int HailDBCursor::open(const char *name, int, uint32_t)
830
820
{
831
821
  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);
 
822
  ib_err_t err= ib_cursor_open_table(haildb_table_name, NULL, &cursor);
833
823
  bool has_hidden_primary_key= false;
834
824
  ib_id_t idx_id;
835
825
 
836
826
  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);
 
827
    return ib_err_t_to_drizzle_error(err);
844
828
 
845
829
  err= ib_index_get_id(haildb_table_name, "HIDDEN_PRIMARY", &idx_id);
846
830
 
871
855
{
872
856
  ib_err_t err= ib_cursor_close(cursor);
873
857
  if (err != DB_SUCCESS)
874
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
858
    return ib_err_t_to_drizzle_error(err);
875
859
 
876
860
  free_share();
877
861
 
904
888
{
905
889
  ib_col_attr_t column_attr= IB_COL_NONE;
906
890
 
907
 
  if (field.has_constraints() && field.constraints().is_notnull())
 
891
  if (field.has_constraints() && ! field.constraints().is_nullable())
908
892
    column_attr= IB_COL_NOT_NULL;
909
893
 
910
894
  switch (field.type())
935
919
    *err= ib_table_schema_add_col(schema, field.name().c_str(), IB_INT,
936
920
                                  column_attr, 0, 4);
937
921
    break;
938
 
  case message::Table::Field::EPOCH:
 
922
  case message::Table::Field::TIMESTAMP:
939
923
    *err= ib_table_schema_add_col(schema, field.name().c_str(), IB_INT,
940
924
                                  column_attr, 0, 8);
941
925
    break;
1035
1019
 
1036
1020
int HailDBEngine::doCreateTable(Session &session,
1037
1021
                                        Table& table_obj,
1038
 
                                        const drizzled::identifier::Table &identifier,
 
1022
                                        const drizzled::TableIdentifier &identifier,
1039
1023
                                        drizzled::message::Table& table_message)
1040
1024
{
1041
1025
  ib_tbl_sch_t haildb_table_schema= NULL;
1079
1063
                        ER_CANT_CREATE_TABLE,
1080
1064
                        _("Cannot create table %s. HailDB Error %d (%s)\n"),
1081
1065
                        haildb_table_name.c_str(), haildb_err, ib_strerror(haildb_err));
1082
 
    return ib_err_t_to_drizzle_error(&session, haildb_err);
 
1066
    return ib_err_t_to_drizzle_error(haildb_err);
1083
1067
  }
1084
1068
 
1085
1069
  for (int colnr= 0; colnr < table_message.field_size() ; colnr++)
1100
1084
                            " HailDB Error %d (%s)\n"),
1101
1085
                          field.name().c_str(), haildb_table_name.c_str(),
1102
1086
                          haildb_err, ib_strerror(haildb_err));
1103
 
      return ib_err_t_to_drizzle_error(&session, haildb_err);
 
1087
      return ib_err_t_to_drizzle_error(haildb_err);
1104
1088
    }
1105
1089
    if (field_err != 0)
1106
1090
      return field_err;
1225
1209
 
1226
1210
  if (table_message.type() == message::Table::TEMPORARY)
1227
1211
  {
1228
 
    session.getMessageCache().storeTableMessage(identifier, table_message);
 
1212
    session.storeTableMessage(identifier, table_message);
1229
1213
    haildb_err= DB_SUCCESS;
1230
1214
  }
1231
1215
  else
1248
1232
                        _("Cannot create table %s. HailDB Error %d (%s)\n"),
1249
1233
                        haildb_table_name.c_str(),
1250
1234
                        haildb_err, ib_strerror(haildb_err));
1251
 
    return ib_err_t_to_drizzle_error(&session, haildb_err);
 
1235
    return ib_err_t_to_drizzle_error(haildb_err);
1252
1236
  }
1253
1237
 
1254
1238
  return 0;
1291
1275
}
1292
1276
 
1293
1277
int HailDBEngine::doDropTable(Session &session,
1294
 
                                      const identifier::Table &identifier)
 
1278
                                      const TableIdentifier &identifier)
1295
1279
{
1296
1280
  ib_trx_t haildb_schema_transaction;
1297
1281
  ib_err_t haildb_err;
1317
1301
 
1318
1302
  if (identifier.getType() == message::Table::TEMPORARY)
1319
1303
  {
1320
 
      session.getMessageCache().removeTableMessage(identifier);
 
1304
      session.removeTableMessage(identifier);
1321
1305
      delete_table_message_from_haildb(haildb_schema_transaction,
1322
1306
                                       haildb_table_name.c_str());
1323
1307
  }
1373
1357
  return 0;
1374
1358
}
1375
1359
 
1376
 
static ib_err_t rename_table_message(ib_trx_t transaction, const identifier::Table &from_identifier, const identifier::Table &to_identifier)
 
1360
static ib_err_t rename_table_message(ib_trx_t transaction, const TableIdentifier &from_identifier, const TableIdentifier &to_identifier)
1377
1361
{
1378
1362
  ib_crsr_t cursor;
1379
1363
  ib_tpl_t search_tuple;
1464
1448
}
1465
1449
 
1466
1450
int HailDBEngine::doRenameTable(drizzled::Session &session,
1467
 
                                        const drizzled::identifier::Table &from,
1468
 
                                        const drizzled::identifier::Table &to)
 
1451
                                        const drizzled::TableIdentifier &from,
 
1452
                                        const drizzled::TableIdentifier &to)
1469
1453
{
1470
1454
  ib_trx_t haildb_schema_transaction;
1471
1455
  ib_err_t err;
1475
1459
  if (to.getType() == message::Table::TEMPORARY
1476
1460
      && from.getType() == message::Table::TEMPORARY)
1477
1461
  {
1478
 
    session.getMessageCache().renameTableMessage(from, to);
 
1462
    session.renameTableMessage(from, to);
1479
1463
    return 0;
1480
1464
  }
1481
1465
 
1515
1499
  assert(rollback_err == DB_SUCCESS);
1516
1500
  rollback_err= ib_trx_rollback(haildb_schema_transaction);
1517
1501
  assert(rollback_err == DB_SUCCESS);
1518
 
  return ib_err_t_to_drizzle_error(&session, err);
 
1502
  return ib_err_t_to_drizzle_error(err);
1519
1503
}
1520
1504
 
1521
1505
void HailDBEngine::getTableNamesInSchemaFromHailDB(
1522
 
                                 const drizzled::identifier::Schema &schema,
 
1506
                                 const drizzled::SchemaIdentifier &schema,
1523
1507
                                 drizzled::plugin::TableNameList *set_of_names,
1524
 
                                 drizzled::identifier::Table::vector *identifiers)
 
1508
                                 drizzled::TableIdentifiers *identifiers)
1525
1509
{
1526
1510
  ib_trx_t   transaction;
1527
1511
  ib_crsr_t  cursor;
1551
1535
    {
1552
1536
      BOOST_FOREACH(std::string table_name, haildb_system_table_names)
1553
1537
      {
1554
 
        identifiers->push_back(identifier::Table(schema.getSchemaName(),
 
1538
        identifiers->push_back(TableIdentifier(schema.getSchemaName(),
1555
1539
                                               table_name));
1556
1540
      }
1557
1541
    }
1594
1578
      if (set_of_names)
1595
1579
        set_of_names->insert(just_table_name);
1596
1580
      if (identifiers)
1597
 
        identifiers->push_back(identifier::Table(schema.getSchemaName(), just_table_name));
 
1581
        identifiers->push_back(TableIdentifier(schema.getSchemaName(), just_table_name));
1598
1582
    }
1599
1583
 
1600
1584
 
1613
1597
}
1614
1598
 
1615
1599
void HailDBEngine::doGetTableIdentifiers(drizzled::CachedDirectory &,
1616
 
                                                 const drizzled::identifier::Schema &schema,
1617
 
                                                 drizzled::identifier::Table::vector &identifiers)
 
1600
                                                 const drizzled::SchemaIdentifier &schema,
 
1601
                                                 drizzled::TableIdentifiers &identifiers)
1618
1602
{
1619
1603
  getTableNamesInSchemaFromHailDB(schema, NULL, &identifiers);
1620
1604
}
1739
1723
}
1740
1724
 
1741
1725
int HailDBEngine::doGetTableDefinition(Session &session,
1742
 
                                               const identifier::Table &identifier,
 
1726
                                               const TableIdentifier &identifier,
1743
1727
                                               drizzled::message::Table &table)
1744
1728
{
1745
1729
  ib_crsr_t haildb_cursor= NULL;
1746
1730
  string haildb_table_name;
1747
1731
 
1748
1732
  /* Check temporary tables!? */
1749
 
  if (session.getMessageCache().getTableMessage(identifier, table))
 
1733
  if (session.getTableMessage(identifier, table))
1750
1734
    return EEXIST;
1751
1735
 
1752
1736
  TableIdentifier_to_haildb_name(identifier, &haildb_table_name);
1768
1752
}
1769
1753
 
1770
1754
bool HailDBEngine::doDoesTableExist(Session &,
1771
 
                                    const identifier::Table& identifier)
 
1755
                                    const TableIdentifier& identifier)
1772
1756
{
1773
1757
  ib_crsr_t haildb_cursor;
1774
1758
  string haildb_table_name;
1793
1777
  return("BTREE");
1794
1778
}
1795
1779
 
1796
 
static ib_err_t write_row_to_haildb_tuple(const unsigned char* buf,
1797
 
                                          Field **fields, ib_tpl_t tuple)
 
1780
static ib_err_t write_row_to_haildb_tuple(Field **fields, ib_tpl_t tuple)
1798
1781
{
1799
1782
  int colnr= 0;
1800
1783
  ib_err_t err= DB_ERROR;
1801
 
  ptrdiff_t row_offset= buf - (*fields)->getTable()->getInsertRecord();
1802
1784
 
1803
1785
  for (Field **field= fields; *field; field++, colnr++)
1804
1786
  {
1805
 
    (**field).move_field_offset(row_offset);
1806
 
 
1807
1787
    if (! (**field).isWriteSet() && (**field).is_null())
1808
 
    {
1809
 
      (**field).move_field_offset(-row_offset);
1810
1788
      continue;
1811
 
    }
1812
1789
 
1813
1790
    if ((**field).is_null())
1814
1791
    {
1815
1792
      err= ib_col_set_value(tuple, colnr, NULL, IB_SQL_NULL);
1816
1793
      assert(err == DB_SUCCESS);
1817
 
      (**field).move_field_offset(-row_offset);
1818
1794
      continue;
1819
1795
    }
1820
1796
 
1826
1802
      */
1827
1803
      String str;
1828
1804
      (**field).setReadSet();
1829
 
      (**field).val_str_internal(&str);
 
1805
      (**field).val_str(&str);
1830
1806
      err= ib_col_set_value(tuple, colnr, str.ptr(), str.length());
1831
1807
    }
1832
1808
    else if ((**field).type() == DRIZZLE_TYPE_ENUM)
1852
1828
    }
1853
1829
 
1854
1830
    assert (err == DB_SUCCESS);
1855
 
 
1856
 
    (**field).move_field_offset(-row_offset);
1857
1831
  }
1858
1832
 
1859
1833
  return err;
1902
1876
 
1903
1877
  tuple= ib_clust_read_tuple_create(cursor);
1904
1878
 
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
 
  }
 
1879
  ib_cursor_attach_trx(cursor, transaction);
1921
1880
 
1922
1881
  err= ib_cursor_first(cursor);
1923
1882
  if (current_session->lex->sql_command == SQLCOM_CREATE_TABLE
1976
1935
 
1977
1936
  }
1978
1937
 
1979
 
  write_row_to_haildb_tuple(record, getTable()->getFields(), tuple);
 
1938
  write_row_to_haildb_tuple(getTable()->getFields(), tuple);
1980
1939
 
1981
1940
  if (share->has_hidden_primary_key)
1982
1941
  {
1983
 
    err= ib_tuple_write_u64(tuple, getTable()->getShare()->sizeFields(),
1984
 
                            share->hidden_pkey_auto_increment_value.fetch_and_increment());
 
1942
    err= ib_tuple_write_u64(tuple, getTable()->getShare()->fields, share->hidden_pkey_auto_increment_value.fetch_and_increment());
1985
1943
  }
1986
1944
 
1987
1945
  err= ib_cursor_insert_row(cursor, tuple);
2010
1968
      err= ib_cursor_first(cursor);
2011
1969
      assert(err == DB_SUCCESS || err == DB_END_OF_INDEX);
2012
1970
 
2013
 
      write_row_to_haildb_tuple(record, getTable()->getFields(), tuple);
 
1971
      write_row_to_haildb_tuple(getTable()->getFields(), tuple);
2014
1972
 
2015
1973
      err= ib_cursor_insert_row(cursor, tuple);
2016
1974
      assert(err==DB_SUCCESS); // probably be nice and process errors
2019
1977
      ret= HA_ERR_FOUND_DUPP_KEY;
2020
1978
  }
2021
1979
  else if (err != DB_SUCCESS)
2022
 
    ret= ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
1980
    ret= ib_err_t_to_drizzle_error(err);
2023
1981
 
2024
1982
  tuple= ib_tuple_clear(tuple);
2025
1983
  ib_tuple_delete(tuple);
2026
 
  tuple= NULL;
2027
1984
  err= ib_cursor_reset(cursor);
2028
1985
 
2029
1986
  return ret;
2030
1987
}
2031
1988
 
2032
 
int HailDBCursor::doUpdateRecord(const unsigned char *old_data,
2033
 
                                 unsigned char *new_data)
 
1989
int HailDBCursor::doUpdateRecord(const unsigned char *,
 
1990
                                         unsigned char *)
2034
1991
{
2035
1992
  ib_tpl_t update_tuple;
2036
1993
  ib_err_t err;
2037
 
  bool created_tuple= false;
2038
1994
 
2039
1995
  update_tuple= ib_clust_read_tuple_create(cursor);
2040
1996
 
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
1997
  err= ib_tuple_copy(update_tuple, tuple);
2086
1998
  assert(err == DB_SUCCESS);
2087
1999
 
2088
 
  write_row_to_haildb_tuple(new_data, getTable()->getFields(), update_tuple);
 
2000
  write_row_to_haildb_tuple(getTable()->getFields(), update_tuple);
2089
2001
 
2090
2002
  err= ib_cursor_update_row(cursor, tuple, update_tuple);
2091
2003
 
2092
2004
  ib_tuple_delete(update_tuple);
2093
2005
 
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
2006
  advance_cursor= true;
2104
2007
 
2105
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2008
  if (err == DB_SUCCESS)
 
2009
    return 0;
 
2010
  else if (err == DB_DUPLICATE_KEY)
 
2011
    return HA_ERR_FOUND_DUPP_KEY;
 
2012
  else
 
2013
    return -1;
2106
2014
}
2107
2015
 
2108
2016
int HailDBCursor::doDeleteRecord(const unsigned char *)
2109
2017
{
2110
2018
  ib_err_t err;
2111
2019
 
2112
 
  assert(ib_cursor_is_positioned(cursor) == IB_TRUE);
2113
2020
  err= ib_cursor_delete_row(cursor);
 
2021
  if (err != DB_SUCCESS)
 
2022
    return -1; // FIXME
2114
2023
 
2115
2024
  advance_cursor= true;
2116
 
 
2117
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2025
  return 0;
2118
2026
}
2119
2027
 
2120
2028
int HailDBCursor::delete_all_rows(void)
2121
2029
{
2122
2030
  /* I *think* ib_truncate is non-transactional....
2123
2031
     so only support TRUNCATE and not DELETE FROM t;
2124
 
     (this is what ha_innodb does)
 
2032
     (this is what ha_haildb does)
2125
2033
  */
2126
 
  if (getTable()->in_use->getSqlCommand() != SQLCOM_TRUNCATE)
 
2034
  if (session_sql_command(getTable()->in_use) != SQLCOM_TRUNCATE)
2127
2035
    return HA_ERR_WRONG_COMMAND;
2128
2036
 
2129
2037
  ib_id_t id;
2131
2039
 
2132
2040
  ib_trx_t transaction= ib_trx_begin(IB_TRX_REPEATABLE_READ);
2133
2041
 
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
 
  }
 
2042
  ib_cursor_attach_trx(cursor, transaction);
2149
2043
 
2150
2044
  err= ib_schema_lock_exclusive(transaction);
2151
2045
  if (err != DB_SUCCESS)
2181
2075
  ib_schema_unlock(transaction);
2182
2076
  ib_err_t rollback_err= ib_trx_rollback(transaction);
2183
2077
  assert(rollback_err == DB_SUCCESS);
2184
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2078
  return err;
2185
2079
}
2186
2080
 
2187
2081
int HailDBCursor::doStartTableScan(bool)
2188
2082
{
2189
 
  ib_err_t err= DB_SUCCESS;
 
2083
  ib_err_t err;
2190
2084
  ib_trx_t transaction;
2191
2085
 
2192
2086
  if (in_table_scan)
2197
2091
 
2198
2092
  assert(transaction != NULL);
2199
2093
 
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);
 
2094
  ib_cursor_attach_trx(cursor, transaction);
2215
2095
 
2216
2096
  err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
2217
2097
  assert(err == DB_SUCCESS); // FIXME
2221
2101
  err= ib_cursor_first(cursor);
2222
2102
  if (err != DB_SUCCESS && err != DB_END_OF_INDEX)
2223
2103
  {
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);
 
2104
    previous_error= ib_err_t_to_drizzle_error(err);
 
2105
    err= ib_cursor_reset(cursor);
 
2106
    return previous_error;
2227
2107
  }
2228
2108
 
2229
2109
  advance_cursor= false;
2230
2110
 
 
2111
  previous_error= 0;
2231
2112
  return(0);
2232
2113
}
2233
2114
 
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)
 
2115
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
2116
{
2236
2117
  ib_err_t err;
2237
2118
  ptrdiff_t row_offset= buf - table->getInsertRecord();
2238
2119
 
2239
2120
  err= ib_cursor_read_row(cursor, tuple);
2240
2121
 
2241
 
  if (err == DB_RECORD_NOT_FOUND)
 
2122
  if (err != DB_SUCCESS) // FIXME
2242
2123
    return HA_ERR_END_OF_FILE;
2243
 
  if (err != DB_SUCCESS)
2244
 
    return ib_err_t_to_drizzle_error(session, err);
2245
2124
 
2246
2125
  int colnr= 0;
2247
2126
 
2252
2131
  for (Field **field= table->getFields() ; *field ; field++, colnr++)
2253
2132
  {
2254
2133
    if (! (**field).isReadSet())
2255
 
      (**field).setReadSet(); /* Fucking broken API screws us royally. */
 
2134
      continue;
2256
2135
 
2257
2136
    (**field).move_field_offset(row_offset);
2258
2137
 
2262
2141
    if (length == IB_SQL_NULL)
2263
2142
    {
2264
2143
      (**field).set_null();
2265
 
      (**field).move_field_offset(-row_offset);
2266
2144
      continue;
2267
2145
    }
2268
2146
    else
2306
2184
 
2307
2185
    (**field).move_field_offset(-row_offset);
2308
2186
 
2309
 
    if (err != DB_SUCCESS)
2310
 
      return ib_err_t_to_drizzle_error(session, err);
2311
2187
  }
2312
2188
 
2313
2189
  if (has_hidden_primary_key)
2315
2191
    err= ib_tuple_read_u64(tuple, colnr, hidden_pkey);
2316
2192
  }
2317
2193
 
2318
 
  return ib_err_t_to_drizzle_error(session, err);
 
2194
  return 0;
2319
2195
}
2320
2196
 
2321
2197
int HailDBCursor::rnd_next(unsigned char *buf)
2323
2199
  ib_err_t err;
2324
2200
  int ret;
2325
2201
 
 
2202
  if (previous_error)
 
2203
    return previous_error;
 
2204
 
2326
2205
  if (advance_cursor)
2327
 
  {
2328
2206
    err= ib_cursor_next(cursor);
2329
 
    if (err != DB_SUCCESS)
2330
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2331
 
  }
2332
2207
 
2333
2208
  tuple= ib_tuple_clear(tuple);
2334
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2335
 
                            getTable(),
 
2209
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2336
2210
                            share->has_hidden_primary_key,
2337
2211
                            &hidden_autoinc_pkey_position);
2338
2212
 
2345
2219
  ib_err_t err;
2346
2220
 
2347
2221
  ib_tuple_delete(tuple);
2348
 
  tuple= NULL;
2349
2222
  err= ib_cursor_reset(cursor);
2350
2223
  assert(err == DB_SUCCESS);
2351
2224
  in_table_scan= false;
2352
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2225
  previous_error= 0;
 
2226
  return 0;
2353
2227
}
2354
2228
 
2355
2229
int HailDBCursor::rnd_pos(unsigned char *buf, unsigned char *pos)
2363
2237
  {
2364
2238
    err= ib_col_set_value(search_tuple, 0,
2365
2239
                          ((uint64_t*)(pos)), sizeof(uint64_t));
2366
 
    if (err != DB_SUCCESS)
2367
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2368
2240
  }
2369
2241
  else
2370
2242
  {
2380
2252
  }
2381
2253
 
2382
2254
  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);
 
2255
  assert(err == DB_SUCCESS);
2385
2256
 
2386
2257
  assert(res==0);
2387
2258
  if (res != 0)
2392
2263
  tuple= ib_tuple_clear(tuple);
2393
2264
 
2394
2265
  if (ret == 0)
2395
 
    ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2396
 
                              getTable(),
 
2266
    ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2397
2267
                              share->has_hidden_primary_key,
2398
2268
                              &hidden_autoinc_pkey_position);
2399
2269
 
2431
2301
      }
2432
2302
 
2433
2303
      String str;
2434
 
      field->val_str_internal(&str);
 
2304
      field->val_str(&str);
2435
2305
 
2436
2306
      *ref++= (char)(str.length() & 0x000000ff);
2437
2307
      *ref++= (char)((str.length()>>8) & 0x000000ff);
2510
2380
 
2511
2381
  if (flag & HA_STATUS_AUTO)
2512
2382
    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
2383
  return(0);
2576
2384
}
2577
2385
 
2578
2386
int HailDBCursor::doStartIndexScan(uint32_t keynr, bool)
2579
2387
{
2580
 
  ib_err_t err;
2581
2388
  ib_trx_t transaction= *get_trx(getTable()->in_use);
2582
2389
 
2583
2390
  active_index= keynr;
2584
2391
 
 
2392
  ib_cursor_attach_trx(cursor, transaction);
 
2393
 
2585
2394
  if (active_index == 0 && ! share->has_hidden_primary_key)
2586
2395
  {
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
2396
    tuple= ib_clust_read_tuple_create(cursor);
2605
2397
  }
2606
2398
  else
2607
2399
  {
 
2400
    ib_err_t err;
2608
2401
    ib_id_t index_id;
2609
2402
    err= ib_index_get_id(table_path_to_haildb_name(getShare()->getPath()),
2610
2403
                         getShare()->getKeyInfo(keynr).name,
2611
2404
                         &index_id);
2612
2405
    if (err != DB_SUCCESS)
2613
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2406
      return -1;
2614
2407
 
2615
2408
    err= ib_cursor_close(cursor);
2616
2409
    assert(err == DB_SUCCESS);
2617
 
 
2618
2410
    err= ib_cursor_open_index_using_id(index_id, transaction, &cursor);
2619
2411
 
2620
2412
    if (err != DB_SUCCESS)
2621
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2622
 
 
2623
 
    cursor_is_sec_index= true;
 
2413
      return -1;
2624
2414
 
2625
2415
    tuple= ib_clust_read_tuple_create(cursor);
2626
2416
    ib_cursor_set_cluster_access(cursor);
2627
2417
  }
2628
2418
 
2629
 
  err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
 
2419
  ib_err_t err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
2630
2420
  assert(err == DB_SUCCESS);
2631
2421
 
2632
2422
  advance_cursor= false;
2771
2561
 
2772
2562
  if (err != DB_SUCCESS)
2773
2563
  {
2774
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2564
    return ib_err_t_to_drizzle_error(err);
2775
2565
  }
2776
2566
 
2777
2567
  tuple= ib_tuple_clear(tuple);
2778
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2779
 
                            getTable(),
 
2568
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2780
2569
                            share->has_hidden_primary_key,
2781
2570
                            &hidden_autoinc_pkey_position,
2782
2571
                            (allocate_blobs)? &blobroot : NULL);
2853
2642
  return 0;
2854
2643
}
2855
2644
 
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
2645
int HailDBCursor::index_next(unsigned char *buf)
2866
2646
{
2867
2647
  int ret= HA_ERR_END_OF_FILE;
2874
2654
  }
2875
2655
 
2876
2656
  tuple= ib_tuple_clear(tuple);
2877
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2878
 
                            getTable(),
 
2657
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2879
2658
                            share->has_hidden_primary_key,
2880
2659
                            &hidden_autoinc_pkey_position);
2881
2660
 
2903
2682
      if (err == DB_END_OF_INDEX)
2904
2683
        return HA_ERR_END_OF_FILE;
2905
2684
      else
2906
 
        return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2685
        return -1; // FIXME
2907
2686
    }
2908
2687
  }
2909
2688
 
2910
2689
  tuple= ib_tuple_clear(tuple);
2911
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2912
 
                            getTable(),
 
2690
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2913
2691
                            share->has_hidden_primary_key,
2914
2692
                            &hidden_autoinc_pkey_position);
2915
2693
 
2926
2704
 
2927
2705
  err= ib_cursor_first(cursor);
2928
2706
  if (err != DB_SUCCESS)
2929
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2707
    return ib_err_t_to_drizzle_error(err);
2930
2708
 
2931
2709
  tuple= ib_tuple_clear(tuple);
2932
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2933
 
                            getTable(),
 
2710
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2934
2711
                            share->has_hidden_primary_key,
2935
2712
                            &hidden_autoinc_pkey_position);
2936
2713
 
2947
2724
 
2948
2725
  err= ib_cursor_last(cursor);
2949
2726
  if (err != DB_SUCCESS)
2950
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2727
    return ib_err_t_to_drizzle_error(err);
2951
2728
 
2952
2729
  tuple= ib_tuple_clear(tuple);
2953
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2954
 
                            getTable(),
 
2730
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2955
2731
                            share->has_hidden_primary_key,
2956
2732
                            &hidden_autoinc_pkey_position);
2957
2733
  advance_cursor= true;
3043
2819
  return err;
3044
2820
}
3045
2821
 
 
2822
static bool  innobase_use_checksums= true;
 
2823
static char*  innobase_data_home_dir      = NULL;
 
2824
static char*  innobase_log_group_home_dir   = NULL;
3046
2825
static bool innobase_use_doublewrite= true;
 
2826
static unsigned long srv_io_capacity= 200;
 
2827
static unsigned long innobase_fast_shutdown= 1;
3047
2828
static bool srv_file_per_table= false;
3048
2829
static bool innobase_adaptive_hash_index;
3049
2830
static bool srv_adaptive_flushing;
3051
2832
static bool innobase_rollback_on_timeout;
3052
2833
static bool innobase_create_status_file;
3053
2834
static bool srv_use_sys_malloc;
3054
 
static string innobase_file_format_name;
3055
 
typedef constrained_check<unsigned int, 1000, 1> autoextend_constraint;
3056
 
static autoextend_constraint srv_auto_extend_increment;
3057
 
typedef constrained_check<size_t, SIZE_MAX, 5242880, 1048576> buffer_pool_constraint;
3058
 
static buffer_pool_constraint innobase_buffer_pool_size;
3059
 
typedef constrained_check<size_t, SIZE_MAX, 512, 1024> additional_mem_pool_constraint;
3060
 
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
 
}
 
2835
static char*  innobase_file_format_name   = const_cast<char *>("Barracuda");
 
2836
static char*  innobase_unix_file_flush_method   = NULL;
 
2837
static unsigned long srv_flush_log_at_trx_commit;
 
2838
static unsigned long srv_max_buf_pool_modified_pct;
 
2839
static unsigned long srv_max_purge_lag;
 
2840
static unsigned long innobase_lru_old_blocks_pct;
 
2841
static unsigned long innobase_lru_block_access_recency;
 
2842
static unsigned long innobase_read_io_threads;
 
2843
static unsigned long innobase_write_io_threads;
 
2844
static unsigned int srv_auto_extend_increment;
 
2845
static unsigned long innobase_lock_wait_timeout;
 
2846
static unsigned long srv_n_spin_wait_rounds;
 
2847
static int64_t innobase_buffer_pool_size;
 
2848
static long innobase_open_files;
 
2849
static long innobase_additional_mem_pool_size;
 
2850
static long innobase_force_recovery;
 
2851
static long innobase_log_buffer_size;
 
2852
static char  default_haildb_data_file_path[]= "ibdata1:10M:autoextend";
 
2853
static char* haildb_data_file_path= NULL;
 
2854
 
 
2855
static int64_t haildb_log_file_size;
 
2856
static int64_t haildb_log_files_in_group;
3159
2857
 
3160
2858
static int haildb_init(drizzled::module::Context &context)
3161
2859
{
3177
2875
  innobase_print_verbose_log= (vm.count("disable-print-verbose-log")) ? false : true;
3178
2876
  srv_use_sys_malloc= (vm.count("use-internal-malloc")) ? false : true;
3179
2877
 
 
2878
  if (vm.count("additional-mem-pool-size"))
 
2879
  {
 
2880
    if (innobase_additional_mem_pool_size > LONG_MAX || innobase_additional_mem_pool_size < 512*1024L)
 
2881
    {
 
2882
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of additional-mem-pool-size"));
 
2883
      exit(-1);
 
2884
    }
 
2885
    innobase_additional_mem_pool_size/= 1024;
 
2886
    innobase_additional_mem_pool_size*= 1024;
 
2887
  }
 
2888
 
 
2889
  if (vm.count("autoextend-increment"))
 
2890
  {
 
2891
    if (srv_auto_extend_increment > 1000L || srv_auto_extend_increment < 1L)
 
2892
    {
 
2893
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of autoextend-increment"));
 
2894
      exit(-1);
 
2895
    }
 
2896
  }
 
2897
 
 
2898
  if (vm.count("buffer-pool-size"))
 
2899
  {
 
2900
    if (innobase_buffer_pool_size > INT64_MAX || innobase_buffer_pool_size < 5*1024*1024L)
 
2901
    {
 
2902
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of buffer-pool-size"));
 
2903
      exit(-1);
 
2904
    }
 
2905
    innobase_buffer_pool_size/= 1024*1024L;
 
2906
    innobase_buffer_pool_size*= 1024*1024L;
 
2907
  }
 
2908
 
 
2909
  if (vm.count("io-capacity"))
 
2910
  {
 
2911
    if (srv_io_capacity > (unsigned long)~0L || srv_io_capacity < 100)
 
2912
    {
 
2913
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of io-capacity"));
 
2914
      exit(-1);
 
2915
    }
 
2916
  }
 
2917
 
 
2918
  if (vm.count("fast-shutdown"))
 
2919
  {
 
2920
    if (innobase_fast_shutdown > 2)
 
2921
    {
 
2922
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of fast-shutdown"));
 
2923
      exit(-1);
 
2924
    }
 
2925
  }
 
2926
 
 
2927
  if (vm.count("flush-log-at-trx-commit"))
 
2928
  {
 
2929
    if (srv_flush_log_at_trx_commit > 2)
 
2930
    {
 
2931
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of flush-log-at-trx-commit"));
 
2932
      exit(-1);
 
2933
    }
 
2934
  }
 
2935
 
 
2936
  if (vm.count("force-recovery"))
 
2937
  {
 
2938
    if (innobase_force_recovery > 6)
 
2939
    {
 
2940
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of force-recovery"));
 
2941
      exit(-1);
 
2942
    }
 
2943
  }
 
2944
 
 
2945
  if (vm.count("log-file-size"))
 
2946
  {
 
2947
    if (haildb_log_file_size > INT64_MAX || haildb_log_file_size < 1*1024*1024L)
 
2948
    {
 
2949
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of log-file-size"));
 
2950
      exit(-1);
 
2951
    }
 
2952
    haildb_log_file_size/= 1024*1024L;
 
2953
    haildb_log_file_size*= 1024*1024L;
 
2954
  }
 
2955
 
 
2956
  if (vm.count("log-files-in-group"))
 
2957
  {
 
2958
    if (haildb_log_files_in_group > 100 || haildb_log_files_in_group < 2)
 
2959
    {
 
2960
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of log-files-in-group"));
 
2961
      exit(-1);
 
2962
    }
 
2963
  }
 
2964
 
 
2965
  if (vm.count("lock-wait-timeout"))
 
2966
  {
 
2967
    if (innobase_lock_wait_timeout > 1024*1024*1024 || innobase_lock_wait_timeout < 1)
 
2968
    {
 
2969
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of lock-wait-timeout"));
 
2970
      exit(-1);
 
2971
    }
 
2972
  }
 
2973
 
 
2974
  if (vm.count("log-buffer-size"))
 
2975
  {
 
2976
    if (innobase_log_buffer_size > LONG_MAX || innobase_log_buffer_size < 256*1024L)
 
2977
    {
 
2978
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of log-buffer-size"));
 
2979
      exit(-1);
 
2980
    }
 
2981
    innobase_log_buffer_size/= 1024;
 
2982
    innobase_log_buffer_size*= 1024;
 
2983
  }
 
2984
 
 
2985
  if (vm.count("lru-old-blocks-pct"))
 
2986
  {
 
2987
    if (innobase_lru_old_blocks_pct > 95 || innobase_lru_old_blocks_pct < 5)
 
2988
    {
 
2989
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of lru-old-blocks-pct"));
 
2990
      exit(-1);
 
2991
    }
 
2992
  }
 
2993
 
 
2994
  if (vm.count("lru-block-access-recency"))
 
2995
  {
 
2996
    if (innobase_lru_block_access_recency > ULONG_MAX)
 
2997
    {
 
2998
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of lru-block-access-recency"));
 
2999
      exit(-1);
 
3000
    }
 
3001
  }
 
3002
 
 
3003
  if (vm.count("max-dirty-pages-pct"))
 
3004
  {
 
3005
    if (srv_max_buf_pool_modified_pct > 99)
 
3006
    {
 
3007
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of max-dirty-pages-pct"));
 
3008
      exit(-1);
 
3009
    }
 
3010
  }
 
3011
 
 
3012
  if (vm.count("max-purge-lag"))
 
3013
  {
 
3014
    if (srv_max_purge_lag > (unsigned long)~0L)
 
3015
    {
 
3016
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of max-purge-lag"));
 
3017
      exit(-1);
 
3018
    }
 
3019
  }
 
3020
 
 
3021
  if (vm.count("open-files"))
 
3022
  {
 
3023
    if (innobase_open_files > LONG_MAX || innobase_open_files < 10L)
 
3024
    {
 
3025
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of open-files"));
 
3026
      exit(-1);
 
3027
    }
 
3028
  }
 
3029
 
 
3030
  if (vm.count("read-io-threads"))
 
3031
  {
 
3032
    if (innobase_read_io_threads > 64 || innobase_read_io_threads < 1)
 
3033
    {
 
3034
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of read-io-threads"));
 
3035
      exit(-1);
 
3036
    }
 
3037
  }
 
3038
 
 
3039
  if (vm.count("sync-spin-loops"))
 
3040
  {
 
3041
    if (srv_n_spin_wait_rounds > (unsigned long)~0L)
 
3042
    {
 
3043
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of sync_spin_loops"));
 
3044
      exit(-1);
 
3045
    }
 
3046
  }
 
3047
 
 
3048
  if (vm.count("data-home-dir"))
 
3049
  {
 
3050
    innobase_data_home_dir= const_cast<char *>(vm["data-home-dir"].as<string>().c_str());
 
3051
  }
 
3052
 
 
3053
  if (vm.count("file-format"))
 
3054
  {
 
3055
    innobase_file_format_name= const_cast<char *>(vm["file-format"].as<string>().c_str());
 
3056
  }
 
3057
 
 
3058
  if (vm.count("log-group-home-dir"))
 
3059
  {
 
3060
    innobase_log_group_home_dir= const_cast<char *>(vm["log-group-home-dir"].as<string>().c_str());
 
3061
  }
 
3062
 
 
3063
  if (vm.count("flush-method"))
 
3064
  {
 
3065
    innobase_unix_file_flush_method= const_cast<char *>(vm["flush-method"].as<string>().c_str());
 
3066
  }
 
3067
 
 
3068
  if (vm.count("data-file-path"))
 
3069
  {
 
3070
    haildb_data_file_path= const_cast<char *>(vm["data-file-path"].as<string>().c_str());
 
3071
  }
3180
3072
 
3181
3073
  ib_err_t err;
3182
3074
 
3184
3076
  if (err != DB_SUCCESS)
3185
3077
    goto haildb_error;
3186
3078
 
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
 
  }
 
3079
  if (innobase_data_home_dir)
 
3080
  {
 
3081
    err= ib_cfg_set_text("data_home_dir", innobase_data_home_dir);
 
3082
    if (err != DB_SUCCESS)
 
3083
      goto haildb_error;
 
3084
  }
 
3085
 
 
3086
  if (innobase_log_group_home_dir)
 
3087
  {
 
3088
    err= ib_cfg_set_text("log_group_home_dir", innobase_log_group_home_dir);
 
3089
    if (err != DB_SUCCESS)
 
3090
      goto haildb_error;
 
3091
  }
 
3092
 
 
3093
  if (haildb_data_file_path == NULL)
 
3094
    haildb_data_file_path= default_haildb_data_file_path;
3202
3095
 
3203
3096
  if (innobase_print_verbose_log)
3204
3097
    err= ib_cfg_set_bool_on("print_verbose_log");
3240
3133
  if (err != DB_SUCCESS)
3241
3134
    goto haildb_error;
3242
3135
 
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());
 
3136
  err= ib_cfg_set_int("additional_mem_pool_size", innobase_additional_mem_pool_size);
 
3137
  if (err != DB_SUCCESS)
 
3138
    goto haildb_error;
 
3139
 
 
3140
  err= ib_cfg_set_int("autoextend_increment", srv_auto_extend_increment);
 
3141
  if (err != DB_SUCCESS)
 
3142
    goto haildb_error;
 
3143
 
 
3144
  err= ib_cfg_set_int("buffer_pool_size", innobase_buffer_pool_size);
 
3145
  if (err != DB_SUCCESS)
 
3146
    goto haildb_error;
 
3147
 
 
3148
  err= ib_cfg_set_int("io_capacity", srv_io_capacity);
3256
3149
  if (err != DB_SUCCESS)
3257
3150
    goto haildb_error;
3258
3151
 
3264
3157
  if (err != DB_SUCCESS)
3265
3158
    goto haildb_error;
3266
3159
 
3267
 
  err= ib_cfg_set_int("flush_log_at_trx_commit",
3268
 
                      srv_flush_log_at_trx_commit.get());
 
3160
  err= ib_cfg_set_int("flush_log_at_trx_commit", srv_flush_log_at_trx_commit);
3269
3161
  if (err != DB_SUCCESS)
3270
3162
    goto haildb_error;
3271
3163
 
3272
 
  if (vm.count("flush-method") != 0)
 
3164
  if (innobase_unix_file_flush_method)
3273
3165
  {
3274
 
    err= ib_cfg_set_text("flush_method", 
3275
 
                         vm["flush-method"].as<string>().c_str());
 
3166
    err= ib_cfg_set_text("flush_method", innobase_unix_file_flush_method);
3276
3167
    if (err != DB_SUCCESS)
3277
3168
      goto haildb_error;
3278
3169
  }
3279
3170
 
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());
 
3171
  err= ib_cfg_set_int("force_recovery", innobase_force_recovery);
 
3172
  if (err != DB_SUCCESS)
 
3173
    goto haildb_error;
 
3174
 
 
3175
  err= ib_cfg_set_text("data_file_path", haildb_data_file_path);
 
3176
  if (err != DB_SUCCESS)
 
3177
    goto haildb_error;
 
3178
 
 
3179
  err= ib_cfg_set_int("log_file_size", haildb_log_file_size);
 
3180
  if (err != DB_SUCCESS)
 
3181
    goto haildb_error;
 
3182
 
 
3183
  err= ib_cfg_set_int("log_buffer_size", innobase_log_buffer_size);
 
3184
  if (err != DB_SUCCESS)
 
3185
    goto haildb_error;
 
3186
 
 
3187
  err= ib_cfg_set_int("log_files_in_group", haildb_log_files_in_group);
3298
3188
  if (err != DB_SUCCESS)
3299
3189
    goto haildb_error;
3300
3190
 
3302
3192
  if (err != DB_SUCCESS)
3303
3193
    goto haildb_error;
3304
3194
 
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());
 
3195
  err= ib_cfg_set_int("lock_wait_timeout", innobase_lock_wait_timeout);
 
3196
  if (err != DB_SUCCESS)
 
3197
    goto haildb_error;
 
3198
 
 
3199
  err= ib_cfg_set_int("max_dirty_pages_pct", srv_max_buf_pool_modified_pct);
 
3200
  if (err != DB_SUCCESS)
 
3201
    goto haildb_error;
 
3202
 
 
3203
  err= ib_cfg_set_int("max_purge_lag", srv_max_purge_lag);
 
3204
  if (err != DB_SUCCESS)
 
3205
    goto haildb_error;
 
3206
 
 
3207
  err= ib_cfg_set_int("open_files", innobase_open_files);
 
3208
  if (err != DB_SUCCESS)
 
3209
    goto haildb_error;
 
3210
 
 
3211
  err= ib_cfg_set_int("read_io_threads", innobase_read_io_threads);
 
3212
  if (err != DB_SUCCESS)
 
3213
    goto haildb_error;
 
3214
 
 
3215
  err= ib_cfg_set_int("write_io_threads", innobase_write_io_threads);
 
3216
  if (err != DB_SUCCESS)
 
3217
    goto haildb_error;
 
3218
 
 
3219
  err= ib_cfg_set_int("sync_spin_loops", srv_n_spin_wait_rounds);
3330
3220
  if (err != DB_SUCCESS)
3331
3221
    goto haildb_error;
3332
3222
 
3338
3228
  if (err != DB_SUCCESS)
3339
3229
    goto haildb_error;
3340
3230
 
3341
 
  err= ib_startup(innobase_file_format_name.c_str());
 
3231
  err= ib_startup(innobase_file_format_name);
3342
3232
  if (err != DB_SUCCESS)
3343
3233
    goto haildb_error;
3344
3234
 
3346
3236
 
3347
3237
  haildb_engine= new HailDBEngine("InnoDB");
3348
3238
  context.add(haildb_engine);
3349
 
  context.registerVariable(new sys_var_bool_ptr_readonly("adaptive_hash_index",
3350
 
                                                         &innobase_adaptive_hash_index));
3351
 
  context.registerVariable(new sys_var_bool_ptr_readonly("adaptive_flushing",
3352
 
                                                         &srv_adaptive_flushing));
3353
 
  context.registerVariable(new sys_var_constrained_value_readonly<size_t>("additional_mem_pool_size",innobase_additional_mem_pool_size));
3354
 
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("autoextend_increment", srv_auto_extend_increment));
3355
 
  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
3239
 
3401
3240
  haildb_datadict_dump_func_initialize(context);
3402
3241
  config_table_function_initialize(context);
3415
3254
  ib_err_t err;
3416
3255
  ib_shutdown_t shutdown_flag= IB_SHUTDOWN_NORMAL;
3417
3256
 
3418
 
  if (innobase_fast_shutdown.get() == 1)
 
3257
  if (innobase_fast_shutdown == 1)
3419
3258
    shutdown_flag= IB_SHUTDOWN_NO_IBUFMERGE_PURGE;
3420
 
  else if (innobase_fast_shutdown.get() == 2)
 
3259
  else if (innobase_fast_shutdown == 2)
3421
3260
    shutdown_flag= IB_SHUTDOWN_NO_BUFPOOL_FLUSH;
3422
3261
 
3423
3262
  err= ib_shutdown(shutdown_flag);
3429
3268
 
3430
3269
}
3431
3270
 
 
3271
static char haildb_file_format_name_storage[100];
 
3272
 
 
3273
static int haildb_file_format_name_validate(Session*, drizzle_sys_var*,
 
3274
                                            void *save,
 
3275
                                            drizzle_value *value)
 
3276
{
 
3277
  ib_err_t err;
 
3278
  char buff[100];
 
3279
  int len= sizeof(buff);
 
3280
  const char *format= value->val_str(value, buff, &len);
 
3281
 
 
3282
  *static_cast<const char**>(save)= NULL;
 
3283
 
 
3284
  if (format == NULL)
 
3285
    return 1;
 
3286
 
 
3287
  err= ib_cfg_set_text("file_format", format);
 
3288
 
 
3289
  if (err == DB_SUCCESS)
 
3290
  {
 
3291
    strncpy(haildb_file_format_name_storage, format, sizeof(haildb_file_format_name_storage));;
 
3292
    haildb_file_format_name_storage[sizeof(haildb_file_format_name_storage)-1]= 0;
 
3293
 
 
3294
    *static_cast<const char**>(save)= haildb_file_format_name_storage;
 
3295
    return 0;
 
3296
  }
 
3297
  else
 
3298
    return 1;
 
3299
}
 
3300
 
 
3301
static void haildb_file_format_name_update(Session*, drizzle_sys_var*,
 
3302
                                           void *var_ptr,
 
3303
                                           const void *save)
 
3304
 
 
3305
{
 
3306
  const char* format;
 
3307
 
 
3308
  assert(var_ptr != NULL);
 
3309
  assert(save != NULL);
 
3310
 
 
3311
  format= *static_cast<const char*const*>(save);
 
3312
 
 
3313
  /* Format is already set in validate */
 
3314
  memmove(haildb_file_format_name_storage, format, sizeof(haildb_file_format_name_storage));;
 
3315
  haildb_file_format_name_storage[sizeof(haildb_file_format_name_storage)-1]= 0;
 
3316
 
 
3317
  *static_cast<const char**>(var_ptr)= haildb_file_format_name_storage;
 
3318
}
 
3319
 
 
3320
static void haildb_lru_old_blocks_pct_update(Session*, drizzle_sys_var*,
 
3321
                                             void *,
 
3322
                                             const void *save)
 
3323
 
 
3324
{
 
3325
  unsigned long pct;
 
3326
 
 
3327
  pct= *static_cast<const unsigned long*>(save);
 
3328
 
 
3329
  ib_err_t err= ib_cfg_set_int("lru_old_blocks_pct", pct);
 
3330
  if (err == DB_SUCCESS)
 
3331
    innobase_lru_old_blocks_pct= pct;
 
3332
}
 
3333
 
 
3334
static void haildb_lru_block_access_recency_update(Session*, drizzle_sys_var*,
 
3335
                                                   void *,
 
3336
                                                   const void *save)
 
3337
 
 
3338
{
 
3339
  unsigned long ms;
 
3340
 
 
3341
  ms= *static_cast<const unsigned long*>(save);
 
3342
 
 
3343
  ib_err_t err= ib_cfg_set_int("lru_block_access_recency", ms);
 
3344
 
 
3345
  if (err == DB_SUCCESS)
 
3346
    innobase_lru_block_access_recency= ms;
 
3347
}
 
3348
 
 
3349
static void haildb_status_file_update(Session*, drizzle_sys_var*,
 
3350
                                      void *,
 
3351
                                      const void *save)
 
3352
 
 
3353
{
 
3354
  bool status_file_enabled;
 
3355
  ib_err_t err;
 
3356
 
 
3357
  status_file_enabled= *static_cast<const bool*>(save);
 
3358
 
 
3359
 
 
3360
  if (status_file_enabled)
 
3361
    err= ib_cfg_set_bool_on("status_file");
 
3362
  else
 
3363
    err= ib_cfg_set_bool_off("status_file");
 
3364
 
 
3365
  if (err == DB_SUCCESS)
 
3366
    innobase_create_status_file= status_file_enabled;
 
3367
}
 
3368
 
 
3369
static DRIZZLE_SYSVAR_BOOL(adaptive_hash_index, innobase_adaptive_hash_index,
 
3370
  PLUGIN_VAR_NOCMDARG,
 
3371
  "Enable HailDB adaptive hash index (enabled by default).  ",
 
3372
  NULL, NULL, true);
 
3373
 
 
3374
static DRIZZLE_SYSVAR_BOOL(adaptive_flushing, srv_adaptive_flushing,
 
3375
  PLUGIN_VAR_NOCMDARG,
 
3376
  "Attempt flushing dirty pages to avoid IO bursts at checkpoints.",
 
3377
  NULL, NULL, true);
 
3378
 
 
3379
static DRIZZLE_SYSVAR_LONG(additional_mem_pool_size, innobase_additional_mem_pool_size,
 
3380
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3381
  "Size of a memory pool HailDB uses to store data dictionary information and other internal data structures.",
 
3382
  NULL, NULL, 8*1024*1024L, 512*1024L, LONG_MAX, 1024);
 
3383
 
 
3384
static DRIZZLE_SYSVAR_UINT(autoextend_increment, srv_auto_extend_increment,
 
3385
  PLUGIN_VAR_RQCMDARG,
 
3386
  "Data file autoextend increment in megabytes",
 
3387
  NULL, NULL, 8L, 1L, 1000L, 0);
 
3388
 
 
3389
static DRIZZLE_SYSVAR_LONGLONG(buffer_pool_size, innobase_buffer_pool_size,
 
3390
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3391
  "The size of the memory buffer HailDB uses to cache data and indexes of its tables.",
 
3392
  NULL, NULL, 128*1024*1024L, 5*1024*1024L, INT64_MAX, 1024*1024L);
 
3393
 
 
3394
static DRIZZLE_SYSVAR_BOOL(checksums, innobase_use_checksums,
 
3395
  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
 
3396
  "Enable HailDB checksums validation (enabled by default). "
 
3397
  "Disable with --skip-haildb-checksums.",
 
3398
  NULL, NULL, true);
 
3399
 
 
3400
static DRIZZLE_SYSVAR_STR(data_home_dir, innobase_data_home_dir,
 
3401
  PLUGIN_VAR_READONLY,
 
3402
  "The common part for HailDB table spaces.",
 
3403
  NULL, NULL, NULL);
 
3404
 
 
3405
static DRIZZLE_SYSVAR_BOOL(doublewrite, innobase_use_doublewrite,
 
3406
  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
 
3407
  "Enable HailDB doublewrite buffer (enabled by default). "
 
3408
  "Disable with --skip-haildb-doublewrite.",
 
3409
  NULL, NULL, true);
 
3410
 
 
3411
static DRIZZLE_SYSVAR_ULONG(io_capacity, srv_io_capacity,
 
3412
  PLUGIN_VAR_RQCMDARG,
 
3413
  "Number of IOPs the server can do. Tunes the background IO rate",
 
3414
  NULL, NULL, 200, 100, ~0L, 0);
 
3415
 
 
3416
static DRIZZLE_SYSVAR_ULONG(fast_shutdown, innobase_fast_shutdown,
 
3417
  PLUGIN_VAR_OPCMDARG,
 
3418
  "Speeds up the shutdown process of the HailDB storage engine. Possible "
 
3419
  "values are 0, 1 (faster)"
 
3420
  " or 2 (fastest - crash-like)"
 
3421
  ".",
 
3422
  NULL, NULL, 1, 0, 2, 0);
 
3423
 
 
3424
static DRIZZLE_SYSVAR_BOOL(file_per_table, srv_file_per_table,
 
3425
  PLUGIN_VAR_NOCMDARG,
 
3426
  "Stores each HailDB table to an .ibd file in the database dir.",
 
3427
  NULL, NULL, false);
 
3428
 
 
3429
static DRIZZLE_SYSVAR_STR(file_format, innobase_file_format_name,
 
3430
  PLUGIN_VAR_RQCMDARG,
 
3431
  "File format to use for new tables in .ibd files.",
 
3432
  haildb_file_format_name_validate,
 
3433
  haildb_file_format_name_update, "Barracuda");
 
3434
 
 
3435
static DRIZZLE_SYSVAR_ULONG(flush_log_at_trx_commit, srv_flush_log_at_trx_commit,
 
3436
  PLUGIN_VAR_OPCMDARG,
 
3437
  "Set to 0 (write and flush once per second),"
 
3438
  " 1 (write and flush at each commit)"
 
3439
  " or 2 (write at commit, flush once per second).",
 
3440
  NULL, NULL, 1, 0, 2, 0);
 
3441
 
 
3442
static DRIZZLE_SYSVAR_STR(flush_method, innobase_unix_file_flush_method,
 
3443
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3444
  "With which method to flush data.", NULL, NULL, NULL);
 
3445
 
 
3446
static DRIZZLE_SYSVAR_LONG(force_recovery, innobase_force_recovery,
 
3447
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3448
  "Helps to save your data in case the disk image of the database becomes corrupt.",
 
3449
  NULL, NULL, 0, 0, 6, 0);
 
3450
 
 
3451
static DRIZZLE_SYSVAR_STR(data_file_path, haildb_data_file_path,
 
3452
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3453
  "Path to individual files and their sizes.",
 
3454
  NULL, NULL, NULL);
 
3455
 
 
3456
static DRIZZLE_SYSVAR_STR(log_group_home_dir, innobase_log_group_home_dir,
 
3457
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3458
  "Path to HailDB log files.", NULL, NULL, NULL);
 
3459
 
 
3460
static DRIZZLE_SYSVAR_LONGLONG(log_file_size, haildb_log_file_size,
 
3461
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3462
  "Size of each log file in a log group.",
 
3463
  NULL, NULL, 20*1024*1024L, 1*1024*1024L, INT64_MAX, 1024*1024L);
 
3464
 
 
3465
static DRIZZLE_SYSVAR_LONGLONG(log_files_in_group, haildb_log_files_in_group,
 
3466
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3467
  "Number of log files in the log group. HailDB writes to the files in a circular fashion. Value 3 is recommended here.",
 
3468
  NULL, NULL, 2, 2, 100, 0);
 
3469
 
 
3470
static DRIZZLE_SYSVAR_ULONG(lock_wait_timeout, innobase_lock_wait_timeout,
 
3471
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3472
  "Timeout in seconds an HailDB transaction may wait for a lock before being rolled back. Values above 100000000 disable the timeout.",
 
3473
  NULL, NULL, 5, 1, 1024 * 1024 * 1024, 0);
 
3474
 
 
3475
static DRIZZLE_SYSVAR_LONG(log_buffer_size, innobase_log_buffer_size,
 
3476
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3477
  "The size of the buffer which HailDB uses to write log to the log files on disk.",
 
3478
  NULL, NULL, 8*1024*1024L, 256*1024L, LONG_MAX, 1024);
 
3479
 
 
3480
static DRIZZLE_SYSVAR_ULONG(lru_old_blocks_pct, innobase_lru_old_blocks_pct,
 
3481
  PLUGIN_VAR_RQCMDARG,
 
3482
  "Sets the point in the LRU list from where all pages are classified as "
 
3483
  "old (Advanced users)",
 
3484
  NULL,
 
3485
  haildb_lru_old_blocks_pct_update, 37, 5, 95, 0);
 
3486
 
 
3487
static DRIZZLE_SYSVAR_ULONG(lru_block_access_recency, innobase_lru_block_access_recency,
 
3488
  PLUGIN_VAR_RQCMDARG,
 
3489
  "Milliseconds between accesses to a block at which it is made young. "
 
3490
  "0=disabled (Advanced users)",
 
3491
  NULL,
 
3492
  haildb_lru_block_access_recency_update, 0, 0, ULONG_MAX, 0);
 
3493
 
 
3494
 
 
3495
static DRIZZLE_SYSVAR_ULONG(max_dirty_pages_pct, srv_max_buf_pool_modified_pct,
 
3496
  PLUGIN_VAR_RQCMDARG,
 
3497
  "Percentage of dirty pages allowed in bufferpool.",
 
3498
  NULL, NULL, 75, 0, 99, 0);
 
3499
 
 
3500
static DRIZZLE_SYSVAR_ULONG(max_purge_lag, srv_max_purge_lag,
 
3501
  PLUGIN_VAR_RQCMDARG,
 
3502
  "Desired maximum length of the purge queue (0 = no limit)",
 
3503
  NULL, NULL, 0, 0, ~0L, 0);
 
3504
 
 
3505
static DRIZZLE_SYSVAR_BOOL(rollback_on_timeout, innobase_rollback_on_timeout,
 
3506
  PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
 
3507
  "Roll back the complete transaction on lock wait timeout, for 4.x compatibility (disabled by default)",
 
3508
  NULL, NULL, false);
 
3509
 
 
3510
static DRIZZLE_SYSVAR_LONG(open_files, innobase_open_files,
 
3511
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3512
  "How many files at the maximum HailDB keeps open at the same time.",
 
3513
  NULL, NULL, 300L, 10L, LONG_MAX, 0);
 
3514
 
 
3515
static DRIZZLE_SYSVAR_ULONG(read_io_threads, innobase_read_io_threads,
 
3516
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3517
  "Number of background read I/O threads in HailDB.",
 
3518
  NULL, NULL, 4, 1, 64, 0);
 
3519
 
 
3520
static DRIZZLE_SYSVAR_ULONG(write_io_threads, innobase_write_io_threads,
 
3521
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
3522
  "Number of background write I/O threads in HailDB.",
 
3523
  NULL, NULL, 4, 1, 64, 0);
 
3524
 
 
3525
static DRIZZLE_SYSVAR_BOOL(print_verbose_log, innobase_print_verbose_log,
 
3526
  PLUGIN_VAR_NOCMDARG,
 
3527
  "Disable if you want to reduce the number of messages written to the log (default: enabled).",
 
3528
  NULL, NULL, true);
 
3529
 
 
3530
static DRIZZLE_SYSVAR_BOOL(status_file, innobase_create_status_file,
 
3531
  PLUGIN_VAR_OPCMDARG,
 
3532
  "Enable SHOW HAILDB STATUS output in the log",
 
3533
  NULL, haildb_status_file_update, false);
 
3534
 
 
3535
static DRIZZLE_SYSVAR_ULONG(sync_spin_loops, srv_n_spin_wait_rounds,
 
3536
  PLUGIN_VAR_RQCMDARG,
 
3537
  "Count of spin-loop rounds in HailDB mutexes (30 by default)",
 
3538
  NULL, NULL, 30L, 0L, ~0L, 0);
 
3539
 
 
3540
static DRIZZLE_SYSVAR_BOOL(use_sys_malloc, srv_use_sys_malloc,
 
3541
  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
 
3542
  "Use OS memory allocator instead of HailDB's internal memory allocator",
 
3543
  NULL, NULL, true);
3432
3544
 
3433
3545
static void init_options(drizzled::module::option_context &context)
3434
3546
{
3437
3549
  context("disable-adaptive-flushing",
3438
3550
          N_("Do not attempt to flush dirty pages to avoid IO bursts at checkpoints."));
3439
3551
  context("additional-mem-pool-size",
3440
 
          po::value<additional_mem_pool_constraint>(&innobase_additional_mem_pool_size)->default_value(8*1024*1024L),
 
3552
          po::value<long>(&innobase_additional_mem_pool_size)->default_value(8*1024*1024L),
3441
3553
          N_("Size of a memory pool HailDB uses to store data dictionary information and other internal data structures."));
3442
3554
  context("autoextend-increment",
3443
 
          po::value<autoextend_constraint>(&srv_auto_extend_increment)->default_value(8),
 
3555
          po::value<unsigned int>(&srv_auto_extend_increment)->default_value(8L),
3444
3556
          N_("Data file autoextend increment in megabytes"));
3445
3557
  context("buffer-pool-size",
3446
 
          po::value<buffer_pool_constraint>(&innobase_buffer_pool_size)->default_value(128*1024*1024L),
 
3558
          po::value<int64_t>(&innobase_buffer_pool_size)->default_value(128*1024*1024L),
3447
3559
          N_("The size of the memory buffer HailDB uses to cache data and indexes of its tables."));
3448
3560
  context("data-home-dir",
3449
 
          po::value<string>()->default_value(""),
 
3561
          po::value<string>(),
3450
3562
          N_("The common part for HailDB table spaces."));
3451
3563
  context("disable-checksums",
3452
3564
          N_("Disable HailDB checksums validation (enabled by default)."));
3453
3565
  context("disable-doublewrite",
3454
3566
          N_("Disable HailDB doublewrite buffer (enabled by default)."));
3455
3567
  context("io-capacity",
3456
 
          po::value<io_capacity_constraint>(&srv_io_capacity)->default_value(200),
 
3568
          po::value<unsigned long>(&srv_io_capacity)->default_value(200),
3457
3569
          N_("Number of IOPs the server can do. Tunes the background IO rate"));
3458
3570
  context("fast-shutdown",
3459
 
          po::value<trinary_constraint>(&innobase_fast_shutdown)->default_value(1),
 
3571
          po::value<unsigned long>(&innobase_fast_shutdown)->default_value(1),
3460
3572
          N_("Speeds up the shutdown process of the HailDB storage engine. Possible values are 0, 1 (faster) or 2 (fastest - crash-like)."));
3461
3573
  context("file-per-table",
3462
3574
          po::value<bool>(&srv_file_per_table)->default_value(false)->zero_tokens(),
3463
3575
          N_("Stores each HailDB table to an .ibd file in the database dir."));
3464
3576
  context("file-format",
3465
 
          po::value<string>(&innobase_file_format_name)->default_value("Barracuda"),
 
3577
          po::value<string>(),
3466
3578
          N_("File format to use for new tables in .ibd files."));
3467
3579
  context("flush-log-at-trx-commit",
3468
 
          po::value<trinary_constraint>(&srv_flush_log_at_trx_commit)->default_value(1),
 
3580
          po::value<unsigned long>(&srv_flush_log_at_trx_commit)->default_value(1),
3469
3581
          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
3582
  context("flush-method",
3471
3583
          po::value<string>(),
3472
3584
          N_("With which method to flush data."));
3473
3585
  context("force-recovery",
3474
 
          po::value<force_recovery_constraint>(&innobase_force_recovery)->default_value(0),
 
3586
          po::value<long>(&innobase_force_recovery)->default_value(0),
3475
3587
          N_("Helps to save your data in case the disk image of the database becomes corrupt."));
3476
3588
  context("data-file-path",
3477
 
          po::value<string>()->default_value("ibdata1:10M:autoextend"),
 
3589
          po::value<string>(),
 
3590
          N_("Path to individual files and their sizes."));
 
3591
  context("log-group-home-dir",
 
3592
          po::value<string>(),
3478
3593
          N_("Path to individual files and their sizes."));
3479
3594
  context("log-group-home-dir",
3480
3595
          po::value<string>(),
3481
3596
          N_("Path to HailDB log files."));
3482
3597
  context("log-file-size",
3483
 
          po::value<log_file_constraint>(&haildb_log_file_size)->default_value(20*1024*1024L),
 
3598
          po::value<int64_t>(&haildb_log_file_size)->default_value(20*1024*1024L),
3484
3599
          N_("Size of each log file in a log group."));
3485
3600
  context("haildb-log-files-in-group",
3486
 
          po::value<log_files_in_group_constraint>(&haildb_log_files_in_group)->default_value(2),
 
3601
          po::value<int64_t>(&haildb_log_files_in_group)->default_value(2),
3487
3602
          N_("Number of log files in the log group. HailDB writes to the files in a circular fashion. Value 3 is recommended here."));
3488
3603
  context("lock-wait-timeout",
3489
 
          po::value<lock_wait_constraint>(&innobase_lock_wait_timeout)->default_value(5),
 
3604
          po::value<unsigned long>(&innobase_lock_wait_timeout)->default_value(5),
3490
3605
          N_("Timeout in seconds an HailDB transaction may wait for a lock before being rolled back. Values above 100000000 disable the timeout."));
3491
3606
  context("log-buffer-size",
3492
 
        po::value<log_buffer_size_constraint>(&innobase_log_buffer_size)->default_value(8*1024*1024L),
 
3607
        po::value<long>(&innobase_log_buffer_size)->default_value(8*1024*1024L),
3493
3608
        N_("The size of the buffer which HailDB uses to write log to the log files on disk."));
3494
3609
  context("lru-old-blocks-pct",
3495
 
          po::value<lru_old_blocks_constraint>(&innobase_lru_old_blocks_pct)->default_value(37),
 
3610
          po::value<unsigned long>(&innobase_lru_old_blocks_pct)->default_value(37),
3496
3611
          N_("Sets the point in the LRU list from where all pages are classified as old (Advanced users)"));
3497
3612
  context("lru-block-access-recency",
3498
 
          po::value<uint32_t>(&innobase_lru_block_access_recency)->default_value(0),
 
3613
          po::value<unsigned long>(&innobase_lru_block_access_recency)->default_value(0),
3499
3614
          N_("Milliseconds between accesses to a block at which it is made young. 0=disabled (Advanced users)"));
3500
3615
  context("max-dirty-pages-pct",
3501
 
          po::value<max_dirty_pages_constraint>(&haildb_max_dirty_pages_pct)->default_value(75),
 
3616
          po::value<unsigned long>(&srv_max_buf_pool_modified_pct)->default_value(75),
3502
3617
          N_("Percentage of dirty pages allowed in bufferpool."));
3503
3618
  context("max-purge-lag",
3504
 
          po::value<uint64_constraint>(&haildb_max_purge_lag)->default_value(0),
 
3619
          po::value<unsigned long>(&srv_max_purge_lag)->default_value(0),
3505
3620
          N_("Desired maximum length of the purge queue (0 = no limit)"));
3506
3621
  context("rollback-on-timeout",
3507
3622
          po::value<bool>(&innobase_rollback_on_timeout)->default_value(false)->zero_tokens(),
3508
3623
          N_("Roll back the complete transaction on lock wait timeout, for 4.x compatibility (disabled by default)"));
3509
3624
  context("open-files",
3510
 
          po::value<open_files_constraint>(&haildb_open_files)->default_value(300),
 
3625
          po::value<long>(&innobase_open_files)->default_value(300),
3511
3626
          N_("How many files at the maximum HailDB keeps open at the same time."));
3512
3627
  context("read-io-threads",
3513
 
          po::value<io_threads_constraint>(&haildb_read_io_threads)->default_value(4),
 
3628
          po::value<unsigned long>(&innobase_read_io_threads)->default_value(4),
3514
3629
          N_("Number of background read I/O threads in HailDB."));
3515
3630
  context("write-io-threads",
3516
 
          po::value<io_threads_constraint>(&haildb_write_io_threads)->default_value(4),
 
3631
          po::value<unsigned long>(&innobase_write_io_threads)->default_value(4),
3517
3632
          N_("Number of background write I/O threads in HailDB."));
3518
3633
  context("disable-print-verbose-log",
3519
3634
          N_("Disable if you want to reduce the number of messages written to the log (default: enabled)."));
3521
3636
          po::value<bool>(&innobase_create_status_file)->default_value(false)->zero_tokens(),
3522
3637
          N_("Enable SHOW HAILDB STATUS output in the log"));
3523
3638
  context("sync-spin-loops",
3524
 
          po::value<uint64_constraint>(&haildb_sync_spin_loops)->default_value(30L),
 
3639
          po::value<unsigned long>(&srv_n_spin_wait_rounds)->default_value(30L),
3525
3640
          N_("Count of spin-loop rounds in HailDB mutexes (30 by default)"));
3526
3641
  context("use-internal-malloc",
3527
3642
          N_("Use HailDB's internal memory allocator instead of the OS memory allocator"));
3528
3643
}
3529
3644
 
 
3645
static drizzle_sys_var* innobase_system_variables[]= {
 
3646
  DRIZZLE_SYSVAR(adaptive_hash_index),
 
3647
  DRIZZLE_SYSVAR(adaptive_flushing),
 
3648
  DRIZZLE_SYSVAR(additional_mem_pool_size),
 
3649
  DRIZZLE_SYSVAR(autoextend_increment),
 
3650
  DRIZZLE_SYSVAR(buffer_pool_size),
 
3651
  DRIZZLE_SYSVAR(checksums),
 
3652
  DRIZZLE_SYSVAR(data_home_dir),
 
3653
  DRIZZLE_SYSVAR(doublewrite),
 
3654
  DRIZZLE_SYSVAR(io_capacity),
 
3655
  DRIZZLE_SYSVAR(fast_shutdown),
 
3656
  DRIZZLE_SYSVAR(file_per_table),
 
3657
  DRIZZLE_SYSVAR(file_format),
 
3658
  DRIZZLE_SYSVAR(flush_log_at_trx_commit),
 
3659
  DRIZZLE_SYSVAR(flush_method),
 
3660
  DRIZZLE_SYSVAR(force_recovery),
 
3661
  DRIZZLE_SYSVAR(log_group_home_dir),
 
3662
  DRIZZLE_SYSVAR(data_file_path),
 
3663
  DRIZZLE_SYSVAR(lock_wait_timeout),
 
3664
  DRIZZLE_SYSVAR(log_file_size),
 
3665
  DRIZZLE_SYSVAR(log_files_in_group),
 
3666
  DRIZZLE_SYSVAR(log_buffer_size),
 
3667
  DRIZZLE_SYSVAR(lru_old_blocks_pct),
 
3668
  DRIZZLE_SYSVAR(lru_block_access_recency),
 
3669
  DRIZZLE_SYSVAR(max_dirty_pages_pct),
 
3670
  DRIZZLE_SYSVAR(max_purge_lag),
 
3671
  DRIZZLE_SYSVAR(open_files),
 
3672
  DRIZZLE_SYSVAR(read_io_threads),
 
3673
  DRIZZLE_SYSVAR(rollback_on_timeout),
 
3674
  DRIZZLE_SYSVAR(write_io_threads),
 
3675
  DRIZZLE_SYSVAR(print_verbose_log),
 
3676
  DRIZZLE_SYSVAR(status_file),
 
3677
  DRIZZLE_SYSVAR(sync_spin_loops),
 
3678
  DRIZZLE_SYSVAR(use_sys_malloc),
 
3679
  NULL
 
3680
};
 
3681
 
3530
3682
DRIZZLE_DECLARE_PLUGIN
3531
3683
{
3532
3684
  DRIZZLE_VERSION_ID,
3536
3688
  "Transactional Storage Engine using the HailDB Library",
3537
3689
  PLUGIN_LICENSE_GPL,
3538
3690
  haildb_init,     /* Plugin Init */
3539
 
  NULL, /* depends */
 
3691
  innobase_system_variables, /* system variables */
3540
3692
  init_options                /* config options   */
3541
3693
}
3542
3694
DRIZZLE_DECLARE_PLUGIN_END;