Commit 0ff7f3e1 authored by unknown's avatar unknown

WL#3072 - Maria Recovery

At the end of recovery, we initialize the transaction manager's
trid generator with the maximum trid seen during the REDO phase.
This ensures that trids always grow (needed for versioning),
even after a crash.
This patch is only preparation, as ma_recover() is not called
from ha_maria yet.


storage/maria/ha_maria.cc:
  trnman_init() needs argument now (soon trnman_init() will rather
  be done via ma_recover() and thus it will not be 0)
storage/maria/ma_recovery.c:
  During the REDO phase, remember the max long trid of transactions
  which we have seen (both in the checkpoint record and the
  LOGREC_LONG_TRANSACTION_ID records)
storage/maria/ma_test1.c:
  trnman_init() needs argument now
storage/maria/ma_test2.c:
  trnman_init() needs argument now
storage/maria/trnman.c:
  new argument to trnman_init() so that caller can decide which
  value the generator of trids starts from.
storage/maria/trnman_public.h:
  trnman_init() needs argument now
storage/maria/unittest/trnman-t.c:
  trnman_init() needs argument now
parent 753ee49f
...@@ -2403,7 +2403,7 @@ static int ha_maria_init(void *p) ...@@ -2403,7 +2403,7 @@ static int ha_maria_init(void *p)
translog_init(maria_data_root, TRANSLOG_FILE_SIZE, translog_init(maria_data_root, TRANSLOG_FILE_SIZE,
MYSQL_VERSION_ID, server_id, maria_log_pagecache, MYSQL_VERSION_ID, server_id, maria_log_pagecache,
TRANSLOG_DEFAULT_FLAGS) || TRANSLOG_DEFAULT_FLAGS) ||
trnman_init(); trnman_init(0);
maria_multi_threaded= TRUE; maria_multi_threaded= TRUE;
return res; return res;
} }
......
...@@ -47,6 +47,7 @@ static HASH all_dirty_pages; ...@@ -47,6 +47,7 @@ static HASH all_dirty_pages;
static struct st_dirty_page *dirty_pages_pool; static struct st_dirty_page *dirty_pages_pool;
static LSN current_group_end_lsn, static LSN current_group_end_lsn,
checkpoint_start= LSN_IMPOSSIBLE; checkpoint_start= LSN_IMPOSSIBLE;
static TrID max_long_trid= 0; /**< max long trid seen by REDO phase */
static FILE *tracef; /**< trace file for debugging */ static FILE *tracef; /**< trace file for debugging */
#define prototype_redo_exec_hook(R) \ #define prototype_redo_exec_hook(R) \
...@@ -143,9 +144,6 @@ int maria_recover() ...@@ -143,9 +144,6 @@ int maria_recover()
fprintf(trace_file, "SUCCESS\n"); fprintf(trace_file, "SUCCESS\n");
fclose(trace_file); fclose(trace_file);
} }
// @todo set global_trid_generator from checkpoint or default value of 1/0,
// and also update it when seeing LOGREC_LONG_TRANSACTION_ID
// suggestion: add an arg to trnman_init
maria_in_recovery= FALSE; maria_in_recovery= FALSE;
DBUG_RETURN(res); DBUG_RETURN(res);
} }
...@@ -336,10 +334,7 @@ static void new_transaction(uint16 sid, TrID long_id, LSN undo_lsn, ...@@ -336,10 +334,7 @@ static void new_transaction(uint16 sid, TrID long_id, LSN undo_lsn,
llbuf, sid); llbuf, sid);
all_active_trans[sid].undo_lsn= undo_lsn; all_active_trans[sid].undo_lsn= undo_lsn;
all_active_trans[sid].first_undo_lsn= first_undo_lsn; all_active_trans[sid].first_undo_lsn= first_undo_lsn;
// @todo set_if_bigger(global_trid_generator, long_id) set_if_bigger(max_long_trid, long_id);
// indeed not only uncommitted transactions should bump generator,
// committed ones too (those not seen by undo phase so not
// into trnman_recreate)
} }
...@@ -1278,6 +1273,7 @@ static int run_redo_phase(LSN lsn, my_bool apply) ...@@ -1278,6 +1273,7 @@ static int run_redo_phase(LSN lsn, my_bool apply)
static uint end_of_redo_phase(my_bool prepare_for_undo_phase) static uint end_of_redo_phase(my_bool prepare_for_undo_phase)
{ {
uint sid, unfinished= 0; uint sid, unfinished= 0;
char llbuf[22];
hash_free(&all_dirty_pages); hash_free(&all_dirty_pages);
/* /*
...@@ -1288,7 +1284,9 @@ static uint end_of_redo_phase(my_bool prepare_for_undo_phase) ...@@ -1288,7 +1284,9 @@ static uint end_of_redo_phase(my_bool prepare_for_undo_phase)
my_free(dirty_pages_pool, MYF(MY_ALLOW_ZERO_PTR)); my_free(dirty_pages_pool, MYF(MY_ALLOW_ZERO_PTR));
dirty_pages_pool= NULL; dirty_pages_pool= NULL;
if (prepare_for_undo_phase && trnman_init()) llstr(max_long_trid, llbuf);
printf("Maximum transaction long id seen: %s\n", llbuf);
if (prepare_for_undo_phase && trnman_init(max_long_trid))
return -1; return -1;
for (sid= 0; sid <= SHORT_TRID_MAX; sid++) for (sid= 0; sid <= SHORT_TRID_MAX; sid++)
......
...@@ -82,7 +82,7 @@ int main(int argc,char *argv[]) ...@@ -82,7 +82,7 @@ int main(int argc,char *argv[])
translog_init(maria_data_root, TRANSLOG_FILE_SIZE, translog_init(maria_data_root, TRANSLOG_FILE_SIZE,
0, 0, maria_log_pagecache, 0, 0, maria_log_pagecache,
TRANSLOG_DEFAULT_FLAGS) || TRANSLOG_DEFAULT_FLAGS) ||
(transactional && trnman_init())) (transactional && trnman_init(0)))
{ {
fprintf(stderr, "Error in initialization"); fprintf(stderr, "Error in initialization");
exit(1); exit(1);
......
...@@ -96,7 +96,7 @@ int main(int argc, char *argv[]) ...@@ -96,7 +96,7 @@ int main(int argc, char *argv[])
translog_init(maria_data_root, TRANSLOG_FILE_SIZE, translog_init(maria_data_root, TRANSLOG_FILE_SIZE,
0, 0, maria_log_pagecache, 0, 0, maria_log_pagecache,
TRANSLOG_DEFAULT_FLAGS) || TRANSLOG_DEFAULT_FLAGS) ||
(transactional && trnman_init())) (transactional && trnman_init(0)))
{ {
fprintf(stderr, "Error in initialization"); fprintf(stderr, "Error in initialization");
exit(1); exit(1);
......
...@@ -102,7 +102,18 @@ static uchar *trn_get_hash_key(const uchar *trn, size_t *len, ...@@ -102,7 +102,18 @@ static uchar *trn_get_hash_key(const uchar *trn, size_t *len,
return (uchar *) & ((*((TRN **)trn))->trid); return (uchar *) & ((*((TRN **)trn))->trid);
} }
int trnman_init()
/**
@brief Initializes transaction manager.
@param initial_trid Generated TrIDs will start from initial_trid+1.
@return Operation status
@retval 0 OK
@retval !=0 Error
*/
int trnman_init(TrID initial_trid)
{ {
DBUG_ENTER("trnman_init"); DBUG_ENTER("trnman_init");
...@@ -138,7 +149,7 @@ int trnman_init() ...@@ -138,7 +149,7 @@ int trnman_init()
trnman_allocated_transactions= 0; trnman_allocated_transactions= 0;
pool= 0; pool= 0;
global_trid_generator= 0; /* set later by the recovery code */ global_trid_generator= initial_trid;
lf_hash_init(&trid_to_committed_trn, sizeof(TRN*), LF_HASH_UNIQUE, lf_hash_init(&trid_to_committed_trn, sizeof(TRN*), LF_HASH_UNIQUE,
0, 0, trn_get_hash_key, 0); 0, 0, trn_get_hash_key, 0);
DBUG_PRINT("info", ("pthread_mutex_init LOCK_trn_list")); DBUG_PRINT("info", ("pthread_mutex_init LOCK_trn_list"));
......
...@@ -34,7 +34,7 @@ typedef struct st_transaction TRN; ...@@ -34,7 +34,7 @@ typedef struct st_transaction TRN;
extern uint trnman_active_transactions, trnman_allocated_transactions; extern uint trnman_active_transactions, trnman_allocated_transactions;
extern TRN dummy_transaction_object; extern TRN dummy_transaction_object;
int trnman_init(void); int trnman_init(TrID);
void trnman_destroy(void); void trnman_destroy(void);
TRN *trnman_new_trn(pthread_mutex_t *, pthread_cond_t *, void *); TRN *trnman_new_trn(pthread_mutex_t *, pthread_cond_t *, void *);
int trnman_end_trn(TRN *trn, my_bool commit); int trnman_end_trn(TRN *trn, my_bool commit);
......
...@@ -174,7 +174,7 @@ int main() ...@@ -174,7 +174,7 @@ int main()
#define CYCLES 10000 #define CYCLES 10000
#define THREADS 10 #define THREADS 10
trnman_init(); trnman_init(0);
test_trnman_read_from(); test_trnman_read_from();
run_test("trnman", test_trnman, THREADS, CYCLES); run_test("trnman", test_trnman, THREADS, CYCLES);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment