List:Commits« Previous MessageNext Message »
From:tomas Date:November 2 2007 5:28pm
Subject:bk commit into 5.1 tree (tomas:1.2703)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of tomas. When tomas does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-11-02 17:28:08+01:00, tomas@stripped +4 -0
  WL#4080
  - rewrite, move handler -> share pointer for retrieving pk
    as handler becomes invalid

  sql/ha_ndbcluster.cc@stripped, 2007-11-02 17:28:05+01:00, tomas@stripped +44
-47
    WL#4080
    - rewrite, move handler -> share pointer for retrieving pk
      as handler becomes invalid

  sql/ha_ndbcluster.h@stripped, 2007-11-02 17:28:05+01:00, tomas@stripped +10
-5
    WL#4080
    - rewrite, move handler -> share pointer for retrieving pk
      as handler becomes invalid

  sql/ha_ndbcluster_binlog.cc@stripped, 2007-11-02 17:28:05+01:00,
tomas@stripped +59 -37
    WL#4080
    - rewrite, move handler -> share pointer for retrieving pk
      as handler becomes invalid

  sql/ha_ndbcluster_binlog.h@stripped, 2007-11-02 17:28:05+01:00,
tomas@stripped +2 -1
    WL#4080
    - rewrite, move handler -> share pointer for retrieving pk
      as handler becomes invalid

