Skip to content

Commit

Permalink
WL#6560 - Clean up the code.
Browse files Browse the repository at this point in the history
 1. Refactor open_or_create_data_files()
 2. Get rid of srv_temp_tablespace_t.
 3. Get rid of open_or_create_temp_data_files()

The refactored code is in srv0space.h and srv0space.cc. Add a new class
Tablespace for handling multi-file tablespaces. Currently the only two
tablespaces that use this class are the System tablespace and Temp tablespace.

Make the create and open into separate steps. Get rid of the extra parameter
to fil_read_first_page(). Always pass in valid min/max flush LSN values.

Simplify the error handling in innobase_init() in ha_innodb.cc.

Change some fprintfs() to ib_logf().
  • Loading branch information
Sunny Bains authored and Sunny Bains committed Nov 19, 2012
1 parent fffce08 commit c61244c
Show file tree
Hide file tree
Showing 14 changed files with 1,576 additions and 1,368 deletions.
1 change: 1 addition & 0 deletions storage/innobase/CMakeLists.txt
Expand Up @@ -345,6 +345,7 @@ SET(INNOBASE_SOURCES
srv/srv0conc.cc
srv/srv0mon.cc
srv/srv0srv.cc
srv/srv0space.cc
srv/srv0start.cc
sync/sync0arr.cc
sync/sync0rw.cc
Expand Down
3 changes: 2 additions & 1 deletion storage/innobase/dict/dict0crea.cc
Expand Up @@ -44,6 +44,7 @@ Created 1/8/1996 Heikki Tuuri
#include "ut0vec.h"
#include "dict0priv.h"
#include "fts0priv.h"
#include "srv0space.h"

/*****************************************************************//**
Based on a table object, this function builds the entry to be inserted
Expand Down Expand Up @@ -325,7 +326,7 @@ dict_build_table_def_step(
/* All non-compressed temporary tables are stored in
shared temp-tablespace */
if (dict_table_is_temporary(table)) {
table->space = srv_temp_tablespace.m_temp_tablespace_id;
table->space = srv_tmp_space.space_id();
}
}

Expand Down
77 changes: 17 additions & 60 deletions storage/innobase/fil/fil0fil.cc
Expand Up @@ -54,6 +54,7 @@ Created 10/25/1995 Heikki Tuuri
# include "srv0srv.h"
static ulint srv_data_read, srv_data_written;
#endif /* !UNIV_HOTBACKUP */
#include "srv0space.h"

/*
IMPLEMENTATION OF THE TABLESPACE MEMORY CACHE
Expand Down Expand Up @@ -1930,73 +1931,43 @@ fil_write_flushed_lsn_to_data_files(
}

/*******************************************************************//**
Reads the flushed lsn, arch no, and tablespace flag fields from a data
Reads the flushed lsn and tablespace flag fields from a data
file at database startup. */
UNIV_INTERN
void
fil_read_first_page(
/*================*/
os_file_t data_file, /*!< in: open data file */
ibool one_read_already, /*!< in: TRUE if min and max
parameters below already
contain sensible data */
ulint* flags, /*!< out: tablespace flags */
ulint* space_id, /*!< out: tablespace ID */
#ifdef UNIV_LOG_ARCHIVE
ulint* min_arch_log_no, /*!< out: min of archived
log numbers in data files */
ulint* max_arch_log_no, /*!< out: max of archived
log numbers in data files */
#endif /* UNIV_LOG_ARCHIVE */
lsn_t* min_flushed_lsn, /*!< out: min of flushed
lsn values in data files */
lsn_t* max_flushed_lsn) /*!< out: max of flushed
lsn values in data files */
{
byte* buf;
byte* page;
lsn_t flushed_lsn;

buf = static_cast<byte*>(ut_malloc(2 * UNIV_PAGE_SIZE));
byte* buf = static_cast<byte*>(ut_malloc(2 * UNIV_PAGE_SIZE));

/* Align the memory for a possible read from a raw device */

page = static_cast<byte*>(ut_align(buf, UNIV_PAGE_SIZE));
byte* page = static_cast<byte*>(ut_align(buf, UNIV_PAGE_SIZE));

os_file_read(data_file, page, 0, UNIV_PAGE_SIZE);

*flags = fsp_header_get_flags(page);

*space_id = fsp_header_get_space_id(page);

flushed_lsn = mach_read_from_8(page + FIL_PAGE_FILE_FLUSH_LSN);
lsn_t flushed_lsn = mach_read_from_8(page + FIL_PAGE_FILE_FLUSH_LSN);

ut_free(buf);

if (!one_read_already) {
*min_flushed_lsn = flushed_lsn;
*max_flushed_lsn = flushed_lsn;
#ifdef UNIV_LOG_ARCHIVE
*min_arch_log_no = arch_log_no;
*max_arch_log_no = arch_log_no;
#endif /* UNIV_LOG_ARCHIVE */
return;
}

if (*min_flushed_lsn > flushed_lsn) {
*min_flushed_lsn = flushed_lsn;
}

if (*max_flushed_lsn < flushed_lsn) {
*max_flushed_lsn = flushed_lsn;
}
#ifdef UNIV_LOG_ARCHIVE
if (*min_arch_log_no > arch_log_no) {
*min_arch_log_no = arch_log_no;
}
if (*max_arch_log_no < arch_log_no) {
*max_arch_log_no = arch_log_no;
}
#endif /* UNIV_LOG_ARCHIVE */
}

