MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / aofWrite

Function aofWrite

src/aof.cpp:335–352  ·  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

333 * true, and in general it looks just more resilient to retry the write. If
334 * there is an actual error condition we'll get it at the next try. */
335ssize_t aofWrite(int fd, const char *buf, size_t len) {
336 ssize_t nwritten = 0, totwritten = 0;
337
338 while(len) {
339 nwritten = write(fd, buf, len);
340
341 if (nwritten < 0) {
342 if (errno == EINTR) continue;
343 return totwritten ? totwritten : -1;
344 }
345
346 len -= nwritten;
347 buf += nwritten;
348 totwritten += nwritten;
349 }
350
351 return totwritten;
352}
353
354/* Write the append only file buffer on disk.
355 *

Callers 1

flushAppendOnlyFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected