Re: Inconsistent error handling in START_REPLICATION command - Mailing list pgsql-hackers

From Craig Ringer
Subject Re: Inconsistent error handling in START_REPLICATION command
Date
Msg-id CAMsr+YH=Ni42okN5HsTpVp=DHzHYFGjn4SL8EQHFh_pXWYZA9Q@mail.gmail.com
Whole thread Raw
In response to Re: Inconsistent error handling in START_REPLICATION command  (Craig Ringer <craig@2ndquadrant.com>)
List pgsql-hackers
On 20 January 2016 at 15:28, Craig Ringer <craig@2ndquadrant.com> wrote:

For that reason I'd actually like to enter COPY BOTH mode before the startup callback, as is currently the case. So I'd like to wrap the decoding startup callback in a PG_TRY that catches an ERROR raised by the startup callback (if any) and exits COPY BOTH mode before re-throwing.

 
I hoped this'd be as simple as:

      PG_TRY();
      {
          logical_decoding_ctx = CreateDecodingContext(
                                                     cmd->startpoint, cmd->options,
                                                       logical_read_xlog_page,
                                              WalSndPrepareWrite, WalSndWriteData);
      }
      PG_CATCH();
      {
          pq_putmessage_noblock('c', NULL, 0);
          pq_flush();
          PG_RE_THROW();
      }
      PG_END_TRY();
  

but that's doesn't look sufficient, presumably as the client never has a chance to ack the exit from CopyBoth mode. Or maybe libpq just isn't prepared to cope with existing COPY then immediately getting an error.

What you have now works and fixes the immediate problem. Preserving the early start of COPY mode isn't actually useful until we're also prepared to accept writes from the output plugin's startup callback at that point, which we are not yet.

Maybe we should just apply your patch as-is, then move the start of COPY back if/when support for emitting output from within a logical decoding startup callback gets added.


--
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

pgsql-hackers by date:

Previous
From: Vladimir Sitnikov
Date:
Subject: Set search_path + server-prepared statements = cached plan must not change result type
Next
From: Craig Ringer
Date:
Subject: Re: Stream consistent snapshot via a logical decoding plugin as a series of INSERTs