mirror of
https://github.com/MariaDB/server.git
synced 2025-01-29 02:05:57 +01:00
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
This commit is contained in:
parent
74f7620636
commit
691c691adc
4 changed files with 39 additions and 53 deletions
|
@ -4087,8 +4087,7 @@ fail:
|
||||||
open_or_create_log_file(i, file_names);
|
open_or_create_log_file(i, file_names);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_sys.log.set_file_names(std::move(file_names));
|
log_sys.log.open_files(std::move(file_names));
|
||||||
log_sys.log.open_files();
|
|
||||||
|
|
||||||
/* create extra LSN dir if it does not exist. */
|
/* create extra LSN dir if it does not exist. */
|
||||||
if (xtrabackup_extra_lsndir
|
if (xtrabackup_extra_lsndir
|
||||||
|
|
|
@ -469,9 +469,10 @@ public:
|
||||||
bool is_opened() const { return m_fd != OS_FILE_CLOSED; }
|
bool is_opened() const { return m_fd != OS_FILE_CLOSED; }
|
||||||
const std::string get_path() const { return m_path; }
|
const std::string get_path() const { return m_path; }
|
||||||
|
|
||||||
|
dberr_t rename(std::string new_path);
|
||||||
bool close();
|
bool close();
|
||||||
dberr_t read(size_t offset, span<byte> buf);
|
dberr_t read(os_offset_t offset, span<byte> buf);
|
||||||
dberr_t write(size_t offset, span<const byte> buf);
|
dberr_t write(os_offset_t offset, span<const byte> buf);
|
||||||
bool flush_data_only();
|
bool flush_data_only();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -568,18 +569,16 @@ struct log_t{
|
||||||
/** file descriptors for all log files */
|
/** file descriptors for all log files */
|
||||||
std::vector<log_file_t> 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 */
|
/** 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
|
/** reads buffer from log files
|
||||||
@param[in] total_offset offset in log files treated as a single file
|
@param[in] total_offset offset in log files treated as a single file
|
||||||
@param[in] buf buffer where to read */
|
@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
|
/** writes buffer to log files
|
||||||
@param[in] total_offset offset in log files treated as a single file
|
@param[in] total_offset offset in log files treated as a single file
|
||||||
@param[in] buf buffer from which to write */
|
@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 */
|
/** flushes OS page cache (excluding metadata!) for all log files */
|
||||||
void flush_data_only();
|
void flush_data_only();
|
||||||
/** closes all log files */
|
/** closes all log files */
|
||||||
|
|
|
@ -620,6 +620,16 @@ bool log_file_t::open()
|
||||||
return success;
|
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()
|
bool log_file_t::close()
|
||||||
{
|
{
|
||||||
ut_a(is_opened());
|
ut_a(is_opened());
|
||||||
|
@ -628,13 +638,13 @@ bool log_file_t::close()
|
||||||
return result;
|
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());
|
ut_ad(is_opened());
|
||||||
return os_file_read(IORequestRead, m_fd, buf.data(), offset, buf.size());
|
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());
|
ut_ad(is_opened());
|
||||||
return os_file_write(IORequestWrite, m_path.c_str(), m_fd, buf.data(),
|
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);
|
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();
|
files.clear();
|
||||||
|
files.reserve(paths.size());
|
||||||
for (auto &&name : names)
|
for (auto &&path : paths)
|
||||||
files.emplace_back(std::move(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
void log_t::files::open_files()
|
|
||||||
{
|
|
||||||
for (auto &file : files)
|
|
||||||
{
|
{
|
||||||
if (!file.open())
|
files.push_back(std::move(path));
|
||||||
ib::fatal() << "os_file_create(" << file.get_path() << ") failed";
|
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)];
|
auto &file= files[total_offset / file_size];
|
||||||
const size_t offset= total_offset % static_cast<size_t>(file_size);
|
const os_offset_t offset= total_offset % file_size;
|
||||||
|
|
||||||
if (const dberr_t err= file.read(offset, buf))
|
if (const dberr_t err= file.read(offset, buf))
|
||||||
ib::fatal() << "log_file_t::read(" << file.get_path() << ") returned "
|
ib::fatal() << "read(" << file.get_path() << ") returned " << err;
|
||||||
<< 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)];
|
auto &file= files[total_offset / file_size];
|
||||||
const size_t offset= total_offset % static_cast<size_t>(file_size);
|
const os_offset_t offset= total_offset % file_size;
|
||||||
|
|
||||||
if (const dberr_t err= file.write(offset, buf))
|
if (const dberr_t err= file.write(offset, buf))
|
||||||
ib::fatal() << "log_file_t::d_write(" << file.get_path() << ") returned "
|
ib::fatal() << "write(" << file.get_path() << ") returned " << err;
|
||||||
<< err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void log_t::files::flush_data_only()
|
void log_t::files::flush_data_only()
|
||||||
|
@ -690,8 +693,7 @@ void log_t::files::flush_data_only()
|
||||||
for (auto &file : files)
|
for (auto &file : files)
|
||||||
{
|
{
|
||||||
if (!file.flush_data_only())
|
if (!file.flush_data_only())
|
||||||
ib::fatal() << "log_file_t::flush_data_only(" << file.get_path()
|
ib::fatal() << "flush_data_only(" << file.get_path() << ") failed";
|
||||||
<< ") failed";
|
|
||||||
}
|
}
|
||||||
log_sys.pending_flushes.fetch_sub(1, std::memory_order_release);
|
log_sys.pending_flushes.fetch_sub(1, std::memory_order_release);
|
||||||
log_sys.flushes.fetch_add(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)
|
for (auto &file : files)
|
||||||
{
|
{
|
||||||
if (file.is_opened() && !file.close())
|
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);
|
return(DB_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_sys.log.set_file_names(std::move(file_names));
|
log_sys.log.open_files(std::move(file_names));
|
||||||
log_sys.log.open_files();
|
|
||||||
fil_open_system_tablespace_files();
|
fil_open_system_tablespace_files();
|
||||||
|
|
||||||
/* Create a log checkpoint. */
|
/* 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,
|
static dberr_t create_log_files_rename(char *logfilename, size_t dirnamelen,
|
||||||
lsn_t lsn, std::string &logfile0)
|
lsn_t lsn, std::string &logfile0)
|
||||||
{
|
{
|
||||||
log_sys.log.flush_data_only();
|
|
||||||
|
|
||||||
ut_ad(!srv_log_files_created);
|
ut_ad(!srv_log_files_created);
|
||||||
ut_d(srv_log_files_created= true);
|
ut_d(srv_log_files_created= true);
|
||||||
|
|
||||||
DBUG_EXECUTE_IF("innodb_log_abort_9", return (DB_ERROR););
|
DBUG_EXECUTE_IF("innodb_log_abort_9", return (DB_ERROR););
|
||||||
DBUG_PRINT("ib_log", ("After innodb_log_abort_9"));
|
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
|
/* Rename the first log file, now that a log
|
||||||
checkpoint has been created. */
|
checkpoint has been created. */
|
||||||
sprintf(logfilename + dirnamelen, "ib_logfile%u", 0);
|
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();
|
log_mutex_enter();
|
||||||
ut_ad(logfile0.size() == 2 + strlen(logfilename));
|
ut_ad(logfile0.size() == 2 + strlen(logfilename));
|
||||||
dberr_t err=
|
dberr_t err= log_sys.log.files[0].rename(logfilename);
|
||||||
os_file_rename(innodb_log_file_key, logfile0.c_str(), logfilename)
|
|
||||||
? DB_SUCCESS
|
|
||||||
: DB_ERROR;
|
|
||||||
|
|
||||||
/* Replace the first file with ib_logfile0. */
|
/* Replace the first file with ib_logfile0. */
|
||||||
logfile0= logfilename;
|
logfile0= logfilename;
|
||||||
log_sys.log.files[0]= log_file_t(logfilename);
|
|
||||||
log_mutex_exit();
|
log_mutex_exit();
|
||||||
|
|
||||||
DBUG_EXECUTE_IF("innodb_log_abort_10", err= DB_ERROR;);
|
DBUG_EXECUTE_IF("innodb_log_abort_10", err= DB_ERROR;);
|
||||||
|
|
||||||
if (err == DB_SUCCESS)
|
if (err == DB_SUCCESS)
|
||||||
{
|
|
||||||
log_sys.log.open_files();
|
|
||||||
ib::info() << "New log files created, LSN=" << lsn;
|
ib::info() << "New log files created, LSN=" << lsn;
|
||||||
}
|
|
||||||
|
|
||||||
return (err);
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create an undo tablespace file
|
/** Create an undo tablespace file
|
||||||
|
@ -1605,8 +1592,7 @@ dberr_t srv_start(bool create_new_db)
|
||||||
file_names.emplace_back(logfilename);
|
file_names.emplace_back(logfilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_sys.log.set_file_names(std::move(file_names));
|
log_sys.log.open_files(std::move(file_names));
|
||||||
log_sys.log.open_files();
|
|
||||||
|
|
||||||
log_sys.log.create(srv_n_log_files_found);
|
log_sys.log.create(srv_n_log_files_found);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue