~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/log.cc

  • Committer: Monty Taylor
  • Date: 2008-12-06 23:17:26 UTC
  • mfrom: (664 drizzle)
  • mto: This revision was merged to the branch mainline in revision 665.
  • Revision ID: monty@inaugust.com-20081206231726-ut9ntnazs3rega56
Merged with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <drizzled/server_includes.h>
28
28
#include <drizzled/replication/replication.h>
29
29
#include <libdrizzle/libdrizzle.h>
 
30
#include <drizzled/replicator.h>
30
31
#include <mysys/hash.h>
31
32
#include <drizzled/replication/rli.h>
32
33
 
387
388
  return(error);
388
389
}
389
390
 
390
 
static int binlog_prepare(handlerton *, Session *, bool)
 
391
static int binlog_prepare(handlerton *, Session *session, bool)
391
392
{
392
393
  /*
393
394
    do nothing.
395
396
    switch to 1pc.
396
397
    real work will be done in DRIZZLE_BIN_LOG::log_xid()
397
398
  */
 
399
 
 
400
  (void)replicator_prepare(session);
 
401
 
398
402
  return 0;
399
403
}
400
404
 
487
491
  {
488
492
    Query_log_event qev(session, STRING_WITH_LEN("COMMIT"), true, false);
489
493
    qev.error_code= 0; // see comment in DRIZZLE_LOG::write(Session, IO_CACHE)
 
494
    /* TODO: Fix return type */
 
495
    (void)replicator_end_transaction(session, all, true);
490
496
    int error= binlog_end_trans(session, trx_data, &qev, all);
491
497
    return(error);
492
498
  }
545
551
     */
546
552
    error= binlog_end_trans(session, trx_data, 0, all);
547
553
  }
 
554
 
 
555
  /* TODO: Fix return type */
 
556
  (void)replicator_end_transaction(session, all, false);
 
557
 
548
558
  return(error);
549
559
}
550
560
 
574
584
 
