[Commits] Rev 3019: Fixed bug that another thread used handler->s->id before it was recorded in the log. in lp:maria/5.1

Michael Widenius monty at askmonty.org
Thu Jan 20 19:26:01 EET 2011


At lp:maria/5.1

------------------------------------------------------------
revno: 3019
revision-id: monty at askmonty.org-20110120172600-qpblwhofksvat7v1
parent: monty at askmonty.org-20110120170812-voi2f1wgknbrs9yf
committer: Michael Widenius <monty at askmonty.org>
branch nick: maria-5.1
timestamp: Thu 2011-01-20 19:26:00 +0200
message:
  Fixed bug that another thread used handler->s->id before it was recorded in the log.
  This fixed an assert in recovert in mi_recovery.c "cmp_translog_addr(rec->lsn, checkpoint_start) < 0"
-------------- next part --------------
=== modified file 'storage/maria/ma_loghandler.c'
--- a/storage/maria/ma_loghandler.c	2010-12-04 23:12:10 +0000
+++ b/storage/maria/ma_loghandler.c	2011-01-20 17:26:00 +0000
@@ -6102,7 +6102,7 @@ my_bool translog_write_record(LSN *lsn,
     DBUG_RETURN(1);
   }
 
-  if (tbl_info)
+  if (tbl_info && type != LOGREC_FILE_ID)
   {
     MARIA_SHARE *share= tbl_info->s;
     DBUG_ASSERT(share->now_transactional);
@@ -7754,6 +7754,7 @@ my_bool translog_flush(TRANSLOG_ADDRESS
 
 int translog_assign_id_to_share(MARIA_HA *tbl_info, TRN *trn)
 {
+  uint16 id;
   MARIA_SHARE *share= tbl_info->s;
   /*
     If you give an id to a non-BLOCK_RECORD table, you also need to release
@@ -7762,13 +7763,14 @@ int translog_assign_id_to_share(MARIA_HA
   DBUG_ASSERT(share->data_file_type == BLOCK_RECORD);
   /* re-check under mutex to avoid having 2 ids for the same share */
   pthread_mutex_lock(&share->intern_lock);
-  if (unlikely(share->id == 0))
+  if (likely(share->id == 0))
   {
     LSN lsn;
     LEX_CUSTRING log_array[TRANSLOG_INTERNAL_PARTS + 2];
     uchar log_data[FILEID_STORE_SIZE];
     /* Inspired by set_short_trid() of trnman.c */
     uint i= share->kfile.file % SHARE_ID_MAX + 1;
+    id= 0;
     do
     {
       my_atomic_rwlock_wrlock(&LOCK_id_to_share);
@@ -7778,14 +7780,15 @@ int translog_assign_id_to_share(MARIA_HA
         if (id_to_share[i] == NULL &&
             my_atomic_casptr((void **)&id_to_share[i], &tmp, share))
         {
-          share->id= (uint16)i;
+          id= (uint16) i;
           break;
         }
       }
       my_atomic_rwlock_wrunlock(&LOCK_id_to_share);
       i= 1; /* scan the whole array */
-    } while (share->id == 0);
-    DBUG_PRINT("info", ("id_to_share: 0x%lx -> %u", (ulong)share, share->id));
+    } while (id == 0);
+    DBUG_PRINT("info", ("id_to_share: 0x%lx -> %u", (ulong)share, id));
+    fileid_store(log_data, id);
     log_array[TRANSLOG_INTERNAL_PARTS + 0].str=    log_data;
     log_array[TRANSLOG_INTERNAL_PARTS + 0].length= sizeof(log_data);
     /*
@@ -7807,11 +7810,17 @@ int translog_assign_id_to_share(MARIA_HA
                                         log_array[TRANSLOG_INTERNAL_PARTS +
                                                   1].length),
                                        sizeof(log_array)/sizeof(log_array[0]),
-                                       log_array, log_data, NULL)))
+                                       log_array, NULL, NULL)))
     {
       pthread_mutex_unlock(&share->intern_lock);
       return 1;
     }
+    /*
+      Now when translog record is done, we can set share->id.
+      If we set it before, then translog_write_record may pick up the id
+      before it's written to the log.
+    */
+    share->id= id;
   }
   pthread_mutex_unlock(&share->intern_lock);
   return 0;

=== modified file 'storage/maria/ma_recovery.c'
--- a/storage/maria/ma_recovery.c	2011-01-06 20:49:17 +0000
+++ b/storage/maria/ma_recovery.c	2011-01-20 17:26:00 +0000
@@ -642,6 +642,7 @@ static void new_transaction(uint16 sid,
 prototype_redo_exec_hook_dummy(CHECKPOINT)
 {
   /* the only checkpoint we care about was found via control file, ignore */
+  tprint(tracef, "CHECKPOINT found\n");
   return 0;
 }
 



More information about the commits mailing list