Re: [PATCH 3/8] Add support for a generic wal reading facility dubbed XLogReader - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: [PATCH 3/8] Add support for a generic wal reading facility dubbed XLogReader
Date
Msg-id 5056D3E1.3060108@vmware.com
Whole thread Raw
In response to [PATCH 3/8] Add support for a generic wal reading facility dubbed XLogReader  (Andres Freund <andres@2ndquadrant.com>)
Responses Re: [PATCH 3/8] Add support for a generic wal reading facility dubbed XLogReader  (Andres Freund <andres@2ndquadrant.com>)
List pgsql-hackers
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


Attachment

pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: [BUGS] BUG #7534: walreceiver takes long time to detect n/w breakdown
Next
From: Andres Freund
Date:
Subject: Re: [PATCH 3/8] Add support for a generic wal reading facility dubbed XLogReader