From: Konstantin Knizhnik <k.knizhnik@postgrespro.ru>
To: Heikki Linnakangas <hlinnaka@iki.fi>
To: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Subject: Re: Deadlock in XLogInsert at AIX
Date: Tue, 31 Jan 2017 16:30:52 +0300
Message-ID: <85a1966c-aeee-fb38-77bd-6cad9a90b35f@postgrespro.ru> (raw)
In-Reply-To: <0184657d-cf64-10f6-9706-7329f23f5f89@iki.fi>
References: <a72cfcb0-37d0-de2f-b3ec-f38ad8d6a8cc@postgrespro.ru>
<0184657d-cf64-10f6-9706-7329f23f5f89@iki.fi>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
On 30.01.2017 19:21, Heikki Linnakangas wrote:
> On 01/24/2017 04:47 PM, Konstantin Knizhnik wrote:
> Interesting.. What should happen here is that for the backend's own
> insertion slot, the "insertingat" value should be greater than the
> requested flush point ('upto' variable). That's because before
> GetXLogBuffer() calls AdvanceXLInsertBuffer(), it updates the
> backend's insertingat value, to the position that it wants to insert
> to. And AdvanceXLInsertBuffer() only calls
> WaitXLogInsertionsToFinish() with value smaller than what was passed
> as the 'upto' argument.
>
>> The comment to WaitXLogInsertionsToFinish says:
>>
>> * Note: When you are about to write out WAL, you must call this
>> function
>> * *before* acquiring WALWriteLock, to avoid deadlocks. This
>> function might
>> * need to wait for an insertion to finish (or at least advance to next
>> * uninitialized page), and the inserter might need to evict an old WAL
>> buffer
>> * to make room for a new one, which in turn requires WALWriteLock.
>>
>> Which contradicts to the observed stack trace.
>
> Not AFAICS. In the stack trace you showed, the backend is not holding
> WALWriteLock. It would only acquire it after the
> WaitXLogInsertionsToFinish() call finished.
>
>
Hmmm, may be I missed something.
I am not telling about WALBufMappingLock which is required after return
from XLogInsertionsToFinish.
But about lock obtained by WALInsertLockAcquire at line 946 in
XLogInsertRecord.
It will be release at line 1021 by WALInsertLockRelease(). But
CopyXLogRecordToWAL is invoked with this lock granted.
> This line in the stack trace is suspicious:
>
>> WaitXLogInsertionsToFinish(upto = 102067874328), line 1583 in "xlog.c"
>
> AdvanceXLInsertBuffer() should only ever call
> WaitXLogInsertionsToFinish() with an xlog position that points to a
> page bounary, but that upto value points to the middle of a page.
>
> Perhaps the value stored in the stack trace is not what the caller
> passed, but it was updated because it was past the 'reserveUpto'
> value? That would explain the "request to flush past end
> of generated WAL" notices you saw in the log. Now, why would that
> happen, I have no idea.
>
> If you can and want to provide me access to the system, I could have a
> look myself. I'd also like to see if the attached additional
> Assertions will fire.
I really get this assertion failed:
ExceptionalCondition(conditionName = "!(OldPageRqstPtr <= upto ||
opportunistic)", errorType = "FailedAssertion", fileName = "xlog.c",
lineNumber = 1917), line 54 in "assert.c"
(dbx) up
unnamed block in AdvanceXLInsertBuffer(upto = 147439056632,
opportunistic = '\0'), line 1917 in "xlog.c"
(dbx) p OldPageRqstPtr
147439058944
(dbx) p upto
147439056632
(dbx) p opportunistic
'\0'
Also , in another run, I encountered yet another assertion failure:
ExceptionalCondition(conditionName = "!((((NewPageBeginPtr) / 8192) %
(XLogCtl->XLogCacheBlck + 1)) == nextidx)", errorType =
"FailedAssertion", fileName = "xlog.c", lineNumber = 1950), line 54 in
"assert.c"
nextidx equals to 1456, while expected value is 1457.
--
Konstantin Knizhnik
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: k.knizhnik@postgrespro.ru, hlinnaka@iki.fi
Subject: Re: Deadlock in XLogInsert at AIX
In-Reply-To: <85a1966c-aeee-fb38-77bd-6cad9a90b35f@postgrespro.ru>
References: <a72cfcb0-37d0-de2f-b3ec-f38ad8d6a8cc@postgrespro.ru> <0184657d-cf64-10f6-9706-7329f23f5f89@iki.fi> <85a1966c-aeee-fb38-77bd-6cad9a90b35f@postgrespro.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox