Skip to content

Commit c3923b1

Browse files
authored
Convert file-specific extern functions, variables and macros to static scope.
Previously, there were several functions, variables and macros declared as extern in postgres_fdw_plus.h that were only used in connection.c or postgres_fdw_plus.c. To enhance clarity and encapsulation, this commit converts these functions, variables and macros to static scope within their respective files. As a result, the extern declarations for them are removed from postgres_fdw_plus.h, further clarifying their limited visibility and usage. Author: @MasaoFujii Reviewed-by: @YKatsuragi Discussion: #11
1 parent 45972f9 commit c3923b1

File tree

3 files changed

+46
-64
lines changed

3 files changed

+46
-64
lines changed

connection.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,22 @@ static void pgfdw_inval_callback(Datum arg, int cacheid, uint32 hashvalue);
138138
static void pgfdw_reject_incomplete_xact_state_change(ConnCacheEntry *entry);
139139
static void pgfdw_reset_xact_state(ConnCacheEntry *entry, bool toplevel);
140140
static bool pgfdw_cancel_query(PGconn *conn);
141+
#endif /* NOT_USED_IN_PGFDWPLUS */
141142
static bool pgfdw_cancel_query_begin(PGconn *conn);
142143
static bool pgfdw_cancel_query_end(PGconn *conn, TimestampTz endtime,
143144
bool consume_input);
145+
#ifdef NOT_USED_IN_PGFDWPLUS
144146
static bool pgfdw_exec_cleanup_query(PGconn *conn, const char *query,
145147
bool ignore_errors);
146148
static bool pgfdw_exec_cleanup_query_begin(PGconn *conn, const char *query);
147149
static bool pgfdw_exec_cleanup_query_end(PGconn *conn, const char *query,
148150
TimestampTz endtime,
149151
bool consume_input,
150152
bool ignore_errors);
153+
#endif /* NOT_USED_IN_PGFDWPLUS */
151154
static bool pgfdw_get_cleanup_result(PGconn *conn, TimestampTz endtime,
152155
PGresult **result, bool *timed_out);
156+
#ifdef NOT_USED_IN_PGFDWPLUS
153157
static void pgfdw_abort_cleanup(ConnCacheEntry *entry, bool toplevel);
154158
static bool pgfdw_abort_cleanup_begin(ConnCacheEntry *entry, bool toplevel,
155159
List **pending_entries,
@@ -1403,10 +1407,7 @@ pgfdw_cancel_query(PGconn *conn)
14031407
return pgfdw_cancel_query_end(conn, endtime, false);
14041408
}
14051409

1406-
#ifdef NOT_USED_IN_PGFDWPLUS
14071410
static bool
1408-
#endif /* NOT_USED_IN_PGFDWPLUS */
1409-
bool
14101411
pgfdw_cancel_query_begin(PGconn *conn)
14111412
{
14121413
PGcancel *cancel;
@@ -1433,10 +1434,7 @@ pgfdw_cancel_query_begin(PGconn *conn)
14331434
return true;
14341435
}
14351436

