| 62 | |
| 63 | |
| 64 | void WriteBufferFromFileDescriptor::nextImpl() |
| 65 | { |
| 66 | if (!offset()) |
| 67 | return; |
| 68 | |
| 69 | Stopwatch watch; |
| 70 | |
| 71 | if (throttler) |
| 72 | throttler->add(offset()); |
| 73 | |
| 74 | size_t bytes_written = 0; |
| 75 | while (bytes_written != offset()) |
| 76 | { |
| 77 | ProfileEvents::increment(ProfileEvents::WriteBufferFromFileDescriptorWrite); |
| 78 | |
| 79 | ssize_t res = 0; |
| 80 | { |
| 81 | CurrentMetrics::Increment metric_increment{CurrentMetrics::Write}; |
| 82 | res = ::write(fd, working_buffer.begin() + bytes_written, offset() - bytes_written); |
| 83 | } |
| 84 | |
| 85 | if ((-1 == res || 0 == res) && errno != EINTR) |
| 86 | { |
| 87 | ProfileEvents::increment(ProfileEvents::WriteBufferFromFileDescriptorWriteFailed); |
| 88 | throwFromErrnoWithPath("Cannot write to file " + getFileName(), getFileName(), |
| 89 | ErrorCodes::CANNOT_WRITE_TO_FILE_DESCRIPTOR); |
| 90 | } |
| 91 | |
| 92 | if (res > 0) |
| 93 | bytes_written += res; |
| 94 | } |
| 95 | |
| 96 | ProfileEvents::increment(ProfileEvents::DiskWriteElapsedMicroseconds, watch.elapsedMicroseconds()); |
| 97 | ProfileEvents::increment(ProfileEvents::WriteBufferFromFileDescriptorWriteBytes, bytes_written); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | /// Name or some description of file. |
nothing calls this directly
no test coverage detected