* 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. */
| 576 | * when the cursor file is closed. |
| 577 | */ |
| 578 | static void |
| 579 | FlushBuffer(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 | /* |
no outgoing calls
no test coverage detected