Commit 691c691a authored by Eugene Kosov's avatar Eugene Kosov

clean up redo log

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
parent 74f76206
......@@ -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
......
......@@ -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:
......@@ -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 */
......
......@@ -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());
......@@ -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(),
......@@ -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()
......@@ -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);
......@@ -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";
}
}
......
......@@ -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. */
......@@ -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);
......@@ -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
......@@ -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);
......
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