Re: [HACKERS] Logical Replication Helpers WIP for discussion

2015-02-15 Thread Petr Jelinek

On 13/02/15 14:04, Petr Jelinek wrote:

On 13/02/15 08:48, Michael Paquier wrote:


Looking at this patch, I don't see what we actually gain much here
except a decoder plugin that speaks a special protocol for a special
background worker that has not been presented yet. What actually is the
value of that defined as a contrib/ module in-core. Note that we have
already test_decoding to basically test the logical decoding facility,
used at least at the SQL level to get logical changes decoded.

Based on those reasons I am planning to mark this as rejected (it has no
documentation as well). So please speak up if you think the contrary,
but it seems to me that this could live happily out of core.


I think you are missing point of this, it's not meant to be committed in
this form at all and even less as contrib module. It was meant as basis
for in-core logical replication discussion, but sadly I didn't really
have time to pursue it in this CF in the end.



That being said and looking at the size of February CF, I think I am 
fine with dropping this in 9.5 cycle, it does not seem likely that there 
will be anything useful done with this fast enough to get to 9.5 so 
there is no point in spending committer resources on it in final CF.


I will pick it up again after the CF is done.

--
 Petr Jelinek  http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Logical Replication Helpers WIP for discussion

2015-02-15 Thread Michael Paquier
On Sun, Feb 15, 2015 at 11:25 PM, Petr Jelinek p...@2ndquadrant.com wrote:

 On 13/02/15 14:04, Petr Jelinek wrote:

 On 13/02/15 08:48, Michael Paquier wrote:


 Looking at this patch, I don't see what we actually gain much here
 except a decoder plugin that speaks a special protocol for a special
 background worker that has not been presented yet. What actually is the
 value of that defined as a contrib/ module in-core. Note that we have
 already test_decoding to basically test the logical decoding facility,
 used at least at the SQL level to get logical changes decoded.

 Based on those reasons I am planning to mark this as rejected (it has no
 documentation as well). So please speak up if you think the contrary,
 but it seems to me that this could live happily out of core.


 I think you are missing point of this, it's not meant to be committed in
 this form at all and even less as contrib module. It was meant as basis
 for in-core logical replication discussion, but sadly I didn't really
 have time to pursue it in this CF in the end.


 That being said and looking at the size of February CF, I think I am fine
 with dropping this in 9.5 cycle, it does not seem likely that there will be
 anything useful done with this fast enough to get to 9.5 so there is no
 point in spending committer resources on it in final CF.

 I will pick it up again after the CF is done.


OK, thanks for the clarifications. Note that I am marking it as rejected
in CF 2014-12 not because it is something that is not wanted, but just not
to re-add it to CF 2015-02 which is what returned with feedback actually
does...
-- 
Michael


Re: [HACKERS] Logical Replication Helpers WIP for discussion

2015-02-13 Thread Petr Jelinek

On 13/02/15 08:48, Michael Paquier wrote:



On Mon, Dec 22, 2014 at 10:26 PM, Robert Haas robertmh...@gmail.com
mailto:robertmh...@gmail.com wrote:

On Fri, Dec 19, 2014 at 8:40 AM, Petr Jelinek p...@2ndquadrant.com
mailto:p...@2ndquadrant.com wrote:
 What I hope to get from this is agreement on the general approach and
 protocol so that we can have common base which will both make it easier to
 create external logical replication solutions and also eventually lead to
 full logical replication inside core PostgreSQL.

The protocol is a really important topic which deserves its own
discussion.  Andres has mentioned some of the ideas he has in mind -
which I think are similar to what you did here - but there hasn't
really been a thread devoted to discussing that topic specifically.  I
think that would be a good idea: lay out what you have in mind, and
why, and solicit feedback.


Looking at this patch, I don't see what we actually gain much here
except a decoder plugin that speaks a special protocol for a special
background worker that has not been presented yet. What actually is the
value of that defined as a contrib/ module in-core. Note that we have
already test_decoding to basically test the logical decoding facility,
used at least at the SQL level to get logical changes decoded.

