~percona-core/percona-server/5.5

« back to all changes in this revision

Viewing changes to Percona-Server/storage/innobase/row/row0sel.c

  • Committer: Laurynas Biveinis
  • Date: 2013-09-06 13:24:59 UTC
  • mfrom: (558.8.3 5.5)
  • Revision ID: laurynas.biveinis@percona.com-20130906132459-jfaquw8dbwluzbsl
MergeĀ lp:~akopytov/percona-server/ahi-fixes-5.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1224
1224
        ut_ad(plan->unique_search);
1225
1225
        ut_ad(!plan->must_get_clust);
1226
1226
#ifdef UNIV_SYNC_DEBUG
1227
 
        ut_ad(rw_lock_own(btr_search_get_latch(index->id), RW_LOCK_SHARED));
 
1227
        ut_ad(rw_lock_own(btr_search_get_latch(index), RW_LOCK_SHARED));
1228
1228
#endif /* UNIV_SYNC_DEBUG */
1229
1229
 
1230
1230
        row_sel_open_pcur(plan, TRUE, mtr);
1395
1395
            && !plan->must_get_clust
1396
1396
            && !plan->table->big_rows) {
1397
1397
                if (!search_latch_locked) {
1398
 
                        rw_lock_s_lock(btr_search_get_latch(index->id));
 
1398
                        rw_lock_s_lock(btr_search_get_latch(index));
1399
1399
 
1400
1400
                        search_latch_locked = TRUE;
1401
 
                } else if (rw_lock_get_writer(btr_search_get_latch(index->id)) == RW_LOCK_WAIT_EX) {
 
1401
                } else if (rw_lock_get_writer(btr_search_get_latch(index))
 
1402
                           == RW_LOCK_WAIT_EX) {
1402
1403
 
1403
1404
                        /* There is an x-latch request waiting: release the
1404
1405
                        s-latch for a moment; as an s-latch here is often
1407
1408
                        from acquiring an s-latch for a long time, lowering
1408
1409
                        performance significantly in multiprocessors. */
1409
1410
 
1410
 
                        rw_lock_s_unlock(btr_search_get_latch(index->id));
1411
 
                        rw_lock_s_lock(btr_search_get_latch(index->id));
 
1411
                        rw_lock_s_unlock(btr_search_get_latch(index));
 
1412
                        rw_lock_s_lock(btr_search_get_latch(index));
1412
1413
                }
1413
1414
 
1414
1415
                found_flag = row_sel_try_search_shortcut(node, plan, &mtr);
1431
1432
        }
1432
1433
 
1433
1434
        if (search_latch_locked) {
1434
 
                rw_lock_s_unlock(btr_search_get_latch(index->id));
 
1435
                rw_lock_s_unlock(btr_search_get_latch(index));
1435
1436
 
1436
1437
                search_latch_locked = FALSE;
1437
1438
        }
2007
2008
 
2008
2009
func_exit:
2009
2010
        if (search_latch_locked) {
2010
 
                rw_lock_s_unlock(btr_search_get_latch(index->id));
 
2011
                rw_lock_s_unlock(btr_search_get_latch(index));
2011
2012
        }
2012
2013
        if (UNIV_LIKELY_NULL(heap)) {
2013
2014
                mem_heap_free(heap);
2744
2745
                        heap */
2745
2746
 
2746
2747
                        ut_a(!prebuilt->trx->has_search_latch);
 
2748
#ifdef UNIV_SYNC_DEBUG
 
2749
                        ut_ad(!btr_search_own_any());
 
2750
#endif
2747
2751
 
2748
2752
                        if (UNIV_UNLIKELY(templ->type == DATA_BLOB)) {
2749
2753
                                if (prebuilt->blob_heap == NULL) {
3320
3324
        ut_ad(!prebuilt->templ_contains_blob);
3321
3325
 
3322
3326
#ifndef UNIV_SEARCH_DEBUG
 
3327
        ut_ad(trx->has_search_latch);
 
3328
 
3323
3329
        btr_pcur_open_with_no_init(index, search_tuple, PAGE_CUR_GE,
3324
3330
                                   BTR_SEARCH_LEAF, pcur,
3325
3331
                                   RW_S_LATCH,
3420
3426
        /* if the returned record was locked and we did a semi-consistent
3421
3427
        read (fetch the newest committed version), then this is set to
3422
3428
        TRUE */
3423
 
        ulint           i;
3424
 
        ulint           should_release;
3425
3429
#ifdef UNIV_SEARCH_DEBUG
3426
3430
        ulint           cnt                             = 0;
3427
3431
#endif /* UNIV_SEARCH_DEBUG */
3438
3442
 
3439
3443
        ut_ad(index && pcur && search_tuple);
3440
3444
 
 
3445
        ut_ad(!trx->has_search_latch);
 
3446
#ifdef UNIV_SYNC_DEBUG
 
3447
        ut_ad(!btr_search_own_any());
 
3448
        ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch));
 
3449
#endif /* UNIV_SYNC_DEBUG */
 
3450
 
3441
3451
        if (UNIV_UNLIKELY(prebuilt->table->ibd_file_missing)) {
3442
3452
                ut_print_timestamp(stderr);
3443
3453
                fprintf(stderr, "  InnoDB: Error:\n"
3453
3463
                        "InnoDB: how you can resolve the problem.\n",
3454
3464
                        prebuilt->table->name);
3455
3465
 
3456
 
#ifdef UNIV_SYNC_DEBUG
3457
 
                ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch));
3458
 
#endif /* UNIV_SYNC_DEBUG */
3459
3466
                return(DB_ERROR);
3460
3467
        }
