From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Fri, 14 Dec 2018 14:12:40 +0300 From: Vladimir Davydov Subject: Re: [PATCH] xlog: fix fallocate vs read race Message-ID: <20181214111240.egnimmmhekj5vzir@esperanza> References: <8548a4bd8439a1e4a7f78ff37216c170c61a33c3.1544783335.git.vdavydov.dev@gmail.com> <20181214110741.GA7745@chai> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181214110741.GA7745@chai> To: Konstantin Osipov Cc: tarantool-patches@freelists.org List-ID: On Fri, Dec 14, 2018 at 02:07:41PM +0300, Konstantin Osipov wrote: > * Vladimir Davydov [18/12/14 13:30]: > > posix_fallocate(), which is used for preallocating disk space for WAL > > files, increases the file size and fills the allocated space with zeros. > > The problem is a WAL file may be read by a relay thread at the same time > > it is written to. We try to handle the zeroed space in xlog_cursor (see > > xlog_cursor_next_tx()), however this turns out to be not enough, because > > transactions are written not atomically so it may occur that a writer > > writes half a transaction when a reader reads it. Without fallocate, the > > reader would stop at EOF until the rest of the transaction is written, > > but with fallocate it reads zeroes instead and thinks that the xlog file > > is corrupted while actually it is not. > > You should use check_program_runs() not check_symbol_exists and > avoid checks at runtime. At compile time we don't know if the filesystem that will be used for storing WALs supports fallocate() so the runtime check is a must.