Based on those reasons I am planning to mark this as rejected (it has no
documentation as well). So please speak up if you think the contrary,
but it seems to me that this could live happily out of core.


I think you are missing point of this, it's not meant to be committed in 
this form at all and even less as contrib module. It was meant as basis 
for in-core logical replication discussion, but sadly I didn't really 
have time to pursue it in this CF in the end.



--
 Petr Jelinek  http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Logical Replication Helpers WIP for discussion

2015-02-12 Thread Michael Paquier
On Mon, Dec 22, 2014 at 10:26 PM, Robert Haas robertmh...@gmail.com wrote:

 On Fri, Dec 19, 2014 at 8:40 AM, Petr Jelinek p...@2ndquadrant.com
 wrote:
  What I hope to get from this is agreement on the general approach and
  protocol so that we can have common base which will both make it easier
 to
  create external logical replication solutions and also eventually lead to
  full logical replication inside core PostgreSQL.

 The protocol is a really important topic which deserves its own
 discussion.  Andres has mentioned some of the ideas he has in mind -
 which I think are similar to what you did here - but there hasn't
 really been a thread devoted to discussing that topic specifically.  I
 think that would be a good idea: lay out what you have in mind, and
 why, and solicit feedback.


Looking at this patch, I don't see what we actually gain much here except a
decoder plugin that speaks a special protocol for a special background
worker that has not been presented yet. What actually is the value of that
defined as a contrib/ module in-core. Note that we have already
test_decoding to basically test the logical decoding facility, used at
least at the SQL level to get logical changes decoded.

Based on those reasons I am planning to mark this as rejected (it has no
documentation as well). So please speak up if you think the contrary, but
it seems to me that this could live happily out of core.
-- 
Michael


Re: [HACKERS] Logical Replication Helpers WIP for discussion

2014-12-22 Thread Robert Haas
On Fri, Dec 19, 2014 at 8:40 AM, Petr Jelinek p...@2ndquadrant.com wrote:
 What I hope to get from this is agreement on the general approach and
 protocol so that we can have common base which will both make it easier to
 create external logical replication solutions and also eventually lead to
 full logical replication inside core PostgreSQL.

The protocol is a really important topic which deserves its own
discussion.  Andres has mentioned some of the ideas he has in mind -
which I think are similar to what you did here - but there hasn't
really been a thread devoted to discussing that topic specifically.  I
think that would be a good idea: lay out what you have in mind, and
why, and solicit feedback.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Logical Replication Helpers WIP for discussion

2014-12-19 Thread Petr Jelinek

On 15/12/14 19:42, Robert Haas wrote:

On Mon, Dec 15, 2014 at 12:57 AM, Petr Jelinek p...@2ndquadrant.com wrote:

we've made few helper functions for making logical replication easier, I
bundled it into contrib module as this is mainly for discussion at this time
(I don't expect this to get committed any time soon, but it is good way to
iron out protocol, etc).

I created sample logical decoding plugin that uses those functions and which
can be used for passing DML changes in platform/version independent
(hopefully) format.

I will post sample apply BG worker also once I get some initial feedback
about this.

It's hard to write tests for this as the binary changes contain transaction
ids and timestamps so the data changes constantly.

This is of course based on the BDR work Andres, Craig and myself have been
doing.


I can't understand, either from what you've written here or the rather
sparse comments in the patch, what this might be good for.



What I tried to achieve here is to provide solution to many of the 
common problems faced by logical replication solutions. I believe the 
first step in designing the logical replication (now that we have the 
logical decoding) is making the output plugin and the efficient protocol 
so I started with that.


