~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/trx/trx0roll.c

  • Committer: Monty Taylor
  • Date: 2010-12-02 22:51:54 UTC
  • mto: (1975.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1976.
  • Revision ID: mordred@inaugust.com-20101202225154-h54ifmga9x6cckgs
Refactored syslog module and changed it to use sys_var directly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (C) 1996, 2009, Innobase Oy. All Rights Reserved.
 
3
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
4
4
 
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
52
52
 
53
53
/** In crash recovery we set this to the undo n:o of the current trx to be
54
54
rolled back. Then we can print how many % the rollback has progressed. */
55
 
static undo_no_t        trx_roll_max_undo_no;
 
55
static ib_int64_t       trx_roll_max_undo_no;
56
56
 
57
57
/** Auxiliary variable which tells the previous progress % we printed */
58
58
static ulint            trx_roll_progress_printed_pct;
93
93
 
94
94
        thr = pars_complete_graph_for_exec(roll_node, trx, heap);
95
95
 
96
 
        ut_a(thr == que_fork_start_command(static_cast<que_fork_t *>(que_node_get_parent(thr))));
 
96
        ut_a(thr == que_fork_start_command(que_node_get_parent(thr)));
97
97
        que_run_threads(thr);
98
98
 
99
99
        mutex_enter(&kernel_mutex);
336
336
 
337
337
        /* Create a new savepoint and add it as the last in the list */
338
338
 
339
 
        savep = static_cast<trx_named_savept_t *>(mem_alloc(sizeof(trx_named_savept_t)));
 
339
        savep = mem_alloc(sizeof(trx_named_savept_t));
340
340
 
341
341
        savep->name = mem_strdup(savepoint_name);
342
342
 
443
443
        ut_a(thr == que_fork_start_command(fork));
444
444
 
445
445
        trx_roll_crash_recv_trx = trx;
446
 
        trx_roll_max_undo_no = trx->undo_no;
 
446
        trx_roll_max_undo_no = ut_conv_dulint_to_longlong(trx->undo_no);
447
447
        trx_roll_progress_printed_pct = 0;
448
448
        rows_to_undo = trx_roll_max_undo_no;
449
449
 
456
456
        fprintf(stderr,
457
457
                "  InnoDB: Rolling back trx with id " TRX_ID_FMT ", %lu%s"
458
458
                " rows to undo\n",
459
 
                trx->id,
 
459
                TRX_ID_PREP_PRINTF(trx->id),
460
460
                (ulong) rows_to_undo, unit);
461
461
        mutex_exit(&kernel_mutex);
462
462
 
478
478
                mutex_exit(&kernel_mutex);
479
479
 
480
480
                fprintf(stderr,
481
 
                        "InnoDB: Waiting for rollback of trx id "
482
 
                        TRX_ID_FMT " to end\n",
483
 
                        trx->id);
 
481
                        "InnoDB: Waiting for rollback of trx id %lu to end\n",
 
482
                        (ulong) ut_dulint_get_low(trx->id));
484
483
                os_thread_sleep(100000);
485
484
 
486
485
                mutex_enter(&kernel_mutex);
489
488
        mutex_exit(&kernel_mutex);
490
489
 
491
490
        if (trx_get_dict_operation(trx) != TRX_DICT_OP_NONE
492
 
            && trx->table_id != 0) {
 
491
            && !ut_dulint_is_zero(trx->table_id)) {
493
492
 
494
493
                /* If the transaction was for a dictionary operation, we
495
494
                drop the relevant table, if it still exists */
496
495
 
497
496
                fprintf(stderr,
498
 
                        "InnoDB: Dropping table with id %llu"
 
497
                        "InnoDB: Dropping table with id %lu %lu"
499
498
                        " in recovery if it exists\n",
500
 
                        (ullint) trx->table_id);
 
499
                        (ulong) ut_dulint_get_high(trx->table_id),
 
500
                        (ulong) ut_dulint_get_low(trx->table_id));
501
501
 
502
502
                table = dict_table_get_on_id_low(trx->table_id);
503
503
 
521
521
 
522
522
        fprintf(stderr, "\nInnoDB: Rolling back of trx id " TRX_ID_FMT
523
523
                " completed\n",
524
 
                trx->id);
 
524
                TRX_ID_PREP_PRINTF(trx->id));
525
525
        mem_heap_free(heap);
526
526
 
527
527
        trx_roll_crash_recv_trx = NULL;
574
574
                        fprintf(stderr,
575
575
                                "InnoDB: Cleaning up trx with id "
576
576
                                TRX_ID_FMT "\n",
577
 
                                trx->id);
 
577
                                TRX_ID_PREP_PRINTF(trx->id));
