~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/log.cc

  • Committer: Brian Aker
  • Date: 2008-12-06 22:41:58 UTC
  • Revision ID: brian@tangent.org-20081206224158-oj4j95n7w0mtxxd1
Completing up replication API.

Show diffs side-by-side

added added

removed removed

Lines of Context:
388
388
  return(error);
389
389
}
390
390
 
391
 
static int binlog_prepare(handlerton *, Session *, bool)
 
391
static int binlog_prepare(handlerton *, Session *session, bool)
392
392
{
393
393
  /*
394
394
    do nothing.
396
396
    switch to 1pc.
397
397
    real work will be done in DRIZZLE_BIN_LOG::log_xid()
398
398
  */
 
399
 
 
400
  (void)replicator_prepare(session);
 
401
 
399
402
  return 0;
400
403
}
401
404
 
581
584
 
582
585
static int binlog_savepoint_set(handlerton *, Session *session, void *sv)
583
586
{
 
587
  (void)replicator_savepoint_set(session, sv);
584
588
  binlog_trans_log_savepos(session, (my_off_t*) sv);
585
589
  /* Write it to the binary log */
586
590
 
592
596
 
593
597
static int binlog_savepoint_rollback(handlerton *, Session *session, void *sv)
594
598
{
 
599
  bool error;
595
600
  /*
596
601
    Write ROLLBACK TO SAVEPOINT to the binlog cache if we have updated some
597
602
    non-transactional table. Otherwise, truncate the binlog cache starting
602
607
  {
603
608
    int error=
604
609
      session->binlog_query(Session::STMT_QUERY_TYPE,
605
 
                        session->query, session->query_length, true, false);
 
610
                            session->query, session->query_length, true, false);
606
611
    return(error);
607
612
  }
608
613
  binlog_trans_log_truncate(session, *(my_off_t*)sv);
 
614
 
 
615
 
 
616
  error= replicator_rollback_to_savepoint(session, sv);
 
617
 
609
618
  return(0);
610
619
}
611
620
 
2144
2153
  return(0);
2145
2154
}
2146
2155
 
2147
 
/*
2148
 
  Function to start a statement and optionally a transaction for the
2149
 
  binary log.
2150
 
 
2151
 
  SYNOPSIS
2152
 
    binlog_start_trans_and_stmt()
2153
 
 
2154
 
  DESCRIPTION
2155
 
 
2156
 
    This function does three things:
2157
 
    - Start a transaction if not in autocommit mode or if a BEGIN
2158
 
      statement has been seen.
2159
 
 
2160
 
    - Start a statement transaction to allow us to truncate the binary
2161
 
      log.
2162
 
 
2163
 
    - Save the currrent binlog position so that we can roll back the
2164
 
      statement by truncating the transaction log.
2165
 
 
2166
 
      We only update the saved position if the old one was undefined,
2167
 
      the reason is that there are some cases (e.g., for CREATE-SELECT)
2168
 
      where the position is saved twice (e.g., both in
2169
 
      select_create::prepare() and Session::binlog_write_table_map()) , but
2170
 
      we should use the first. This means that calls to this function
2171
 
      can be used to start the statement before the first table map
2172
 
      event, to include some extra events.
2173
 
 */
2174
 
 
2175
 
void
2176
 
Session::binlog_start_trans_and_stmt()
2177
 
{
2178
 
  binlog_trx_data *trx_data= (binlog_trx_data*) session_get_ha_data(this, binlog_hton);
2179
 
 
2180
 
  if (trx_data == NULL ||
2181
 
      trx_data->before_stmt_pos == MY_OFF_T_UNDEF)
2182
 
  {
2183
 
    this->binlog_set_stmt_begin();
2184
 
    if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
2185
 
      trans_register_ha(this, true, binlog_hton);
2186
 
    trans_register_ha(this, false, binlog_hton);
2187
 
    /*
2188
 
      Mark statement transaction as read/write. We never start
2189
 
      a binary log transaction and keep it read-only,
2190
 
      therefore it's best to mark the transaction read/write just
2191
 
      at the same time we start it.
2192
 
      Not necessary to mark the normal transaction read/write
2193
 
      since the statement-level flag will be propagated automatically
2194
 
      inside ha_commit_trans.
2195
 
    */
2196
 
    ha_data[binlog_hton->slot].ha_info[0].set_trx_read_write();
2197
 
  }
2198
 
  return;
2199
 
}
2200
 
 
2201
2156
void Session::binlog_set_stmt_begin() {
2202
2157
  binlog_trx_data *trx_data=
2203
2158
    (binlog_trx_data*) session_get_ha_data(this, binlog_hton);
2215
2170
}
2216
2171
 
2217
2172
 
2218
 
/*
2219
 
  Write a table map to the binary log.
2220
 
 */
2221
 
 
2222
 
int Session::binlog_write_table_map(Table *table, bool is_trans)
2223
 
{
2224
 
  int error;
2225
 
 
2226
 
  /* Pre-conditions */
2227
 
  assert(table->s->table_map_id != UINT32_MAX);
2228
 
 
2229
 
  Table_map_log_event::flag_set const
2230
 
    flags= Table_map_log_event::TM_NO_FLAGS;
2231
 
 
2232
 
  Table_map_log_event
2233
 
    the_event(this, table, table->s->table_map_id, is_trans, flags);
2234
 
 
2235
 
  if (is_trans && binlog_table_maps == 0)
2236
 
    binlog_start_trans_and_stmt();
2237
 
 
2238
 
  if ((error= drizzle_bin_log.write(&the_event)))
2239
 
    return(error);
2240
 
 
2241
 
  binlog_table_maps++;
2242
 
  table->s->table_map_version= drizzle_bin_log.table_map_version();
2243
 
  return(0);
2244
 
}
2245
 
 
2246
2173
Rows_log_event*
2247
2174
Session::binlog_get_pending_rows_event() const
2248
2175
{
2429
2356
      my_off_t trans_log_pos= my_b_tell(trans_log);
2430
2357
      if (event_info->get_cache_stmt() || trans_log_pos != 0)
2431
2358
      {
2432
 
        if (trans_log_pos == 0)
2433
 
          session->binlog_start_trans_and_stmt();
2434
2359
        file= trans_log;
2435
2360
      }
2436
2361
      /*