2011-03-07 00:39:14 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* syncrep.h
|
|
|
|
* Exports from replication/syncrep.c.
|
|
|
|
*
|
2016-01-02 19:33:40 +01:00
|
|
|
* Portions Copyright (c) 2010-2016, PostgreSQL Global Development Group
|
2011-03-07 00:39:14 +01:00
|
|
|
*
|
2011-03-10 07:05:33 +01:00
|
|
|
* IDENTIFICATION
|
|
|
|
* src/include/replication/syncrep.h
|
2011-03-07 00:39:14 +01:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef _SYNCREP_H
|
|
|
|
#define _SYNCREP_H
|
|
|
|
|
2012-08-28 15:46:08 +02:00
|
|
|
#include "access/xlogdefs.h"
|
2011-03-07 00:39:14 +01:00
|
|
|
#include "utils/guc.h"
|
|
|
|
|
2012-01-24 21:22:37 +01:00
|
|
|
#define SyncRepRequested() \
|
|
|
|
(max_wal_senders > 0 && synchronous_commit > SYNCHRONOUS_COMMIT_LOCAL_FLUSH)
|
|
|
|
|
|
|
|
/* SyncRepWaitMode */
|
|
|
|
#define SYNC_REP_NO_WAIT -1
|
|
|
|
#define SYNC_REP_WAIT_WRITE 0
|
|
|
|
#define SYNC_REP_WAIT_FLUSH 1
|
2016-03-30 03:16:12 +02:00
|
|
|
#define SYNC_REP_WAIT_APPLY 2
|
2012-01-24 21:22:37 +01:00
|
|
|
|
2016-03-30 03:16:12 +02:00
|
|
|
#define NUM_SYNC_REP_WAIT_MODE 3
|
2012-01-24 21:22:37 +01:00
|
|
|
|
2011-03-07 00:39:14 +01:00
|
|
|
/* syncRepState */
|
|
|
|
#define SYNC_REP_NOT_WAITING 0
|
|
|
|
#define SYNC_REP_WAITING 1
|
|
|
|
#define SYNC_REP_WAIT_COMPLETE 2
|
|
|
|
|
Support multiple synchronous standby servers.
Previously synchronous replication offered only the ability to confirm
that all changes made by a transaction had been transferred to at most
one synchronous standby server.
This commit extends synchronous replication so that it supports multiple
synchronous standby servers. It enables users to consider one or more
standby servers as synchronous, and increase the level of transaction
durability by ensuring that transaction commits wait for replies from
all of those synchronous standbys.
Multiple synchronous standby servers are configured in
synchronous_standby_names which is extended to support new syntax of
'num_sync ( standby_name [ , ... ] )', where num_sync specifies
the number of synchronous standbys that transaction commits need to
wait for replies from and standby_name is the name of a standby
server.
The syntax of 'standby_name [ , ... ]' which was used in 9.5 or before
is also still supported. It's the same as new syntax with num_sync=1.
This commit doesn't include "quorum commit" feature which was discussed
in pgsql-hackers. Synchronous standbys are chosen based on their priorities.
synchronous_standby_names determines the priority of each standby for
being chosen as a synchronous standby. The standbys whose names appear
earlier in the list are given higher priority and will be considered as
synchronous. Other standby servers appearing later in this list
represent potential synchronous standbys.
The regression test for multiple synchronous standbys is not included
in this commit. It should come later.
Authors: Sawada Masahiko, Beena Emerson, Michael Paquier, Fujii Masao
Reviewed-By: Kyotaro Horiguchi, Amit Kapila, Robert Haas, Simon Riggs,
Amit Langote, Thomas Munro, Sameer Thakur, Suraj Kharage, Abhijit Menon-Sen,
Rajeev Rastogi
Many thanks to the various individuals who were involved in
discussing and developing this feature.
2016-04-06 10:18:25 +02:00
|
|
|
/*
|
|
|
|
* Struct for the configuration of synchronous replication.
|
|
|
|
*/
|
|
|
|
typedef struct SyncRepConfigData
|
|
|
|
{
|
|
|
|
int num_sync; /* number of sync standbys that we need to wait for */
|
|
|
|
List *members; /* list of names of potential sync standbys */
|
|
|
|
} SyncRepConfigData;
|
|
|
|
|
|
|
|
extern SyncRepConfigData *syncrep_parse_result;
|
|
|
|
extern SyncRepConfigData *SyncRepConfig;
|
|
|
|
|
2011-03-07 00:39:14 +01:00
|
|
|
/* user-settable parameters for synchronous replication */
|
|
|
|
extern char *SyncRepStandbyNames;
|
|
|
|
|
|
|
|
/* called by user backend */
|
2016-03-30 03:16:12 +02:00
|
|
|
extern void SyncRepWaitForLSN(XLogRecPtr lsn, bool commit);
|
2011-03-07 00:39:14 +01:00
|
|
|
|
2011-08-10 18:20:30 +02:00
|
|
|
/* called at backend exit */
|
|
|
|
extern void SyncRepCleanupAtProcExit(void);
|
2011-03-07 00:39:14 +01:00
|
|
|
|
|
|
|
/* called by wal sender */
|
|
|
|
extern void SyncRepInitConfig(void);
|
|
|
|
extern void SyncRepReleaseWaiters(void);
|
|
|
|
|
Support multiple synchronous standby servers.
Previously synchronous replication offered only the ability to confirm
that all changes made by a transaction had been transferred to at most
one synchronous standby server.
This commit extends synchronous replication so that it supports multiple
synchronous standby servers. It enables users to consider one or more
standby servers as synchronous, and increase the level of transaction
durability by ensuring that transaction commits wait for replies from
all of those synchronous standbys.
Multiple synchronous standby servers are configured in
synchronous_standby_names which is extended to support new syntax of
'num_sync ( standby_name [ , ... ] )', where num_sync specifies
the number of synchronous standbys that transaction commits need to
wait for replies from and standby_name is the name of a standby
server.
The syntax of 'standby_name [ , ... ]' which was used in 9.5 or before
is also still supported. It's the same as new syntax with num_sync=1.
This commit doesn't include "quorum commit" feature which was discussed
in pgsql-hackers. Synchronous standbys are chosen based on their priorities.
synchronous_standby_names determines the priority of each standby for
being chosen as a synchronous standby. The standbys whose names appear
earlier in the list are given higher priority and will be considered as
synchronous. Other standby servers appearing later in this list
represent potential synchronous standbys.
The regression test for multiple synchronous standbys is not included
in this commit. It should come later.
Authors: Sawada Masahiko, Beena Emerson, Michael Paquier, Fujii Masao
Reviewed-By: Kyotaro Horiguchi, Amit Kapila, Robert Haas, Simon Riggs,
Amit Langote, Thomas Munro, Sameer Thakur, Suraj Kharage, Abhijit Menon-Sen,
Rajeev Rastogi
Many thanks to the various individuals who were involved in
discussing and developing this feature.
2016-04-06 10:18:25 +02:00
|
|
|
/* called by wal sender and user backend */
|
|
|
|
extern List *SyncRepGetSyncStandbys(bool *am_sync);
|
|
|
|
extern void SyncRepUpdateConfig(void);
|
|
|
|
extern void SyncRepFreeConfig(SyncRepConfigData *config);
|
|
|
|
|
2013-05-23 17:34:30 +02:00
|
|
|
/* called by checkpointer */
|
Fix various possible problems with synchronous replication.
1. Don't ignore query cancel interrupts. Instead, if the user asks to
cancel the query after we've already committed it, but before it's on
the standby, just emit a warning and let the COMMIT finish.
2. Don't ignore die interrupts (pg_terminate_backend or fast shutdown).
Instead, emit a warning message and close the connection without
acknowledging the commit. Other backends will still see the effect of
the commit, but there's no getting around that; it's too late to abort
at this point, and ignoring die interrupts altogether doesn't seem like
a good idea.
3. If synchronous_standby_names becomes empty, wake up all backends
waiting for synchronous replication to complete. Without this, someone
attempting to shut synchronous replication off could easily wedge the
entire system instead.
4. Avoid depending on the assumption that if a walsender updates
MyProc->syncRepState, we'll see the change even if we read it without
holding the lock. The window for this appears to be quite narrow (and
probably doesn't exist at all on machines with strong memory ordering)
but protecting against it is practically free, so do that.
5. Remove useless state SYNC_REP_MUST_DISCONNECT, which isn't needed and
doesn't actually do anything.
There's still some further work needed here to make the behavior of fast
shutdown plausible, but that looks complex, so I'm leaving it for a
separate commit. Review by Fujii Masao.
2011-03-17 18:10:42 +01:00
|
|
|
extern void SyncRepUpdateSyncStandbysDefined(void);
|
|
|
|
|
2011-04-07 06:11:01 +02:00
|
|
|
extern bool check_synchronous_standby_names(char **newval, void **extra, GucSource source);
|
2012-01-24 21:22:37 +01:00
|
|
|
extern void assign_synchronous_commit(int newval, void *extra);
|
2011-03-07 00:39:14 +01:00
|
|
|
|
Support multiple synchronous standby servers.
Previously synchronous replication offered only the ability to confirm
that all changes made by a transaction had been transferred to at most
one synchronous standby server.
This commit extends synchronous replication so that it supports multiple
synchronous standby servers. It enables users to consider one or more
standby servers as synchronous, and increase the level of transaction
durability by ensuring that transaction commits wait for replies from
all of those synchronous standbys.
Multiple synchronous standby servers are configured in
synchronous_standby_names which is extended to support new syntax of
'num_sync ( standby_name [ , ... ] )', where num_sync specifies
the number of synchronous standbys that transaction commits need to
wait for replies from and standby_name is the name of a standby
server.
The syntax of 'standby_name [ , ... ]' which was used in 9.5 or before
is also still supported. It's the same as new syntax with num_sync=1.
This commit doesn't include "quorum commit" feature which was discussed
in pgsql-hackers. Synchronous standbys are chosen based on their priorities.
synchronous_standby_names determines the priority of each standby for
being chosen as a synchronous standby. The standbys whose names appear
earlier in the list are given higher priority and will be considered as
synchronous. Other standby servers appearing later in this list
represent potential synchronous standbys.
The regression test for multiple synchronous standbys is not included
in this commit. It should come later.
Authors: Sawada Masahiko, Beena Emerson, Michael Paquier, Fujii Masao
Reviewed-By: Kyotaro Horiguchi, Amit Kapila, Robert Haas, Simon Riggs,
Amit Langote, Thomas Munro, Sameer Thakur, Suraj Kharage, Abhijit Menon-Sen,
Rajeev Rastogi
Many thanks to the various individuals who were involved in
discussing and developing this feature.
2016-04-06 10:18:25 +02:00
|
|
|
/*
|
|
|
|
* Internal functions for parsing synchronous_standby_names grammar,
|
|
|
|
* in syncrep_gram.y and syncrep_scanner.l
|
|
|
|
*/
|
|
|
|
extern int syncrep_yyparse(void);
|
|
|
|
extern int syncrep_yylex(void);
|
|
|
|
extern void syncrep_yyerror(const char *str);
|
|
|
|
extern void syncrep_scanner_init(const char *query_string);
|
|
|
|
extern void syncrep_scanner_finish(void);
|
|
|
|
|
2011-03-07 00:39:14 +01:00
|
|
|
#endif /* _SYNCREP_H */
|