Skip to content

Commit

Permalink
Merge 10.2 into bb-10.2-ext
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-m committed Jan 22, 2018
2 parents 27a5d96 + 4f8555f commit c425dcd
Show file tree
Hide file tree
Showing 18 changed files with 666 additions and 652 deletions.
12 changes: 0 additions & 12 deletions mysql-test/suite/innodb/r/innodb_stats_debug.result

This file was deleted.

13 changes: 0 additions & 13 deletions mysql-test/suite/innodb/t/innodb_stats_debug.test

This file was deleted.

2 changes: 1 addition & 1 deletion mysql-test/suite/innodb/t/innodb_stats_drop_locked.test
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ SELECT table_name FROM mysql.innodb_index_stats
WHERE table_name='innodb_stats_drop_locked';

--disable_query_log
call mtr.add_suppression("Unable to delete statistics for table test\\.innodb_stats_drop_locked: Lock wait");
call mtr.add_suppression("Unable to delete statistics for table test.innodb_stats_drop_locked: Lock wait timeout. They can be deleted later using DELETE FROM mysql.innodb_index_stats WHERE database_name");
--enable_query_log
35 changes: 14 additions & 21 deletions storage/innobase/btr/btr0defragment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,6 @@ DECLARE_THREAD(btr_defragment_thread)(void*)
buf_block_t* first_block;
buf_block_t* last_block;

trx_t* trx = trx_allocate_for_background();

while (srv_shutdown_state == SRV_SHUTDOWN_NONE) {
ut_ad(btr_defragment_thread_active);

Expand Down Expand Up @@ -828,36 +826,31 @@ DECLARE_THREAD(btr_defragment_thread)(void*)
/* Update the last_processed time of this index. */
item->last_processed = now;
} else {
dberr_t err = DB_SUCCESS;
mtr_commit(&mtr);
/* Reaching the end of the index. */
dict_stats_empty_defrag_stats(index);
trx->error_state = DB_SUCCESS;
ut_d(trx->persistent_stats = true);
++trx->will_lock;
dberr_t err = dict_stats_save_defrag_stats(index, trx);
if (err == DB_SUCCESS) {
err = dict_stats_save_defrag_summary(
index, trx);
}

err = dict_stats_save_defrag_stats(index);
if (err != DB_SUCCESS) {
trx_rollback_to_savepoint(trx, NULL);
ib::error() << "Saving defragmentation stats for table "
<< index->table->name
<< " index " << index->name
<< " failed with error "
<< ut_strerr(err);
} else if (trx->state != TRX_STATE_NOT_STARTED) {
trx_commit_for_mysql(trx);
<< index->table->name.m_name
<< " index " << index->name()
<< " failed with error " << err;
} else {
err = dict_stats_save_defrag_summary(index);

if (err != DB_SUCCESS) {
ib::error() << "Saving defragmentation summary for table "
<< index->table->name.m_name
<< " index " << index->name()
<< " failed with error " << err;
}
}

ut_d(trx->persistent_stats = false);
btr_defragment_remove_item(item);
}
}

trx_free_for_background(trx);

btr_defragment_thread_active = false;
os_thread_exit();
OS_THREAD_DUMMY_RETURN;
Expand Down
140 changes: 72 additions & 68 deletions storage/innobase/dict/dict0defrag_bg.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*****************************************************************************
Copyright (c) 2016, 2017, MariaDB Corporation.
Copyright (c) 2016, MariaDB Corporation. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -29,7 +29,6 @@ Created 25/08/2016 Jan Lindström
#include "dict0defrag_bg.h"
#include "row0mysql.h"
#include "srv0start.h"
#include "trx0roll.h"
#include "ut0new.h"

#include <vector>
Expand Down Expand Up @@ -202,18 +201,17 @@ dict_stats_defrag_pool_del(
mutex_exit(&defrag_pool_mutex);
}

/** Get the first index that has been added for updating persistent defrag
stats and eventually save its stats.
@param[in,out] trx transaction that will be started and committed */
/*****************************************************************//**
Get the first index that has been added for updating persistent defrag
stats and eventually save its stats. */
static
void
dict_stats_process_entry_from_defrag_pool(trx_t* trx)
dict_stats_process_entry_from_defrag_pool()
{
table_id_t table_id;
index_id_t index_id;

ut_ad(!srv_read_only_mode);
ut_ad(trx->persistent_stats);

/* pop the first index from the auto defrag pool */
if (!dict_stats_defrag_pool_get(&table_id, &index_id)) {
Expand Down Expand Up @@ -242,64 +240,62 @@ dict_stats_process_entry_from_defrag_pool(trx_t* trx)
return;
}

mutex_exit(&dict_sys->mutex);
trx->error_state = DB_SUCCESS;
++trx->will_lock;
dberr_t err = dict_stats_save_defrag_stats(index, trx);

if (err != DB_SUCCESS) {
trx_rollback_to_savepoint(trx, NULL);
ib::error() << "Saving defragmentation status for table "
<< index->table->name
<< " index " << index->name
<< " failed " << err;
} else if (trx->state != TRX_STATE_NOT_STARTED) {
trx_commit_for_mysql(trx);
}

dict_stats_save_defrag_stats(index);
dict_table_close(table, FALSE, FALSE);
}

