| 1668 | |
| 1669 | |
| 1670 | bytea * |
| 1671 | DrainPersistedFileCursor(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 | /* |
no test coverage detected