diff -Nrup a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
--- a/sql/ha_ndbcluster.cc	2007-11-02 17:24:07 +01:00
+++ b/sql/ha_ndbcluster.cc	2007-11-02 17:28:05 +01:00
@@ -294,15 +294,16 @@ static int ndb_to_mysql_error(const NdbE
 
 #ifdef HAVE_NDB_BINLOG
 /* Write conflicting row to exceptions table. */
-int
-ha_ndbcluster::write_conflict_row(NdbTransaction* trans,
-                                  const uchar* row,
-                                  NdbError& err)
+static int write_conflict_row(NDB_SHARE *share,
+                              NdbTransaction *trans,
+                              const uchar *row,
+                              NdbError& err)
 {
   DBUG_ENTER("write_conflict_row");
 
   /* get exceptions table */
-  const NDBTAB *ex_tab= m_share->m_cfn_share->m_ex_tab;
+  NDB_CONFLICT_FN_SHARE *cfn_share= share->m_cfn_share;
+  const NDBTAB *ex_tab= cfn_share->m_ex_tab;
   DBUG_ASSERT(ex_tab != NULL);
 
   /* get insert op */
@@ -318,11 +319,10 @@ ha_ndbcluster::write_conflict_row(NdbTra
     DBUG_RETURN(-1);
   }
   {
-    (m_share->m_cfn_share->m_count)++;
     uint32 server_id= (uint32)::server_id;
     uint32 master_server_id= (uint32)active_mi->master_server_id;
     uint64 master_epoch= (uint64)active_mi->master_epoch;
-    uint32 count= (uint32)m_share->m_cfn_share->m_count;
+    uint32 count= (uint32)++(cfn_share->m_count);
     if (ex_op->setValue((Uint32)0, (const char *)&(server_id)) ||
         ex_op->setValue((Uint32)1, (const char *)&(master_server_id)) ||
         ex_op->setValue((Uint32)2, (const char *)&(master_epoch)) ||
@@ -335,24 +335,16 @@ ha_ndbcluster::write_conflict_row(NdbTra
   /* copy primary keys */
   {
     const int fixed_cols= 4;
-    const NDBTAB* tab= m_table;
-    int ncol= tab->getNoOfColumns();
-    int nkey= tab->getNoOfPrimaryKeys();
-    int i, k;
-    for (i= k= 0; i < ncol && k < nkey; i++)
-    {
-      const NdbDictionary::Column* col= tab->getColumn(i);
-      if (col->getPrimaryKey())
-      {
-        DBUG_ASSERT(row != NULL);
-        ptrdiff_t offset= table->field[i]->ptr - table->record[0];
-        const uchar* data= row + offset;
-        if (ex_op->setValue((Uint32)(fixed_cols + k), (const char*)data) == -1)
-        {
-          err= ex_op->getNdbError();
-          DBUG_RETURN(-1);
-        }
-        k++;
+    int nkey= cfn_share->m_pk_cols;
+    int k;
+    for (k= 0; k < nkey; k++)
+    {
+      DBUG_ASSERT(row != NULL);
+      const uchar* data= row + cfn_share->m_offset[k];
+      if (ex_op->setValue((Uint32)(fixed_cols + k), (const char*)data) == -1)
+      {
+        err= ex_op->getNdbError();
+        DBUG_RETURN(-1);
       }
     }
   }
@@ -395,16 +387,15 @@ check_completed_operations_pre_commit(Th
         {
           Ndb_exceptions_data ex_data;
           memcpy(&ex_data, buffer, sizeof(ex_data));
-          ha_ndbcluster* h= ex_data.handler;
+          NDB_SHARE *share= ex_data.share;
           const uchar* row= ex_data.row;
-          DBUG_ASSERT(h != NULL && row != NULL);
+          DBUG_ASSERT(share != NULL && row != NULL);
 
-          NDB_SHARE* share= h->m_share;
           NDB_CONFLICT_FN_SHARE* cfn_share= share->m_cfn_share;
           if (cfn_share && cfn_share->m_ex_tab)
           {
             NdbError ex_err;
-            if (h->write_conflict_row(trans, row, ex_err))
+            if (write_conflict_row(share, trans, row, ex_err))
             {
               char msg[FN_REFLEN];
               my_snprintf(msg, sizeof(msg), "table %s NDB error %d '%s'",
@@ -415,7 +406,6 @@ check_completed_operations_pre_commit(Th
 
               if (ex_err.classification == NdbError::SchemaError)
               {
-                sql_print_warning("NDB Slave: exceptions table invalid, conflict logging
stopped: %s", msg);
                 dict->removeTableGlobal(*(cfn_share->m_ex_tab), false);
                 cfn_share->m_ex_tab= NULL;
               }
@@ -434,7 +424,9 @@ check_completed_operations_pre_commit(Th
               }
             }
             else
+            {
               conflict_rows_written++;
+            }
           }
           else
           {
@@ -466,6 +458,10 @@ check_completed_operations_pre_commit(Th
       abort();
       //err= trans->getNdbError();
     }
+    if (trans->getNdbError().code)
+    {
+      sql_print_error("NDB slave: write conflict row error code %d",
trans->getNdbError().code);
+    }
   }
 #endif
   DBUG_RETURN(0);
@@ -1470,7 +1466,8 @@ int cmp_frm(const NDBTAB *ndbtab, const 
 
 int ha_ndbcluster::get_metadata(const char *path)
 {
-  Ndb *ndb= get_ndb();
+  THD *thd= current_thd;
+  Ndb *ndb= get_thd_ndb(thd)->ndb;
   NDBDICT *dict= ndb->getDictionary();
   const NDBTAB *tab;
   int error;
@@ -1541,6 +1538,7 @@ int ha_ndbcluster::get_metadata(const ch
   if ((error= open_indexes(ndb, table, FALSE)) == 0)
   {
     ndbtab_g.release();
+    ndbcluster_read_binlog_replication(thd, ndb, m_share, m_table, ::server_id, table);
     DBUG_RETURN(0);
   }
 
@@ -4278,8 +4276,10 @@ int ha_ndbcluster::ndb_update_row(const 
     }
 
     NdbInterpretedCode *code= NULL;
+    uchar* ex_data_buffer= NULL;
 #ifdef HAVE_NDB_BINLOG
-    if (thd->slave_thread && m_share->m_cfn_share)
+    if (thd->slave_thread && m_share->m_cfn_share &&
+        (m_share->m_cfn_share->m_resolve_cft != CFT_NDB_UNDEF))
     {
       /*
         Room for 10 instruction words, two labels, and two jumps.
@@ -4297,26 +4297,23 @@ int ha_ndbcluster::ndb_update_row(const 
         abort();
       }
       thd_ndb->m_conflict_fn_usage_count++;
-    }
-#endif /* HAVE_NDB_BINLOG */
-    if (!(op= trans->updateTuple(key_rec, (const char *)key_row,
-                                 m_ndb_record, (const char*)row, mask,
-                                 NULL, NULL, code)))
-      ERR_RETURN(trans->getNdbError());  
-#ifdef HAVE_NDB_BINLOG
-    {
+
       Ndb_exceptions_data ex_data;
-      ex_data.handler= this;
+      ex_data.share= m_share;
       ex_data.row= row;
-      uchar* buffer= get_buffer(sizeof(ex_data));
+      ex_data_buffer= get_buffer(sizeof(ex_data));
       if (buffer == NULL)
       {
         DBUG_RETURN(HA_ERR_OUT_OF_MEM);
       }
-      memcpy(buffer, &ex_data, sizeof(ex_data));
-      op->setCustomData((void*)buffer);
+      memcpy(ex_data_buffer, &ex_data, sizeof(ex_data));
     }
-#endif
+#endif /* HAVE_NDB_BINLOG */
+    if (!(op= trans->updateTuple(key_rec, (const char *)key_row,
+                                 m_ndb_record, (const char*)row, mask,
+                                 NULL, NULL, code)))
+      ERR_RETURN(trans->getNdbError());  
+    op->setCustomData((void*)ex_data_buffer);
   }
 
   if (m_user_defined_partitioning)
@@ -6926,7 +6923,7 @@ int ha_ndbcluster::create(const char *na
     while (!IS_TMP_PREFIX(m_tabname))
     {
       if (share)
-        ndbcluster_read_binlog_replication(thd, ndb, share, m_table, ::server_id);
+        ndbcluster_read_binlog_replication(thd, ndb, share, m_table, ::server_id, NULL);
       String event_name(INJECTOR_EVENT_LEN);
       ndb_rep_event_name(&event_name, m_dbname, m_tabname,
                          get_binlog_full(share));
@@ -7318,7 +7315,7 @@ int ha_ndbcluster::rename_table(const ch
     const NDBTAB *ndbtab= ndbtab_g2.get_table();
 
     if (share)
-      ndbcluster_read_binlog_replication(thd, ndb, share, ndbtab, ::server_id);
+      ndbcluster_read_binlog_replication(thd, ndb, share, ndbtab, ::server_id, NULL);
 
     /* always create an event for the table */
     String event_name(INJECTOR_EVENT_LEN);
diff -Nrup a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h
--- a/sql/ha_ndbcluster.h	2007-11-01 14:19:58 +01:00
+++ b/sql/ha_ndbcluster.h	2007-11-02 17:28:05 +01:00
@@ -136,14 +136,20 @@ enum enum_conflict_fn_type
 
 /* NdbOperation custom data which points out handler and record. */
 struct Ndb_exceptions_data {
-  class ha_ndbcluster* handler;
+  struct st_ndbcluster_share *share;
   const uchar* row;
 };
 
 typedef struct st_ndbcluster_conflict_fn_share {
   enum_conflict_fn_type m_resolve_cft;
-  uint32 m_resolve_column;
-  uint32 m_resolve_size;
+
+  /* info about original table */
+  uint8 m_pk_cols;
+  uint8 m_resolve_column;
+  uint8 m_resolve_size;
+  uint8 unused;
+  uint16 m_offset[16];
+
   const NdbDictionary::Table *m_ex_tab;
   uint32 m_count;
 } NDB_CONFLICT_FN_SHARE;
@@ -279,7 +285,7 @@ class Thd_ndb 
   Ndb_cluster_connection *connection;
   Ndb *ndb;
   /* this */
-  ha_ndbcluster *m_handler;
+  class ha_ndbcluster *m_handler;
   ulong count;
   uint lock_count;
   uint start_stmt_count;
@@ -695,7 +701,6 @@ private:
     return start_transaction(error);
   }
 
-  int write_conflict_row(NdbTransaction*, const uchar* row, NdbError&);
   friend int check_completed_operations_pre_commit(Thd_ndb*,
                                                    NdbTransaction*,
                                                    const NdbOperation*,
diff -Nrup a/sql/ha_ndbcluster_binlog.cc b/sql/ha_ndbcluster_binlog.cc
--- a/sql/ha_ndbcluster_binlog.cc	2007-11-01 20:13:40 +01:00
+++ b/sql/ha_ndbcluster_binlog.cc	2007-11-02 17:28:05 +01:00
@@ -2731,11 +2731,22 @@ set_binlog_flags(NDB_SHARE *share,
   }
   set_binlog_logging(share);
 }
+
+
+inline void slave_reset_conflict_fn(NDB_SHARE *share)
+{
+  NDB_CONFLICT_FN_SHARE *cfn_share= share->m_cfn_share;
+  if (cfn_share)
+  {
+    bzero((char*)cfn_share, sizeof(*cfn_share));
+  }
+}
+
 static int
-slave_set_resolve_max(NDB_SHARE *share, const NDBTAB *ndbtab, uint field_index,
-                      enum_conflict_fn_type type)
+slave_set_resolve_fn(NDB_SHARE *share, const NDBTAB *ndbtab, uint field_index,
+                     enum_conflict_fn_type type, TABLE *table)
 {
-  DBUG_ENTER("slave_set_resolve_max");
+  DBUG_ENTER("slave_set_resolve_fn");
 
   Thd_ndb *thd_ndb= get_thd_ndb(current_thd);
   Ndb *ndb= thd_ndb->ndb;
@@ -2757,19 +2768,22 @@ slave_set_resolve_max(NDB_SHARE *share, 
   default:
     DBUG_PRINT("info", ("resolve column %u has wrong type",
                         field_index));
+    slave_reset_conflict_fn(share);
     DBUG_RETURN(-1);
     break;
   }
-  if (share->m_cfn_share == NULL)
+
+  NDB_CONFLICT_FN_SHARE *cfn_share= share->m_cfn_share;
+  if (cfn_share == NULL)
   {
-    share->m_cfn_share= (NDB_CONFLICT_FN_SHARE*)
+    share->m_cfn_share= cfn_share= (NDB_CONFLICT_FN_SHARE*)
       alloc_root(&share->mem_root, sizeof(NDB_CONFLICT_FN_SHARE));
+    slave_reset_conflict_fn(share);
   }
-  share->m_cfn_share->m_resolve_size= sz;
-  share->m_cfn_share->m_resolve_column= field_index;
-  share->m_cfn_share->m_resolve_cft= type;
-  share->m_cfn_share->m_ex_tab= NULL;
-  share->m_cfn_share->m_count= 0;
+  cfn_share->m_resolve_size= sz;
+  cfn_share->m_resolve_column= field_index;
+  cfn_share->m_resolve_cft= type;
+
   {
     /* get exceptions table */
     char ex_tab_name[FN_REFLEN];
@@ -2805,13 +2819,15 @@ slave_set_resolve_max(NDB_SHARE *share, 
               col->getLength() == ex_col->getLength() &&
               col->getNullable() == ex_col->getNullable();
             if (!ok)
-             break;
+              break;
+            cfn_share->m_offset[k]= (uint16)(table->field[i]->ptr -
table->record[0]);
             k++;
           }
         }
         if (ok)
         {
-          share->m_cfn_share->m_ex_tab= ex_tab;
+          cfn_share->m_ex_tab= ex_tab;
+          cfn_share->m_pk_cols= nkey;
           ndbtab_g.release();
           if (ndb_extra_logging)
             sql_print_information("NDB Slave: log exceptions to %s", ex_tab_name);
@@ -2859,12 +2875,11 @@ set_conflict_fn(NDB_SHARE *share,
                 const NDBTAB *ndbtab,
                 const NDBCOL *conflict_col,
                 char *conflict_fn,
-                char *msg, uint msg_len)
+                char *msg, uint msg_len,
+                TABLE *table)
 {
   DBUG_ENTER("set_conflict_fn");
   uint len= 0;
-  Ndb_event_data *event_data= (share->event_data != 0) ?
-    share->event_data : (Ndb_event_data *)share->op->getCustomData();
   switch (conflict_col->getArrayType())
   {
   case NDBCOL::ArrayTypeShortVar:
@@ -2961,7 +2976,7 @@ set_conflict_fn(NDB_SHARE *share,
       {
         /* find column in table */
         DBUG_PRINT("info", ("searching for %s %u", start_arg, len));
-        TABLE_SHARE *table_s= event_data->table_share;
+        TABLE_SHARE *table_s= table->s;
         for (uint j= 0; j < table_s->fields; j++)
         {
           Field *field= table_s->field[j];
@@ -3013,22 +3028,20 @@ set_conflict_fn(NDB_SHARE *share,
     case CFT_NDB_OLD:
       if (args[0].fieldno == (uint32)-1)
         break;
-      if (slave_set_resolve_max(share, ndbtab, args[0].fieldno, fn.type))
+      if (slave_set_resolve_fn(share, ndbtab, args[0].fieldno, fn.type, table))
       {
         /* wrong data type */
-        TABLE_SHARE *table_s= event_data->table_share;
         snprintf(msg, msg_len,
                  "column '%s' has wrong datatype",
-                 table_s->field[args[0].fieldno]->field_name);
+                 table->s->field[args[0].fieldno]->field_name);
         DBUG_PRINT("info", (msg));
         DBUG_RETURN(-1);
       }
       if (ndb_extra_logging)
       {
-        TABLE_SHARE *table_s= event_data->table_share;
         sql_print_information("NDB Slave: conflict_fn %s on attribute %s",
                               fn.name,
-                              table_s->field[args[0].fieldno]->field_name);
+                              table->s->field[args[0].fieldno]->field_name);
       }
       break;
     case CFT_NDB_UNDEF:
@@ -3054,7 +3067,8 @@ int
 ndbcluster_read_binlog_replication(THD *thd, Ndb *ndb,
                                    NDB_SHARE *share,
                                    const NDBTAB *ndbtab,
-                                   uint server_id)
+                                   uint server_id,
+                                   TABLE *table)
 {
   DBUG_ENTER("ndbcluster_read_binlog_replication");
   const char *db= share->db;
@@ -3071,7 +3085,8 @@ ndbcluster_read_binlog_replication(THD *
       dict->getNdbError().classification == NdbError::SchemaError)
   {
     DBUG_PRINT("info", ("No %s.%s table", ndb_rep_db, ndb_replication_table));
-    set_binlog_flags(share, NBT_DEFAULT);
+    if (!table)
+      set_binlog_flags(share, NBT_DEFAULT);
     DBUG_RETURN(0);
   }
   const NDBCOL
@@ -3201,20 +3216,26 @@ ndbcluster_read_binlog_replication(THD *
       ndb_conflict_fn[1]= ndb_conflict_fn[0];
     }
 
-    if (col_binlog_type_rec_attr[1] == NULL ||
-        col_binlog_type_rec_attr[1]->isNULL())
-      set_binlog_flags(share, NBT_DEFAULT);
+    if (!table)
+    {
+      if (col_binlog_type_rec_attr[1] == NULL ||
+          col_binlog_type_rec_attr[1]->isNULL())
+        set_binlog_flags(share, NBT_DEFAULT);
+      else
+        set_binlog_flags(share, (enum Ndb_binlog_type) ndb_binlog_type[1]);
+    }
     else
-      set_binlog_flags(share, (enum Ndb_binlog_type) ndb_binlog_type[1]);
-    if (col_conflict_fn_rec_attr[1] == NULL ||
-        col_conflict_fn_rec_attr[1]->isNULL())
-      ; /* no conflict_fn */
-    else if (set_conflict_fn(share, ndbtab, col_conflict_fn, ndb_conflict_fn[1],
-                             tmp_buf, sizeof(tmp_buf)))
-    {
-      error_str= tmp_buf;
-      error= 1;
-      goto err;
+    {
+      if (col_conflict_fn_rec_attr[1] == NULL ||
+          col_conflict_fn_rec_attr[1]->isNULL())
+        slave_reset_conflict_fn(share); /* no conflict_fn */
+      else if (set_conflict_fn(share, ndbtab, col_conflict_fn, ndb_conflict_fn[1],
+                               tmp_buf, sizeof(tmp_buf), table))
+      {
+        error_str= tmp_buf;
+        error= 1;
+        goto err;
+      }
     }
 
     DBUG_RETURN(0);
@@ -3424,7 +3445,8 @@ int ndbcluster_create_binlog_setup(Ndb *
 
     /*
      */
-    ndbcluster_read_binlog_replication(current_thd, ndb, share, ndbtab, ::server_id);
+    ndbcluster_read_binlog_replication(current_thd, ndb, share, ndbtab,
+                                       ::server_id, NULL);
 
     /*
       check if logging turned off for this table
diff -Nrup a/sql/ha_ndbcluster_binlog.h b/sql/ha_ndbcluster_binlog.h
--- a/sql/ha_ndbcluster_binlog.h	2007-10-30 16:16:13 +01:00
+++ b/sql/ha_ndbcluster_binlog.h	2007-11-02 17:28:05 +01:00
@@ -208,7 +208,8 @@ int
 ndbcluster_read_binlog_replication(THD *thd, Ndb *ndb,
                                    NDB_SHARE *share,
                                    const NDBTAB *ndbtab,
-                                   uint server_id);
+                                   uint server_id,
+                                   TABLE *table);
 int ndb_create_table_from_engine(THD *thd, const char *db,
                                  const char *table_name);
 int ndbcluster_binlog_start();
Thread
bk commit into 5.1 tree (tomas:1.2703)tomas2 Nov