MCPcopy Create free account
hub / github.com/documentdb/documentdb / FlushBuffer

Function FlushBuffer

pg_documentdb/src/infrastructure/cursor_store.c:578–607  ·  view source on GitHub ↗

* Writes whatever bytes have been filed into the buffer to the * cursor file. This is called when the buffer is full or * when the cursor file is closed. */

Source from the content-addressed store, hash-verified

576 * when the cursor file is closed.
577 */
578static void
579FlushBuffer(CursorFileState *cursorFileState)
580{
581 if (cursorFileState->pos > 0)
582 {
583 int bytesWritten = FileWrite(cursorFileState->bufFile,
584 cursorFileState->buffer.data, cursorFileState->pos,
585 cursorFileState->cursorState.file_offset,
586 WAIT_EVENT_BUFFILE_WRITE);
587
588 if (bytesWritten != cursorFileState->pos)
589 {
590 ereport(ERROR,
591 (errcode_for_file_access(),
592 errmsg("Failed to save data to file")));
593 }
594
595 cursorFileState->cursorState.file_offset += cursorFileState->pos;
596 cursorFileState->pos = 0;
597
598 Size maxFileSize = ((Size) MaxAllowedCursorIntermediateFileSizeMB) * 1024L * 1024;
599 if (cursorFileState->cursorState.file_offset > maxFileSize)
600 {
601 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
602 errmsg("Cursor file size %u exceeded the limit %d MB",
603 cursorFileState->cursorState.file_offset,
604 MaxAllowedCursorIntermediateFileSizeMB)));
605 }
606 }
607}
608
609
610/*

Callers 2

WriteToCursorFileFunction · 0.85
CursorFileStateCloseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected