|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* logicalproto.h
|
|
|
|
* logical replication protocol
|
|
|
|
*
|
|
|
|
* Copyright (c) 2015-2019, PostgreSQL Global Development Group
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
|
|
|
* src/include/replication/logicalproto.h
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef LOGICAL_PROTO_H
|
|
|
|
#define LOGICAL_PROTO_H
|
|
|
|
|
|
|
|
#include "replication/reorderbuffer.h"
|
|
|
|
#include "utils/rel.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Protocol capabilities
|
|
|
|
*
|
|
|
|
* LOGICAL_PROTO_VERSION_NUM is our native protocol and the greatest version
|
|
|
|
* we can support. PGLOGICAL_PROTO_MIN_VERSION_NUM is the oldest version we
|
|
|
|
* have backwards compatibility for. The client requests protocol version at
|
|
|
|
* connect time.
|
|
|
|
*/
|
|
|
|
#define LOGICALREP_PROTO_MIN_VERSION_NUM 1
|
|
|
|
#define LOGICALREP_PROTO_VERSION_NUM 1
|
|
|
|
|
|
|
|
/* Tuple coming via logical replication. */
|
|
|
|
typedef struct LogicalRepTupleData
|
|
|
|
{
|
|
|
|
/* column values in text format, or NULL for a null value: */
|
|
|
|
char *values[MaxTupleAttributeNumber];
|
|
|
|
/* markers for changed/unchanged column values: */
|
|
|
|
bool changed[MaxTupleAttributeNumber];
|
|
|
|
} LogicalRepTupleData;
|
|
|
|
|
|
|
|
typedef uint32 LogicalRepRelId;
|
|
|
|
|
|
|
|
/* Relation information */
|
|
|
|
typedef struct LogicalRepRelation
|
|
|
|
{
|
|
|
|
/* Info coming from the remote side. */
|
|
|
|
LogicalRepRelId remoteid; /* unique id of the relation */
|
|
|
|
char *nspname; /* schema name */
|
|
|
|
char *relname; /* relation name */
|
|
|
|
int natts; /* number of columns */
|
|
|
|
char **attnames; /* column names */
|
|
|
|
Oid *atttyps; /* column types */
|
|
|
|
char replident; /* replica identity */
|
|
|
|
Bitmapset *attkeys; /* Bitmap of key columns */
|
|
|
|
} LogicalRepRelation;
|
|
|
|
|
|
|
|
/* Type mapping info */
|
|
|
|
typedef struct LogicalRepTyp
|
|
|
|
{
|
logical replication: fix OID type mapping mechanism
The logical replication type map seems to have been misused by its only
caller -- it would try to use the remote OID as input for local type
routines, which unsurprisingly could result in bogus "cache lookup
failed for type XYZ" errors, or random other type names being picked up
if they happened to use the right OID. Fix that, changing
Oid logicalrep_typmap_getid(Oid remoteid) to
char *logicalrep_typmap_gettypname(Oid remoteid)
which is more useful. If the remote type is not part of the typmap,
this simply prints "unrecognized type" instead of choking trying to
figure out -- a pointless exercise (because the only input for that
comes from replication messages, which are not under the local node's
control) and dangerous to boot, when called from within an error context
callback.
Once that is done, it comes to light that the local OID in the typmap
entry was not being used for anything; the type/schema names are what we
need, so remove local type OID from that struct.
Once you do that, it becomes pointless to attach a callback to regular
syscache invalidation. So remove that also.
Reported-by: Dang Minh Huong
Author: Masahiko Sawada
Reviewed-by: Álvaro Herrera, Petr Jelínek, Dang Minh Huong, Atsushi Torikoshi
Discussion: https://postgr.es/m/75DB81BEEA95B445AE6D576A0A5C9E936A6BE964@BPXM05GP.gisp.nec.co.jp
Discussion: https://postgr.es/m/75DB81BEEA95B445AE6D576A0A5C9E936A6C4B0A@BPXM05GP.gisp.nec.co.jp
8 years ago
|
|
|
Oid remoteid; /* unique id of the remote type */
|
|
|
|
char *nspname; /* schema name of remote type */
|
|
|
|
char *typname; /* name of the remote type */
|
|
|
|
} LogicalRepTyp;
|
|
|
|
|
|
|
|
/* Transaction info */
|
|
|
|
typedef struct LogicalRepBeginData
|
|
|
|
{
|
|
|
|
XLogRecPtr final_lsn;
|
|
|
|
TimestampTz committime;
|
|
|
|
TransactionId xid;
|
|
|
|
} LogicalRepBeginData;
|
|
|
|
|
|
|
|
typedef struct LogicalRepCommitData
|
|
|
|
{
|
|
|
|
XLogRecPtr commit_lsn;
|
|
|
|
XLogRecPtr end_lsn;
|
|
|
|
TimestampTz committime;
|
|
|
|
} LogicalRepCommitData;
|
|
|
|
|
|
|
|
extern void logicalrep_write_begin(StringInfo out, ReorderBufferTXN *txn);
|
|
|
|
extern void logicalrep_read_begin(StringInfo in,
|
|
|
|
LogicalRepBeginData *begin_data);
|
|
|
|
extern void logicalrep_write_commit(StringInfo out, ReorderBufferTXN *txn,
|
|
|
|
XLogRecPtr commit_lsn);
|
|
|
|
extern void logicalrep_read_commit(StringInfo in,
|
|
|
|
LogicalRepCommitData *commit_data);
|
|
|
|
extern void logicalrep_write_origin(StringInfo out, const char *origin,
|
|
|
|
XLogRecPtr origin_lsn);
|
|
|
|
extern char *logicalrep_read_origin(StringInfo in, XLogRecPtr *origin_lsn);
|
|
|
|
extern void logicalrep_write_insert(StringInfo out, Relation rel,
|
|
|
|
HeapTuple newtuple);
|
|
|
|
extern LogicalRepRelId logicalrep_read_insert(StringInfo in, LogicalRepTupleData *newtup);
|
|
|
|
extern void logicalrep_write_update(StringInfo out, Relation rel, HeapTuple oldtuple,
|
|
|
|
HeapTuple newtuple);
|
|
|
|
extern LogicalRepRelId logicalrep_read_update(StringInfo in,
|
|
|
|
bool *has_oldtuple, LogicalRepTupleData *oldtup,
|
|
|
|
LogicalRepTupleData *newtup);
|
|
|
|
extern void logicalrep_write_delete(StringInfo out, Relation rel,
|
|
|
|
HeapTuple oldtuple);
|
|
|
|
extern LogicalRepRelId logicalrep_read_delete(StringInfo in,
|
|
|
|
LogicalRepTupleData *oldtup);
|
|
|
|
extern void logicalrep_write_truncate(StringInfo out, int nrelids, Oid relids[],
|
|
|
|
bool cascade, bool restart_seqs);
|
|
|
|
extern List *logicalrep_read_truncate(StringInfo in,
|
|
|
|
bool *cascade, bool *restart_seqs);
|
|
|
|
extern void logicalrep_write_rel(StringInfo out, Relation rel);
|
|
|
|
extern LogicalRepRelation *logicalrep_read_rel(StringInfo in);
|
|
|
|
extern void logicalrep_write_typ(StringInfo out, Oid typoid);
|
|
|
|
extern void logicalrep_read_typ(StringInfo out, LogicalRepTyp *ltyp);
|
|
|
|
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
8 years ago
|
|
|
#endif /* LOGICALREP_PROTO_H */
|