Skip to content

Commit

Permalink
clean up redo log
Browse files Browse the repository at this point in the history
main change: rename first redo log without file close

second change: use os_offset_t to represent offset in a file

third change: fix log texts
  • Loading branch information
kevgs committed Feb 1, 2020
1 parent 74f7620 commit 691c691
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 53 deletions.
3 changes: 1 addition & 2 deletions extra/mariabackup/xtrabackup.cc
Expand Up @@ -4087,8 +4087,7 @@ static bool xtrabackup_backup_func()
open_or_create_log_file(i, file_names);
}

log_sys.log.set_file_names(std::move(file_names));
log_sys.log.open_files();
log_sys.log.open_files(std::move(file_names));

/* create extra LSN dir if it does not exist. */
if (xtrabackup_extra_lsndir
Expand Down
13 changes: 6 additions & 7 deletions storage/innobase/include/log0log.h
Expand Up @@ -469,9 +469,10 @@ class log_file_t
bool is_opened() const { return m_fd != OS_FILE_CLOSED; }
const std::string get_path() const { return m_path; }

dberr_t rename(std::string new_path);
bool close();
dberr_t read(size_t offset, span<byte> buf);
dberr_t write(size_t offset, span<const byte> buf);
dberr_t read(os_offset_t offset, span<byte> buf);
dberr_t write(os_offset_t offset, span<const byte> buf);
bool flush_data_only();

private:
Expand Down Expand Up @@ -568,18 +569,16 @@ struct log_t{
/** file descriptors for all log files */
std::vector<log_file_t> files;

/** simple setter, does not close or open log files */
void set_file_names(std::vector<std::string> names);
/** opens log files which must be closed prior this call */
void open_files();
void open_files(std::vector<std::string> paths);
/** reads buffer from log files
@param[in] total_offset offset in log files treated as a single file
@param[in] buf buffer where to read */
void read(size_t total_offset, span<byte> buf);
void read(os_offset_t total_offset, span<byte> buf);
/** writes buffer to log files
@param[in] total_offset offset in log files treated as a single file
@param[in] buf buffer from which to write */
void write(size_t total_offset, span<byte> buf);
void write(os_offset_t total_offset, span<byte> buf);
/** flushes OS page cache (excluding metadata!) for all log files */
void flush_data_only();
/** closes all log files */
Expand Down
54 changes: 28 additions & 26 deletions storage/innobase/log/log0log.cc
Expand Up @@ -620,6 +620,16 @@ bool log_file_t::open()
return success;
}

dberr_t log_file_t::rename(std::string new_path)
{
if (!os_file_rename(innodb_log_file_key, m_path.c_str(),
new_path.c_str())) {
return DB_ERROR;
}
m_path = std::move(new_path);
return DB_SUCCESS;
}

bool log_file_t::close()
{
ut_a(is_opened());
Expand All @@ -628,13 +638,13 @@ bool log_file_t::close()
return result;
}

dberr_t log_file_t::read(size_t offset, span<byte> buf)
dberr_t log_file_t::read(os_offset_t offset, span<byte> buf)
{
ut_ad(is_opened());
return os_file_read(IORequestRead, m_fd, buf.data(), offset, buf.size());
}

dberr_t log_file_t::write(size_t offset, span<const byte> buf)
dberr_t log_file_t::write(os_offset_t offset, span<const byte> buf)
{
ut_ad(is_opened());
return os_file_write(IORequestWrite, m_path.c_str(), m_fd, buf.data(),
Expand All @@ -647,41 +657,34 @@ bool log_file_t::flush_data_only()
return os_file_flush_data(m_fd);
}

void log_t::files::set_file_names(std::vector<std::string> names)
void log_t::files::open_files(std::vector<std::string> paths)
{
files.clear();

for (auto &&name : names)
files.emplace_back(std::move(name));
}

void log_t::files::open_files()
{
for (auto &file : files)
files.reserve(paths.size());
for (auto &&path : paths)
{
if (!file.open())
ib::fatal() << "os_file_create(" << file.get_path() << ") failed";
files.push_back(std::move(path));
if (!files.back().open())
ib::fatal() << "create(" << files.back().get_path() << ") failed";
}
}

void log_t::files::read(size_t total_offset, span<byte> buf)
void log_t::files::read(os_offset_t total_offset, span<byte> buf)
{
auto &file= files[total_offset / static_cast<size_t>(file_size)];
const size_t offset= total_offset % static_cast<size_t>(file_size);
auto &file= files[total_offset / file_size];
const os_offset_t offset= total_offset % file_size;

if (const dberr_t err= file.read(offset, buf))
ib::fatal() << "log_file_t::read(" << file.get_path() << ") returned "
<< err;
ib::fatal() << "read(" << file.get_path() << ") returned " << err;
}

void log_t::files::write(size_t total_offset, span<byte> buf)
void log_t::files::write(os_offset_t total_offset, span<byte> buf)
{
auto &file= files[total_offset / static_cast<size_t>(file_size)];
const size_t offset= total_offset % static_cast<size_t>(file_size);
auto &file= files[total_offset / file_size];
const os_offset_t offset= total_offset % file_size;

if (const dberr_t err= file.write(offset, buf))
ib::fatal() << "log_file_t::d_write(" << file.get_path() << ") returned "
<< err;
ib::fatal() << "write(" << file.get_path() << ") returned " << err;
}

void log_t::files::flush_data_only()
Expand All @@ -690,8 +693,7 @@ void log_t::files::flush_data_only()
for (auto &file : files)
{
if (!file.flush_data_only())
ib::fatal() << "log_file_t::flush_data_only(" << file.get_path()
<< ") failed";
ib::fatal() << "flush_data_only(" << file.get_path() << ") failed";
}
log_sys.pending_flushes.fetch_sub(1, std::memory_order_release);
log_sys.flushes.fetch_add(1, std::memory_order_release);
Expand All @@ -702,7 +704,7 @@ void log_t::files::close_files()
for (auto &file : files)
{
if (file.is_opened() && !file.close())
ib::fatal() << "log_file_t::close(" << file.get_path() << ") failed";
ib::fatal() << "close(" << file.get_path() << ") failed";
}
}

Expand Down
22 changes: 4 additions & 18 deletions storage/innobase/srv/srv0start.cc
Expand Up @@ -373,8 +373,7 @@ create_log_files(
return(DB_ERROR);
}

log_sys.log.set_file_names(std::move(file_names));
log_sys.log.open_files();
log_sys.log.open_files(std::move(file_names));
fil_open_system_tablespace_files();

/* Create a log checkpoint. */
Expand Down Expand Up @@ -421,17 +420,12 @@ MY_ATTRIBUTE((warn_unused_result, nonnull))
static dberr_t create_log_files_rename(char *logfilename, size_t dirnamelen,
lsn_t lsn, std::string &logfile0)
{
log_sys.log.flush_data_only();

ut_ad(!srv_log_files_created);
ut_d(srv_log_files_created= true);

DBUG_EXECUTE_IF("innodb_log_abort_9", return (DB_ERROR););
DBUG_PRINT("ib_log", ("After innodb_log_abort_9"));

/* Close the log files, so that we can rename the first one. */
log_sys.log.close_files();

/* Rename the first log file, now that a log
checkpoint has been created. */
sprintf(logfilename + dirnamelen, "ib_logfile%u", 0);
Expand All @@ -440,25 +434,18 @@ static dberr_t create_log_files_rename(char *logfilename, size_t dirnamelen,

log_mutex_enter();
ut_ad(logfile0.size() == 2 + strlen(logfilename));
dberr_t err=
os_file_rename(innodb_log_file_key, logfile0.c_str(), logfilename)
? DB_SUCCESS
: DB_ERROR;
dberr_t err= log_sys.log.files[0].rename(logfilename);

/* Replace the first file with ib_logfile0. */
logfile0= logfilename;
log_sys.log.files[0]= log_file_t(logfilename);
log_mutex_exit();

DBUG_EXECUTE_IF("innodb_log_abort_10", err= DB_ERROR;);

if (err == DB_SUCCESS)
{
log_sys.log.open_files();
ib::info() << "New log files created, LSN=" << lsn;
}

return (err);
return err;
}

/** Create an undo tablespace file
Expand Down Expand Up @@ -1605,8 +1592,7 @@ dberr_t srv_start(bool create_new_db)
file_names.emplace_back(logfilename);
}

log_sys.log.set_file_names(std::move(file_names));
log_sys.log.open_files();
log_sys.log.open_files(std::move(file_names));

log_sys.log.create(srv_n_log_files_found);

Expand Down

0 comments on commit 691c691

Please sign in to comment.