~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/handler.cc

Merged in latest plugin-slot-reorg.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include "drizzled/unireg.h" // for mysql_frm_type
40
40
#include "drizzled/field/timestamp.h"
41
41
#include "drizzled/message/table.pb.h"
 
42
#include "drizzled/plugin/client.h"
42
43
 
43
44
using namespace std;
44
45
using namespace drizzled;
362
363
  in each engine independently. The two-phase commit protocol
363
364
  is used only if:
364
365
  - all participating engines support two-phase commit (provide
365
 
    StorageEngine::prepare PSEA API call) and
 
366
    plugin::StorageEngine::prepare PSEA API call) and
366
367
  - transactions in at least two engines modify data (i.e. are
367
368
  not read-only).
368
369
 
426
427
 
427
428
  At the end of a statement, server call
428
429
  ha_autocommit_or_rollback() is invoked. This call in turn
429
 
  invokes StorageEngine::prepare() for every involved engine.
430
 
  Prepare is followed by a call to StorageEngine::commit_one_phase()
431
 
  If a one-phase commit will suffice, StorageEngine::prepare() is not
432
 
  invoked and the server only calls StorageEngine::commit_one_phase().
 
430
  invokes plugin::StorageEngine::prepare() for every involved engine.
 
431
  Prepare is followed by a call to plugin::StorageEngine::commit_one_phase()
 
432
  If a one-phase commit will suffice, plugin::StorageEngine::prepare() is not
 
433
  invoked and the server only calls plugin::StorageEngine::commit_one_phase().
433
434
  At statement commit, the statement-related read-write engine
434
435
  flag is propagated to the corresponding flag in the normal
435
436
  transaction.  When the commit is complete, the list of registered
488
489
    times per transaction.
489
490
 
490
491
*/
491
 
void trans_register_ha(Session *session, bool all, StorageEngine *engine)
 
