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

Function ReadFromCursorFile

pg_documentdb/src/infrastructure/cursor_store.c:497–523  ·  view source on GitHub ↗

* Given a cursor file state, reads the next document from the * cursor file. The file is expected to be in the cursor directory. * Blocks are pre-buffered in BLCKSZ chunks. * * Also updates the flush state of the cursor file state based on the * prior value read. This ensures that if we return a document, that we * only advance the cursor to include that when the next Read is called. */

Source from the content-addressed store, hash-verified

495 * only advance the cursor to include that when the next Read is called.
496 */
497pgbson *
498ReadFromCursorFile(CursorFileState *cursorFileState)
499{
500 /* First step, advance the file stream forward with what was buffered before */
501 cursorFileState->cursorState.file_offset = cursorFileState->next_offset;
502
503 int32_t length = 0;
504 if (!FillBuffer(cursorFileState, (char *) &length, 4))
505 {
506 return NULL;
507 }
508
509 if ((Size) length > BSON_MAX_SIZE)
510 {
511 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
512 errmsg("Invalid BSON size in cursor file %d", length)));
513 }
514
515 pgbson *bson = palloc(length);
516 if (!FillBuffer(cursorFileState, (char *) bson, length))
517 {
518 pfree(bson);
519 return NULL;
520 }
521
522 return bson;
523}
524
525
526/*

Callers 1

DrainPersistedFileCursorFunction · 0.85

Calls 1

FillBufferFunction · 0.85

Tested by

no test coverage detected