Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1joKY7-0007EU-6y for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jun 2020 05:35:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1joKY4-0003Vn-Vz for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jun 2020 05:35:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1joKY4-0003Vg-P7 for pgsql-hackers@lists.postgresql.org; Thu, 25 Jun 2020 05:35:44 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1joKY0-0006pw-Iz for pgsql-hackers@lists.postgresql.org; Thu, 25 Jun 2020 05:35:42 +0000 Received: from hnk.local (p2604028-ipngn12401funabasi.chiba.ocn.ne.jp [180.1.110.28]) by oss.nttdata.com (Postfix) with ESMTPSA id 32086601D8; Thu, 25 Jun 2020 14:35:35 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com Subject: Re: Review for GetWALAvailability() To: Alvaro Herrera Cc: Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org References: <20200625035718.GA28721@alvherre.pgsql> From: Fujii Masao Message-ID: Date: Thu, 25 Jun 2020 14:35:34 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200625035718.GA28721@alvherre.pgsql> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020/06/25 12:57, Alvaro Herrera wrote: > On 2020-Jun-25, Fujii Masao wrote: > >> /* >> * Find the oldest extant segment file. We get 1 until checkpoint removes >> * the first WAL segment file since startup, which causes the status being >> * wrong under certain abnormal conditions but that doesn't actually harm. >> */ >> oldestSeg = XLogGetLastRemovedSegno() + 1; >> >> I see the point of the above comment, but this can cause wal_status to be >> changed from "lost" to "unreserved" after the server restart. Isn't this >> really confusing? At least it seems better to document that behavior. > > Hmm. > >> Or if we *can ensure* that the slot with invalidated_at set always means >> "lost" slot, we can judge that wal_status is "lost" without using fragile >> XLogGetLastRemovedSegno(). Thought? > > Hmm, this sounds compelling -- I think it just means we need to ensure > we reset invalidated_at to zero if the slot's restart_lsn is set to a > correct position afterwards. Yes. > I don't think we have any operation that > does that, so it should be safe -- hopefully I didn't overlook anything? We need to call ReplicationSlotMarkDirty() and ReplicationSlotSave() just after setting invalidated_at and restart_lsn in InvalidateObsoleteReplicationSlots()? Otherwise, restart_lsn can go back to the previous value after the restart. diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index e8761f3a18..5584e5dd2c 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -1229,6 +1229,13 @@ restart: s->data.invalidated_at = s->data.restart_lsn; s->data.restart_lsn = InvalidXLogRecPtr; SpinLockRelease(&s->mutex); + + /* + * Save this invalidated slot to disk, to ensure that the slot + * is still invalid even after the server restart. + */ + ReplicationSlotMarkDirty(); + ReplicationSlotSave(); ReplicationSlotRelease(); /* if we did anything, start from scratch */ Maybe we don't need to do this if the slot is temporary? > Neither copy nor advance seem to work with a slot that has invalid > restart_lsn. > >> Or XLogGetLastRemovedSegno() should be fixed so that it returns valid >> value even after the restart? > > This seems more work to implement. Yes. Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION