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 1nlZyx-0000Wf-9m for pgsql-hackers@arkaria.postgresql.org; Mon, 02 May 2022 17:37:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nlZyv-0001pl-CL for pgsql-hackers@arkaria.postgresql.org; Mon, 02 May 2022 17:37:09 +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 1nlZyv-0001pc-0L for pgsql-hackers@lists.postgresql.org; Mon, 02 May 2022 17:37:09 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nlZyo-00033R-9A for pgsql-hackers@postgresql.org; Mon, 02 May 2022 17:37:08 +0000 Received: by mail-pf1-x42c.google.com with SMTP id bo5so12833426pfb.4 for ; Mon, 02 May 2022 10:37:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=XQzSwFIRibSxwqnScQGGEuXX7TmyHw5Yv4y2POkKNqs=; b=cAWwN0OlXYL+C01agnAO/T9jc56yRcp0PsRPNTzzhgXvZF4FBuoOG2BcHb98vrnkrg 6n1ln8Yq/5ColPu5r3I+x19TY3B2T8T4VZFHLwqju/lf96elcbH8JVpBjEEvOy7JOSio JNKCTw2q8f3GXG+BObp2bbK5AwhzZi8mO6srvLfzzpIYBXHoBeaR2LU47JpWgEQtJkZ9 UN7hmEeaUI7J1B65k7d4D1sHxdD/6jX7GlMhytITCTxfw9YJDX6D8yd9FdzkwDbcE4D0 M8sJWGKS+AwhzsBVBlhyRMPA0pSvOvLcNSdbjM0pBxD96UwgZabl8pgGzPLWFRoGhgKW YWMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=XQzSwFIRibSxwqnScQGGEuXX7TmyHw5Yv4y2POkKNqs=; b=Rouqh/B3V9ZNRQOrr6tuB4OgbKSOm4srByTB3CL68StyZxctIA6bLnYWvbuGCMf/Cb GdxRVz+nrNv/aek/ysThYp4KQVKRZxAlvZwSRShxkExQhmdn2GF9jWpuSyXoFaKMksRq zFiv0Y59XOLUm+Cfqhe71SAmhIIn4D+rcwvXSqPjJDxMFpe3NBFFHKCBDF5gnqoMFA74 6PetdRK8O/xt70A5tMt2jhvm6/H0c1hrxaKmfFkdxB4MbSZuzd+g2W43xx4+/u2VmiMK XF9g0GRHaNuNalUddOJJ2pUGJqDoZ6i3En9EBoz1q1jmdY79vHGtLRW6xpTgVE5DAg62 ruQQ== X-Gm-Message-State: AOAM530SCTiGTPYHSGviCkOxZWV0kwn5SE33n5vJPoNWlMaEW5ldIcxg 2L50nmwhS0xgWsEMFbnKCPQ= X-Google-Smtp-Source: ABdhPJxbglSeaiPFlNYLbZHY7dANPNV0CzatNfhiIqHWHcdMvSnQke9kOy7Z+UCElD458sV4SFPyaQ== X-Received: by 2002:a62:e518:0:b0:4fa:9333:ddbd with SMTP id n24-20020a62e518000000b004fa9333ddbdmr12606760pff.11.1651513020087; Mon, 02 May 2022 10:37:00 -0700 (PDT) Received: from nathanxps13 ([50.54.155.70]) by smtp.gmail.com with ESMTPSA id z1-20020aa785c1000000b0050dc7628138sm5139213pfn.18.2022.05.02.10.36.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 10:36:59 -0700 (PDT) Date: Mon, 2 May 2022 10:36:57 -0700 From: Nathan Bossart To: Michael Paquier Cc: Kyotaro Horiguchi , tgl@sss.pgh.pa.us, robertmhaas@gmail.com, pgsql-hackers@postgresql.org Subject: Re: avoid multiple hard links to same WAL file after a crash Message-ID: <20220502173657.GA3351307@nathanxps13> References: <289699.1649694527@sss.pgh.pa.us> <20220411165257.GB1915258@nathanxps13> <20220412.154631.417529439388886590.horikyota.ntt@gmail.com> <20220412162742.GB2062175@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, May 01, 2022 at 10:08:53PM +0900, Michael Paquier wrote: > At the end, switching directly from durable_rename_excl() to > durable_rename() should be fine for the WAL segment initialization, > but we could do things a bit more carefully by adding a check on the > file existence before calling durable_rename() and issue a elog(LOG) > if a file is found, giving a mean for the WAL recycling to give up > peacefully as it does now. Per my analysis, the TLI history file > created at the end of recovery ought to issue an elog(ERROR). My only concern with this approach is that it inevitably introduces a race condition. In most cases, the file existence check will prevent overwrites, but it might not always. Furthermore, we believe that such overwrites either 1) should not happen (e.g., WAL recycling) or 2) won't cause problems if they happen (e.g., when the WAL receiver writes the TLI history file). Also, these races will be difficult to test, so we won't know what breaks when they occur. My instinct is to just let the overwrites happen. That way, we are more likely to catch breakage in tests, and we'll have one less race condition to worry about. I don't mind asserting that the file doesn't exist when we don't expect it to, as that might help catch potential problems in development without affecting behavior in production. If we do want to add file existence checks, I think we'd better add a comment about the potential for race conditions. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com