~drizzle-pbxt/drizzle/drizzle-pbxt-2

« back to all changes in this revision

Viewing changes to drizzled/cursor.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-11-11 01:26:04 UTC
  • mfrom: (1014.3.194 staging)
  • Revision ID: osullivan.padraig@gmail.com-20091111012604-p339jz8jeqtk4ot4
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
690
690
      session->transaction.cleanup();
691
691
    }
692
692
  }
 
693
  if (error == 0)
 
694
  {
 
695
    if (is_real_trans)
 
696
    {
 
697
      /* 
 
698
        * We commit the normal transaction by finalizing the transaction message
 
699
        * and propogating the message to all registered replicators.
 
700
        */
 
701
      ReplicationServices &replication_services= ReplicationServices::singleton();
 
702
      replication_services.commitNormalTransaction(session);
 
703
    }
 
704
  }
693
705
  return error;
694
706
}
695
707
 
1589
1601
*/
1590
1602
void Cursor::print_error(int error, myf errflag)
1591
1603
{
1592
 
  int textno=ER_GET_ERRNO;
 
1604
  int textno= ER_GET_ERRNO;
1593
1605
  switch (error) {
1594
1606
  case EACCES:
1595
1607
    textno=ER_OPEN_AS_READONLY;
1747
1759
    return;
1748
1760
  default:
1749
1761
    {
1750
 
      /* The error was "unknown" to this function.
1751
 
         Ask Cursor if it has got a message for this error */
 
1762
      /* 
 
1763
        The error was "unknown" to this function.
 
1764
        Ask Cursor if it has got a message for this error 
 
1765
      */
1752
1766
      bool temporary= false;
1753
1767
      String str;
1754
1768
      temporary= get_error_message(error, &str);
2519
2533
  Check if the conditions for row-based binlogging is correct for the table.
2520
2534
 
2521
2535
  A row in the given table should be replicated if:
2522
 
  - Row-based replication is enabled in the current thread
2523
 
  - The binlog is enabled
2524
2536
  - It is not a temporary table
2525
 
  - The binary log is open
2526
 
  - The database the table resides in shall be binlogged (binlog_*_db rules)
2527
 
  - table is not mysql.event
2528
2537
*/
2529
2538
 
2530
2539
static bool log_row_for_replication(Table* table,
2531
 
                           const unsigned char *before_record,
2532
 
                           const unsigned char *after_record)
 
2540
                                    const unsigned char *before_record,
 
2541
                                    const unsigned char *after_record)
2533
2542
{
2534
2543
  ReplicationServices &replication_services= ReplicationServices::singleton();
2535
2544
  Session *const session= table->in_use;
2536
2545
 
 
2546
  if (table->s->tmp_table || ! replication_services.isActive())
 
2547
    return false;
 
2548
 
2537
2549
  switch (session->lex->sql_command)
2538
2550
  {
2539
2551
  case SQLCOM_REPLACE:
 
2552
  case SQLCOM_REPLACE_SELECT:
 
2553
    /*
 
2554
     * This is a total hack because of the code that is
 
2555
     * in write_record() in sql_insert.cc. During
 
2556
     * a REPLACE statement, a call to ha_write_row() is
 
2557
     * called.  If it fails, then a call to ha_delete_row()
 
2558
     * is called, followed by a repeat of the original
 
2559
     * call to ha_write_row().  So, log_row_for_replication
 
2560
     * could be called either once or twice for a REPLACE
 
2561
     * statement.  The below looks at the values of before_record
 
2562
     * and after_record to determine which call to this
 
2563
     * function is for the delete or the insert, since NULL
 
2564
     * is passed for after_record for the delete and NULL is
 
2565
     * passed for before_record for the insert...
 
2566
     *
 
2567
     * In addition, there is an optimization that allows an
 
2568
     * engine to convert the above delete + insert into an
 
2569
     * update, so we must also check for this case below...
 
2570
     */
 
2571
    if (after_record == NULL)
 
2572
    {
 
2573
      replication_services.deleteRecord(session, table);
 
2574
      /* 
 
2575
       * We set the "current" statement message to NULL.  This triggers
 
2576
       * the replication services component to generate a new statement
 
2577
       * message for the inserted record which will come next.
 
2578
       */
 
2579
      replication_services.finalizeStatement(*session->getStatementMessage(), session);
 
2580
    }
 
2581
    else
 
2582
    {
 
2583
      if (before_record == NULL)
 
2584
        replication_services.insertRecord(session, table);
 
2585
      else
 
2586
        replication_services.updateRecord(session, table, before_record, after_record);
 
2587
    }
 
2588
    break;
2540
2589
  case SQLCOM_INSERT:
2541
 
  case SQLCOM_REPLACE_SELECT:
2542
2590
  case SQLCOM_INSERT_SELECT:
2543
 
  case SQLCOM_CREATE_TABLE:
2544
 
    replication_services.insertRecord(session, table);
 
2591
    /*
 
2592
     * The else block below represents an 
 
2593
     * INSERT ... ON DUPLICATE KEY UPDATE that
 
2594
     * has hit a key conflict and actually done
 
2595
     * an update.
 
2596
     */
 
2597
    if (before_record == NULL)
 
2598
      replication_services.insertRecord(session, table);
 
2599
    else
 
2600
      replication_services.updateRecord(session, table, before_record, after_record);
2545
2601
    break;
2546
2602
 
2547
2603
  case SQLCOM_UPDATE:
2551
2607
  case SQLCOM_DELETE:
2552
2608
    replication_services.deleteRecord(session, table);
2553
2609
    break;
2554
 
 
2555
 
    /*
2556
 
      For everything else we ignore the event (since it just involves a temp table)
2557
 
    */
2558
2610
  default:
2559
2611
    break;
2560
2612
  }
2561
2613
 
2562
 
  return false; //error;
 
2614
  return false;
2563
2615
}
2564
2616
 
2565
2617
int Cursor::ha_external_lock(Session *session, int lock_type)
2625
2677
    return error;
2626
2678
  }
2627
2679
 
2628
 
  if (unlikely(log_row_for_replication(table, 0, buf)))
 
2680
  if (unlikely(log_row_for_replication(table, NULL, buf)))
2629
2681
    return HA_ERR_RBR_LOGGING_FAILED;
2630
2682
 
2631
2683
  return 0;
2664
2716
  if (unlikely(error= delete_row(buf)))
2665
2717
    return error;
2666
2718
 
2667
 
  if (unlikely(log_row_for_replication(table, buf, 0)))
 
2719
  if (unlikely(log_row_for_replication(table, buf, NULL)))
2668
2720
    return HA_ERR_RBR_LOGGING_FAILED;
2669
2721
 
2670
2722
  return 0;