~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/handler.cc

  • Committer: Brian Aker
  • Date: 2009-03-25 22:03:13 UTC
  • mfrom: (960.2.47 mordred)
  • Revision ID: brian@tangent.org-20090325220313-fffae098oufxiaqg
Merge of Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
 
47
47
KEY_CREATE_INFO default_key_create_info= { HA_KEY_ALG_UNDEF, 0, {NULL,0}, {NULL,0} };
48
48
 
49
 
/* number of entries in handlertons[] */
 
49
/* number of entries in storage_engines[] */
50
50
uint32_t total_ha= 0;
51
 
/* number of storage engines (from handlertons[]) that support 2pc */
 
51
/* number of storage engines (from storage_engines[]) that support 2pc */
52
52
uint32_t total_ha_2pc= 0;
53
53
/* size of savepoint storage area (see ha_init) */
54
54
uint32_t savepoint_alloc_size= 0;
184
184
  return(error);
185
185
}
186
186
 
187
 
static bool dropdb_handlerton(Session *,
188
 
                              plugin_ref plugin,
189
 
                              void *path)
 
187
static bool dropdb_storage_engine(Session *,
 
188
                                  plugin_ref plugin,
 
189
                                  void *path)
190
190
{
191
 
  handlerton *hton= plugin_data(plugin, handlerton *);
192
 
  if (hton->state == SHOW_OPTION_YES && hton->drop_database)
193
 
    hton->drop_database(hton, (char *)path);
 
191
  StorageEngine *engine= plugin_data(plugin, StorageEngine *);
 
192
  if (engine->state == SHOW_OPTION_YES)
 
193
    engine->drop_database((char *)path);
194
194
  return false;
195
195
}
196
196
 
197
197
 
198
198
void ha_drop_database(char* path)
199
199
{
200
 
  plugin_foreach(NULL, dropdb_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, path);
 
200
  plugin_foreach(NULL, dropdb_storage_engine, DRIZZLE_STORAGE_ENGINE_PLUGIN, path);
201
201
}
202
202
 
203
203
 
204
 
static bool closecon_handlerton(Session *session, plugin_ref plugin,
 
204
static bool closecon_storage_engine(Session *session, plugin_ref plugin,
205
205
                                void *)
206
206
{
207
 
  handlerton *hton= plugin_data(plugin, handlerton *);
 
207
  StorageEngine *engine= plugin_data(plugin, StorageEngine *);
208
208
  /*
209
209
    there's no need to rollback here as all transactions must
210
210
    be rolled back already
211
211
  */
212
 
  if (hton->state == SHOW_OPTION_YES && hton->close_connection &&
213
 
      session_get_ha_data(session, hton))
214
 
    hton->close_connection(hton, session);
 
212
  if (engine->state == SHOW_OPTION_YES && 
 
213
      session_get_ha_data(session, engine))
 
214
    engine->close_connection(session);
215
215
  return false;
216
216
}
217
217
 
222
222
*/
223
223
void ha_close_connection(Session* session)
224
224
{
225
 
  plugin_foreach(session, closecon_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, 0);
 
225
  plugin_foreach(session, closecon_storage_engine, DRIZZLE_STORAGE_ENGINE_PLUGIN, 0);
226
226
}
227
227
 
228
228
/* ========================================================================
405
405
  in each engine independently. The two-phase commit protocol
406
406
  is used only if:
407
407
  - all participating engines support two-phase commit (provide
408
 
    handlerton::prepare PSEA API call) and
 
408
    StorageEngine::prepare PSEA API call) and
409
409
  - transactions in at least two engines modify data (i.e. are
410
410
  not read-only).
411
411
 
469
469
 
470
470
  At the end of a statement, server call
471
471
  ha_autocommit_or_rollback() is invoked. This call in turn
472
 
  invokes handlerton::prepare() for every involved engine.
473
 
  Prepare is followed by a call to handlerton::commit_one_phase()
474
 
  If a one-phase commit will suffice, handlerton::prepare() is not
475
 
  invoked and the server only calls handlerton::commit_one_phase().
 
472
  invokes StorageEngine::prepare() for every involved engine.
 
473
  Prepare is followed by a call to StorageEngine::commit_one_phase()
 
474
  If a one-phase commit will suffice, StorageEngine::prepare() is not
 
475
  invoked and the server only calls StorageEngine::commit_one_phase().
476
476
  At statement commit, the statement-related read-write engine
477
477
  flag is propagated to the corresponding flag in the normal
478
478
  transaction.  When the commit is complete, the list of registered
531
531
    times per transaction.
532
532
 
533
533
*/
534
 
void trans_register_ha(Session *session, bool all, handlerton *ht_arg)
 
534
void trans_register_ha(Session *session, bool all, StorageEngine *engine)
535
535
{
536
536
  Session_TRANS *trans;
537
537
  Ha_trx_info *ha_info;
544
544
  else
545
545
    trans= &session->transaction.stmt;
546
546
 
547
 
  ha_info= session->ha_data[ht_arg->slot].ha_info + static_cast<unsigned>(all);
 
547
  ha_info= session->ha_data[engine->slot].ha_info + static_cast<unsigned>(all);
548
548
 
549
549
  if (ha_info->is_started())
550
550
    return; /* already registered, return */
551
551
 
552
 
  ha_info->register_ha(trans, ht_arg);
 
552
  ha_info->register_ha(trans, engine);
553
553
 
554
 
  trans->no_2pc|=(ht_arg->prepare==0);
 
554
  trans->no_2pc|= not engine->has_2pc();
555
555
  if (session->transaction.xid_state.xid.is_null())
556
556
    session->transaction.xid_state.xid.set(session->query_id);
557
557
 
574
574
    for (; ha_info; ha_info= ha_info->next())
575
575
    {
576
576
      int err;
577
 
      handlerton *ht= ha_info->ht();
 
577
      StorageEngine *engine= ha_info->engine();
578
578
      status_var_increment(session->status_var.ha_prepare_count);
579
 
      if (ht->prepare)
 
579
      if ((err= engine->prepare(session, all)))
580
580
      {
581
 
        if ((err= ht->prepare(ht, session, all)))
582
 
        {
583
 
          my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
584
 
          ha_rollback_trans(session, all);
585
 
          error=1;
586
 
          break;
587
 
        }
 
581
        my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
 
582
        ha_rollback_trans(session, all);
 
583
        error=1;
 
584
        break;
588
585
      }
589
586
      else
590
587
      {
591
588
        push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
592
589
                            ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
593
 
                            ha_resolve_storage_engine_name(ht));
 
590
                            ha_resolve_storage_engine_name(engine));
594
591
      }
595
592
    }
