[Groonga-mysql-commit] mroonga/mroonga [master] Invalid update to slave if using RBR. refs #1379

Back to archive index

null+****@clear***** null+****@clear*****
2012年 5月 28日 (月) 00:45:05 JST


Kentoku	2012-05-28 00:45:05 +0900 (Mon, 28 May 2012)

  New Revision: b1d73739fb826854f07bf04a3c4317ecf7812c5f

  Log:
    Invalid update to slave if using RBR. refs #1379

  Modified files:
    ha_mroonga.cpp
    ha_mroonga.hpp
    mrn_mysql.h

  Modified: ha_mroonga.cpp (+45 -3)
===================================================================
--- ha_mroonga.cpp    2012-05-25 18:38:10 +0900 (9b4e2d6)
+++ ha_mroonga.cpp    2012-05-28 00:45:05 +0900 (a980f69)
@@ -1723,7 +1723,8 @@ ha_mroonga::ha_mroonga(handlerton *hton, TABLE_SHARE *share_arg)
    inserting_with_update(false),
    fulltext_searching(false),
    ignoring_no_key_columns(false),
-   replacing_(false)
+   replacing_(false),
+   written_by_row_based_binlog(0)
 {
   MRN_DBUG_ENTER_METHOD();
   grn_ctx_init(ctx, 0);
@@ -8586,6 +8587,17 @@ void ha_mroonga::storage_store_fields_for_prep_update(const uchar *old_data,
   DBUG_PRINT("info", ("mroonga: stored record ID: %d", record_id));
   my_ptrdiff_t ptr_diff_old = PTR_BYTE_DIFF(old_data, table->record[0]);
   my_ptrdiff_t ptr_diff_new = 0;
+#ifdef MRN_RBR_UPDATE_NEED_ALL_COLUMNS
+  if (!written_by_row_based_binlog) {
+    if (check_written_by_row_based_binlog()) {
+      written_by_row_based_binlog = 2;
+    } else {
+      written_by_row_based_binlog = 1;
+    }
+  }
+  bool need_all_columns =
+    (new_data && written_by_row_based_binlog == 2);
+#endif
   if (new_data) {
     ptr_diff_new = PTR_BYTE_DIFF(new_data, table->record[0]);
   }
@@ -8597,10 +8609,18 @@ void ha_mroonga::storage_store_fields_for_prep_update(const uchar *old_data,
     if (
       !bitmap_is_set(table->read_set, field->field_index) &&
       !bitmap_is_set(table->write_set, field->field_index) &&
-      bitmap_is_set(&multiple_column_key_bitmap, field->field_index)
+#ifdef MRN_RBR_UPDATE_NEED_ALL_COLUMNS
+      (
+        need_all_columns ||
+#endif
+        bitmap_is_set(&multiple_column_key_bitmap, field->field_index)
+#ifdef MRN_RBR_UPDATE_NEED_ALL_COLUMNS
+      )
+#endif
     ) {
       mrn::DebugColumnAccess debug_column_access(table, table->write_set);
-      DBUG_PRINT("info", ("mroonga: store column %d(%d)",i,field->field_index));      const char *value;
+      DBUG_PRINT("info", ("mroonga: store column %d(%d)",i,field->field_index));
+      const char *value;
       uint32 value_length;
       value = grn_obj_get_value_(ctx, grn_columns[i], record_id,
                                  &value_length);
@@ -9220,6 +9240,7 @@ int ha_mroonga::reset()
   ignoring_duplicated_key = false;
   fulltext_searching = false;
   replacing_ = false;
+  written_by_row_based_binlog = 0;
   mrn_lock_type = F_UNLCK;
   mrn_clear_alter_share(thd);
   DBUG_RETURN(error);
@@ -12264,6 +12285,27 @@ void ha_mroonga::free_foreign_key_create_info(char* str)
   DBUG_VOID_RETURN;
 }
 
+bool ha_mroonga::check_written_by_row_based_binlog()
+{
+  MRN_DBUG_ENTER_METHOD();
+  THD *thd = ha_thd();
+  DBUG_RETURN(
+#ifdef MRN_ROW_BASED_CHECK_IS_METHOD
+    thd->is_current_stmt_binlog_format_row() &&
+#else
+    thd->current_stmt_binlog_row_based &&
+#endif
+    table->s->tmp_table == NO_TMP_TABLE &&
+    binlog_filter->db_ok(table->s->db.str) &&
+#ifdef MRN_OPTION_BITS_IS_UNDER_VARIABLES
+    (thd->variables.option_bits & OPTION_BIN_LOG) &&
+#else
+    (thd->options & OPTION_BIN_LOG) &&
+#endif
+    mysql_bin_log.is_open()
+  );
+}
+
 #ifdef __cplusplus
 }
 #endif

  Modified: ha_mroonga.hpp (+11 -0)
===================================================================
--- ha_mroonga.hpp    2012-05-25 18:38:10 +0900 (6ebf913)
+++ ha_mroonga.hpp    2012-05-28 00:45:05 +0900 (cbeb428)
@@ -135,6 +135,15 @@ extern "C" {
 #  define MRN_HANDLER_AUTO_REPAIR_HAVE_ERROR
 #endif
 
+#if MYSQL_VERSION_ID < 50600
+#  define MRN_RBR_UPDATE_NEED_ALL_COLUMNS
+#endif
+
+#if MYSQL_VERSION_ID >= 50500
+#  define MRN_ROW_BASED_CHECK_IS_METHOD
+#  define MRN_OPTION_BITS_IS_UNDER_VARIABLES
+#endif
+
 class ha_mroonga;
 
 /* structs */
@@ -232,6 +241,7 @@ private:
   bool fulltext_searching;
   bool ignoring_no_key_columns;
   bool replacing_;
+  uint written_by_row_based_binlog;
 
 public:
   ha_mroonga(handlerton *hton, TABLE_SHARE *share_arg);
@@ -937,6 +947,7 @@ private:
   void storage_free_foreign_key_create_info(char* str);
   void wrapper_set_keys_in_use();
   void storage_set_keys_in_use();
+  bool check_written_by_row_based_binlog();
 };
 
 #ifdef __cplusplus

  Modified: mrn_mysql.h (+1 -0)
===================================================================
--- mrn_mysql.h    2012-05-25 18:38:10 +0900 (dd4803c)
+++ mrn_mysql.h    2012-05-28 00:45:05 +0900 (b975f89)
@@ -52,6 +52,7 @@
 #  include <probes_mysql.h>
 #  include <sql_partition.h>
 #endif
+#include "rpl_filter.h"
 
 #ifdef MARIADB_BASE_VERSION
 #  define MRN_MARIADB_P 1




Groonga-mysql-commit メーリングリストの案内
Back to archive index