| 287 | return success ? Void() : IAsyncFile::zeroRange(offset, length); |
| 288 | } |
| 289 | Future<Void> truncate(int64_t size) override { |
| 290 | ++countFileLogicalWrites; |
| 291 | ++countLogicalWrites; |
| 292 | |
| 293 | if (failed) { |
| 294 | return io_timeout(); |
| 295 | } |
| 296 | |
| 297 | #if KAIO_LOGGING |
| 298 | uint32_t id = OpLogEntry::nextID(); |
| 299 | #endif |
| 300 | int result = -1; |
| 301 | KAIOLogEvent(logFile, id, OpLogEntry::TRUNCATE, OpLogEntry::START, size / 4096); |
| 302 | bool completed = false; |
| 303 | double begin = timer_monotonic(); |
| 304 | |
| 305 | if (ctx.fallocateSupported && size >= lastFileSize) { |
| 306 | result = fallocate(fd, 0, 0, size); |
| 307 | if (result != 0) { |
| 308 | int fallocateErrCode = errno; |
| 309 | TraceEvent("AsyncFileKAIOAllocateError") |
| 310 | .detail("Fd", fd) |
| 311 | .detail("Filename", filename) |
| 312 | .detail("Size", size) |
| 313 | .GetLastError(); |
| 314 | if (fallocateErrCode == EOPNOTSUPP) { |
| 315 | // Mark fallocate as unsupported. Try again with truncate. |
| 316 | ctx.fallocateSupported = false; |
| 317 | } else { |
| 318 | KAIOLogEvent(logFile, id, OpLogEntry::TRUNCATE, OpLogEntry::COMPLETE, size / 4096, result); |
| 319 | return io_error(); |
| 320 | } |
| 321 | } else { |
| 322 | completed = true; |
| 323 | } |
| 324 | } |
| 325 | if (!completed) |
| 326 | result = ftruncate(fd, size); |
| 327 | |
| 328 | double end = timer_monotonic(); |
| 329 | if (nondeterministicRandom()->random01() < end - begin) { |
| 330 | TraceEvent("SlowKAIOTruncate") |
| 331 | .detail("TruncateTime", end - begin) |
| 332 | .detail("TruncateBytes", size - lastFileSize); |
| 333 | } |
| 334 | KAIOLogEvent(logFile, id, OpLogEntry::TRUNCATE, OpLogEntry::COMPLETE, size / 4096, result); |
| 335 | |
| 336 | if (result != 0) { |
| 337 | TraceEvent("AsyncFileKAIOTruncateError").detail("Fd", fd).detail("Filename", filename).GetLastError(); |
| 338 | return io_error(); |
| 339 | } |
| 340 | |
| 341 | lastFileSize = nextFileSize = size; |
| 342 | |
| 343 | return Void(); |
| 344 | } |
| 345 | |
| 346 | ACTOR static Future<Void> throwErrorIfFailed(Reference<AsyncFileKAIO> self, Future<Void> sync) { |
no test coverage detected