The code itself provides two main parts:
First is the lrep_utils common utility functions that solve things like 
transporting DML statements, and more importantly the changed data in 
efficient manner, trying to not do any conversion if not needed (when 
architecture/version matches) but falling back to binary/textual IO 
representation of individual types so that the cross platform/version 
replication works too. I think those should eventually end up in core 
(ie not in contrib) as they are helper functions likely to be shared by 
multiple extensions, but for now I keep them with the rest of the 
contrib module as I feel better experimenting inside that module.
There are also read functions that show how the other side could look 
like, but they are currently unused as the example apply worker is not 
part of the submission yet.


The second part is extensible output plugin which serves both as an 
example of the intended use of those common utility functions and also 
as actual working solution that can be used as base for several 
replication solutions.
It provides hooks for the replication solutions built on top of it that 
can be used for deciding if to replicate specific action on specific 
object and also injecting additional information to both BEGIN and 
COMMIT message - this can be useful for example when you are forwarding 
changes from another node and you wish to pass the information about the 
original node to the target one.


What I hope to get from this is agreement on the general approach and 
protocol so that we can have common base which will both make it easier 
to create external logical replication solutions and also eventually 
lead to full logical replication inside core PostgreSQL.


--
 Petr Jelinek  http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Logical Replication Helpers WIP for discussion

2014-12-15 Thread Robert Haas
On Mon, Dec 15, 2014 at 12:57 AM, Petr Jelinek p...@2ndquadrant.com wrote:
 we've made few helper functions for making logical replication easier, I
 bundled it into contrib module as this is mainly for discussion at this time
 (I don't expect this to get committed any time soon, but it is good way to
 iron out protocol, etc).

 I created sample logical decoding plugin that uses those functions and which
 can be used for passing DML changes in platform/version independent
 (hopefully) format.

 I will post sample apply BG worker also once I get some initial feedback
 about this.

 It's hard to write tests for this as the binary changes contain transaction
 ids and timestamps so the data changes constantly.

 This is of course based on the BDR work Andres, Craig and myself have been
 doing.

I can't understand, either from what you've written here or the rather
sparse comments in the patch, what this might be good for.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] Logical Replication Helpers WIP for discussion

2014-12-14 Thread Petr Jelinek

Hello,

we've made few helper functions for making logical replication easier, I 
bundled it into contrib module as this is mainly for discussion at this 
time (I don't expect this to get committed any time soon, but it is good 
way to iron out protocol, etc).


I created sample logical decoding plugin that uses those functions and 
which can be used for passing DML changes in platform/version 
independent (hopefully) format.


I will post sample apply BG worker also once I get some initial feedback 
about this.


It's hard to write tests for this as the binary changes contain 
transaction ids and timestamps so the data changes constantly.


This is of course based on the BDR work Andres, Craig and myself have 
been doing.


--
 Petr Jelinek  http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services
