Re: [PATCH 3/8] Add support for a generic wal reading facility dubbed XLogReader

Heikki Linnakangas <hlinnakangas@vmware.com>

From: Heikki Linnakangas <hlinnakangas@vmware.com>
To: Andres Freund <andres@2ndquadrant.com>
Cc: pgsql-hackers@postgresql.org, Robert Haas <robertmhaas@gmail.com>, Kevin Grittner <Kevin.Grittner@wicourts.gov>, Alvaro Herrera <alvherre@2ndquadrant.com>, Simon Riggs <simon@2ndquadrant.com>
Date: 2012-09-17T07:40:17Z
Lists: pgsql-hackers

Attachments

On 15.09.2012 03:39, Andres Freund wrote:
>
> Features:
> - streaming reading/writing
> - filtering
> - reassembly of records
>
> Reusing the ReadRecord infrastructure in situations where the code that wants
> to do so is not tightly integrated into xlog.c is rather hard and would require
> changes to rather integral parts of the recovery code which doesn't seem to be
> a good idea.

My previous objections to this approach still apply. 1. I don't want to 
maintain a second copy of the code to read xlog. 2. We should focus on 
reading WAL, I don't see the point of mixing WAL writing into this. 3. I 
don't like the callback-style API.

I came up with the attached. I moved ReadRecord and some supporting 
functions from xlog.c to xlogreader.c, and made it operate on 
XLogReaderState instead of global global variables. As discussed before, 
I didn't like the callback-style API, I think the consumer of the API 
should rather just call ReadRecord repeatedly to get each record. So 
that's what I did.

There is still one callback, XLogPageRead(), to obtain a given page in 
WAL. The XLogReader facility is responsible for decoding the WAL into 
records, but the user of the facility is responsible for supplying the 
physical bytes, via the callback.

So the usage is like this:

/*
  * Callback to read the page starting at 'RecPtr' into *readBuf. It's
  * up to you to do this any way you like. Typically you'd read from a
  * file. The WAL recovery implementation of this in xlog.c is more
  * complicated. It checks the archive, waits for streaming replication
  * etc.
  */
static bool
MyXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr RecPtr, char 
*readBuf, void *private_data)
{
   ...
}


state = XLogReaderAllocate(&MyXLogPageRead);

while ((record = XLogReadRecord(state, ...)))
{
   /* do something with the record */
}

XLogReaderFree(state);



- Heikki

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Move "hot" members of PGPROC into a separate PGXACT array.