Re: Snapshot management, final

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Pg Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: Snapshot management, final
Date: 2008-04-23 01:15:49
Message-ID: 20080423011549.GN6912@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

Tom Lane wrote:
> Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
>
> > CopySnapshot always copies snapshots to SnapshotContext, which is a
> > context that lives until transaction end. There's no mechanism for
> > copying a snapshot into another context, because I don't see the need.
>
> The only reason we have memory contexts at all is to avoid the need to
> track individual palloc'd objects. Since we're instituting exactly such
> tracking for snapshots, there's no value in placing them in
> general-purpose memory contexts.

The problem is that we reuse snapshots, and not all uses have the same
longevity. If a context goes away from under a snapshot and there are
other references to it, the result is a dangling pointer somewhere.
That's why we have reference counts on snaps: we know we can free one
when its refcounts are zero. At the same time, the snapshots all go
away at transaction end with TopTransactionContext.

The other possible approach to this problem is creating a separate copy
each time a snapshot is reused, but this just causes extra palloc'ing
for no gain at all.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

In response to

Browse pgsql-patches by date

  From Date Subject
Next Message Simon Riggs 2008-04-23 07:51:32 Re: Snapshot management, final
Previous Message Tom Lane 2008-04-22 23:30:46 Re: Snapshot management, final