Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhKAt-00ArIQ-JX for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Mar 2024 02:05:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rhKAs-00COQ5-7O for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Mar 2024 02:04:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhKAr-00COOS-To for pgsql-hackers@lists.postgresql.org; Tue, 05 Mar 2024 02:04:58 +0000 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rhKAo-002tLk-Fh for pgsql-hackers@lists.postgresql.org; Tue, 05 Mar 2024 02:04:57 +0000 Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-7beda6a274bso228313439f.2 for ; Mon, 04 Mar 2024 18:04:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709604295; x=1710209095; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=o3ovu/A2L+2pDCGb2vXpmwlnRdIrnIQ0BNdjYgYduCU=; b=XB0UMLWWrYmUNqGVdEqSf5ts9DIy+NE8XTF+7VqEPqhsWnIRG/vePTryTtgMck68N9 C6ZwIN8OO6rTKScWmXAshBfBOdoEmPS+AHwyirqdzdLxcoZoqSBCgPd4gw7OSGQETzh1 JCE8M+hPpT9FOVdxTZBu1h4UlNYkv6MA4olpULnqRKvHrAUu6K+EWOXRAr0R2tJ/ABOP OVEXM5CYBeMZLSwIa/Hqgxhb59ApjyNxaxgLBbyxYPY4OHnhIvBRTfAHExQqe9Jv777B c+1+DnCuSgOK8GXZVJmdKuEOakb6QfaWTF0scmpFmo2Nx9qeeSNZvDK1ig5XnAYC1HJ8 dSyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709604295; x=1710209095; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=o3ovu/A2L+2pDCGb2vXpmwlnRdIrnIQ0BNdjYgYduCU=; b=UA6IMVWk/JZi3l8Lw7LyjGhnMazP8vyLhhEey4U1tUnfZhYrQ25glmoivRCfgZkRB3 7jKOwE4BF/LHpssHZ4iDqWPxDQCZJ5pZSu8KKJwDglYHDCc+V+kOe3PK33yDXfu1Grmv I3eQASNREpCuPSaXIpSWbilAF13sUA5mFKE2gBx8H16DoTQKhdA6CZkkfOQm5nijXrR7 zp9PFG+IwU3RofOeNUDXPRuujx0EPGhKKLec+eBHXNBVj7bdNig+qirVdQ145UljvFeX Cj2/sE39/aqevKiXFqOWLhz8To8gUZWwmnoONwAsNvZ1UdM6BIrcIO2JcZmOJFW7gbDG 4TmQ== X-Forwarded-Encrypted: i=1; AJvYcCXCTVuLust4cOBetEOR3hH5ViiCQy43KJYzJKqeBfPsArhMBBvt05WLi7LzWbnUKcNOSVuyt2Z1UEQfellDc/rE4UD4a1u8LwgkNsLMdGLaomHd X-Gm-Message-State: AOJu0Yx2xPKCG84P/KPaRv4inbQcSzgGKQ9sSWc00BkTSoIF96aTDexe 7AmQaVtZhRgqc96QK7KajBSPIxWGFLB0GtfUR99kZ9guTxz/HlxY/cxAMbVm X-Google-Smtp-Source: AGHT+IEDDgFh7OMbfLXVk7GcJht93j1pD7xhoAufxDS69+4Ql9W7yZj+oDqerskd9h3GuVlIgYoA8g== X-Received: by 2002:a6b:6309:0:b0:7c8:22c3:2e81 with SMTP id p9-20020a6b6309000000b007c822c32e81mr11721898iog.4.1709604294716; Mon, 04 Mar 2024 18:04:54 -0800 (PST) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id j13-20020a02cc6d000000b00474ab85e3ebsm2575523jaq.130.2024.03.04.18.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 18:04:54 -0800 (PST) Date: Mon, 4 Mar 2024 20:04:52 -0600 From: Nathan Bossart To: Bharath Rupireddy Cc: Japin Li , Ian Lawrence Barwick , Kyotaro Horiguchi , Cary Huang , SATYANARAYANA NARLAPURAM , pgsql-hackers@lists.postgresql.org Subject: Re: Switching XLog source from archive to streaming when primary available Message-ID: <20240305020452.GA3373526@nathanxps13> References: 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 cfbot claims that this one needs another rebase. I've spent some time thinking about this one. I'll admit I'm a bit worried about adding more complexity to this state machine, but I also haven't thought of any other viable approaches, and this still seems like a useful feature. So, for now, I think we should continue with the current approach. + fails to switch to stream mode, it falls back to archive mode. If this + parameter value is specified without units, it is taken as + milliseconds. Default is 5min. With a lower value Does this really need to be milliseconds? I would think that any reasonable setting would at least on the order of seconds. + attempts. To avoid this, it is recommended to set a reasonable value. I think we might want to suggest what a "reasonable value" is. + static bool canSwitchSource = false; + bool switchSource = false; IIUC "canSwitchSource" indicates that we are trying to force a switch to streaming, but we are currently exhausting anything that's present in the pg_wal directory, while "switchSource" indicates that we should force a switch to streaming right now. Furthermore, "canSwitchSource" is static while "switchSource" is not. Is there any way to simplify this? For example, would it be possible to make an enum that tracks the streaming_replication_retry_interval state? /* * Don't allow any retry loops to occur during nonblocking - * readahead. Let the caller process everything that has been - * decoded already first. + * readahead if we failed to read from the current source. Let the + * caller process everything that has been decoded already first. */ - if (nonblocking) + if (nonblocking && lastSourceFailed) return XLREAD_WOULDBLOCK; Why do we skip this when "switchSource" is set? + /* Reset the WAL source switch state */ + if (switchSource) + { + Assert(canSwitchSource); + Assert(currentSource == XLOG_FROM_STREAM); + Assert(oldSource == XLOG_FROM_ARCHIVE); + switchSource = false; + canSwitchSource = false; + } How do we know that oldSource is guaranteed to be XLOG_FROM_ARCHIVE? Is there no way it could be XLOG_FROM_PG_WAL? +#streaming_replication_retry_interval = 5min # time after which standby + # attempts to switch WAL source from archive to + # streaming replication + # in milliseconds; 0 disables I think we might want to turn this feature off by default, at least for the first release. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com