Skip to content

Commit a82bb5d

Browse files
committed
Merge branch 'merge-xtradb-5.6' into 10.0
2 parents 3699a4b + cd33250 commit a82bb5d

File tree

24 files changed

+515
-66
lines changed

24 files changed

+515
-66
lines changed

storage/xtradb/btr/btr0pcur.cc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,40 @@ Created 2/23/1996 Heikki Tuuri
3333
#include "rem0cmp.h"
3434
#include "trx0trx.h"
3535
#include "srv0srv.h"
36+
37+
/** Updates fragmentation statistics for a single page transition.
38+
@param[in] page the current page being processed
39+
@param[in] page_no page number to move to (next_page_no
40+
if forward_direction is true,
41+
prev_page_no otherwise.
42+
@param[in] forward_direction move direction: true means moving
43+
forward, false - backward. */
44+
static
45+
void
46+
btr_update_scan_stats(const page_t* page, ulint page_no, bool forward_direction)
47+
{
48+
fragmentation_stats_tstats;
49+
memset(&stats, 0, sizeof(stats));
50+
ulint extracted_page_no = page_get_page_no(page);
51+
ulint delta = forward_direction ?
52+
page_no - extracted_page_no :
53+
extracted_page_no - page_no;
54+
55+
if (delta == 1) {
56+
++stats.scan_pages_contiguous;
57+
} else {
58+
++stats.scan_pages_disjointed;
59+
}
60+
stats.scan_pages_total_seek_distance +=
61+
extracted_page_no > page_no ?
62+
extracted_page_no - page_no :
63+
page_no - extracted_page_no;
64+
65+
stats.scan_data_size += page_get_data_size(page);
66+
stats.scan_deleted_recs_size +=
67+
page_header_get_field(page, PAGE_GARBAGE);
68+
thd_add_fragmentation_stats(current_thd, &stats);
69+
}
3670
/**************************************************************//**
3771
Allocates memory for a persistent cursor object and initializes the cursor.
3872
@return own: persistent cursor */
@@ -426,6 +460,8 @@ btr_pcur_move_to_next_page(
426460

427461
ut_ad(next_page_no != FIL_NULL);
428462

463+
btr_update_scan_stats(page, next_page_no, true /* forward */);
464+
429465
next_block = btr_block_get(space, zip_size, next_page_no,
430466
cursor->latch_mode,
431467
btr_pcur_get_btr_cur(cursor)->index, mtr);
@@ -509,6 +545,10 @@ btr_pcur_move_backward_from_page(
509545

510546
prev_page_no = btr_page_get_prev(page, mtr);
511547

548+
if (prev_page_no != FIL_NULL) {
549+
btr_update_scan_stats(page, prev_page_no, false /* backward */);
550+
}
551+
512552
if (prev_page_no == FIL_NULL) {
513553
} else if (btr_pcur_is_before_first_on_page(cursor)) {
514554

storage/xtradb/buf/buf0rea.cc

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ buf_read_page_low(
123123
use to stop dangling page reads from a tablespace
124124
which we have DISCARDed + IMPORTed back */
125125
ulint offset,/*!< in: page number */
126-
trx_t* trx)
126+
trx_t* trx,
127+
boolshould_buffer)/*!< in: whether to buffer an aio request.
128+
AIO read ahead uses this. If you plan to
129+
use this parameter, make sure you remember
130+
to call os_aio_dispatch_read_array_submit()
131+
when you're ready to commit all your requests.*/
127132
{
128133
buf_page_t* bpage;
129134
ulint wake_later;
@@ -229,14 +234,15 @@ buf_read_page_low(
229234
*err = _fil_io(OS_FILE_READ | wake_later
230235
| ignore_nonexistent_pages,
231236
sync, space, zip_size, offset, 0, zip_size,
232-
bpage->zip.data, bpage, trx);
237+
bpage->zip.data, bpage, trx, should_buffer);
233238
} else {
234239
ut_a(buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE);
235240

236241
*err = _fil_io(OS_FILE_READ | wake_later
237242
| ignore_nonexistent_pages,
238243
sync, space, 0, offset, 0, UNIV_PAGE_SIZE,
239-
((buf_block_t*) bpage)->frame, bpage, trx);
244+
((buf_block_t*) bpage)->frame, bpage, trx,
245+
should_buffer);
240246
}
241247

242248
if (sync) {
@@ -395,7 +401,7 @@ buf_read_ahead_random(
395401
&err, false,
396402
ibuf_mode | OS_AIO_SIMULATED_WAKE_LATER,
397403
space, zip_size, FALSE,
398-
tablespace_version, i, trx);
404+
tablespace_version, i, trx, false);
399405
if (err == DB_TABLESPACE_DELETED) {
400406
ut_print_timestamp(stderr);
401407
fprintf(stderr,
@@ -459,7 +465,7 @@ buf_read_page(
459465

460466
count = buf_read_page_low(&err, true, BUF_READ_ANY_PAGE, space,
461467
zip_size, FALSE,
462-
tablespace_version, offset, trx);
468+
tablespace_version, offset, trx, false);
463469
srv_stats.buf_pool_reads.add(count);
464470
if (err == DB_TABLESPACE_DELETED) {
465471
ut_print_timestamp(stderr);
@@ -507,7 +513,7 @@ buf_read_page_async(
507513
| OS_AIO_SIMULATED_WAKE_LATER
508514
| BUF_READ_IGNORE_NONEXISTENT_PAGES,
509515
space, zip_size, FALSE,
510-
tablespace_version, offset, NULL);
516+
tablespace_version, offset, NULL, false);
511517
srv_stats.buf_pool_reads.add(count);
512518

513519
/* We do not increment number of I/O operations used for LRU policy
@@ -775,7 +781,8 @@ buf_read_ahead_linear(
775781
count += buf_read_page_low(
776782
&err, false,
777783
ibuf_mode,
778-
space, zip_size, FALSE, tablespace_version, i, trx);
784+
space, zip_size, FALSE, tablespace_version,
785+
i, trx, true);
779786
if (err == DB_TABLESPACE_DELETED) {
780787
ut_print_timestamp(stderr);
781788
fprintf(stderr,
@@ -788,6 +795,7 @@ buf_read_ahead_linear(
788795
}
789796
}
790797
}
798+
os_aio_dispatch_read_array_submit();
791799

792800
/* In simulated aio we wake the aio handler threads only after
793801
queuing all aio requests, in native aio the following call does
@@ -865,7 +873,7 @@ buf_read_ibuf_merge_pages(
865873
buf_read_page_low(&err, sync && (i + 1 == n_stored),
866874
BUF_READ_ANY_PAGE, space_ids[i],
867875
zip_size, TRUE, space_versions[i],
868-
page_nos[i], NULL);
876+
page_nos[i], NULL, false);
869877

870878
if (UNIV_UNLIKELY(err == DB_TABLESPACE_DELETED)) {
871879
tablespace_deleted:
@@ -1001,12 +1009,13 @@ buf_read_recv_pages(
10011009
if ((i + 1 == n_stored) && sync) {
10021010
buf_read_page_low(&err, true, BUF_READ_ANY_PAGE, space,
10031011
zip_size, TRUE, tablespace_version,
1004-
page_nos[i], NULL);
1012+
page_nos[i], NULL, false);
10051013
} else {
10061014
buf_read_page_low(&err, false, BUF_READ_ANY_PAGE
10071015
| OS_AIO_SIMULATED_WAKE_LATER,
10081016
space, zip_size, TRUE,
1009-
tablespace_version, page_nos[i], NULL);
1017+
tablespace_version, page_nos[i],
1018+
NULL, false);
10101019
}
10111020
}
10121021

storage/xtradb/dict/dict0stats_bg.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ dict_stats_wait_bg_to_stop_using_table(
203203
unlocking/locking the data dict */
204204
{
205205
while (!dict_stats_stop_bg(table)) {
206-
DICT_STATS_BG_YIELD(trx);
206+
DICT_BG_YIELD(trx);
207207
}
208208
}
209209

storage/xtradb/fil/fil0fil.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5111,7 +5111,7 @@ fil_extend_space_to_desired_size(
51115111
success = os_aio(OS_FILE_WRITE, OS_AIO_SYNC,
51125112
node->name, node->handle, buf,
51135113
offset, page_size * n_pages,
5114-
NULL, NULL, space_id, NULL);
5114+
NULL, NULL, space_id, NULL, false);
51155115
#endif /* UNIV_HOTBACKUP */
51165116

51175117
DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28",
@@ -5485,7 +5485,12 @@ _fil_io(
54855485
appropriately aligned */
54865486
void* message,/*!< in: message for aio handler if non-sync
54875487
aio used, else ignored */
5488-
trx_t* trx)
5488+
trx_t* trx,
5489+
boolshould_buffer)/*!< in: whether to buffer an aio request.
5490+
AIO read ahead uses this. If you plan to
5491+
use this parameter, make sure you remember
5492+
to call os_aio_dispatch_read_array_submit()
5493+
when you're ready to commit all your requests.*/
54895494
{
54905495
ulint mode;
54915496
fil_space_t* space;
@@ -5705,7 +5710,7 @@ _fil_io(
57055710
const char* name = node->name == NULL ? space->name : node->name;
57065711

57075712
ret = os_aio(type, mode | wake_later, name, node->handle, buf,
5708-
offset, len, node, message, space_id, trx);
5713+
offset, len, node, message, space_id, trx, should_buffer);
57095714

57105715
#else
57115716
/* In mysqlbackup do normal i/o, not aio */

storage/xtradb/fts/fts0fts.cc

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 2011, 2016, Oracle and/or its affiliates. All Rights Reserved.
3+
Copyright (c) 2011, 2017, Oracle and/or its affiliates. All Rights Reserved.
44
Copyright (c) 2016, 2017, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
@@ -26,6 +26,7 @@ Full Text Search interface
2626
#include "row0mysql.h"
2727
#include "row0upd.h"
2828
#include "dict0types.h"
29+
#include "dict0stats_bg.h"
2930
#include "row0sel.h"
3031

3132
#include "fts0fts.h"
@@ -868,18 +869,37 @@ fts_drop_index(
868869

869870
err = fts_drop_index_tables(trx, index);
870871

871-
fts_free(table);
872-
872+
for(;;) {
873+
bool retry = false;
874+
if (index->index_fts_syncing) {
875+
retry = true;
876+
}
877+
if (!retry){
878+
fts_free(table);
879+
break;
880+
}
881+
DICT_BG_YIELD(trx);
882+
}
873883
return(err);
874884
}
875885

876-
current_doc_id = table->fts->cache->next_doc_id;
877-
first_doc_id = table->fts->cache->first_doc_id;
878-
fts_cache_clear(table->fts->cache);
879-
fts_cache_destroy(table->fts->cache);
880-
table->fts->cache = fts_cache_create(table);
881-
table->fts->cache->next_doc_id = current_doc_id;
882-
table->fts->cache->first_doc_id = first_doc_id;
886+
for(;;) {
887+
bool retry = false;
888+
if (index->index_fts_syncing) {
889+
retry = true;
890+
}
891+
if (!retry){
892+
current_doc_id = table->fts->cache->next_doc_id;
893+
first_doc_id = table->fts->cache->first_doc_id;
894+
fts_cache_clear(table->fts->cache);
895+
fts_cache_destroy(table->fts->cache);
896+
table->fts->cache = fts_cache_create(table);
897+
table->fts->cache->next_doc_id = current_doc_id;
898+
table->fts->cache->first_doc_id = first_doc_id;
899+
break;
900+
}
901+
DICT_BG_YIELD(trx);
902+
}
883903
} else {
884904
fts_cache_t* cache = table->fts->cache;
885905
fts_index_cache_t* index_cache;
@@ -889,9 +909,17 @@ fts_drop_index(
889909
index_cache = fts_find_index_cache(cache, index);
890910

891911
if (index_cache != NULL) {
892-
if (index_cache->words) {
893-
fts_words_free(index_cache->words);
894-
rbt_free(index_cache->words);
912+
for(;;) {
913+
bool retry = false;
914+
if (index->index_fts_syncing) {
915+
retry = true;
916+
}
917+
if (!retry && index_cache->words) {
918+
fts_words_free(index_cache->words);
919+
rbt_free(index_cache->words);
920+
break;
921+
}
922+
DICT_BG_YIELD(trx);
895923
}
896924

897925
ib_vector_remove(cache->indexes, *(void**) index_cache);
@@ -4568,10 +4596,16 @@ fts_sync(
45684596
index_cache = static_cast<fts_index_cache_t*>(
45694597
ib_vector_get(cache->indexes, i));
45704598

4571-
if (index_cache->index->to_be_dropped) {
4599+
if (index_cache->index->to_be_dropped
4600+
|| index_cache->index->table->to_be_dropped) {
45724601
continue;
45734602
}
45744603

4604+
index_cache->index->index_fts_syncing = true;
4605+
DBUG_EXECUTE_IF("fts_instrument_sync_sleep_drop_waits",
4606+
os_thread_sleep(10000000);
4607+
);
4608+
45754609
error = fts_sync_index(sync, index_cache);
45764610

45774611
if (error != DB_SUCCESS && !sync->interrupted) {
@@ -4604,11 +4638,33 @@ fts_sync(
46044638
end_sync:
46054639
if (error == DB_SUCCESS && !sync->interrupted) {
46064640
error = fts_sync_commit(sync);
4641+
if (error == DB_SUCCESS) {
4642+
for (i = 0; i < ib_vector_size(cache->indexes); ++i) {
4643+
fts_index_cache_t* index_cache;
4644+
index_cache = static_cast<fts_index_cache_t*>(
4645+
ib_vector_get(cache->indexes, i));
4646+
if (index_cache->index->index_fts_syncing) {
4647+
index_cache->index->index_fts_syncing
4648+
= false;
4649+
}
4650+
}
4651+
}
46074652
} else {
46084653
fts_sync_rollback(sync);
46094654
}
46104655

46114656
rw_lock_x_lock(&cache->lock);
4657+
/* Clear fts syncing flags of any indexes incase sync is
4658+
interrupeted */
4659+
for (i = 0; i < ib_vector_size(cache->indexes); ++i) {
4660+
fts_index_cache_t* index_cache;
4661+
index_cache = static_cast<fts_index_cache_t*>(
4662+
ib_vector_get(cache->indexes, i));
4663+
if (index_cache->index->index_fts_syncing == true) {
4664+
index_cache->index->index_fts_syncing = false;
4665+
}
4666+
}
4667+
46124668
sync->interrupted = false;
46134669
sync->in_progress = false;
46144670
os_event_set(sync->event);

storage/xtradb/fts/fts0opt.cc

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 2007, 2016, Oracle and/or its affiliates. All Rights Reserved.
3+
Copyright (c) 2007, 2017, Oracle and/or its affiliates. All Rights Reserved.
44
Copyright (c) 2016, MariaDB Corporation. All Rights reserved.
55
66
This program is free software; you can redistribute it and/or modify it under
@@ -2971,13 +2971,6 @@ fts_optimize_sync_table(
29712971
{
29722972
dict_table_t* table = NULL;
29732973

2974-
/* Prevent DROP INDEX etc. from running when we are syncing
2975-
cache in background. */
2976-
if (!rw_lock_s_lock_nowait(&dict_operation_lock, __FILE__, __LINE__)) {
2977-
/* Exit when fail to get dict operation lock. */
2978-
return;
2979-
}
2980-
29812974
table = dict_table_open_on_id(table_id, FALSE, DICT_TABLE_OP_NORMAL);
29822975

29832976
if (table) {
@@ -2987,8 +2980,6 @@ fts_optimize_sync_table(
29872980

29882981
dict_table_close(table, FALSE, FALSE);
29892982
}
2990-
2991-
rw_lock_s_unlock(&dict_operation_lock);
29922983
}
29932984

29942985
/**********************************************************************//**

storage/xtradb/fts/fts0que.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 2007, 2016, Oracle and/or its affiliates. All Rights Reserved.
3+
Copyright (c) 2007, 2017, Oracle and/or its affiliates. All Rights Reserved.
44
Copyright (c) 2017, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
@@ -3656,6 +3656,7 @@ fts_query_free(
36563656

36573657
if (query->intersection) {
36583658
fts_query_free_doc_ids(query, query->intersection);
3659+
query->intersection = NULL;
36593660
}
36603661

36613662
if (query->doc_ids) {

0 commit comments

Comments
 (0)