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

Function DrainPersistedFileCursor

pg_documentdb/src/commands/cursors.c:1670–1715  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1668
1669
1670bytea *
1671DrainPersistedFileCursor(const char *cursorName, int batchSize,
1672 int32_t *numIterations, uint32_t accumulatedSize,
1673 pgbson_array_writer *arrayWriter, bytea *cursorFileState)
1674{
1675 if (!UseFileBasedPersistedCursors)
1676 {
1677 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
1678 errmsg("File based cursor is not enabled")));
1679 }
1680
1681 CursorFileState *cursorState = DeserializeFileState(cursorFileState);
1682
1683 bool closeCursor = true;
1684 bool isSingleResult = false;
1685 PersistentTupleDestReceiver *destReceiver = CreatePersistentTupleDestReceiver(
1686 arrayWriter,
1687 CurrentMemoryContext,
1688 batchSize, cursorName,
1689 accumulatedSize,
1690 closeCursor,
1691 isSingleResult);
1692 destReceiver->cursorFileState = cursorState;
1693
1694 pgbson *nextDocument = ReadFromCursorFile(cursorState);
1695 while (nextDocument != NULL)
1696 {
1697 if (!PersistentDestReceiveCore(nextDocument, destReceiver))
1698 {
1699 /* Batch size limit reached */
1700 break;
1701 }
1702
1703 pfree(nextDocument);
1704 nextDocument = ReadFromCursorFile(cursorState);
1705 }
1706
1707 PersistentDestReceiverShutdown((DestReceiver *) destReceiver);
1708
1709 if (nextDocument == NULL)
1710 {
1711 return NULL;
1712 }
1713
1714 return destReceiver->continuationState;
1715}
1716
1717
1718/*

Callers 1

Calls 5

DeserializeFileStateFunction · 0.85
ReadFromCursorFileFunction · 0.85

Tested by

no test coverage detected