578
578
                        trx_cleanup_at_db_startup(trx);
579
579
                        goto loop;
580
580
 
610
610
os_thread_ret_t
611
611
trx_rollback_or_clean_all_recovered(
612
612
/*================================*/
613
 
        void*   /*arg*/)
 
613
        void*   arg __attribute__((unused)))
614
614
                        /*!< in: a dummy parameter required by
615
615
                        os_thread_create */
616
616
{
642
642
 
643
643
        heap = mem_heap_create(1024);
644
644
 
645
 
        arr = static_cast<trx_undo_arr_t *>(mem_heap_alloc(heap, sizeof(trx_undo_arr_t)));
 
645
        arr = mem_heap_alloc(heap, sizeof(trx_undo_arr_t));
646
646
 
647
 
        arr->infos = static_cast<trx_undo_inf_t *>(mem_heap_alloc(heap, sizeof(trx_undo_inf_t)
648
 
                                                                  * UNIV_MAX_PARALLELISM));
 
647
        arr->infos = mem_heap_alloc(heap, sizeof(trx_undo_inf_t)
 
648
                                    * UNIV_MAX_PARALLELISM);
649
649
        arr->n_cells = UNIV_MAX_PARALLELISM;
650
650
        arr->n_used = 0;
651
651
 
710
710
                } else {
711
711
                        n++;
712
712
 
713
 
                        if (cell->undo_no == undo_no) {
 
713
                        if (0 == ut_dulint_cmp(cell->undo_no, undo_no)) {
714
714
 
715
715
                                if (stored_here) {
716
716
                                        stored_here->in_use = FALSE;
743
743
        undo_no_t       undo_no)/*!< in: undo number */
744
744
{
745
745
        trx_undo_inf_t* cell;
 
746
        ulint           n_used;
 
747
        ulint           n;
746
748
        ulint           i;
747
749
 
 
750
        n_used = arr->n_used;
 
751
        n = 0;
 
752
 
748
753
        for (i = 0;; i++) {
749
754
                cell = trx_undo_arr_get_nth_info(arr, i);
750
755
 
751
756
                if (cell->in_use
752
 
                    && cell->undo_no == undo_no) {
 
757
                    && 0 == ut_dulint_cmp(cell->undo_no, undo_no)) {
753
758
 
754
759
                        cell->in_use = FALSE;
755
760
 
764
769
 
765
770
/*******************************************************************//**
766
771
Gets the biggest undo number in an array.
767
 
@return biggest value, 0 if the array is empty */
 
772
@return biggest value, ut_dulint_zero if the array is empty */
768
773
static
769
774
undo_no_t
770
775
trx_undo_arr_get_biggest(
779
784
 
780
785
        n = 0;
781
786
        n_used = arr->n_used;
782
 
        biggest = 0;
 
787
        biggest = ut_dulint_zero;
783
788
 
784
789
        for (i = 0;; i++) {
785
790
                cell = trx_undo_arr_get_nth_info(arr, i);
786
791
 
787
792
                if (cell->in_use) {
788
793
                        n++;
789
 
                        if (cell->undo_no > biggest) {
 
794
                        if (ut_dulint_cmp(cell->undo_no, biggest) > 0) {
790
795
 
791
796
                                biggest = cell->undo_no;
792
797
                        }
822
827
        if (arr->n_used > 0) {
823
828
                biggest = trx_undo_arr_get_biggest(arr);
824
829
 
825
 
                if (biggest >= limit) {
 
830
                if (ut_dulint_cmp(biggest, limit) >= 0) {
826
831
 
827
 
                        limit = biggest + 1;
 
832
                        limit = ut_dulint_add(biggest, 1);
828
833
                }
829
834
        }
830
835
 
860
865
                                                undo->top_page_no, mtr);
861
866
        offset = undo->top_offset;
862
867
 
863
 
        /*      fprintf(stderr, "Thread %lu undoing trx " TRX_ID_FMT
864
 
                        " undo record " TRX_ID_FMT "\n",
865
 
        os_thread_get_curr_id(), trx->id, undo->top_undo_no); */
 
868
        /*      fprintf(stderr, "Thread %lu undoing trx %lu undo record %lu\n",
 
869
        os_thread_get_curr_id(), ut_dulint_get_low(trx->id),
 
870
        ut_dulint_get_low(undo->top_undo_no)); */
866
871
 
867
872
        prev_rec = trx_undo_get_prev_rec(undo_page + offset,
868
873
                                         undo->hdr_page_no, undo->hdr_offset,
933
938
                undo = upd_undo;
934
939
        } else if (!upd_undo || upd_undo->empty) {
935
940
                undo = ins_undo;
936
 
        } else if (upd_undo->top_undo_no > ins_undo->top_undo_no) {
 
941
        } else if (ut_dulint_cmp(upd_undo->top_undo_no,
 
942
                                 ins_undo->top_undo_no) > 0) {
937
943
                undo = upd_undo;
938
944
        } else {
939
945
                undo = ins_undo;
940
946
        }
941
947
 
942
948
        if (!undo || undo->empty
943
 
            || limit > undo->top_undo_no) {
 
949
            || (ut_dulint_cmp(limit, undo->top_undo_no) > 0)) {
944
950
 
945
951
                if ((trx->undo_no_arr)->n_used == 0) {
946
952
                        /* Rollback is ending */
972
978
 
973
979
        undo_no = trx_undo_rec_get_undo_no(undo_rec);
974
980
 
975
 
        ut_ad(undo_no + 1 == trx->undo_no);
 
981
        ut_ad(ut_dulint_cmp(ut_dulint_add(undo_no, 1), trx->undo_no) == 0);
976
982
 
977
983
        /* We print rollback progress info if we are in a crash recovery
978
984
        and the transaction has at least 1000 row operations to undo. */
980
986
        if (trx == trx_roll_crash_recv_trx && trx_roll_max_undo_no > 1000) {
981
987
 
982
988
                progress_pct = 100 - (ulint)
983
 
                        ((undo_no * 100) / trx_roll_max_undo_no);
 
989
                        ((ut_conv_dulint_to_longlong(undo_no) * 100)
 
990
                         / trx_roll_max_undo_no);
984
991
                if (progress_pct != trx_roll_progress_printed_pct) {
985
992
                        if (trx_roll_progress_printed_pct == 0) {
986
993
                                fprintf(stderr,
1083
1090
 
1084
1091
        /* Initialize the rollback field in the transaction */
1085
1092
 
1086
 
        switch (sig->type) {
1087
 
        case TRX_SIG_TOTAL_ROLLBACK:
1088
 
                trx->roll_limit = 0;
1089
 
                break;
1090
 
        case TRX_SIG_ROLLBACK_TO_SAVEPT:
 
1093
        if (sig->type == TRX_SIG_TOTAL_ROLLBACK) {
 
1094
 
 
1095
                trx->roll_limit = ut_dulint_zero;
 
1096
 
 
1097
        } else if (sig->type == TRX_SIG_ROLLBACK_TO_SAVEPT) {
 
1098
 
1091
1099
                trx->roll_limit = (sig->savept).least_undo_no;
1092
 
                break;
1093
 
        case TRX_SIG_ERROR_OCCURRED:
 
1100
 
 
1101
        } else if (sig->type == TRX_SIG_ERROR_OCCURRED) {
 
1102
 
1094
1103
                trx->roll_limit = trx->last_sql_stat_start.least_undo_no;
1095
 
                break;
1096
 
        default:
 
1104
        } else {
1097
1105
                ut_error;
1098
1106
        }
1099
1107
 
1100
 
        ut_a(trx->roll_limit <= trx->undo_no);
 
1108
        ut_a(ut_dulint_cmp(trx->roll_limit, trx->undo_no) <= 0);
1101
1109
 
1102
1110
        trx->pages_undone = 0;
1103
1111
 
1261
1269
 
1262
1270
#ifdef UNIV_DEBUG
1263
1271
        if (lock_print_waits) {
1264
 
                fprintf(stderr, "Trx " TRX_ID_FMT " rollback finished\n",
1265
 
                        trx->id);
 
1272
                fprintf(stderr, "Trx %lu rollback finished\n",
 
1273
                        (ulong) ut_dulint_get_low(trx->id));
1266
1274
        }
1267
1275
#endif /* UNIV_DEBUG */
1268
1276
 
1298
1306
{
1299
1307
        roll_node_t*    node;
1300
1308
 
1301
 
        
1302
 
        node = static_cast<roll_node_t *>(mem_heap_alloc(heap, sizeof(roll_node_t)));
 
1309
        node = mem_heap_alloc(heap, sizeof(roll_node_t));
1303
1310
        node->common.type = QUE_NODE_ROLLBACK;
1304
1311
        node->state = ROLL_NODE_SEND;
1305
1312
 
1321
1328
        ulint           sig_no;
1322
1329
        trx_savept_t*   savept;
1323
1330
 
1324
 
        node = static_cast<roll_node_t *>(thr->run_node);
 
1331
        node = thr->run_node;
1325
1332
 
1326
1333
        ut_ad(que_node_get_type(node) == QUE_NODE_ROLLBACK);
1327
1334