1436-
#ifdef NOT_USED_IN_PGFDWPLUS
14371437
static bool
1438-
#endif /* NOT_USED_IN_PGFDWPLUS */
1439-
bool
14401438
pgfdw_cancel_query_end(PGconn *conn, TimestampTz endtime, bool consume_input)
14411439
{
14421440
PGresult *result = NULL;

postgres_fdw_plus.c

+39-14
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
/*
1313
* GUC parameters
1414
*/
15-
bool pgfdw_two_phase_commit = false;
16-
bool pgfdw_skip_commit_phase = false;
17-
bool pgfdw_track_xact_commits = true;
18-
bool pgfdw_use_read_committed = false;
15+
static bool pgfdw_two_phase_commit = false;
16+
static bool pgfdw_skip_commit_phase = false;
17+
static bool pgfdw_track_xact_commits = true;
18+
static bool pgfdw_use_read_committed = false;
1919

2020
/*
2121
* Global variables
2222
*/
23-
2423
/*
2524
* This flag indicates whether the current local transaction uses
2625
* the read committed isolation level when starting remote transactions.
@@ -38,12 +37,38 @@ bool pgfdw_use_read_committed_in_xact = false;
3837
* accesses to remote servers, which is not allowed when the read committed
3938
* isolation level is used for remote transactions.
4039
*/
41-
CommandId pgfdw_last_cid = InvalidCommandId;
40+
static CommandId pgfdw_last_cid = InvalidCommandId;
41+
42+
/*
43+
* Private macros
44+
*/
45+
/*
46+
* Construct the prepared transaction command like PREPARE TRANSACTION
47+
* that's issued to the foreign server. It consists of full transaction ID,
48+
* user mapping OID, process ID and cluster name.
49+
*/
50+
#define PreparedXactCommand(sql, cmd, entry) \
51+
snprintf(sql, sizeof(sql), "%s 'pgfdw_" UINT64_FORMAT "_%u_%d_%s'", \
52+
cmd, U64FromFullTransactionId(entry->fxid), \
53+
(Oid) entry->key, MyProcPid, \
54+
(*cluster_name == '\0') ? "null" : cluster_name)
4255

4356
/*
4457
* Private functions
4558
*/
59+
static void pgfdw_abort_cleanup_with_sql(ConnCacheEntry *entry,
60+
const char *sql, bool toplevel);
61+
static void pgfdw_prepare_xacts(ConnCacheEntry *entry,
62+
List **pending_entries_prepare);
63+
static void pgfdw_finish_prepare_cleanup(List **pending_entries_prepare);
4664
static void pgfdw_cleanup_pending_entries(List **pending_entries_prepare);
65+
static void pgfdw_commit_prepared(ConnCacheEntry *entry,
66+
List **pending_entries_commit_prepared);
67+
static void pgfdw_finish_commit_prepared_cleanup(
68+
List *pending_entries_commit_prepared);
69+
static bool pgfdw_rollback_prepared(ConnCacheEntry *entry);
70+
static void pgfdw_deallocate_all(ConnCacheEntry *entry);
71+
static void pgfdw_insert_xact_commits(List *umids);
4772

4873
/*
4974
* Define GUC parameters for postgres_fdw_plus.
@@ -110,7 +135,7 @@ pgfdw_abort_cleanup(ConnCacheEntry *entry, bool toplevel)
110135
pgfdw_abort_cleanup_with_sql(entry, sql, toplevel);
111136
}
112137

113-
void
138+
static void
114139
pgfdw_abort_cleanup_with_sql(ConnCacheEntry *entry, const char *sql,
115140
bool toplevel)
116141
{
@@ -351,7 +376,7 @@ pgfdw_xact_two_phase(XactEvent event)
351376
return true;
352377
}
353378

354-
void
379+
static void
355380
pgfdw_prepare_xacts(ConnCacheEntry *entry, List **pending_entries_prepare)
356381
{
357382
char sql[256];
@@ -373,7 +398,7 @@ pgfdw_prepare_xacts(ConnCacheEntry *entry, List **pending_entries_prepare)
373398
entry->changing_xact_state = false;
374399
}
375400

376-
void
401+
static void
377402
pgfdw_finish_prepare_cleanup(List **pending_entries_prepare)
378403
{
379404
ConnCacheEntry *entry;
@@ -433,7 +458,7 @@ pgfdw_cleanup_pending_entries(List **pending_entries_prepare)
433458
*pending_entries_prepare = NIL;
434459
}
435460

436-
void
461+
static void
437462
pgfdw_commit_prepared(ConnCacheEntry *entry,
438463
List **pending_entries_commit_prepared)
439464
{
@@ -470,7 +495,7 @@ pgfdw_commit_prepared(ConnCacheEntry *entry,
470495
pgfdw_deallocate_all(entry);
471496
}
472497

473-
void
498+
static void
474499
pgfdw_finish_commit_prepared_cleanup(List *pending_entries_commit_prepared)
475500
{
476501
ConnCacheEntry *entry;
@@ -509,7 +534,7 @@ pgfdw_finish_commit_prepared_cleanup(List *pending_entries_commit_prepared)
509534
}
510535
}
511536

512-
bool
537+
static bool
513538
pgfdw_rollback_prepared(ConnCacheEntry *entry)
514539
{
515540
char sql[256];
@@ -534,7 +559,7 @@ pgfdw_rollback_prepared(ConnCacheEntry *entry)
534559
* Do a DEALLOCATE ALL to make sure we get rid of all prepared statements.
535560
* See comments in pgfdw_xact_callback().
536561
*/
537-
void
562+
static void
538563
pgfdw_deallocate_all(ConnCacheEntry *entry)
539564
{
540565
if (entry->have_prep_stmt && entry->have_error)
@@ -564,7 +589,7 @@ pgfdw_deallocate_all(ConnCacheEntry *entry)
564589
* If the transaction is rollbacked, the record inserted by this function
565590
* obviously gets unvisiable.
566591
*/
567-
void
592+
static void
568593
pgfdw_insert_xact_commits(List *umids)
569594
{
570595
Datum values[PGFDW_PLUS_XACT_COMMITS_COLS];

postgres_fdw_plus.h

+3-44
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,12 @@
33

44
#include "access/xact.h"
55
#include "miscadmin.h"
6-
#include "nodes/pg_list.h"
76
#include "postgres_fdw/postgres_fdw.h"
8-
#include "utils/guc.h"
9-
10-
/*
11-
* GUC parameters
12-
*/
13-
extern bool pgfdw_two_phase_commit;
14-
extern bool pgfdw_skip_commit_phase;
15-
extern bool pgfdw_track_xact_commits;
16-
extern bool pgfdw_use_read_committed;
177

188
/*
199
* Global variables
2010
*/
2111
extern bool pgfdw_use_read_committed_in_xact;
22-
extern CommandId pgfdw_last_cid;
2312

2413
/*
2514
* Connection cache hash table entry
@@ -84,61 +73,31 @@ extern HTAB *ConnectionHash;
8473
(entry)->xact_depth, (entry)->xact_depth); \
8574
} while(0)
8675

87-
/* option.c */
88-
extern void DefineCustomVariablesForPgFdwPlus(void);
89-
9076
/* connection.c */
9177
extern void do_sql_command_begin(PGconn *conn, const char *sql);
9278
extern void do_sql_command_end(PGconn *conn, const char *sql,
9379
bool consume_input);
94-
9580
extern void pgfdw_reject_incomplete_xact_state_change(ConnCacheEntry *entry);
9681
extern void pgfdw_reset_xact_state(ConnCacheEntry *entry, bool toplevel);
9782
extern bool pgfdw_cancel_query(PGconn *conn);
98-
extern bool pgfdw_cancel_query_begin(PGconn *conn);
99-
extern bool pgfdw_cancel_query_end(PGconn *conn, TimestampTz endtime,
100-
bool consume_input);
10183
extern bool pgfdw_exec_cleanup_query(PGconn *conn, const char *query,
10284
bool ignore_errors);
10385
extern bool pgfdw_exec_cleanup_query_begin(PGconn *conn, const char *query);
10486
extern bool pgfdw_exec_cleanup_query_end(PGconn *conn, const char *query,
10587
TimestampTz endtime,
10688
bool consume_input,
10789
bool ignore_errors);
108-
extern bool pgfdw_get_cleanup_result(PGconn *conn, TimestampTz endtime,
109-
PGresult **result, bool *timed_out);
110-
extern void pgfdw_abort_cleanup(ConnCacheEntry *entry, bool toplevel);
111-
extern void pgfdw_abort_cleanup_with_sql(ConnCacheEntry *entry,
112-
const char *sql, bool toplevel);
11390
extern bool pgfdw_abort_cleanup_begin(ConnCacheEntry *entry, bool toplevel,
11491
List **pending_entries,
11592
List **cancel_requested);
11693
extern void pgfdw_finish_abort_cleanup(List *pending_entries,
11794
List *cancel_requested,
11895
bool toplevel);
11996

97+
/* postgres_fdw_plus.c */
98+
extern void DefineCustomVariablesForPgFdwPlus(void);
99+
extern void pgfdw_abort_cleanup(ConnCacheEntry *entry, bool toplevel);
120100
extern void pgfdw_arrange_read_committed(bool xact_got_connection);
121101
extern bool pgfdw_xact_two_phase(XactEvent event);
122-
extern void pgfdw_prepare_xacts(ConnCacheEntry *entry,
123-
List **pending_entries_prepare);
124-
extern void pgfdw_finish_prepare_cleanup(List **pending_entries_prepare);
125-
extern void pgfdw_commit_prepared(ConnCacheEntry *entry,
126-
List **pending_entries_commit_prepared);
127-
extern void pgfdw_finish_commit_prepared_cleanup(
128-
List *pending_entries_commit_prepared);
129-
extern bool pgfdw_rollback_prepared(ConnCacheEntry *entry);
130-
extern void pgfdw_deallocate_all(ConnCacheEntry *entry);
131-
extern void pgfdw_insert_xact_commits(List *umids);
132-
133-
/*
134-
* Construct the prepared transaction command like PREPARE TRANSACTION
135-
* that's issued to the foreign server. It consists of full transaction ID,
136-
* user mapping OID, process ID and cluster name.
137-
*/
138-
#define PreparedXactCommand(sql, cmd, entry) \
139-
snprintf(sql, sizeof(sql), "%s 'pgfdw_" UINT64_FORMAT "_%u_%d_%s'", \
140-
cmd, U64FromFullTransactionId(entry->fxid), \
141-
(Oid) entry->key, MyProcPid, \
142-
(*cluster_name == '\0') ? "null" : cluster_name)
143102

144103
#endif /* POSTGRES_FDW_PLUS_H */

0 commit comments

Comments
 (0)