MCPcopy Create free account
hub / github.com/F-Stack/f-stack / aofWrite

Function aofWrite

app/redis-6.2.6/src/aof.c:322–339  ·  view source on GitHub ↗

This is a wrapper to the write syscall in order to retry on short writes * or if the syscall gets interrupted. It could look strange that we retry * on short writes given that we are writing to a block device: normally if * the first call is short, there is a end-of-space condition, so the next * is likely to fail. However apparently in modern systems this is no longer * true, and in general

Source from the content-addressed store, hash-verified

320 * true, and in general it looks just more resilient to retry the write. If
321 * there is an actual error condition we'll get it at the next try. */
322ssize_t aofWrite(int fd, const char *buf, size_t len) {
323 ssize_t nwritten = 0, totwritten = 0;
324
325 while(len) {
326 nwritten = write(fd, buf, len);
327
328 if (nwritten < 0) {
329 if (errno == EINTR) continue;
330 return totwritten ? totwritten : -1;
331 }
332
333 len -= nwritten;
334 buf += nwritten;
335 totwritten += nwritten;
336 }
337
338 return totwritten;
339}
340
341/* Write the append only file buffer on disk.
342 *

Callers 1

flushAppendOnlyFileFunction · 0.85

Calls 1

writeFunction · 0.70

Tested by

no test coverage detected