diff --git a/contrib/lrep/Makefile b/contrib/lrep/Makefile
new file mode 100644
index 000..d3f7ba3
--- /dev/null
+++ b/contrib/lrep/Makefile
@@ -0,0 +1,20 @@
+# contrib/lrep/Makefile
+
+MODULE_big = lrep
+OBJS = lrep_utils.o lrep_output.o $(WIN32RES)
+PG_CPPFLAGS = -I$(libpq_srcdir)
+
+#EXTENSION = lrep
+#REGRESS = lrep
+#REGRESS_OPTS = --temp-config $(top_srcdir)/contrib/lrep/logical.conf
+
+ifdef USE_PGXS
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
+else
+subdir = contrib/lrep
+top_builddir = ../..
+include $(top_builddir)/src/Makefile.global
+include $(top_srcdir)/contrib/contrib-global.mk
+endif
diff --git a/contrib/lrep/lrep.h b/contrib/lrep/lrep.h
new file mode 100644
index 000..e2910c4
--- /dev/null
+++ b/contrib/lrep/lrep.h
@@ -0,0 +1,108 @@
+/*-
+ *
+ * lrep.h
+ *		LREP public interfaces
+ *
+ * Copyright (c) 2012-2014, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ *		contrib/lrep/lrep.h
+ *
+ *-
+ */
+#ifndef LREP_H
+#define LREP_H
+
+#include libpq-fe.h
+
+#include nodes/parsenodes.h
+
+#include replication/logical.h
+#include replication/output_plugin.h
+
+#include storage/lock.h
+
+#define LREP_PROTO_VERSION_NUM 1
+#define LREP_PROTO_MIN_REMOTE_VERSION_NUM 1
+
+typedef struct
+{
+	MemoryContext context;
+
+	bool allow_binary_protocol;
+	bool allow_sendrecv_protocol;
+	bool int_datetime_mismatch;
+	bool forward_changesets;
+
+	uint32 client_pg_version;
+	uint32 client_pg_catversion;
+	uint32 client_proto_version;
+	uint32 client_min_proto_version;
+	size_t client_sizeof_int;
+	size_t client_sizeof_long;
+	size_t client_sizeof_datum;
+	size_t client_maxalign;
+	bool client_bigendian;
+	bool client_float4_byval;
+	bool client_float8_byval;
+	bool client_int_datetime;
+	char *client_db_encoding;
+
+	void *extra;		/* Additional data */
+} LREPOutputData;
+
+
+typedef struct LREPTupleData
+{
+	Datum	values[MaxTupleAttributeNumber];
+	bool	nulls[MaxTupleAttributeNumber];
+	bool	changed[MaxTupleAttributeNumber];
+} LREPTupleData;
+
+
+extern void lrep_write_begin(StringInfo out, ReorderBufferTXN *txn, int flags,
+			 StringInfo extradata);
+extern void lrep_write_commit(StringInfo out, ReorderBufferTXN *txn,
+			  XLogRecPtr commit_lsn, int flags,
+			  StringInfo extradata);
+
+extern void lrep_write_insert(LREPOutputData *data, StringInfo out,
+			  Relation rel, HeapTuple newtuple);
+extern void lrep_write_update(LREPOutputData *data, StringInfo out,
+			  Relation rel, HeapTuple oldtuple,
+			  HeapTuple newtuple);
+extern void lrep_write_delete(LREPOutputData *data, StringInfo out,
+			  Relation rel, HeapTuple oldtuple);
+
+extern void lrep_write_rel(StringInfo out, Relation rel);
+extern void lrep_write_tuple(LREPOutputData *data, StringInfo out, Relation rel,
+		HeapTuple tuple);
+
+extern int lrep_read_begin(StringInfo in, XLogRecPtr *origlsn,
+		   TimestampTz *committime, TransactionId *remote_xid);
+extern int lrep_read_commit(StringInfo in, XLogRecPtr *commit_lsn,
+			XLogRecPtr *end_lsn, TimestampTz *committime);
+extern Relation lrep_read_insert(StringInfo in, LOCKMODE lockmode,
+ LREPTupleData *tuple);
+extern Relation lrep_read_update(StringInfo in, LOCKMODE lockmode,
+ LREPTupleData *oldtuple,
+ LREPTupleData *newtuple, bool *pkeysent);
+extern Relation lrep_read_delete(StringInfo in, LOCKMODE lockmode,
+ LREPTupleData *tuple, bool *pkeysent);
+
+extern void lrep_read_tuple_parts(StringInfo s, TupleDesc desc,
+  LREPTupleData *tuple);
+extern RangeVar *lrep_read_rel(StringInfo s);
+
+extern bool lrep_send_feedback(PGconn *conn, XLogRecPtr recvpos,
+			   XLogRecPtr writepos, XLogRecPtr flushpos,
+			   int64 now, bool force);
+
+extern void lrep_opt_parse_notnull(DefElem *elem, const char *paramtype);
+extern void lrep_opt_parse_uint32(DefElem *elem, uint32 *res);
+extern void lrep_opt_parse_size_t(DefElem *elem, size_t *res);
+extern void