From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 1/3] xlog: erase eof marker when reopening existing file for writing Date: Fri, 15 Jun 2018 18:48:20 +0300 Message-Id: <3ce2e8070f75cbd3022add41faf940a8809a8d1c.1529075903.git.vdavydov.dev@gmail.com> In-Reply-To: References: <20180614125920.GD959@chai> In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: When reopening an existing xlog file (as in case of vylog), we do not erase the eof marker immediately. Instead we reposition file offset to (file_size - sizeof eof_marker), assuming the eof marker will be overwritten on the first write. However, it isn't enough if we want to reuse this function for reopening WAL files, because when scanning the WAL directory we close a file if we read eof marker and never reopen it again, see recover_remaining_wals(). So to avoid skipping rows written to a once closed WAL, we have to erase the eof marker when reopening an xlog file. Let's do it with truncate(). --- src/box/xlog.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/box/xlog.c b/src/box/xlog.c index be7b3459..142262b4 100644 --- a/src/box/xlog.c +++ b/src/box/xlog.c @@ -787,10 +787,7 @@ xlog_open(struct xlog *xlog, const char *name) goto err_read; } - /* - * If the file has eof marker, reposition the file pointer so - * that the next write will overwrite it. - */ + /* Check if the file has EOF marker. */ xlog->offset = fio_lseek(xlog->fd, -(off_t)sizeof(magic), SEEK_END); if (xlog->offset < 0) goto no_eof; @@ -809,6 +806,13 @@ no_eof: xlog->filename); goto err_read; } + } else { + /* Truncate the file to erase the EOF marker. */ + if (ftruncate(xlog->fd, xlog->offset) != 0) { + diag_set(SystemError, "failed to truncate file '%s'", + xlog->filename); + goto err_read; + } } return 0; err_read: -- 2.11.0