-- citus--13.2-1--13.3-1
-- bump version to 13.3-1
CREATE OR REPLACE FUNCTION citus_internal.get_next_colocation_id()
    RETURNS bigint
    LANGUAGE C STRICT
    AS 'MODULE_PATHNAME', $$citus_internal_get_next_colocation_id$$;
COMMENT ON FUNCTION citus_internal.get_next_colocation_id()
    IS 'retrieves the next colocation id from pg_dist_colocationid_seq';

CREATE OR REPLACE FUNCTION citus_internal.adjust_identity_column_seq_settings(sequence_id regclass,
                                                                              last_value bigint,
                                                                              is_called boolean)
    RETURNS VOID
    LANGUAGE C STRICT
    AS 'MODULE_PATHNAME', $$citus_internal_adjust_identity_column_seq_settings$$;
COMMENT ON FUNCTION citus_internal.adjust_identity_column_seq_settings(regclass, bigint, boolean)
    IS 'modify identity column sequence settings to produce globally unique values';
CREATE OR REPLACE FUNCTION pg_catalog.worker_apply_sequence_command(create_sequence_command text,
                                                                    sequence_type_id regtype,
                                                                    last_value bigint,
                                                                    is_called boolean)
    RETURNS VOID
    LANGUAGE C STRICT
    AS 'MODULE_PATHNAME', $$worker_apply_sequence_command$$;
COMMENT ON FUNCTION pg_catalog.worker_apply_sequence_command(text,regtype,bigint,boolean)
    IS 'create a sequence which produces globally unique values';

CREATE OR REPLACE FUNCTION citus_internal.lock_colocation_id(colocation_id int, lock_mode int)
    RETURNS VOID
    LANGUAGE C STRICT
    AS 'MODULE_PATHNAME', $$citus_internal_lock_colocation_id$$;
COMMENT ON FUNCTION citus_internal.lock_colocation_id(int, int)
    IS 'acquire a lock on a colocation id';

CREATE OR REPLACE FUNCTION citus_internal.acquire_placement_colocation_lock(lock_id bigint, lock_mode int)
    RETURNS int
    LANGUAGE C STRICT
    AS 'MODULE_PATHNAME', $$citus_internal_acquire_placement_colocation_lock$$;
COMMENT ON FUNCTION citus_internal.acquire_placement_colocation_lock(bigint, int)
    IS 'acquire a placement colocation lock on a colocation id';

-- cluster changes block UDFs
CREATE OR REPLACE FUNCTION pg_catalog.citus_cluster_changes_block(
    timeout_ms int DEFAULT 300000)
RETURNS boolean
LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$citus_cluster_changes_block$$;
COMMENT ON FUNCTION pg_catalog.citus_cluster_changes_block(int)
IS 'block distributed write transactions, DDL, and topology changes across the Citus cluster';
REVOKE ALL ON FUNCTION pg_catalog.citus_cluster_changes_block(int) FROM PUBLIC;
CREATE OR REPLACE FUNCTION pg_catalog.citus_cluster_changes_unblock()
RETURNS boolean
LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$citus_cluster_changes_unblock$$;
COMMENT ON FUNCTION pg_catalog.citus_cluster_changes_unblock()
IS 'release the cluster changes block';
REVOKE ALL ON FUNCTION pg_catalog.citus_cluster_changes_unblock() FROM PUBLIC;
CREATE OR REPLACE FUNCTION pg_catalog.citus_cluster_changes_block_status(
    OUT state text,
    OUT worker_pid int,
    OUT requestor_pid int,
    OUT block_start_time timestamptz,
    OUT timeout_ms int,
    OUT node_count int)
RETURNS record
LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$citus_cluster_changes_block_status$$;
COMMENT ON FUNCTION pg_catalog.citus_cluster_changes_block_status()
IS 'return the current status of the cluster changes block';
-- Intentionally readable by PUBLIC: this function only exposes
-- non-sensitive state (state name, PIDs, timestamps, counts) and is
-- meant to be observable by monitoring tools without superuser rights.
-- citus_cluster_changes_block() and citus_cluster_changes_unblock()
-- are the privileged operations and have REVOKE ALL FROM PUBLIC.

