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-05-11 04:54:49
Message-ID: 20080511045449.GA7767@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

[Reposting with compressed patch]

Okay, I think I've fixed most of the issues in the reviewed patch.
Updated patch attached.

The most interesting change is that I've done away with CopySnapshot as
a public routine in favor of a new PushUpdatedSnapshot which does the
copy-update-push sequence. Also I added a refcount to RegdSnapshotElt
as suggested, and changed the subxact logic to substract that exact
amount on abort.

There's something I'm not sure what to do about:

Tom Lane wrote:

> Also, I think that the whole snapshot-sharing mechanism is not working
> as intended except for the serializable case; otherwise sequences
> like
> x = RegisterSnapshot(GetTransactionSnapshot());
> y = RegisterSnapshot(GetTransactionSnapshot());
> will result in x and y being separate copies. Or are you assuming
> that this just isn't worth optimizing?

It's not that I don't think it's worth optimizing, but I think it's a
bit away from the scope of this patch. The problem here is how to
notice that two consecutive GetTransactionSnapshot calls should really
return different snapshots, considering that shared state may change in
between. Perhaps there's an easy way to optimize that; I don't know.

What does work is to get (say) a registered snapshot and push it as
active snapshot. That results in a successfully shared snapshot. For
example PortalStart does that for cursors, etc.

(FWIW another thing which is probably worth rethinking is the handling
of snapshots around PortalStart. Some callers pass the currently active
snapshot; Others pass InvalidSnapshot. Another passes an arbitrary
snapshot. When it's Invalid, PortalStart calls GetTransactionSnapshot,
otherwise it uses the passed snap for PushActiveSnapshot. So this is
all a bit confusing and wasteful and could use some clean up. This is
material for a new patch however.)

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

Attachment Content-Type Size
snapshot-9.patch.gz application/octet-stream 21.0 KB

In response to

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Nikhils 2008-05-11 07:57:49 Re: [badalex@gmail.com: Re: [BUGS] Problem identifying constraints which should not be inherited]
Previous Message David Fetter 2008-05-10 18:25:16 Re: Posting to hackers and patches lists