mirror of
https://github.com/FerretDB/documentdb.git
synced 2026-11-26 04:09:50 -05:00
### Does this PR have any customer impact? No ### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) PoC/Feature ### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes) Yes ### Are you introducing any new config? If yes, do you have tests with and without them being set? Yes ### ChangeLog (Refer [Template](../oss/CHANGELOG.md)) ### Description Today, persisted cursors require the connections to be held. This is bad since Connections/Backends are a limited resource. This introduces the option to save the cursor state in a file on disk and reuse that across backends. This is behind a GUC due to the presence of the following: 1) Needs more testing and validation 2) Needs backpressure to ensure that disk consumption doesn't balloon up 3) There is a procedure added to clean up these files but it is not wired up 4) We need to handle ultra-large responses (beyond 4 GB it fails outright at the moment). This needs more graceful handling to split into chunks. ---- #### AI description (iteration 1) #### PR Classification This pull request is a new feature implementation that introduces file‐based persisted cursors to allow query results to be “drained” and stored on disk without holding on to active database connections. #### PR Summary This PR adds support for persisting cursor state to the filesystem in both the pg_documentdb and pgmongo modules, enabling connections to be released while still allowing cursors to be later resumed. The changes include: - **`infrastructure/cursor_store.c` and `cursor_store.h`** – New APIs for creating, writing to, reading from, and closing persisted cursor files. - **Commands integration** – Modifications in `commands/cursors.c`, `commands/aggregation_commands.c`, and `cursor_private.h` to use file-based cursor functions for draining and continuation. - **SQL test suites** – Addition of new test files (e.g. in `.../regress/sql/bson_aggregation_cursor_tests_file.sql`) to validate cursor behavior across various query scenarios. - **Configuration updates** – New custom GUCs in `feature_flag_configs.c` and adjustments in test PostgreSQL configuration files to enable and control file-based persisted cursors. - **Executor enhancements** – Updates in cursor draining and query plan execution functions to support both in-memory and file-based cursor paging. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
26 lines
913 B
PL/PgSQL
26 lines
913 B
PL/PgSQL
#include "udfs/query/bson_orderby--0.104-0.sql"
|
|
#include "operators/bson_orderby_operators--0.104-0.sql"
|
|
#include "operators/bson_btree_orderby_operators_family--0.104-0.sql"
|
|
#include "schema/bson_orderby_hash_operator_class--0.104-0.sql"
|
|
|
|
#include "udfs/projection/bson_projection--0.104-0.sql"
|
|
#include "udfs/index_mgmt/create_index_background--0.104-0.sql"
|
|
#include "udfs/schema_mgmt/compact--0.104-0.sql"
|
|
|
|
#include "udfs/schema_mgmt/cursor_support--0.104-0.sql"
|
|
|
|
-- Schedule the index build task
|
|
DO LANGUAGE plpgsql $cmd$
|
|
BEGIN
|
|
PERFORM __API_SCHEMA_INTERNAL__.schedule_background_index_build_jobs();
|
|
END;
|
|
$cmd$;
|
|
|
|
DO LANGUAGE plpgsql $cmd$
|
|
BEGIN
|
|
IF NOT EXISTS(SELECT 1 FROM cron.job where jobname = 'documentdb_cursor_cleanup_task') THEN
|
|
PERFORM cron.schedule('documentdb_cursor_cleanup_task', '* * * * *', $$CALL documentdb_api_internal.cursor_directory_cleanup();$$);
|
|
END IF;
|
|
END;
|
|
$cmd$;
|