Skip to content

Commit 4cc27e9

Browse files
author
Antonin Houska
committed
Adapted the code to PG 11.
1 parent 343abbf commit 4cc27e9

File tree

8 files changed

+93
-9
lines changed

8 files changed

+93
-9
lines changed

src/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
all: walbouncer
22

3-
# Check for PostgrSQL 9.5/9.6
4-
ifeq ($(shell pg_config --version | grep -E "PostgreSQL 9.[56]|10"),)
5-
$(error PostgreSQL version 9.5/9.6 required, pg_config provides $(shell pg_config --version))
3+
# Check for PostgrSQL 9.5 through 11
4+
ifeq ($(shell pg_config --version | grep -E "PostgreSQL 9.[56]|10|11"),)
5+
$(error PostgreSQL version 9.5 through 11 required, pg_config provides $(shell pg_config --version))
66
endif
77

88
CFLAGS=-O2 -Wall -Werror -g -std=gnu99

src/include/parser/parser.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ typedef enum {
1111
REPL_DROP_SLOT,
1212
REPL_START_PHYSICAL,
1313
REPL_START_LOGICAL,
14-
REPL_TIMELINE
14+
REPL_TIMELINE,
15+
REPL_SHOW_VAR
1516
} ReplCommandType;
1617

1718
typedef struct ReplicationCommand {
1819
ReplCommandType command;
1920
char *slotname;
21+
char *varname;
2022
TimeLineID timeline;
2123
XLogRecPtr startpoint;
2224
} ReplicationCommand;

src/include/wbmasterconn.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ bool WbMcIdentifySystem(MasterConn* master,
5151
char** primary_sysid, char** primary_tli, char** primary_xpos);
5252
bool WbMcGetTimelineHistory(MasterConn* master, TimeLineID timeline,
5353
TimelineHistory *history);
54+
char *WbMcShowVariable(MasterConn* master, char *varname);
5455
Oid * WbMcResolveOids(MasterConn *master, OidResolveKind kind, bool include, char** names, int n_items);
5556
const char *WbMcParameterStatus(MasterConn *master, char *name);
5657
#endif

src/include/wbpgtypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ typedef struct BkpBlock
6767
* Each page of XLOG file has a header like this:
6868
*/
6969
#define XLOG_PAGE_MAGIC_MIN 0xD087 /* in WB case it's OK to use a range of versions as we're only interested in fixing the RelFileNode location */
70-
#define XLOG_PAGE_MAGIC_MAX 0xD097
70+
#define XLOG_PAGE_MAGIC_MAX 0xD098
7171

7272
typedef struct XLogPageHeaderData
7373
{

src/parser/repl_gram.y

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ReplicationCommand *replication_parse_result;
6464
/* Keyword tokens. */
6565
%token K_BASE_BACKUP
6666
%token K_IDENTIFY_SYSTEM
67+
%token K_SHOW
6768
%token K_START_REPLICATION
6869
%token K_CREATE_REPLICATION_SLOT
6970
%token K_DROP_REPLICATION_SLOT
@@ -80,7 +81,7 @@ ReplicationCommand *replication_parse_result;
8081
%token K_SLOT
8182

8283
%type <cmd> command
83-
%type <cmd> base_backup start_replication start_logical_replication create_replication_slot drop_replication_slot identify_system timeline_history
84+
%type <cmd> base_backup start_replication start_logical_replication create_replication_slot drop_replication_slot identify_system timeline_history show
8485
//%type <list> base_backup_opt_list
8586
//%type <defelt> base_backup_opt
8687
%type <str> base_backup_opt_list
@@ -94,7 +95,7 @@ ReplicationCommand *replication_parse_result;
9495
%type <str> plugin_opt_elem
9596
%type <str> plugin_opt_arg
9697

97-
%type <str> opt_slot
98+
%type <str> opt_slot var_name
9899

99100
%%
100101

@@ -116,6 +117,7 @@ command:
116117
| create_replication_slot
117118
| drop_replication_slot
118119
| timeline_history
120+
| show
119121
;
120122

121123
/*
@@ -128,6 +130,28 @@ identify_system:
128130
}
129131
;
130132

133+
/*
134+
* SHOW setting
135+
*/
136+
show:
137+
K_SHOW var_name
138+
{
139+
ReplicationCommand *cmd = MakeReplCommand(REPL_SHOW_VAR);
140+
141+
cmd->varname = $2;
142+
$$ = cmd;
143+
}
144+
145+
var_name: IDENT { $$ = $1; }
146+
| var_name '.' IDENT
147+
{ char *s1 = $1;
148+
char *s2 = $3;
149+
char *res = wballoc(strlen(s1) + strlen(s2) + 1);
150+
151+
sprintf(res, "%s.%s", s1, s2);
152+
$$ = res;}
153+
;
154+
131155
/*
132156
* BASE_BACKUP [LABEL '<label>'] [PROGRESS] [FAST] [WAL] [NOWAIT] [MAX_RATE %d]
133157
*/

src/parser/repl_scanner.l

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ identifier {ident_start}{ident_cont}*
8383
BASE_BACKUP { return K_BASE_BACKUP; }
8484
FAST { return K_FAST; }
8585
IDENTIFY_SYSTEM { return K_IDENTIFY_SYSTEM; }
86+
SHOW { return K_SHOW; }
8687
LABEL { return K_LABEL; }
8788
NOWAIT { return K_NOWAIT; }
8889
PROGRESS { return K_PROGRESS; }
@@ -146,9 +147,12 @@ SLOT { return K_SLOT; }
146147
}
147148

