From e171a219d592b1bda9b654db126f04d4d834a815 Mon Sep 17 00:00:00 2001 From: Yuqi Gu Date: Thu, 5 Mar 2020 17:15:49 -0800 Subject: [PATCH] Fix db_wal_test::TruncateLastLogAfterRecoverWithoutFlush failure (#6437) Summary: `TruncateLastLogAfterRecoverWithoutFlush` case depends on fallocate support of underlying file system. On a file system which lacks of this feature, like zfs, it will fail to allocate predefined file size as this test case intends to do; So a check block is added to detect fallocate support and skip test if not. The related work is done by JunHe77. Thanks! Signed-off-by: Yuqi Gu Pull Request resolved: https://github.com/facebook/rocksdb/pull/6437 Differential Revision: D20145032 Pulled By: pdillinger fbshipit-source-id: c8b691dc508e95acfa2a004ddbc07e2faa76680d --- db/db_wal_test.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/db/db_wal_test.cc b/db/db_wal_test.cc index ef81de803..b903e0f8f 100644 --- a/db/db_wal_test.cc +++ b/db/db_wal_test.cc @@ -1528,6 +1528,24 @@ TEST_F(DBWALTest, TruncateLastLogAfterRecoverWithoutFlush) { constexpr size_t kKB = 1024; Options options = CurrentOptions(); options.avoid_flush_during_recovery = true; + // Test fallocate support of running file system. + // Skip this test if fallocate is not supported. + std::string fname_test_fallocate = dbname_ + "/preallocate_testfile"; + int fd = -1; + do { + fd = open(fname_test_fallocate.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0644); + } while (fd < 0 && errno == EINTR); + ASSERT_GT(fd, 0); + int alloc_status = fallocate(fd, 0, 0, 1); + int err_number = errno; + close(fd); + ASSERT_OK(options.env->DeleteFile(fname_test_fallocate)); + if (err_number == ENOSYS || err_number == EOPNOTSUPP) { + fprintf(stderr, "Skipped preallocated space check: %s\n", strerror(err_number)); + return; + } + ASSERT_EQ(0, alloc_status); + DestroyAndReopen(options); size_t preallocated_size = dbfull()->TEST_GetWalPreallocateBlockSize(options.write_buffer_size);