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);