Skip site navigation (1) Skip section navigation (2)

Re: xlog.c: WALInsertLock vs. WALWriteLock

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: fazool mein <fazoolmein(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: xlog.c: WALInsertLock vs. WALWriteLock
Date: 2010-10-26 01:31:04
Message-ID: AANLkTik9dDqyroesEZcSqGaQ750kzFuwcD7mmLkV4tcW@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackers
On Fri, Oct 22, 2010 at 3:08 PM, fazool mein <fazoolmein(at)gmail(dot)com> wrote:
> I'm writing a function that will read data from the buffer in xlog (i.e.
> from XLogCtl->pages and XLogCtl->xlblocks). I want to make sure that I am
> doing it correctly.
> For reading from the buffer, do I need to lock WALInsertLock or
> WALWriteLock? Also, can you explain a bit the usage of 'LW_SHARED'. Can we
> use it for read purposes?

Holding WALInsertLock in shared mode prevents other processes from
inserting WAL, or in other words it keeps the "end" position from
moving, while holding WALWriteLock in shared mode prevents other
processes from writing the WAL from the buffers out to the operating
system, or in other words it keeps the "start" position from moving.
So you could probably take WALInsertLock in shared mode, figure out
the current end of WAL position, release the lock; then take
WALWriteLock in shared mode, read any WAL before the end of WAL
position, and release the lock.  But note that this wouldn't guarantee
that you read all WAL as it's generated....

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

In response to

Responses

pgsql-hackers by date

Next:From: Andrew DunstanDate: 2010-10-26 01:32:26
Subject: Re: Composite Types and Function Parameters
Previous:From: Itagaki TakahiroDate: 2010-10-26 01:30:49
Subject: Re: Tab completion for view triggers in psql

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group