3461
3468
 
3462
3469
        if (UNIV_UNLIKELY(!prebuilt->index_usable)) {
3463
3470
 
3464
 
#ifdef UNIV_SYNC_DEBUG
3465
 
                ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch));
3466
 
#endif /* UNIV_SYNC_DEBUG */
3467
3471
                return(DB_MISSING_HISTORY);
3468
3472
        }
3469
3473
 
3470
3474
        if (dict_index_is_corrupted(index)) {
3471
 
#ifdef UNIV_SYNC_DEBUG
3472
 
                ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch));
3473
 
#endif /* UNIV_SYNC_DEBUG */
3474
3475
                return(DB_CORRUPTION);
3475
3476
        }
3476
3477
 
3515
3516
        fprintf(stderr, "N tables locked %lu\n",
3516
3517
                (ulong) trx->mysql_n_tables_locked);
3517
3518
#endif
3518
 
        /*-------------------------------------------------------------*/
3519
 
        /* PHASE 0: Release a possible s-latch we are holding on the
3520
 
        adaptive hash index latch if there is someone waiting behind */
3521
 
 
3522
 
        should_release = 0;
3523
 
        for (i = 0; i < btr_search_index_num; i++) {
3524
 
                /* we should check all latches (fix Bug#791030) */
3525
 
                if (UNIV_UNLIKELY(rw_lock_get_writer(btr_search_latch_part[i])
3526
 
                                  != RW_LOCK_NOT_LOCKED)) {
3527
 
                        should_release |= ((ulint)1 << i);
3528
 
                }
3529
 
        }
3530
 
 
3531
 
        if (UNIV_UNLIKELY(should_release)) {
3532
 
 
3533
 
                /* There is an x-latch request on the adaptive hash index:
3534
 
                release the s-latch to reduce starvation and wait for
3535
 
                BTR_SEA_TIMEOUT rounds before trying to keep it again over
3536
 
                calls from MySQL */
3537
 
 
3538
 
                for (i = 0; i < btr_search_index_num; i++) {
3539
 
                        /* we should release all s-latches (fix Bug#791030) */
3540
 
                        if (trx->has_search_latch & ((ulint)1 << i)) {
3541
 
                                rw_lock_s_unlock(btr_search_latch_part[i]);
3542
 
                                trx->has_search_latch &= (~((ulint)1 << i));
3543
 
                        }
3544
 
                }
3545
 
 
3546
 
                if (!trx->has_search_latch) {
3547
 
                trx->search_latch_timeout = BTR_SEA_TIMEOUT;
3548
 
                }
3549
 
        }
3550
3519
 
3551
3520
        /* Reset the new record lock info if srv_locks_unsafe_for_binlog
3552
3521
        is set or session is using a READ COMMITED isolation level. Then
3696
3665
                        hash index semaphore! */
3697
3666
 
