mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 20:12:31 +01:00
MDEV-21774 Innodb, Windows : restore file sharing logic in Innodb
recv_sys_t opened redo log files along with log_sys_t. That's why I
removed file sharing logic from InnoDB
in 9ef2d29ff4
But it was actually used to ensure that only one MariaDB instance
will touch the same InnoDB files.
os0file.cc: revert some changes done previously
mapped_file_t::map(): now has arguments read_only, nvme
file_io::open(): now has argument read_only
class file_os_io: make final
log_file_t::open(): now has argument read_only
This commit is contained in:
parent
84e3f9ce84
commit
6618fc2974
4 changed files with 44 additions and 34 deletions
|
@ -468,7 +468,8 @@ public:
|
|||
mapped_file_t &operator=(mapped_file_t &&)= delete;
|
||||
~mapped_file_t() noexcept;
|
||||
|
||||
dberr_t map(const char *path, int flags= 0) noexcept;
|
||||
dberr_t map(const char *path, bool read_only= false,
|
||||
bool nvme= false) noexcept;
|
||||
dberr_t unmap() noexcept;
|
||||
byte *data() noexcept { return m_area.data(); }
|
||||
|
||||
|
@ -482,7 +483,7 @@ class file_io
|
|||
public:
|
||||
file_io(bool durable_writes= false) : m_durable_writes(durable_writes) {}
|
||||
virtual ~file_io() noexcept {};
|
||||
virtual dberr_t open(const char *path) noexcept= 0;
|
||||
virtual dberr_t open(const char *path, bool read_only) noexcept= 0;
|
||||
virtual dberr_t rename(const char *old_path,
|
||||
const char *new_path) noexcept= 0;
|
||||
virtual dberr_t close() noexcept= 0;
|
||||
|
@ -498,7 +499,7 @@ protected:
|
|||
bool m_durable_writes;
|
||||
};
|
||||
|
||||
class file_os_io : public file_io
|
||||
class file_os_io final: public file_io
|
||||
{
|
||||
public:
|
||||
file_os_io()= default;
|
||||
|
@ -508,7 +509,7 @@ public:
|
|||
file_os_io &operator=(file_os_io &&rhs);
|
||||
~file_os_io() noexcept;
|
||||
|
||||
dberr_t open(const char *path) noexcept final;
|
||||
dberr_t open(const char *path, bool read_only) noexcept final;
|
||||
bool is_opened() const noexcept { return m_fd != OS_FILE_CLOSED; }
|
||||
dberr_t rename(const char *old_path, const char *new_path) noexcept final;
|
||||
dberr_t close() noexcept final;
|
||||
|
@ -527,7 +528,7 @@ class log_file_t
|
|||
public:
|
||||
log_file_t(std::string path= "") noexcept : m_path{std::move(path)} {}
|
||||
|
||||
dberr_t open() noexcept;
|
||||
dberr_t open(bool read_only) noexcept;
|
||||
bool is_opened() const noexcept;
|
||||
|
||||
const std::string &get_path() const noexcept { return m_path; }
|
||||
|
|
|
@ -573,32 +573,27 @@ mapped_file_t::~mapped_file_t() noexcept
|
|||
unmap();
|
||||
}
|
||||
|
||||
dberr_t mapped_file_t::map(const char *path, int flags) noexcept
|
||||
dberr_t mapped_file_t::map(const char *path, bool read_only,
|
||||
bool nvme) noexcept
|
||||
{
|
||||
auto fd=
|
||||
mysql_file_open(innodb_log_file_key, path,
|
||||
srv_read_only_mode ? O_RDONLY : O_RDWR, MYF(MY_WME));
|
||||
|
||||
auto fd= mysql_file_open(innodb_log_file_key, path,
|
||||
read_only ? O_RDONLY : O_RDWR, MYF(MY_WME));
|
||||
if (fd == -1)
|
||||
return DB_ERROR;
|
||||
|
||||
MY_STAT stat;
|
||||
if (mysql_file_fstat(fd, &stat, MYF(0)))
|
||||
{
|
||||
mysql_file_close(fd, MYF(MY_WME));
|
||||
return DB_ERROR;
|
||||
}
|
||||
const auto file_size= os_file_get_size(path).m_total_size;
|
||||
|
||||
void *ptr= my_mmap(0, static_cast<size_t>(stat.st_size),
|
||||
srv_read_only_mode ? PROT_READ : PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED_VALIDATE | flags, fd, 0);
|
||||
const int nvme_flag= nvme ? MAP_SYNC : 0;
|
||||
void *ptr= my_mmap(0, static_cast<size_t>(file_size),
|
||||
read_only ? PROT_READ : PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED_VALIDATE | nvme_flag, fd, 0);
|
||||
mysql_file_close(fd, MYF(MY_WME));
|
||||
|
||||
if (ptr == MAP_FAILED)
|
||||
return DB_ERROR;
|
||||
|
||||
m_area= {static_cast<byte *>(ptr),
|
||||
static_cast<span<byte>::index_type>(stat.st_size)};
|
||||
static_cast<span<byte>::index_type>(file_size)};
|
||||
return DB_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -630,14 +625,14 @@ file_os_io::~file_os_io() noexcept
|
|||
close();
|
||||
}
|
||||
|
||||
dberr_t file_os_io::open(const char *path) noexcept
|
||||
dberr_t file_os_io::open(const char *path, bool read_only) noexcept
|
||||
{
|
||||
ut_ad(!is_opened());
|
||||
|
||||
bool success;
|
||||
auto tmp_fd= os_file_create(
|
||||
innodb_log_file_key, path, OS_FILE_OPEN | OS_FILE_ON_ERROR_NO_EXIT,
|
||||
OS_FILE_NORMAL, OS_LOG_FILE, srv_read_only_mode, &success);
|
||||
OS_FILE_NORMAL, OS_LOG_FILE, read_only, &success);
|
||||
if (!success)
|
||||
return DB_ERROR;
|
||||
|
||||
|
@ -685,7 +680,7 @@ dberr_t file_os_io::flush_data_only() noexcept
|
|||
static bool is_pmem(const char *path) noexcept
|
||||
{
|
||||
mapped_file_t mf;
|
||||
return mf.map(path, MAP_SYNC) == DB_SUCCESS ? true : false;
|
||||
return mf.map(path, true, true) == DB_SUCCESS ? true : false;
|
||||
}
|
||||
|
||||
class file_pmem_io final : public file_io
|
||||
|
@ -693,9 +688,9 @@ class file_pmem_io final : public file_io
|
|||
public:
|
||||
file_pmem_io() noexcept : file_io(true) {}
|
||||
|
||||
dberr_t open(const char *path) noexcept final
|
||||
dberr_t open(const char *path, bool read_only) noexcept final
|
||||
{
|
||||
return m_file.map(path, MAP_SYNC);
|
||||
return m_file.map(path, read_only, true);
|
||||
}
|
||||
dberr_t rename(const char *old_path, const char *new_path) noexcept final
|
||||
{
|
||||
|
@ -725,7 +720,7 @@ private:
|
|||
};
|
||||
#endif
|
||||
|
||||
dberr_t log_file_t::open() noexcept
|
||||
dberr_t log_file_t::open(bool read_only) noexcept
|
||||
{
|
||||
ut_a(!is_opened());
|
||||
|
||||
|
@ -737,7 +732,7 @@ dberr_t log_file_t::open() noexcept
|
|||
auto ptr= std::unique_ptr<file_io>(new file_os_io);
|
||||
#endif
|
||||
|
||||
if (dberr_t err= ptr->open(m_path.c_str()))
|
||||
if (dberr_t err= ptr->open(m_path.c_str(), read_only))
|
||||
return err;
|
||||
|
||||
m_file= std::move(ptr);
|
||||
|
@ -795,7 +790,7 @@ dberr_t log_file_t::flush_data_only() noexcept
|
|||
void log_t::file::open_file(std::string path)
|
||||
{
|
||||
fd= log_file_t(std::move(path));
|
||||
if (const dberr_t err= fd.open())
|
||||
if (const dberr_t err= fd.open(srv_read_only_mode))
|
||||
ib::fatal() << "open(" << fd.get_path() << ") returned " << err;
|
||||
}
|
||||
|
||||
|
|
|
@ -598,7 +598,7 @@ void recv_sys_t::open_log_files_if_needed()
|
|||
for (auto &&path : get_existing_log_files_paths())
|
||||
{
|
||||
recv_sys.files.emplace_back(std::move(path));
|
||||
ut_a(recv_sys.files.back().open() == DB_SUCCESS);
|
||||
ut_a(recv_sys.files.back().open(true) == DB_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2136,7 +2136,7 @@ os_file_create_simple_func(
|
|||
|
||||
file = CreateFile(
|
||||
(LPCTSTR) name, access,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
||||
FILE_SHARE_READ | FILE_SHARE_DELETE,
|
||||
NULL, create_flag, attributes, NULL);
|
||||
|
||||
if (file == INVALID_HANDLE_VALUE) {
|
||||
|
@ -2404,8 +2404,9 @@ os_file_create_func(
|
|||
);
|
||||
|
||||
DWORD create_flag;
|
||||
const DWORD share_mode =
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
|
||||
DWORD share_mode = read_only
|
||||
? FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE
|
||||
: FILE_SHARE_READ | FILE_SHARE_DELETE;
|
||||
|
||||
if (create_mode != OS_FILE_OPEN && create_mode != OS_FILE_OPEN_RAW) {
|
||||
WAIT_ALLOW_WRITES();
|
||||
|
@ -2423,6 +2424,12 @@ os_file_create_func(
|
|||
|
||||
ut_a(!read_only);
|
||||
|
||||
/* On Windows Physical devices require admin privileges and
|
||||
have to have the write-share mode set. See the remarks
|
||||
section for the CreateFile() function documentation in MSDN. */
|
||||
|
||||
share_mode |= FILE_SHARE_WRITE;
|
||||
|
||||
create_flag = OPEN_EXISTING;
|
||||
|
||||
} else if (create_mode == OS_FILE_OPEN
|
||||
|
@ -2605,8 +2612,9 @@ os_file_create_simple_no_error_handling_func(
|
|||
DWORD access;
|
||||
DWORD create_flag;
|
||||
DWORD attributes = 0;
|
||||
const DWORD share_mode =
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
|
||||
DWORD share_mode = read_only
|
||||
? FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE
|
||||
: FILE_SHARE_READ | FILE_SHARE_DELETE;
|
||||
|
||||
ut_a(name);
|
||||
|
||||
|
@ -2652,6 +2660,12 @@ os_file_create_simple_no_error_handling_func(
|
|||
|
||||
access = GENERIC_READ;
|
||||
|
||||
/*!< A backup program has to give mysqld the maximum
|
||||
freedom to do what it likes with the file */
|
||||
|
||||
share_mode |= FILE_SHARE_DELETE | FILE_SHARE_WRITE
|
||||
| FILE_SHARE_READ;
|
||||
|
||||
} else {
|
||||
|
||||
ib::error()
|
||||
|
|
Loading…
Reference in a new issue