MDEV-34422 Corrupted ib_logfile0 due to uninitialized log_sys.lsn_lock
In commit bf0b82d2 (MDEV-33515) the function log_t::init_lsn_lock() was removed. This was fine on those platforms where InnoDB uses futex-based mutexes (Linux, FreeBSD, OpenBSD, NetBSD, DragonflyBSD). Dave Gosselin debugged this on Apple macOS and submitted a fix where pthread_mutex_wrapper::pthread_mutex_wrapper() would invoke init(). We do not really need that; we only need to invoke lsn_lock.init() like we used to do before commit bf0b82d2. This should be a no-op for the futex based mutexes, which intentionally rely on zero initialization. The missing pthread_mutex_init() call would cause race conditions and corruption of log_sys.buf because multiple threads could apparently hold log_sys.lsn_lock concurrently in log_t::append_prepare(). The error would be caught by a debug assertion in log_t::write_buf(), or in non-debug builds by the fact that the server cannot be restarted due to an apparently missing FILE_CHECKPOINT record (because it had been written to wrong offset in log_sys.buf). The failure in log_t::append_prepare() was caught on Microsoft Windows after enabling SUX_LOCK_GENERIC and therefore forcing the use of pthread_mutex_wrapper for the log_sys.lsn_lock. It appears to be fine to omit the pthread_mutex_init() call on GNU/Linux. log_t::create(): Invoke lsn_lock.init(). log_t::close(): Invoke lsn_lock.destroy(). To better catch this kind of issues in the future by simply defining SUX_LOCK_GENERIC on any platform, a separate debug instrumentation patch will be applied to the 10.6 branch later. Reviewed by: Debarun Banerjee
Showing
Please register or sign in to comment