3698
3667
#ifndef UNIV_SEARCH_DEBUG
3699
 
                        if (!(trx->has_search_latch
3700
 
                              & ((ulint)1 << (index->id % btr_search_index_num)))) {
3701
 
                                if (trx->has_search_latch
3702
 
                                    < ((ulint)1 << (index->id % btr_search_index_num))) {
3703
 
                                        rw_lock_s_lock(btr_search_get_latch(index->id));
3704
 
                                        trx->has_search_latch |=
3705
 
                                                ((ulint)1 << (index->id % btr_search_index_num));
3706
 
                                } else {
3707
 
                                        /* should re-lock to obay latch-order */
3708
 
                                        for (i = 0; i < btr_search_index_num; i++) {
3709
 
                                                if (trx->has_search_latch & ((ulint)1 << i)) {
3710
 
                                                        rw_lock_s_unlock(btr_search_latch_part[i]);
3711
 
                                                }
3712
 
                                        }
3713
 
                                        trx->has_search_latch |=
3714
 
                                                ((ulint)1 << (index->id % btr_search_index_num));
3715
 
                                        for (i = 0; i < btr_search_index_num; i++) {
3716
 
                                                if (trx->has_search_latch & ((ulint)1 << i)) {
3717
 
                                                        rw_lock_s_lock(btr_search_latch_part[i]);
3718
 
                                                }
3719
 
                                        }
3720
 
                                }
3721
 
                        }
 
3668
                        ut_ad(!trx->has_search_latch);
 
3669
                        rw_lock_s_lock(btr_search_get_latch(index));
 
3670
                        trx->has_search_latch = TRUE;
3722
3671
#endif
3723
3672
                        switch (row_sel_try_search_shortcut_for_mysql(
3724
3673
                                        &rec, prebuilt, &offsets, &heap,
3763
3712
                                srv_n_rows_read++;
3764
3713
 
3765
3714
                                err = DB_SUCCESS;
3766
 
                                goto release_search_latch_if_needed;
 
3715
                                goto release_search_latch;
3767
3716
 
3768
3717
                        case SEL_EXHAUSTED:
3769
3718
                                mtr_commit(&mtr);
3772
3721
                                fputs(" record not found 2\n", stderr); */
3773
3722
 
3774
3723
                                err = DB_RECORD_NOT_FOUND;
3775
 
release_search_latch_if_needed:
3776
 
                                if (trx->search_latch_timeout > 0
3777
 
                                    && trx->has_search_latch) {
3778
 
 
3779
 
                                        trx->search_latch_timeout--;
3780
 
 
3781
 
                                        for (i = 0; i < btr_search_index_num; i++) {
3782
 
                                                if (trx->has_search_latch & ((ulint)1 << i)) {
3783
 
                                                        rw_lock_s_unlock(btr_search_latch_part[i]);
3784
 
                                                }
3785
 
                                        }
3786
 
                                        trx->has_search_latch = FALSE;
3787
 
                                }
 
3724
release_search_latch:
 
3725
                                rw_lock_s_unlock(
 
3726
                                        btr_search_get_latch(index));
 
3727
                                trx->has_search_latch = FALSE;
3788
3728
 
3789
3729
                                /* NOTE that we do NOT store the cursor
3790
3730
                                position */
3799
3739
 
3800
3740
                        mtr_commit(&mtr);
3801
3741
                        mtr_start(&mtr);
 
3742
 
 
3743
                        rw_lock_s_unlock(btr_search_get_latch(index));
 
3744
                        trx->has_search_latch = FALSE;
3802
3745
                }
3803
3746
        }
3804
3747
 
3805
3748
        /*-------------------------------------------------------------*/
3806
3749
        /* PHASE 3: Open or restore index cursor position */
3807
3750
 
3808
 
        if (trx->has_search_latch) {
3809
 
 
3810
 
                for (i = 0; i < btr_search_index_num; i++) {
3811
 
                        if (trx->has_search_latch & ((ulint)1 << i)) {
3812
 
                                rw_lock_s_unlock(btr_search_latch_part[i]);
3813
 
                        }
3814
 
                }
3815
 
                trx->has_search_latch = FALSE;
3816
 
        }
3817
 
 
 
3751
        ut_ad(!trx->has_search_latch);
 
3752
#ifdef UNIV_SYNC_DEBUG
 
3753
        ut_ad(!btr_search_own_any());
 
3754
#endif
3818
3755
        ut_ad(prebuilt->sql_stat_start || trx->state == TRX_ACTIVE);
3819
3756
        ut_ad(trx->state == TRX_NOT_STARTED
3820
3757
              || trx->state == TRX_ACTIVE);
4851
4788
                }
4852
4789
        }
4853
4790
 
 
4791
        ut_ad(!trx->has_search_latch);
4854
4792
#ifdef UNIV_SYNC_DEBUG
 
4793
        ut_ad(!btr_search_own_any());
4855
4794
        ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch));
4856
4795
#endif /* UNIV_SYNC_DEBUG */
4857
4796
        return(err);