/** Process indexes that have been scheduled for defragmenting.
@param[in,out] trx transaction that will be started and committed */
/*****************************************************************//**
Get the first index that has been added for updating persistent defrag
stats and eventually save its stats. */
void
dict_defrag_process_entries_from_defrag_pool(trx_t* trx)
dict_defrag_process_entries_from_defrag_pool()
/*==========================================*/
{
while (defrag_pool->size() && !dict_stats_start_shutdown) {
dict_stats_process_entry_from_defrag_pool(trx);
dict_stats_process_entry_from_defrag_pool();
}
}

/** Save defragmentation result.
@param[in] index index that was defragmented
@param[in,out] trx transaction
/*********************************************************************//**
Save defragmentation result.
@return DB_SUCCESS or error code */
dberr_t
dict_stats_save_defrag_summary(dict_index_t* index, trx_t* trx)
dict_stats_save_defrag_summary(
/*============================*/
dict_index_t* index) /*!< in: index */
{
ut_ad(trx->persistent_stats);
dberr_t ret=DB_SUCCESS;
lint now = (lint) ut_time();

if (dict_index_is_ibuf(index)) {
return DB_SUCCESS;
}

return dict_stats_save_index_stat(index, ut_time(), "n_pages_freed",
index->stat_defrag_n_pages_freed,
NULL,
"Number of pages freed during"
" last defragmentation run.",
trx);
rw_lock_x_lock(dict_operation_lock);
mutex_enter(&dict_sys->mutex);

ret = dict_stats_save_index_stat(index, now, "n_pages_freed",
index->stat_defrag_n_pages_freed,
NULL,
"Number of pages freed during"
" last defragmentation run.",
NULL);

mutex_exit(&dict_sys->mutex);
rw_lock_x_unlock(dict_operation_lock);

return (ret);
}

/** Save defragmentation stats for a given index.
@param[in] index index that is being defragmented
@param[in,out] trx transaction
/*********************************************************************//**
Save defragmentation stats for a given index.
@return DB_SUCCESS or error code */
dberr_t
dict_stats_save_defrag_stats(dict_index_t* index, trx_t* trx)
dict_stats_save_defrag_stats(
/*============================*/
dict_index_t* index) /*!< in: index */
{
ut_ad(trx->error_state == DB_SUCCESS);
ut_ad(trx->persistent_stats);
dberr_t ret;

if (dict_index_is_ibuf(index)) {
return DB_SUCCESS;
Expand All @@ -309,6 +305,7 @@ dict_stats_save_defrag_stats(dict_index_t* index, trx_t* trx)
return dict_stats_report_error(index->table, true);
}

lint now = (lint) ut_time();
mtr_t mtr;
ulint n_leaf_pages;
ulint n_leaf_reserved;
Expand All @@ -325,33 +322,40 @@ dict_stats_save_defrag_stats(dict_index_t* index, trx_t* trx)
return DB_SUCCESS;
}

ib_time_t now = ut_time();
dberr_t err = dict_stats_save_index_stat(
index, now, "n_page_split",
index->stat_defrag_n_page_split,
NULL,
"Number of new page splits on leaves"
" since last defragmentation.",
trx);
if (err == DB_SUCCESS) {
err = dict_stats_save_index_stat(
index, now, "n_leaf_pages_defrag",
n_leaf_pages,
NULL,
"Number of leaf pages when this stat is saved to disk",
trx);
rw_lock_x_lock(dict_operation_lock);

mutex_enter(&dict_sys->mutex);
ret = dict_stats_save_index_stat(index, now, "n_page_split",
index->stat_defrag_n_page_split,
NULL,
"Number of new page splits on leaves"
" since last defragmentation.",
NULL);
if (ret != DB_SUCCESS) {
goto end;
}

if (err == DB_SUCCESS) {
err = dict_stats_save_index_stat(
index, now, "n_leaf_pages_reserved",
n_leaf_reserved,
NULL,
"Number of pages reserved for this "
"index leaves when this stat "
"is saved to disk",
trx);
ret = dict_stats_save_index_stat(
index, now, "n_leaf_pages_defrag",
n_leaf_pages,
NULL,
"Number of leaf pages when this stat is saved to disk",
NULL);
if (ret != DB_SUCCESS) {
goto end;
}

return err;
ret = dict_stats_save_index_stat(
index, now, "n_leaf_pages_reserved",
n_leaf_reserved,
NULL,
"Number of pages reserved for this index leaves when this stat "
"is saved to disk",
NULL);

end:
mutex_exit(&dict_sys->mutex);
rw_lock_x_unlock(dict_operation_lock);

return (ret);
}
Loading

0 comments on commit c425dcd

Please sign in to comment.