Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/common/local_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,19 +571,24 @@ int64_t LocalFileSystem::Write(FileHandle &handle, void *buffer, int64_t nr_byte
}

bool LocalFileSystem::Trim(FileHandle &handle, idx_t offset_bytes, idx_t length_bytes) {
bool trimmed = false;
#if defined(DUCKDB_RUN_SLOW_VERIFIERS) || defined(DUCKDB_ALTERNATIVE_VERIFY)
std::vector<char> zeros(length_bytes, '\0');
Write(handle, zeros.data(), length_bytes, offset_bytes);
trimmed = true;
#endif
#if defined(__linux__)
// FALLOC_FL_PUNCH_HOLE requires glibc 2.18 or up
#if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 18)
return false;
// Nothing
#else
int fd = handle.Cast<UnixFileHandle>().fd;
int res = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, UnsafeNumericCast<int64_t>(offset_bytes),
UnsafeNumericCast<int64_t>(length_bytes));
return res == 0;
trimmed = (res == 0);
#endif
#else
return false;
#endif
return trimmed;
}

int64_t LocalFileSystem::GetFileSize(FileHandle &handle) {
Expand Down
Loading