1
0
mirror of https://github.com/postgres/postgres.git synced 2026-01-27 21:43:08 +03:00

Move some code from src/bin/scripts to src/fe_utils to permit reuse.

The parallel slots infrastructure (which implements client-side
multiplexing of server connections doing similar things, not
threading or multiple processes or anything like that) are moved from
src/bin/scripts/scripts_parallel.c to src/fe_utils/parallel_slot.c.

The functions consumeQueryResult() and processQueryResult() which were
previously part of src/bin/scripts/common.c are now moved into that
file as well, becoming static helper functions. This might need to be
changed in the future, but currently they're not used for anything
else.

Some other functions from src/bin/scripts/common.c are moved to to
src/fe_utils and are split up among several files.  connectDatabase(),
connectMaintenanceDatabase(), and disconnectDatabase() are moved to
connect_utils.c.  executeQuery(), executeCommand(), and
executeMaintenanceCommand() are move to query_utils.c.
handle_help_version_opts() is moved to option_utils.c.

Mark Dilger, reviewed by me. The larger patch series of which this is
a part has also had review from Peter Geoghegan, Andres Freund, Álvaro
Herrera, Michael Paquier, and Amul Sul, but I don't know whether any
of them have reviewed this bit specifically.

Discussion: http://postgr.es/m/12ED3DA8-25F0-4B68-937D-D907CFBF08E7@enterprisedb.com
Discussion: http://postgr.es/m/5F743835-3399-419C-8324-2D424237E999@enterprisedb.com
Discussion: http://postgr.es/m/70655DF3-33CE-4527-9A4D-DDEB582B6BA0@enterprisedb.com
This commit is contained in:
Robert Haas
2021-02-05 13:33:38 -05:00
parent c444472af5
commit e955bd4b6c
22 changed files with 498 additions and 385 deletions

View File

@@ -0,0 +1,48 @@
/*-------------------------------------------------------------------------
*
* Facilities for frontend code to connect to and disconnect from databases.
*
* Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/fe_utils/connect_utils.h
*
*-------------------------------------------------------------------------
*/
#ifndef CONNECT_UTILS_H
#define CONNECT_UTILS_H
#include "libpq-fe.h"
enum trivalue
{
TRI_DEFAULT,
TRI_NO,
TRI_YES
};
/* Parameters needed by connectDatabase/connectMaintenanceDatabase */
typedef struct _connParams
{
/* These fields record the actual command line parameters */
const char *dbname; /* this may be a connstring! */
const char *pghost;
const char *pgport;
const char *pguser;
enum trivalue prompt_password;
/* If not NULL, this overrides the dbname obtained from command line */
/* (but *only* the DB name, not anything else in the connstring) */
const char *override_dbname;
} ConnParams;
extern PGconn *connectDatabase(const ConnParams *cparams,
const char *progname,
bool echo, bool fail_ok,
bool allow_password_reuse);
extern PGconn *connectMaintenanceDatabase(ConnParams *cparams,
const char *progname, bool echo);
extern void disconnectDatabase(PGconn *conn);
#endif /* CONNECT_UTILS_H */

View File

@@ -0,0 +1,23 @@
/*-------------------------------------------------------------------------
*
* Command line option processing facilities for frontend code
*
* Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/fe_utils/option_utils.h
*
*-------------------------------------------------------------------------
*/
#ifndef OPTION_UTILS_H
#define OPTION_UTILS_H
#include "postgres_fe.h"
typedef void (*help_handler) (const char *progname);
extern void handle_help_version_opts(int argc, char *argv[],
const char *fixed_progname,
help_handler hlp);
#endif /* OPTION_UTILS_H */

View File

@@ -0,0 +1,35 @@
/*-------------------------------------------------------------------------
*
* parallel_slot.h
* Parallel support for bin/scripts/
*
* Copyright (c) 2003-2021, PostgreSQL Global Development Group
*
* src/include/fe_utils/parallel_slot.h
*
*-------------------------------------------------------------------------
*/
#ifndef PARALLEL_SLOT_H
#define PARALLEL_SLOT_H
#include "fe_utils/connect_utils.h"
#include "libpq-fe.h"
typedef struct ParallelSlot
{
PGconn *connection; /* One connection */
bool isFree; /* Is it known to be idle? */
} ParallelSlot;
extern ParallelSlot *ParallelSlotsGetIdle(ParallelSlot *slots, int numslots);
extern ParallelSlot *ParallelSlotsSetup(const ConnParams *cparams,
const char *progname, bool echo,
PGconn *conn, int numslots);
extern void ParallelSlotsTerminate(ParallelSlot *slots, int numslots);
extern bool ParallelSlotsWaitCompletion(ParallelSlot *slots, int numslots);
#endif /* PARALLEL_SLOT_H */

View File

@@ -0,0 +1,26 @@
/*-------------------------------------------------------------------------
*
* Facilities for frontend code to query a databases.
*
* Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/fe_utils/query_utils.h
*
*-------------------------------------------------------------------------
*/
#ifndef QUERY_UTILS_H
#define QUERY_UTILS_H
#include "postgres_fe.h"
#include "libpq-fe.h"
extern PGresult *executeQuery(PGconn *conn, const char *query, bool echo);
extern void executeCommand(PGconn *conn, const char *query, bool echo);
extern bool executeMaintenanceCommand(PGconn *conn, const char *query,
bool echo);
#endif /* QUERY_UTILS_H */