Commit d4e1fa39 authored by Marko Mäkelä's avatar Marko Mäkelä

Use C++11 "range for" in crash recovery code

parent dadc53ff
...@@ -289,8 +289,8 @@ class mlog_init_t ...@@ -289,8 +289,8 @@ class mlog_init_t
{ {
ut_ad(mutex_own(&recv_sys.mutex)); ut_ad(mutex_own(&recv_sys.mutex));
ut_ad(recv_no_ibuf_operations); ut_ad(recv_no_ibuf_operations);
for (map::iterator i= inits.begin(); i != inits.end(); i++) { for (map::value_type& i : inits) {
i->second.created = false; i.second.created = false;
} }
} }
...@@ -312,18 +312,17 @@ class mlog_init_t ...@@ -312,18 +312,17 @@ class mlog_init_t
ut_ad(!recv_no_ibuf_operations); ut_ad(!recv_no_ibuf_operations);
mtr.start(); mtr.start();
for (map::const_iterator i= inits.begin(); i != inits.end(); for (const map::value_type& i : inits) {
i++) { if (!i.second.created) {
if (!i->second.created) {
continue; continue;
} }
if (buf_block_t* block = buf_page_get_gen( if (buf_block_t* block = buf_page_get_gen(
i->first, 0, RW_X_LATCH, NULL, i.first, 0, RW_X_LATCH, NULL,
BUF_GET_IF_IN_POOL, __FILE__, __LINE__, BUF_GET_IF_IN_POOL, __FILE__, __LINE__,
&mtr, NULL)) { &mtr, NULL)) {
mutex_exit(&recv_sys.mutex); mutex_exit(&recv_sys.mutex);
ibuf_merge_or_delete_for_page( ibuf_merge_or_delete_for_page(
block, i->first, block, i.first,
block->zip_size(), true); block->zip_size(), true);
mtr.commit(); mtr.commit();
mtr.start(); mtr.start();
...@@ -3428,21 +3427,19 @@ recv_validate_tablespace(bool rescan, bool& missing_tablespace) ...@@ -3428,21 +3427,19 @@ recv_validate_tablespace(bool rescan, bool& missing_tablespace)
return(err); return(err);
} }
/* When rescan is not needed then recv_sys.addr_hash will have /* When rescan is not needed, recv_sys.addr_hash will contain the
all space id belongs to redo log. If rescan is needed and entire redo log. If rescan is needed or innodb_force_recovery
innodb_force_recovery > 0 then InnoDB can ignore missing tablespace. */ is set, we can ignore missing tablespaces. */
for (recv_spaces_t::iterator i = recv_spaces.begin(); for (const recv_spaces_t::value_type& rs : recv_spaces) {
i != recv_spaces.end(); i++) { if (rs.second.status != file_name_t::MISSING) {
if (i->second.status != file_name_t::MISSING) {
continue; continue;
} }
missing_tablespace = true; missing_tablespace = true;
if (srv_force_recovery > 0) { if (srv_force_recovery > 0) {
ib::warn() << "Tablespace " << i->first ib::warn() << "Tablespace " << rs.first
<<" was not found at " << i->second.name <<" was not found at " << rs.second.name
<<", and innodb_force_recovery was set." <<", and innodb_force_recovery was set."
<<" All redo log for this tablespace" <<" All redo log for this tablespace"
<<" will be ignored!"; <<" will be ignored!";
...@@ -3450,9 +3447,9 @@ recv_validate_tablespace(bool rescan, bool& missing_tablespace) ...@@ -3450,9 +3447,9 @@ recv_validate_tablespace(bool rescan, bool& missing_tablespace)
} }
if (!rescan) { if (!rescan) {
ib::info() << "Tablespace " << i->first ib::info() << "Tablespace " << rs.first
<< " was not found at '" << " was not found at '"
<< i->second.name << "', but there" << rs.second.name << "', but there"
<<" were no modifications either."; <<" were no modifications either.";
} }
} }
...@@ -3477,33 +3474,34 @@ recv_init_crash_recovery_spaces(bool rescan, bool& missing_tablespace) ...@@ -3477,33 +3474,34 @@ recv_init_crash_recovery_spaces(bool rescan, bool& missing_tablespace)
ut_ad(!srv_read_only_mode); ut_ad(!srv_read_only_mode);
ut_ad(recv_needed_recovery); ut_ad(recv_needed_recovery);
for (recv_spaces_t::iterator i = recv_spaces.begin(); for (recv_spaces_t::value_type& rs : recv_spaces) {
i != recv_spaces.end(); i++) { ut_ad(!is_predefined_tablespace(rs.first));
ut_ad(!is_predefined_tablespace(i->first)); ut_ad(rs.second.status != file_name_t::DELETED
ut_ad(i->second.status != file_name_t::DELETED || !i->second.space); || !rs.second.space);
if (i->second.status == file_name_t::DELETED) { if (rs.second.status == file_name_t::DELETED) {
/* The tablespace was deleted, /* The tablespace was deleted,
so we can ignore any redo log for it. */ so we can ignore any redo log for it. */
flag_deleted = true; flag_deleted = true;
} else if (i->second.space != NULL) { } else if (rs.second.space != NULL) {
/* The tablespace was found, and there /* The tablespace was found, and there
are some redo log records for it. */ are some redo log records for it. */
fil_names_dirty(i->second.space); fil_names_dirty(rs.second.space);
i->second.space->enable_lsn = i->second.enable_lsn; rs.second.space->enable_lsn = rs.second.enable_lsn;
} else if (i->second.name == "") { } else if (rs.second.name == "") {
ib::error() << "Missing MLOG_FILE_NAME" ib::error() << "Missing MLOG_FILE_NAME"
" or MLOG_FILE_DELETE" " or MLOG_FILE_DELETE"
" before MLOG_CHECKPOINT for tablespace " " before MLOG_CHECKPOINT for tablespace "
<< i->first; << rs.first;
recv_sys.found_corrupt_log = true; recv_sys.found_corrupt_log = true;
return(DB_CORRUPTION); return(DB_CORRUPTION);
} else { } else {
i->second.status = file_name_t::MISSING; rs.second.status = file_name_t::MISSING;
flag_deleted = true; flag_deleted = true;
} }
ut_ad(i->second.status == file_name_t::DELETED || i->second.name != ""); ut_ad(rs.second.status == file_name_t::DELETED
|| rs.second.name != "");
} }
if (flag_deleted) { if (flag_deleted) {
...@@ -3900,36 +3898,24 @@ recv_recovery_rollback_active(void) ...@@ -3900,36 +3898,24 @@ recv_recovery_rollback_active(void)
const byte* const byte*
recv_dblwr_t::find_page(ulint space_id, ulint page_no) recv_dblwr_t::find_page(ulint space_id, ulint page_no)
{ {
typedef std::vector<const byte*, ut_allocator<const byte*> > std::vector<const byte*, ut_allocator<const byte*> > matches;
matches_t;
matches_t matches;
const byte* result = 0; const byte* result = 0;
for (list::iterator i = pages.begin(); i != pages.end(); ++i) { for (const byte* page : pages) {
if (page_get_space_id(*i) == space_id if (page_get_space_id(page) == space_id
&& page_get_page_no(*i) == page_no) { && page_get_page_no(page) == page_no) {
matches.push_back(*i); matches.push_back(page);
} }
} }
if (matches.size() == 1) { lsn_t max_lsn = 0;
result = matches[0];
} else if (matches.size() > 1) {
lsn_t max_lsn = 0;
lsn_t page_lsn = 0;
for (matches_t::iterator i = matches.begin(); for (const byte* page : matches) {
i != matches.end(); lsn_t page_lsn = mach_read_from_8(page + FIL_PAGE_LSN);
++i) {
page_lsn = mach_read_from_8(*i + FIL_PAGE_LSN); if (page_lsn > max_lsn) {
max_lsn = page_lsn;
if (page_lsn > max_lsn) { result = page;
max_lsn = page_lsn;
result = *i;
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment