1
0
Fork 0

try using fallocate to zero out file

This commit is contained in:
jsteemann 2016-11-29 10:42:00 +01:00
parent ddd0c0877b
commit 49515f1f02
1 changed files with 40 additions and 28 deletions

View File

@ -174,6 +174,17 @@ static int CreateDatafile(std::string const& filename, TRI_voc_size_t maximalSiz
return -1;
}
#ifdef __linux__
// try fallocate first
int res = fallocate(fd, FALLOC_FL_ZERO_RANGE, 0, maximalSize);
#else
// no fallocate present, or at least pretend it's not there...
int res = TRI_ERROR_NOT_IMPLEMENTED;
#endif
if (res != TRI_ERROR_NO_ERROR) {
// either fallocate failed or it is not there...
// fill file with zeros from FileNullBuffer
size_t writeSize = TRI_GetNullBufferSizeFiles();
size_t written = 0;
@ -209,6 +220,7 @@ static int CreateDatafile(std::string const& filename, TRI_voc_size_t maximalSiz
written += static_cast<size_t>(writeResult);
}
}
// go back to offset 0
TRI_lseek_t offset = TRI_LSEEK(fd, (TRI_lseek_t)0, SEEK_SET);