summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-12-16 17:24:48 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2021-07-26 08:54:15 +0300
commit2c27ea3690abcc33a449b6ca82ee90ceec7a73f1 (patch)
treec9daeb1d1a0d8875b924ae5244bf7ac7cb558169
parente5246ebbc3f84e4fe288c953e660558d183e92aa (diff)
downloadmariadb-git-2c27ea3690abcc33a449b6ca82ee90ceec7a73f1.tar.gz
WIP: Append to ib_logfile0
FIXME: This would actually overwrite the ib_logfile0 header, because log_sys.log.fd_offset is incorrectly starting from 0.
-rw-r--r--storage/innobase/fil/fil0fil.cc4
-rw-r--r--storage/innobase/handler/ha_innodb.cc2
-rw-r--r--storage/innobase/include/log0log.h15
-rw-r--r--storage/innobase/include/univ.i1
-rw-r--r--storage/innobase/log/log0log.cc14
-rw-r--r--storage/innobase/srv/srv0start.cc3
6 files changed, 31 insertions, 8 deletions
diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc
index 07a6c1a713e..9d605e10c87 100644
--- a/storage/innobase/fil/fil0fil.cc
+++ b/storage/innobase/fil/fil0fil.cc
@@ -1454,8 +1454,8 @@ static void file_op(mfile_type_t type, uint32_t space_id,
mach_write_to_4(end, ut_crc32(log_ptr, end - log_ptr));
end+= 4;
ut_ad(end <= &log_ptr[size]);
-#if 0 /* FIXME: implement this! */
- write(ib_logfile0, log_ptr, end - log_ptr);
+#if 0 /* FIXME: this breaks server restart! */
+ log_sys.append({log_ptr, end});
#endif
ut_free(log_ptr);
}
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index c743df09bad..ddeae5bd051 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -514,6 +514,7 @@ mysql_pfs_key_t fts_pll_tokenize_mutex_key;
mysql_pfs_key_t ibuf_bitmap_mutex_key;
mysql_pfs_key_t ibuf_mutex_key;
mysql_pfs_key_t ibuf_pessimistic_insert_mutex_key;
+mysql_pfs_key_t log_sys_file_mutex_key;
mysql_pfs_key_t log_sys_mutex_key;
mysql_pfs_key_t log_cmdq_mutex_key;
mysql_pfs_key_t log_flush_order_mutex_key;
@@ -558,6 +559,7 @@ static PSI_mutex_info all_innodb_mutexes[] = {
PSI_KEY(ibuf_mutex),
PSI_KEY(ibuf_pessimistic_insert_mutex),
PSI_KEY(index_online_log),
+ PSI_KEY(log_sys_file_mutex),
PSI_KEY(log_sys_mutex),
PSI_KEY(page_zip_stat_per_index_mutex),
PSI_KEY(purge_sys_pq_mutex),
diff --git a/storage/innobase/include/log0log.h b/storage/innobase/include/log0log.h
index 366c03ebfcb..56217c12e5b 100644
--- a/storage/innobase/include/log0log.h
+++ b/storage/innobase/include/log0log.h
@@ -513,10 +513,14 @@ public:
lsn_t lsn;
/** the byte offset of the above lsn */
lsn_t lsn_offset;
- /** main log file */
- log_file_t fd;
/** log data file */
log_file_t data_fd;
+ /** mutex protecting appending to fd */
+ MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) mysql_mutex_t fd_mutex;
+ /** write position of fd */
+ os_offset_t fd_offset;
+ /** main log file */
+ log_file_t fd;
public:
/** used only in recovery: recovery scan succeeded up to this
@@ -581,11 +585,13 @@ public:
void create();
/** Close the redo log buffer. */
- void close() { close_files(); }
+ void close() { close_files(); mysql_mutex_destroy(&fd_mutex); }
void set_lsn(lsn_t a_lsn);
lsn_t get_lsn() const { return lsn; }
void set_lsn_offset(lsn_t a_lsn);
lsn_t get_lsn_offset() const { return lsn_offset; }
+
+ dberr_t append(span<const byte> buf) noexcept;
} log;
/** The fields involved in the log buffer flush @{ */
@@ -713,6 +719,9 @@ public:
return flushes.load(std::memory_order_relaxed);
}
+ /** Append to the log */
+ dberr_t append(span<const byte> buf) noexcept { return log.append(buf); }
+
/** Initialise the redo log subsystem. */
void create();
diff --git a/storage/innobase/include/univ.i b/storage/innobase/include/univ.i
index cc2ccd0ebaf..ad997442173 100644
--- a/storage/innobase/include/univ.i
+++ b/storage/innobase/include/univ.i
@@ -548,6 +548,7 @@ extern mysql_pfs_key_t fts_pll_tokenize_mutex_key;
extern mysql_pfs_key_t ibuf_bitmap_mutex_key;
extern mysql_pfs_key_t ibuf_mutex_key;
extern mysql_pfs_key_t ibuf_pessimistic_insert_mutex_key;
+extern mysql_pfs_key_t log_sys_file_mutex_key;
extern mysql_pfs_key_t log_sys_mutex_key;
extern mysql_pfs_key_t log_cmdq_mutex_key;
extern mysql_pfs_key_t log_flush_order_mutex_key;
diff --git a/storage/innobase/log/log0log.cc b/storage/innobase/log/log0log.cc
index b17bc5933b8..cc39dabc788 100644
--- a/storage/innobase/log/log0log.cc
+++ b/storage/innobase/log/log0log.cc
@@ -218,6 +218,7 @@ void log_t::create()
buf_free= LOG_BLOCK_HDR_SIZE;
checkpoint_buf= static_cast<byte*>
(aligned_malloc(OS_FILE_LOG_BLOCK_SIZE, OS_FILE_LOG_BLOCK_SIZE));
+ log.create();
}
mapped_file_t::~mapped_file_t() noexcept
@@ -566,6 +567,19 @@ void log_t::file::create()
file_size= srv_log_file_size;
lsn= LOG_START_LSN;
lsn_offset= 0;
+
+ mysql_mutex_init(log_sys_file_mutex_key, &fd_mutex, nullptr);
+ fd_offset= 0;
+}
+
+dberr_t log_t::file::append(span<const byte> buf) noexcept
+{
+ mysql_mutex_lock(&fd_mutex);
+ dberr_t err= fd.write(fd_offset, buf);
+ if (err == DB_SUCCESS)
+ fd_offset+= buf.size();
+ mysql_mutex_unlock(&fd_mutex);
+ return err;
}
/******************************************************//**
diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc
index 85d9805b628..f8cb46eb140 100644
--- a/storage/innobase/srv/srv0start.cc
+++ b/storage/innobase/srv/srv0start.cc
@@ -290,7 +290,6 @@ static dberr_t create_log_file(bool create_new_db, lsn_t lsn,
that crash recovery cannot find it until it has been completed and
renamed. */
- log_sys.log.create();
if (!log_set_capacity(srv_log_file_size_requested)) {
return DB_ERROR;
}
@@ -1331,8 +1330,6 @@ dberr_t srv_start(bool create_new_db)
log_sys.log.open_files(get_log_file_path());
- log_sys.log.create();
-
if (!log_set_capacity(srv_log_file_size_requested)) {
return(srv_init_abort(DB_ERROR));
}