/*================ SINGLE-TABLE TABLESPACES ==========================*/
Expand Down Expand Up @@ -3636,11 +3607,7 @@ fil_open_single_table_tablespace(
/* Read the first page of the datadir tablespace, if found. */
if (def.success) {
fil_read_first_page(
def.file, FALSE, &def.flags, &def.id,
#ifdef UNIV_LOG_ARCHIVE
&space_arch_log_no, &space_arch_log_no,
#endif /* UNIV_LOG_ARCHIVE */
&def.lsn, &def.lsn);
def.file, &def.flags, &def.id, &def.lsn, &def.lsn);

/* Validate this single-table-tablespace with SYS_TABLES,
but do not compare the DATA_DIR flag, in case the
Expand All @@ -3660,16 +3627,15 @@ fil_open_single_table_tablespace(
/* Read the first page of the remote tablespace */
if (remote.success) {
fil_read_first_page(
remote.file, FALSE, &remote.flags, &remote.id,
#ifdef UNIV_LOG_ARCHIVE
&remote.arch_log_no, &remote.arch_log_no,
#endif /* UNIV_LOG_ARCHIVE */
remote.file, &remote.flags, &remote.id,
&remote.lsn, &remote.lsn);

/* Validate this single-table-tablespace with SYS_TABLES,
but do not compare the DATA_DIR flag, in case the
tablespace was relocated. */
ulint mod_remote_flags = remote.flags & ~FSP_FLAGS_MASK_DATA_DIR;
ulint mod_remote_flags =
remote.flags & ~FSP_FLAGS_MASK_DATA_DIR;

if (remote.id == id && mod_remote_flags == mod_flags) {
valid_tablespaces_found++;
remote.valid = TRUE;
Expand All @@ -3685,11 +3651,7 @@ fil_open_single_table_tablespace(
/* Read the first page of the datadir tablespace, if found. */
if (dict.success) {
fil_read_first_page(
dict.file, FALSE, &dict.flags, &dict.id,
#ifdef UNIV_LOG_ARCHIVE
&dict.arch_log_no, &dict.arch_log_no,
#endif /* UNIV_LOG_ARCHIVE */
&dict.lsn, &dict.lsn);
dict.file, &dict.flags, &dict.id, &dict.lsn, &dict.lsn);

/* Validate this single-table-tablespace with SYS_TABLES,
but do not compare the DATA_DIR flag, in case the
Expand Down Expand Up @@ -3914,11 +3876,7 @@ fil_validate_single_table_tablespace(
fsp_open_info* fsp) /*!< in/out: tablespace info */
{
fil_read_first_page(
fsp->file, FALSE, &fsp->flags, &fsp->id,
#ifdef UNIV_LOG_ARCHIVE
&fsp->arch_log_no, &fsp->arch_log_no,
#endif /* UNIV_LOG_ARCHIVE */
&fsp->lsn, &fsp->lsn);
fsp->file, &fsp->flags, &fsp->id, &fsp->lsn, &fsp->lsn);

if (fsp->id == ULINT_UNDEFINED || fsp->id == 0) {
fprintf(stderr,
Expand Down Expand Up @@ -4841,14 +4799,14 @@ fil_extend_space_to_desired_size(
*actual_size = space->size;

#ifndef UNIV_HOTBACKUP
if (space_id == 0) {
if (space_id == TRX_SYS_SPACE) {
ulint pages_per_mb = (1024 * 1024) / page_size;

/* Keep the last data file size info up to date, rounded to
full megabytes */

srv_data_file_sizes[srv_n_data_files - 1]
= (node->size / pages_per_mb) * pages_per_mb;
srv_sys_space.set_last_file_size(
(node->size / pages_per_mb) * pages_per_mb);
}
#endif /* !UNIV_HOTBACKUP */

Expand Down Expand Up @@ -5649,13 +5607,12 @@ fil_validate(void)
fil_space_t* space;
fil_node_t* fil_node;
ulint n_open = 0;
ulint i;

mutex_enter(&fil_system->mutex);

/* Look for spaces in the hash table */

for (i = 0; i < hash_get_n_cells(fil_system->spaces); i++) {
for (ulint i = 0; i < hash_get_n_cells(fil_system->spaces); i++) {

for (space = static_cast<fil_space_t*>(
HASH_GET_FIRST(fil_system->spaces, i));
Expand Down
31 changes: 8 additions & 23 deletions storage/innobase/fsp/fsp0fsp.cc
Expand Up @@ -48,7 +48,7 @@ Created 11/29/1995 Heikki Tuuri
# include "log0log.h"
#endif /* UNIV_HOTBACKUP */
#include "dict0mem.h"
#include "srv0start.h"
#include "srv0space.h"


#ifndef UNIV_HOTBACKUP
Expand Down Expand Up @@ -943,7 +943,7 @@ fsp_try_extend_data_file(

*actual_increase = 0;

if (space == 0 && !srv_auto_extend_last_data_file) {
if (space == 0 && !srv_sys_space.can_auto_extend_last_file()) {

/* We print the error message only once to avoid
spamming the error log. Note that we don't need
Expand All @@ -967,27 +967,10 @@ fsp_try_extend_data_file(

old_size = size;

if (space == 0) {
if (!srv_last_file_size_max) {
size_increase = SRV_AUTO_EXTEND_INCREMENT;
} else {
if (srv_last_file_size_max
< srv_data_file_sizes[srv_n_data_files - 1]) {
if (space == TRX_SYS_SPACE) {

fprintf(stderr,
"InnoDB: Error: Last data file size"
" is %lu, max size allowed %lu\n",
(ulong) srv_data_file_sizes[
srv_n_data_files - 1],
(ulong) srv_last_file_size_max);
}
size_increase = srv_sys_space.get_increment();

size_increase = srv_last_file_size_max
- srv_data_file_sizes[srv_n_data_files - 1];
if (size_increase > SRV_AUTO_EXTEND_INCREMENT) {
size_increase = SRV_AUTO_EXTEND_INCREMENT;
}
}
} else {
/* We extend single-table tablespaces first one extent
at a time, but 4 at a time for bigger tablespaces. It is
Expand Down Expand Up @@ -1108,15 +1091,17 @@ fsp_fill_free_list(
ut_a(zip_size <= UNIV_ZIP_SIZE_MAX);
ut_a(!zip_size || zip_size >= UNIV_ZIP_SIZE_MIN);

if (space == 0 && srv_auto_extend_last_data_file
if (space == TRX_SYS_SPACE
&& srv_sys_space.can_auto_extend_last_file()
&& size < limit + FSP_EXTENT_SIZE * FSP_FREE_ADD) {

/* Try to increase the last data file size */
fsp_try_extend_data_file(&actual_increase, space, header, mtr);
size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr);
}

if (space != 0 && !init_space
if (space != 0
&& !init_space
&& size < limit + FSP_EXTENT_SIZE * FSP_FREE_ADD) {

/* Try to increase the .ibd file size */
Expand Down

0 comments on commit c61244c

Please sign in to comment.