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

Function WriteToCursorFile

pg_documentdb/src/infrastructure/cursor_store.c:333–371  ·  view source on GitHub ↗

* Given a cursor file that is created, writes a given document to that * cursor file. The file is written as * where length is the size of the pgbson including the * varlen header. * The data is buffered in memory and flushed every BLCKSZ bytes. */

Source from the content-addressed store, hash-verified

331 * The data is buffered in memory and flushed every BLCKSZ bytes.
332 */
333void
334WriteToCursorFile(CursorFileState *cursorFileState, pgbson *dataBson)
335{
336 int32_t sizeRemaining = BLCKSZ - cursorFileState->pos;
337
338 /* We don't have enough to write even the length - flush the buffer */
339 if (sizeRemaining < 4)
340 {
341 FlushBuffer(cursorFileState);
342 }
343
344 int32_t dataSize = VARSIZE(dataBson);
345 char *data = (char *) dataBson;
346
347 /* Write the length to the buffer */
348 memcpy(cursorFileState->buffer.data + cursorFileState->pos, &dataSize, 4);
349 cursorFileState->pos += 4;
350
351 /* Now write the file into the buffer and then write it out to the file */
352 while (dataSize > 0)
353 {
354 sizeRemaining = BLCKSZ - cursorFileState->pos;
355 if (sizeRemaining >= dataSize)
356 {
357 memcpy(cursorFileState->buffer.data + cursorFileState->pos, data, dataSize);
358 cursorFileState->pos += dataSize;
359 break;
360 }
361 else
362 {
363 memcpy(cursorFileState->buffer.data + cursorFileState->pos, data,
364 sizeRemaining);
365 cursorFileState->pos += sizeRemaining;
366 data += sizeRemaining;
367 dataSize -= sizeRemaining;
368 FlushBuffer(cursorFileState);
369 }
370 }
371}
372
373
374void

Callers 1

Calls 1

FlushBufferFunction · 0.85

Tested by

no test coverage detected