575
585
static int binlog_savepoint_set(handlerton *, Session *session, void *sv)
576
586
{
 
587
  (void)replicator_savepoint_set(session, sv);
577
588
  binlog_trans_log_savepos(session, (my_off_t*) sv);
578
589
  /* Write it to the binary log */
579
590
 
585
596
 
586
597
static int binlog_savepoint_rollback(handlerton *, Session *session, void *sv)
587
598
{
 
599
  bool error;
588
600
  /*
589
601
    Write ROLLBACK TO SAVEPOINT to the binlog cache if we have updated some
590
602
    non-transactional table. Otherwise, truncate the binlog cache starting
595
607
  {
596
608
    int error=
597
609
      session->binlog_query(Session::STMT_QUERY_TYPE,
598
 
                        session->query, session->query_length, true, false);
 
610
                            session->query, session->query_length, true, false);
599
611
    return(error);
600
612
  }
601
613
  binlog_trans_log_truncate(session, *(my_off_t*)sv);
 
614
 
 
615
 
 
616
  error= replicator_rollback_to_savepoint(session, sv);
 
617
 
602
618
  return(0);
603
619
}
604
620
 
2137
2153
  return(0);
2138
2154
}
2139
2155
 
2140
 
/*
2141
 
  Function to start a statement and optionally a transaction for the
2142
 
  binary log.
2143
 
 
2144
 
  SYNOPSIS
2145
 
    binlog_start_trans_and_stmt()
2146
 
 
2147
 
  DESCRIPTION
2148
 
 
2149
 
    This function does three things:
2150
 
    - Start a transaction if not in autocommit mode or if a BEGIN
2151
 
      statement has been seen.
2152
 
 
2153
 
    - Start a statement transaction to allow us to truncate the binary
2154
 
      log.
2155
 
 
2156
 
    - Save the currrent binlog position so that we can roll back the
2157
 
      statement by truncating the transaction log.
2158
 
 
2159
 
      We only update the saved position if the old one was undefined,
2160
 
      the reason is that there are some cases (e.g., for CREATE-SELECT)
2161
 
      where the position is saved twice (e.g., both in
2162
 
      select_create::prepare() and Session::binlog_write_table_map()) , but
2163
 
      we should use the first. This means that calls to this function
2164
 
      can be used to start the statement before the first table map
2165
 
      event, to include some extra events.
2166
 
 */
2167
 
 
2168
 
void
2169
 
Session::binlog_start_trans_and_stmt()
2170
 
{
2171
 
  binlog_trx_data *trx_data= (binlog_trx_data*) session_get_ha_data(this, binlog_hton);
2172
 
 
2173
 
  if (trx_data == NULL ||
2174
 
      trx_data->before_stmt_pos == MY_OFF_T_UNDEF)
2175
 
  {
2176
 
    this->binlog_set_stmt_begin();
2177
 
    if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
2178
 
      trans_register_ha(this, true, binlog_hton);
2179
 
    trans_register_ha(this, false, binlog_hton);
2180
 
    /*
2181
 
      Mark statement transaction as read/write. We never start
2182
 
      a binary log transaction and keep it read-only,
2183
 
      therefore it's best to mark the transaction read/write just
2184
 
      at the same time we start it.
2185
 
      Not necessary to mark the normal transaction read/write
2186
 
      since the statement-level flag will be propagated automatically
2187
 
      inside ha_commit_trans.
2188
 
    */
2189
 
    ha_data[binlog_hton->slot].ha_info[0].set_trx_read_write();
2190
 
  }
2191
 
  return;
2192
 
}
2193
 
 
2194
2156
void Session::binlog_set_stmt_begin() {
2195
2157
  binlog_trx_data *trx_data=
2196
2158
    (binlog_trx_data*) session_get_ha_data(this, binlog_hton);
2208
2170
}
2209
2171
 
2210
2172
 
2211
 
/*
2212
 
  Write a table map to the binary log.
2213
 
 */
2214
 
 
2215
 
int Session::binlog_write_table_map(Table *table, bool is_trans)
2216
 
{
2217
 
  int error;
2218
 
 
2219
 
  /* Pre-conditions */
2220
 
  assert(table->s->table_map_id != UINT32_MAX);
2221
 
 
2222
 
  Table_map_log_event::flag_set const
2223
 
    flags= Table_map_log_event::TM_NO_FLAGS;
2224
 
 
2225
 
  Table_map_log_event
2226
 
    the_event(this, table, table->s->table_map_id, is_trans, flags);
2227
 
 
2228
 
  if (is_trans && binlog_table_maps == 0)
2229
 
    binlog_start_trans_and_stmt();
2230
 
 
2231
 
  if ((error= drizzle_bin_log.write(&the_event)))
2232
 
    return(error);
2233
 
 
2234
 
  binlog_table_maps++;
2235
 
  table->s->table_map_version= drizzle_bin_log.table_map_version();
2236
 
  return(0);
2237
 
}
2238
 
 
2239
2173
Rows_log_event*
2240
2174
Session::binlog_get_pending_rows_event() const
2241
2175
{
2422
2356
      my_off_t trans_log_pos= my_b_tell(trans_log);
2423
2357
      if (event_info->get_cache_stmt() || trans_log_pos != 0)
2424
2358
      {
2425
 
        if (trans_log_pos == 0)
2426
 
          session->binlog_start_trans_and_stmt();
2427
2359
        file= trans_log;
2428
2360
      }
2429
2361
      /*
3618
3550
  Xid_log_event xle(session, xid);
3619
3551
  binlog_trx_data *trx_data=
3620
3552
    (binlog_trx_data*) session_get_ha_data(session, binlog_hton);
 
3553
  /* TODO: Fix return type */
 
3554
  (void)replicator_end_transaction(session, true, true);
3621
3555
  /*
3622
3556
    We always commit the entire transaction when writing an XID. Also
3623
3557
    note that the return value is inverted.