148149
<xd>{xdstop} {
150+
int len;
149151
yyless(1);
150152
BEGIN(INITIAL);
151153
yylval.str = litbufdup();
154+
len = strlen(yylval.str);
155+
truncate_identifier(yylval.str, len, true);
152156
return IDENT;
153157
}
154158

@@ -157,9 +161,9 @@ SLOT { return K_SLOT; }
157161
}
158162

159163
{identifier} {
160-
//int len = strlen(yytext);
164+
int len = strlen(yytext);
161165

162-
yylval.str = litbufdup();//downcase_truncate_identifier(yytext, len, true);
166+
yylval.str = downcase_truncate_identifier(yytext, len, true);
163167
return IDENT;
164168
}
165169

src/wbclientconn.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static void WbCCExecIdentifySystem(WbConn conn, MasterConn *master);
4040
static bool WbCCWaitForData(WbConn conn, MasterConn *master);
4141
static void WbCCExecStartPhysical(WbConn conn, MasterConn *master, ReplicationCommand *cmd);
4242
static void WbCCExecTimeline(WbConn conn, MasterConn *master, ReplicationCommand *cmd);
43+
static void WbCCExecShow(WbConn conn, MasterConn *master, ReplicationCommand *cmd);
4344
static void WbCCLookupFilteringOids(WbConn conn, FilterData *fl);
4445
//static void WbCCSendWALRecord(XfConn conn, char *data, int len, XLogRecPtr sentPtr, TimestampTz lastSend);
4546
//static void WbCCSendEndOfWal(XfConn conn);
@@ -527,6 +528,9 @@ WbCCExecCommand(WbConn conn, MasterConn *master, char *query_string)
527528
case REPL_TIMELINE:
528529
WbCCExecTimeline(conn, master, cmd);
529530
break;
531+
case REPL_SHOW_VAR:
532+
WbCCExecShow(conn, master, cmd);
533+
break;
530534
}
531535

532536

@@ -814,6 +818,27 @@ WbCCExecTimeline(WbConn conn, MasterConn *master, ReplicationCommand *cmd)
814818
wbfree(history.content);
815819
}
816820

821+
static void
822+
WbCCExecShow(WbConn conn, MasterConn *master, ReplicationCommand *cmd)
823+
{
824+
char *value;
825+
826+
log_info("Received request for variable %s", cmd->varname);
827+
828+
value = WbMcShowVariable(master, cmd->varname);
829+
830+
{
831+
ResultCol cols[1] = {
832+
{ cmd->varname, TEXTOID, value, 0}
833+
};
834+
WbCCSendResultset(conn, 1, cols);
835+
}
836+
837+
log_info("Sent out variable value %s", value);
838+
839+
wbfree(value);
840+
}
841+
817842
static void
818843
WbCCLookupFilteringOids(WbConn conn, FilterData *fl)
819844
{

src/wbmasterconn.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,34 @@ WbMcGetTimelineHistory(MasterConn* master, TimeLineID timeline,
387387
return true;
388388
}
389389

390+
char *
391+
WbMcShowVariable(MasterConn* master, char *varname)
392+
{
393+
PGconn *mc = master->conn;
394+
char query[1024];
395+
PGresult *result;
396+
char *value;
397+
398+
snprintf(query, 1024, "SHOW %s", varname);
399+
400+
result = PQexec(mc, query);
401+
402+
if (PQresultStatus(result) != PGRES_TUPLES_OK)
403+
{
404+
log_debug1("Variable returned %s", PQresStatus(PQresultStatus(result)));
405+
PQclear(result);
406+
error("Getting variable from master failed with: %s", PQerrorMessage(mc));
407+
}
408+
if (PQntuples(result) != 1)
409+
{
410+
error("Invalid response for SHOW command: %d tuples", PQnfields(result));
411+
}
412+
413+
value = wbstrdup(PQgetvalue(result, 0, 0));
414+
PQclear(result);
415+
return value;
416+
}
417+
390418
Oid *
391419
WbMcResolveOids(MasterConn *master, OidResolveKind kind, bool include, char** names, int n_items)
392420
{

0 commit comments

Comments
 (0)