Re: [sqlsmith] Crash in GetOldestSnapshot() - Mailing list pgsql-hackers

From Amit Kapila
Subject Re: [sqlsmith] Crash in GetOldestSnapshot()
Date
Msg-id CAA4eK1LiRxT_iPfJ=uK13tLCtaGAQqn_YOY=6zCBqoi2mW333A@mail.gmail.com
Whole thread Raw
In response to Re: [sqlsmith] Crash in GetOldestSnapshot()  (Andrew Gierth <andrew@tao11.riddles.org.uk>)
Responses Re: [sqlsmith] Crash in GetOldestSnapshot()  (Andrew Gierth <andrew@tao11.riddles.org.uk>)
List pgsql-hackers
On Sat, Aug 6, 2016 at 5:51 PM, Andrew Gierth
<andrew@tao11.riddles.org.uk> wrote:
>>>>>> "Andreas" == Andreas Seltenreich <seltenreich@gmx.de> writes:
>
> 418   if (OldestActiveSnapshot != NULL)
> 419       ActiveLSN = OldestActiveSnapshot->as_snap->lsn;
> 420
> 421   if (XLogRecPtrIsInvalid(RegisteredLSN) || RegisteredLSN > ActiveLSN)
> 422       return OldestActiveSnapshot->as_snap;
>
> This second conditional should clearly be inside the first one...
>

Sure, that is the reason of crash, but even if we do that it will lead
to an error "no known snapshots".  Here, what is going on is that we
initialized toast snapshot when there is no active snapshot in the
backend, so GetOldestSnapshot() won't return any snapshot.  I think
for such situations, we need to initialize the lsn and whenTaken of
ToastSnapshot as we do in GetSnapshotData() [1].  We need to do this
when snapshot returned by GetOldestSnapshot() is NULL.

Thoughts?


[1]
In below code
if (old_snapshot_threshold < 0)
{
..
}
else
{
/*
* Capture the current time and WAL stream location in case this
* snapshot becomes old enough to need to fall back on the special
* "old snapshot" logic.
*/
snapshot->lsn = GetXLogInsertRecPtr();
snapshot->whenTaken = GetSnapshotCurrentTimestamp();
MaintainOldSnapshotTimeMapping(snapshot->whenTaken, xmin);
}


-- 
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com



pgsql-hackers by date:

Previous
From: Andrew Gierth
Date:
Subject: Re: [sqlsmith] Crash in GetOldestSnapshot()
Next
From: Andrew Gierth
Date:
Subject: Re: [sqlsmith] Crash in GetOldestSnapshot()