596
593
  }
627
624
 
628
625
    if (! all)
629
626
    {
630
 
      Ha_trx_info *ha_info_all= &session->ha_data[ha_info->ht()->slot].ha_info[1];
 
627
      Ha_trx_info *ha_info_all= &session->ha_data[ha_info->engine()->slot].ha_info[1];
631
628
      assert(ha_info != ha_info_all);
632
629
      /*
633
630
        Merge read-only/read-write information about statement
704
701
      for (; ha_info && !error; ha_info= ha_info->next())
705
702
      {
706
703
        int err;
707
 
        handlerton *ht= ha_info->ht();
 
704
        StorageEngine *engine= ha_info->engine();
708
705
        /*
709
706
          Do not call two-phase commit if this particular
710
707
          transaction is read-only. This allows for simpler
716
713
          Sic: we know that prepare() is not NULL since otherwise
717
714
          trans->no_2pc would have been set.
718
715
        */
719
 
        if ((err= ht->prepare(ht, session, all)))
 
716
        if ((err= engine->prepare(session, all)))
720
717
        {
721
718
          my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
722
719
          error= 1;
753
750
    for (; ha_info; ha_info= ha_info_next)
754
751
    {
755
752
      int err;
756
 
      handlerton *ht= ha_info->ht();
757
 
      if ((err= ht->commit(ht, session, all)))
 
753
      StorageEngine *engine= ha_info->engine();
 
754
      if ((err= engine->commit(session, all)))
758
755
      {
759
756
        my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
760
757
        error=1;
796
793
    for (; ha_info; ha_info= ha_info_next)
797
794
    {
798
795
      int err;
799
 
      handlerton *ht= ha_info->ht();
800
 
      if ((err= ht->rollback(ht, session, all)))
 
796
      StorageEngine *engine= ha_info->engine();
 
797
      if ((err= engine->rollback(session, all)))
801
798
      { // cannot happen
802
799
        my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
803
800
        error=1;
868
865
}
869
866
 
870
867
 
871
 
struct xahton_st {
 
868
struct xaengine_st {
872
869
  XID *xid;
873
870
  int result;
874
871
};
875
872
 
876
 
static bool xacommit_handlerton(Session *,
877
 
                                plugin_ref plugin,
878
 
                                void *arg)
 
873
static bool xacommit_storage_engine(Session *,
 
874
                                    plugin_ref plugin,
 
875
                                    void *arg)
879
876
{
880
 
  handlerton *hton= plugin_data(plugin, handlerton *);
881
 
  if (hton->state == SHOW_OPTION_YES && hton->recover)
 
877
  StorageEngine *engine= plugin_data(plugin, StorageEngine *);
 
878
  if (engine->state == SHOW_OPTION_YES)
882
879
  {
883
 
    hton->commit_by_xid(hton, ((struct xahton_st *)arg)->xid);
884
 
    ((struct xahton_st *)arg)->result= 0;
 
880
    engine->commit_by_xid(((struct xaengine_st *)arg)->xid);
 
881
    ((struct xaengine_st *)arg)->result= 0;
885
882
  }
886
883
  return false;
887
884
}
888
885
 
889
 
static bool xarollback_handlerton(Session *,
 
886
static bool xarollback_storage_engine(Session *,
890
887
                                  plugin_ref plugin,
891
888
                                  void *arg)
892
889
{
893
 
  handlerton *hton= plugin_data(plugin, handlerton *);
894
 
  if (hton->state == SHOW_OPTION_YES && hton->recover)
 
890
  StorageEngine *engine= plugin_data(plugin, StorageEngine *);
 
891
  if (engine->state == SHOW_OPTION_YES)
895
892
  {
896
 
    hton->rollback_by_xid(hton, ((struct xahton_st *)arg)->xid);
897
 
    ((struct xahton_st *)arg)->result= 0;
 
893
    engine->rollback_by_xid(((struct xaengine_st *)arg)->xid);
 
894
    ((struct xaengine_st *)arg)->result= 0;
898
895
  }
899
896
  return false;
900
897
}
902
899
 
903
900
int ha_commit_or_rollback_by_xid(XID *xid, bool commit)
904
901
{
905
 
  struct xahton_st xaop;
 
902
  struct xaengine_st xaop;
906
903
  xaop.xid= xid;
907
904
  xaop.result= 1;
908
905
 
909
 
  plugin_foreach(NULL, commit ? xacommit_handlerton : xarollback_handlerton,
 
906
  plugin_foreach(NULL, commit ? xacommit_storage_engine : xarollback_storage_engine,
910
907
                 DRIZZLE_STORAGE_ENGINE_PLUGIN, &xaop);
911
908
 
912
909
  return xaop.result;
936
933
  bool dry_run;
937
934
};
938
935
 
939
 
static bool xarecover_handlerton(Session *,
940
 
                                 plugin_ref plugin,
941
 
                                 void *arg)
 
936
static bool xarecover_storage_engine(Session *,
 
937
                                     plugin_ref plugin,
 
938
                                     void *arg)
942
939
{
943
 
  handlerton *hton= plugin_data(plugin, handlerton *);
 
940
  StorageEngine *engine= plugin_data(plugin, StorageEngine *);
944
941
  struct xarecover_st *info= (struct xarecover_st *) arg;
945
942
  int got;
946
943
 
947
 
  if (hton->state == SHOW_OPTION_YES && hton->recover)
 
944
  if (engine->state == SHOW_OPTION_YES)
948
945
  {
949
 
    while ((got= hton->recover(hton, info->list, info->len)) > 0 )
 
946
    while ((got= engine->recover(info->list, info->len)) > 0 )
950
947
    {
951
948
      errmsg_printf(ERRMSG_LVL_INFO, _("Found %d prepared transaction(s) in %s"),
952
 
                            got, ha_resolve_storage_engine_name(hton));
 
949
                            got, ha_resolve_storage_engine_name(engine));
953
950
      for (int i=0; i < got; i ++)
954
951
      {
955
952
        my_xid x=info->list[i].get_my_xid();
969
966
            hash_search(info->commit_list, (unsigned char *)&x, sizeof(x)) != 0 :
970
967
            tc_heuristic_recover == TC_HEURISTIC_RECOVER_COMMIT)
971
968
        {
972
 
          hton->commit_by_xid(hton, info->list+i);
 
969
          engine->commit_by_xid(info->list+i);
973
970
        }
974
971
        else
975
972
        {
976
 
          hton->rollback_by_xid(hton, info->list+i);
 
973
          engine->rollback_by_xid(info->list+i);
977
974
        }
978
975
      }
979
976
      if (got < info->len)
1027
1024
    return(1);
1028
1025
  }
1029
1026
 
1030
 
  plugin_foreach(NULL, xarecover_handlerton,
 
1027
  plugin_foreach(NULL, xarecover_storage_engine,
1031
1028
                 DRIZZLE_STORAGE_ENGINE_PLUGIN, &info);
1032
1029
 
1033
1030
  free((unsigned char*)info.list);
1120
1117
static bool release_temporary_latches(Session *session, plugin_ref plugin,
1121
1118
                                      void *)
1122
1119
{
1123
 
  handlerton *hton= plugin_data(plugin, handlerton *);
 
1120
  StorageEngine *engine= plugin_data(plugin, StorageEngine *);
1124
1121
 
1125
 
  if (hton->state == SHOW_OPTION_YES && hton->release_temporary_latches)
1126
 
    hton->release_temporary_latches(hton, session);
 
1122
  if (engine->state == SHOW_OPTION_YES)
 
1123
    engine->release_temporary_latches(session);
1127
1124
 
1128
1125
  return false;
1129
1126
}
1151
1148
  for (ha_info= sv->ha_list; ha_info; ha_info= ha_info->next())
1152
1149
  {
1153
1150
    int err;
1154
 
    handlerton *ht= ha_info->ht();
1155
 
    assert(ht);
1156
 
    assert(ht->savepoint_set != 0);
1157
 
    if ((err= ht->savepoint_rollback(ht, session,
1158
 
                                     (unsigned char *)(sv+1)+ht->savepoint_offset)))
 
1151
    StorageEngine *engine= ha_info->engine();
 
1152
    assert(engine);
 
1153
    if ((err= engine->savepoint_rollback(session,
 
1154
                                     (unsigned char *)(sv+1)+engine->savepoint_offset)))
1159
1155
    { // cannot happen
1160
1156
      my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
1161
1157
      error=1;
1162
1158
    }
1163
1159
    status_var_increment(session->status_var.ha_savepoint_rollback_count);
1164
 
    trans->no_2pc|= ht->prepare == 0;
 
1160
    trans->no_2pc|= not engine->has_2pc();
1165
1161
  }
1166
1162
  /*
1167
1163
    rolling back the transaction in all storage engines that were not part of
1171
1167
       ha_info= ha_info_next)
1172
1168
  {
1173
1169
    int err;
1174
 
    handlerton *ht= ha_info->ht();
1175
 
    if ((err= ht->rollback(ht, session, !(0))))
 
1170
    StorageEngine *engine= ha_info->engine();
 
1171
    if ((err= engine->rollback(session, !(0))))
1176
1172
    { // cannot happen
1177
1173
      my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
1178
1174
      error=1;
1199
1195
  for (; ha_info; ha_info= ha_info->next())
1200
1196
  {
1201
1197
    int err;
1202
 
    handlerton *ht= ha_info->ht();
1203
 
    assert(ht);
1204
 
    if (! ht->savepoint_set)
 
1198
    StorageEngine *engine= ha_info->engine();
 
1199
    assert(engine);
 
1200
/*    if (! engine->savepoint_set)
1205
1201
    {
1206
1202
      my_error(ER_CHECK_NOT_IMPLEMENTED, MYF(0), "SAVEPOINT");
1207
1203
      error=1;
1208
1204
      break;
1209
 
    }
1210
 
    if ((err= ht->savepoint_set(ht, session, (unsigned char *)(sv+1)+ht->savepoint_offset)))
 
1205
    } */
 
1206
    if ((err= engine->savepoint_set(session, (unsigned char *)(sv+1)+engine->savepoint_offset)))
1211
1207
    { // cannot happen
1212
1208
      my_error(ER_GET_ERRNO, MYF(0), err);
1213
1209
      error=1;
1230
1226
  for (; ha_info; ha_info= ha_info->next())
1231
1227
  {
1232
1228
    int err;
1233
 
    handlerton *ht= ha_info->ht();
 
1229
    StorageEngine *engine= ha_info->engine();
1234
1230
    /* Savepoint life time is enclosed into transaction life time. */
1235
 
    assert(ht);
1236
 
    if (!ht->savepoint_release)
1237
 
      continue;
1238
 
    if ((err= ht->savepoint_release(ht, session,
1239
 
                                    (unsigned char *)(sv+1) + ht->savepoint_offset)))
 
1231
    assert(engine);
 
1232
    if ((err= engine->savepoint_release(session,
 
1233
                                    (unsigned char *)(sv+1) + engine->savepoint_offset)))
1240
1234
    { // cannot happen
1241
1235
      my_error(ER_GET_ERRNO, MYF(0), err);
1242
1236
      error=1;
1246
1240
}
1247
1241
 
1248
1242
 
1249
 
static bool snapshot_handlerton(Session *session, plugin_ref plugin, void *arg)
 
1243
static bool snapshot_storage_engine(Session *session, plugin_ref plugin, void *arg)
1250
1244
{
1251
 
  handlerton *hton= plugin_data(plugin, handlerton *);
1252
 
  if (hton->state == SHOW_OPTION_YES &&
1253
 
      hton->start_consistent_snapshot)
 
1245
  StorageEngine *engine= plugin_data(plugin, StorageEngine *);
 
1246
  if (engine->state == SHOW_OPTION_YES)
1254
1247
  {
1255
 
    hton->start_consistent_snapshot(hton, session);
 
1248
    engine->start_consistent_snapshot(session);
1256
1249
    *((bool *)arg)= false;
1257
1250
  }
1258
1251
  return false;
1262
1255
{
1263
1256
  bool warn= true;
1264
1257
 
1265
 
  plugin_foreach(session, snapshot_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, &warn);
 
1258
  plugin_foreach(session, snapshot_storage_engine, DRIZZLE_STORAGE_ENGINE_PLUGIN, &warn);
1266
1259
 
1267
1260
  /*
1268
1261
    Same idea as when one wants to CREATE TABLE in one engine which does not
1276
1269
}
1277
1270
 
1278
1271
 
1279
 
static bool flush_handlerton(Session *,
 
1272
static bool flush_storage_engine(Session *,
1280
1273
                             plugin_ref plugin,
1281
1274
                             void *)
1282
1275
{
1283
 
  handlerton *hton= plugin_data(plugin, handlerton *);
1284
 
  if (hton->state == SHOW_OPTION_YES && hton->flush_logs &&
1285
 
      hton->flush_logs(hton))
 
1276
  StorageEngine *engine= plugin_data(plugin, StorageEngine *);
 
1277
  if (engine->state == SHOW_OPTION_YES &&
 
1278
      engine->flush_logs())
1286
1279
    return true;
1287
1280
  return false;
1288
1281
}
1289
1282
 
1290
1283
 
1291
 
bool ha_flush_logs(handlerton *db_type)
 
1284
bool ha_flush_logs(StorageEngine *engine)
1292
1285
{
1293
 
  if (db_type == NULL)
 
1286
  if (engine == NULL)
1294
1287
  {
1295
 
    if (plugin_foreach(NULL, flush_handlerton,
 
1288
    if (plugin_foreach(NULL, flush_storage_engine,
1296
1289
                          DRIZZLE_STORAGE_ENGINE_PLUGIN, 0))
1297
1290
      return true;
1298
1291
  }
1299
1292
  else
1300
1293
  {
1301
 
    if (db_type->state != SHOW_OPTION_YES ||
1302
 
        (db_type->flush_logs && db_type->flush_logs(db_type)))
 
1294
    if (engine->state != SHOW_OPTION_YES ||
 
1295
        (engine->flush_logs()))
1303
1296
      return true;
1304
1297
  }
1305
1298
  return false;
1355
1348
}
1356
1349
 
1357
1350
 
1358
 
struct handlerton_delete_table_args {
 
1351
struct storage_engine_delete_table_args {
1359
1352
  Session *session;
1360
1353
  const char *path;
1361
1354
  handler *file;
1362
1355
  int error;
1363
1356
};
1364
1357
 
1365
 
static bool deletetable_handlerton(Session *,
1366
 
                                   plugin_ref plugin,
1367
 
                                   void *args)
 
1358
static bool deletetable_storage_engine(Session *,
 
1359
                                       plugin_ref plugin,
 
1360
                                       void *args)
1368
1361
{
1369
 
  struct handlerton_delete_table_args *dtargs= (struct handlerton_delete_table_args *) args;
 
1362
  struct storage_engine_delete_table_args *dtargs= (struct storage_engine_delete_table_args *) args;
1370
1363
 
1371
1364
  Session *session= dtargs->session;
1372
1365
  const char *path= dtargs->path;
1377
1370
  if(dtargs->error!=ENOENT) /* already deleted table */
1378
1371
    return false;
1379
1372
 
1380
 
  handlerton *table_type= plugin_data(plugin, handlerton *);
1381
 
 
1382
 
  if(!table_type)
1383
 
    return false;
1384
 
 
1385
 
  if(!(table_type->state == SHOW_OPTION_YES && table_type->create))
1386
 
    return false;
1387
 
 
1388
 
  if ((file= table_type->create(table_type, NULL, session->mem_root)))
 
1373
  StorageEngine *engine= plugin_data(plugin, StorageEngine *);
 
1374
 
 
1375
  if(!engine)
 
1376
    return false;
 
1377
 
 
1378
  if(!(engine->state == SHOW_OPTION_YES))
 
1379
    return false;
 
1380
 
 
1381
  if ((file= engine->create(NULL, session->mem_root)))
1389
1382
    file->init();
1390
1383
  else
1391
1384
    return false;
1417
1410
  TABLE_SHARE dummy_share;
1418
1411
  Table dummy_table;
1419
1412
 
1420
 
  struct handlerton_delete_table_args dtargs;
 
1413
  struct storage_engine_delete_table_args dtargs;
1421
1414
  dtargs.error= ENOENT;
1422
1415
  dtargs.session= session;
1423
1416
  dtargs.path= path;
1424
1417
  dtargs.file= NULL;
1425
1418
 
1426
 
  plugin_foreach(NULL, deletetable_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN,
 
1419
  plugin_foreach(NULL, deletetable_storage_engine, DRIZZLE_STORAGE_ENGINE_PLUGIN,
1427
1420
                 &dtargs);
1428
1421
 
1429
1422
  memset(&dummy_table, 0, sizeof(dummy_table));
1575
1568
 
1576
1569
void **handler::ha_data(Session *session) const
1577
1570
{
1578
 
  return session_ha_data(session, ht);
 
1571
  return session_ha_data(session, engine);
1579
1572
}
1580
1573
 
1581
1574
Session *handler::ha_session(void) const
2294
2287
      temporary= get_error_message(error, &str);
2295
2288
      if (!str.is_empty())
2296
2289
      {
2297
 
        const char* engine= table_type();
2298
 
        if (temporary)
2299
 
          my_error(ER_GET_TEMPORARY_ERRMSG, MYF(0), error, str.ptr(), engine);
2300
 
        else
2301
 
          my_error(ER_GET_ERRMSG, MYF(0), error, str.ptr(), engine);
 
2290
              const char* engine_name= table_type();
 
2291
              if (temporary)
 
2292
                my_error(ER_GET_TEMPORARY_ERRMSG, MYF(0), error, str.ptr(),
 
2293
                   engine_name);
 
2294
              else
 
2295
                my_error(ER_GET_ERRMSG, MYF(0), error, str.ptr(), engine_name);
2302
2296
      }
2303
2297
      else
2304
 
        my_error(ER_GET_ERRNO,errflag,error);
 
2298
      {
 
2299
              my_error(ER_GET_ERRNO,errflag,error);
 
2300
      }
2305
2301
      return;
2306
2302
    }
2307
2303
  }
2478
2474
void
2479
2475
handler::mark_trx_read_write()
2480
2476
{
2481
 
  Ha_trx_info *ha_info= &ha_session()->ha_data[ht->slot].ha_info[0];
 
2477
  Ha_trx_info *ha_info= &ha_session()->ha_data[engine->slot].ha_info[0];
2482
2478
  /*
2483
2479
    When a storage engine method is called, the transaction must
2484
2480
    have been started, unless it's a DDL call, for which the
2990
2986
  @retval
2991
2987
    \#                  Error code
2992
2988
*/
2993
 
struct st_table_exists_in_engine_args
 
2989
struct st_table_exists_in_storage_engine_args
2994
2990
{
2995
2991
  const char *db;
2996
2992
  const char *name;
2997
2993
  int err;
2998
 
  handlerton* hton;
 
2994
  StorageEngine* engine;
2999
2995
};
3000
2996
 
3001
 
static bool table_exists_in_engine_handlerton(Session *session, plugin_ref plugin,
 
2997
static bool table_exists_in_storage_engine(Session *session, plugin_ref plugin,
3002
2998
                                              void *arg)
3003
2999
{
3004
 
  st_table_exists_in_engine_args *vargs= (st_table_exists_in_engine_args *)arg;
3005
 
  handlerton *hton= plugin_data(plugin, handlerton *);
 
3000
  st_table_exists_in_storage_engine_args *vargs= (st_table_exists_in_storage_engine_args *)arg;
 
3001
  StorageEngine *engine= plugin_data(plugin, StorageEngine *);
3006
3002
 
3007
3003
  int err= HA_ERR_NO_SUCH_TABLE;
3008
3004
 
3009
 
  if (hton->state == SHOW_OPTION_YES && hton->table_exists_in_engine)
3010
 
    err = hton->table_exists_in_engine(hton, session, vargs->db, vargs->name);
 
3005
  if (engine->state == SHOW_OPTION_YES)
 
3006
    err = engine->table_exists_in_engine(session, vargs->db, vargs->name);
3011
3007
 
3012
3008
  vargs->err = err;
3013
3009
  if (vargs->err == HA_ERR_TABLE_EXIST)
3014
3010
  {
3015
 
    vargs->hton= hton;
 
3011
    vargs->engine= engine;
3016
3012
    return true;
3017
3013
  }
3018
3014
 
3021
3017
 
3022
3018
int ha_table_exists_in_engine(Session* session,
3023
3019
                              const char* db, const char* name,
3024
 
                              handlerton **hton)
 
3020
                              StorageEngine **engine)
3025
3021
{
3026
 
  st_table_exists_in_engine_args args= {db, name, HA_ERR_NO_SUCH_TABLE, NULL};
3027
 
  plugin_foreach(session, table_exists_in_engine_handlerton,
 
3022
  st_table_exists_in_storage_engine_args args= {db, name, HA_ERR_NO_SUCH_TABLE, NULL};
 
3023
  plugin_foreach(session, table_exists_in_storage_engine,
3028
3024
                 DRIZZLE_STORAGE_ENGINE_PLUGIN, &args);
3029
3025
 
3030
3026
  if(args.err==HA_ERR_NO_SUCH_TABLE)
3050
3046
                                 strlen(table.engine().name().c_str()) };
3051
3047
        plugin_ref plugin= ha_resolve_by_name(session, &engine_name);
3052
3048
        if(plugin)
3053
 
          args.hton= plugin_data(plugin,handlerton *);
 
3049
          args.engine= plugin_data(plugin,StorageEngine *);
3054
3050
      }
3055
3051
    }
3056
3052
  }
3057
3053
 
3058
 
  if(hton)
3059
 
    *hton= args.hton;
 
3054
  if(engine)
 
3055
    *engine= args.engine;
3060
3056
 
3061
3057
  return(args.err);
3062
3058
}
4089
4085
                            void *arg)
4090
4086
{
4091
4087
  List<char> *found_exts= (List<char> *) arg;
4092
 
  handlerton *hton= plugin_data(plugin, handlerton *);
 
4088
  StorageEngine *engine= plugin_data(plugin, StorageEngine *);
4093
4089
  handler *file;
4094
 
  if (hton->state == SHOW_OPTION_YES && hton->create &&
4095
 
      (file= hton->create(hton, (TABLE_SHARE*) 0, current_session->mem_root)))
 
4090
  if (engine->state == SHOW_OPTION_YES &&
 
4091
      (file= engine->create((TABLE_SHARE*) 0, current_session->mem_root)))
4096
4092
  {
4097
4093
    List_iterator_fast<char> it(*found_exts);
4098
4094
    const char **ext, *old_ext;
4157
4153
  return false;
4158
4154
}
4159
4155
 
4160
 
bool ha_show_status(Session *session, handlerton *db_type, enum ha_stat_type stat)
 
4156
bool ha_show_status(Session *session, StorageEngine *engine, enum ha_stat_type stat)
4161
4157
{
4162
4158
  List<Item> field_list;
4163
4159
  Protocol *protocol= session->protocol;
4171
4167
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
4172
4168
    return true;
4173
4169
 
4174
 
  result= db_type->show_status &&
4175
 
    db_type->show_status(db_type, session, stat_print, stat) ? 1 : 0;
 
4170
  result= engine->show_status(session, stat_print, stat) ? 1 : 0;
4176
4171
 
4177
4172
  if (!result)
4178
4173
    session->my_eof();