492
void trans_register_ha(Session *session, bool all, plugin::StorageEngine *engine)
492
493
{
493
494
  Session_TRANS *trans;
494
495
  Ha_trx_info *ha_info;
620
621
      for (; ha_info && !error; ha_info= ha_info->next())
621
622
      {
622
623
        int err;
623
 
        StorageEngine *engine= ha_info->engine();
 
624
        plugin::StorageEngine *engine= ha_info->engine();
624
625
        /*
625
626
          Do not call two-phase commit if this particular
626
627
          transaction is read-only. This allows for simpler
669
670
    for (; ha_info; ha_info= ha_info_next)
670
671
    {
671
672
      int err;
672
 
      StorageEngine *engine= ha_info->engine();
 
673
      plugin::StorageEngine *engine= ha_info->engine();
673
674
      if ((err= engine->commit(session, all)))
674
675
      {
675
676
        my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
712
713
    for (; ha_info; ha_info= ha_info_next)
713
714
    {
714
715
      int err;
715
 
      StorageEngine *engine= ha_info->engine();
 
716
      plugin::StorageEngine *engine= ha_info->engine();
716
717
      if ((err= engine->rollback(session, all)))
717
718
      { // cannot happen
718
719
        my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
795
796
bool mysql_xa_recover(Session *session)
796
797
{
797
798
  List<Item> field_list;
798
 
  plugin::Protocol *protocol= session->protocol;
799
799
  int i= 0;
800
800
  XID_STATE *xs;
801
801
 
804
804
  field_list.push_back(new Item_int("bqual_length", 0, MY_INT32_NUM_DECIMAL_DIGITS));
805
805
  field_list.push_back(new Item_empty_string("data",XIDDATASIZE));
806
806
 
807
 
  if (protocol->sendFields(&field_list))
 
807
  if (session->client->sendFields(&field_list))
808
808
    return 1;
809
809
 
810
810
  pthread_mutex_lock(&LOCK_xid_cache);
812
812
  {
813
813
    if (xs->xa_state==XA_PREPARED)
814
814
    {
815
 
      protocol->prepareForResend();
816
 
      protocol->store((int64_t)xs->xid.formatID);
817
 
      protocol->store((int64_t)xs->xid.gtrid_length);
818
 
      protocol->store((int64_t)xs->xid.bqual_length);
819
 
      protocol->store(xs->xid.data, xs->xid.gtrid_length+xs->xid.bqual_length);
820
 
      if (protocol->write())
 
815
      session->client->store((int64_t)xs->xid.formatID);
 
816
      session->client->store((int64_t)xs->xid.gtrid_length);
 
817
      session->client->store((int64_t)xs->xid.bqual_length);
 
818
      session->client->store(xs->xid.data,
 
819
                             xs->xid.gtrid_length+xs->xid.bqual_length);
 
820
      if (session->client->flush())
821
821
      {
822
822
        pthread_mutex_unlock(&LOCK_xid_cache);
823
823
        return 1;
845
845
  for (ha_info= sv->ha_list; ha_info; ha_info= ha_info->next())
846
846
  {
847
847
    int err;
848
 
    StorageEngine *engine= ha_info->engine();
 
848
    plugin::StorageEngine *engine= ha_info->engine();
849
849
    assert(engine);
850
850
    if ((err= engine->savepoint_rollback(session,
851
851
                                         (void *)(sv+1))))
864
864
       ha_info= ha_info_next)
865
865
  {
866
866
    int err;
867
 
    StorageEngine *engine= ha_info->engine();
 
867
    plugin::StorageEngine *engine= ha_info->engine();
868
868
    if ((err= engine->rollback(session, !(0))))
869
869
    { // cannot happen
870
870
      my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
892
892
  for (; ha_info; ha_info= ha_info->next())
893
893
  {
894
894
    int err;
895
 
    StorageEngine *engine= ha_info->engine();
 
895
    plugin::StorageEngine *engine= ha_info->engine();
896
896
    assert(engine);
897
897
#ifdef NOT_IMPLEMENTED /*- TODO (examine this againt the original code base) */
898
898
    if (! engine->savepoint_set)
925
925
  for (; ha_info; ha_info= ha_info->next())
926
926
  {
927
927
    int err;
928
 
    StorageEngine *engine= ha_info->engine();
 
928
    plugin::StorageEngine *engine= ha_info->engine();
929
929
    /* Savepoint life time is enclosed into transaction life time. */
930
930
    assert(engine);
931
931
    if ((err= engine->savepoint_release(session,
2604
2604
                       const char *file, uint32_t file_len,
2605
2605
                       const char *status, uint32_t status_len)
2606
2606
{
2607
 
  plugin::Protocol *protocol= session->protocol;
2608
 
  protocol->prepareForResend();
2609
 
  protocol->store(type, type_len);
2610
 
  protocol->store(file, file_len);
2611
 
  protocol->store(status, status_len);
2612
 
  if (protocol->write())
 
2607
  session->client->store(type, type_len);
 
2608
  session->client->store(file, file_len);
 
2609
  session->client->store(status, status_len);
 
2610
  if (session->client->flush())
2613
2611
    return true;
2614
2612
  return false;
2615
2613
}
2616
2614
 
2617
 
bool ha_show_status(Session *session, StorageEngine *engine, enum ha_stat_type stat)
 
2615
bool ha_show_status(Session *session, plugin::StorageEngine *engine, enum ha_stat_type stat)
2618
2616
{
2619
2617
  List<Item> field_list;
2620
 
  plugin::Protocol *protocol= session->protocol;
2621
2618
  bool result;
2622
2619
 
2623
2620
  field_list.push_back(new Item_empty_string("Type",10));
2624
2621
  field_list.push_back(new Item_empty_string("Name",FN_REFLEN));
2625
2622
  field_list.push_back(new Item_empty_string("Status",10));
2626
2623
 
2627
 
  if (protocol->sendFields(&field_list))
 
2624
  if (session->client->sendFields(&field_list))
2628
2625
    return true;
2629
2626
 
2630
2627
  result= engine->show_status(session, stat_print, stat) ? 1 : 0;
2695
2692
    We cache the table flags if the locking succeeded. Otherwise, we
2696
2693
    keep them as they were when they were fetched in ha_open().
2697
2694
  */
2698
 
  DRIZZLE_EXTERNAL_LOCK(lock_type);
2699
2695
 
2700
2696
  int error= external_lock(session, lock_type);
 
2697
 
2701
2698
  if (error == 0)
2702
2699
    cached_table_flags= table_flags();
2703
2700
  return error;
2728
2725
int handler::ha_write_row(unsigned char *buf)
2729
2726
{
2730
2727
  int error;
2731
 
  DRIZZLE_INSERT_ROW_START();
2732
2728
 
2733
2729
  /* 
2734
2730
   * If we have a timestamp column, update it to the current time 
2742
2738
  mark_trx_read_write();
2743
2739
 
2744
2740
  if (unlikely(error= write_row(buf)))
 
2741
  {
2745
2742
    return error;
 
2743
  }
2746
2744
 
2747
2745
  if (unlikely(log_row_for_replication(table, 0, buf)))
2748
 
    return HA_ERR_RBR_LOGGING_FAILED; /* purecov: inspected */
 
2746
    return HA_ERR_RBR_LOGGING_FAILED;
2749
2747
 
2750
 
  DRIZZLE_INSERT_ROW_END();
2751
2748
  return 0;
2752
2749
}
2753
2750
 
2765
2762
  mark_trx_read_write();
2766
2763
 
2767
2764
  if (unlikely(error= update_row(old_data, new_data)))
 
2765
  {
2768
2766
    return error;
 
2767
  }
2769
2768
 
2770
2769
  if (unlikely(log_row_for_replication(table, old_data, new_data)))
2771
2770
    return HA_ERR_RBR_LOGGING_FAILED;