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 1pKUPq-00025X-5p for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Jan 2023 01:17:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pKUPo-00028V-3b for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Jan 2023 01:17:28 +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 1pKUPn-00028K-Ob for pgsql-hackers@lists.postgresql.org; Wed, 25 Jan 2023 01:17:27 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pKUPl-0004x7-JZ for pgsql-hackers@postgresql.org; Wed, 25 Jan 2023 01:17:27 +0000 Received: by mail-pj1-x1036.google.com with SMTP id k10-20020a17090a590a00b0022ba875a1a4so429617pji.3 for ; Tue, 24 Jan 2023 17:17:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=7vSdWzAJg7R3X5Ei8Zroj/yicHhCQ0QnCkRqEV2CLp0=; b=JPgpZ6kiBluJvcJwpzdOu65gV8lsZxtAUjZbPAxHdorsHISWz02qCVcowTPGANJjaN reZAh2S/Bflh1P3ULFsblwSA1Hs6INJ7siD/wQTxo0XaNk7KI9BJOHsHSgxD/Eyzx2JF cIwba9dSaw6ZAh/Jqd556e83VLv4VrlVSxjjenmDy+HuwxzBchDMVh5YllVABJC/zOn1 9AlyyGjNkcZQ+k+zX19Nibr+UKoW/GKJ9tOWUsYYLYFXVA5nmMwbLD1ppRQDUIyObvJH nkRKI+g3DIxB87mjdzrgkasmsuXBb0zeeONCxEU6C1pR2lSNwmeMi7p+yUoknyQ2fwmZ /X0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=7vSdWzAJg7R3X5Ei8Zroj/yicHhCQ0QnCkRqEV2CLp0=; b=BB+EF80BAo3zHhxlvN66uh5HhCLyB8ATwrqwURTqDdSarYv5/6FJ83558qti9iNeQ4 9h1R1oZFpOlCjAPsd7V5j8GDEKMJ0YbD1b5R7XBSbOp/l9i1uF/V8T8dutq9YsjmjRdB zFgUJjKQAneCxgCz7tJEVeXt6igt9u89h1wQL4y2xdvWEyEHk1E++nbRcweF3aG7HJ0T nTqbyM2MPJu3SaDtspe7E/j2UpXeNCM4tWUcgjY+yByA+X/WI5++t+lQWy0flIn+OnHN RUgHfJS6vIWwWPBK05o9+KRCwx01wFiaxgxipzvWapU48/rRvGwUKUwypYvCAgVhu5dk ZcUg== X-Gm-Message-State: AFqh2kpc5QfWvN0MpTf6I+PKANCR+KFZMOIPtJwVNPmi+DBSNK/0Tpok g4WgEhywxLLdBHZ4y3MQEtc= X-Google-Smtp-Source: AMrXdXuCN93/xg/CTlyvHZzZR7+4a1/rIUYB/FJJvv28Db/PJKtZKvmdcwEqHDpWdRpLht0LTSQLdg== X-Received: by 2002:a05:6a20:4294:b0:b5:a64d:a181 with SMTP id o20-20020a056a20429400b000b5a64da181mr41132605pzj.19.1674609443137; Tue, 24 Jan 2023 17:17:23 -0800 (PST) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id z11-20020a6552cb000000b004d1d675610esm1976561pgp.89.2023.01.24.17.17.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 24 Jan 2023 17:17:22 -0800 (PST) Date: Wed, 25 Jan 2023 10:17:18 +0900 (JST) Message-Id: <20230125.101718.700668541820262311.horikyota.ntt@gmail.com> To: amit.kapila16@gmail.com Cc: osumi.takamichi@fujitsu.com, smithpb2250@gmail.com, vignesh21@gmail.com, kuroda.hayato@fujitsu.com, shveta.malik@gmail.com, dilipbalaut@gmail.com, euler@eulerto.com, m.melihmutlu@gmail.com, andres@anarazel.de, marcos@f10.com.br, pgsql-hackers@postgresql.org Subject: Re: Time delayed LR (WAS Re: logical replication restrictions) From: Kyotaro Horiguchi In-Reply-To: References: <20230124.114535.1107425862791533999.horikyota.ntt@gmail.com> User-Agent: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk In short, I'd like to propose renaming the parameter in_delayed_apply of send_feedback to "has_unprocessed_change". At Tue, 24 Jan 2023 12:27:58 +0530, Amit Kapila wrote in > > send_feedback(): > > + * If the subscriber side apply is delayed (because of time-delayed > > + * replication) then do not tell the publisher that the received latest > > + * LSN is already applied and flushed, otherwise, it leads to the > > + * publisher side making a wrong assumption of logical replication > > + * progress. Instead, we just send a feedback message to avoid a publisher > > + * timeout during the delay. > > */ > > - if (!have_pending_txes) > > + if (!have_pending_txes && !in_delayed_apply) > > flushpos = writepos = recvpos; > > > > Honestly I don't like this wart. The reason for this is the function > > assumes recvpos = applypos but we actually call it while holding > > unapplied changes, that is, applypos < recvpos. > > > > Couldn't we maintain an additional static variable "last_applied" > > along with last_received? > > > > It won't be easy to maintain the meaning of last_applied because there > are cases where we don't apply the change directly. For example, in > case of streaming xacts, we will just keep writing it to the file, > now, say, due to some reason, we have to send the feedback, then it > will not allow you to update the latest write locations. This would > then become different then what we are doing without the patch. > Another point to think about is that we also need to keep the variable > updated for keep-alive ('k') messages even though we don't apply > anything in that case. Still, other cases to consider are where we > have mix of streaming and non-streaming transactions. Yeah. Even though I named it as "last_applied", its objective is to have get_flush_position returning the correct have_pending_txes without a hint from callers, that is, "let g_f_position know if store_flush_position has been called with the last received data". Anyway I tried that but didn't find a clean and simple way. However, while on it, I realized what the code made me confused. +static void send_feedback(XLogRecPtr recvpos, bool force, bool requestReply, + bool in_delayed_apply); The name "in_delayed_apply" doesn't donsn't give me an idea of what the function should do for it. If it is named "has_unprocessed_change", I think it makes sense that send_feedback should think there may be an outstanding transaction that is not known to the function. So, my conclusion here is I'd like to propose changing the parameter name to "has_unapplied_change". > > In this case the condition cited above > > would be as follows and in_delayed_apply will become unnecessary. > > > > + if (!have_pending_txes && last_received == last_applied) > > > > The function is a static function and always called with a variable > > last_received that has the same scope with the function, as the first Sorry for the noise, I misread it. Maybe I took the "function-scoped" variable as file-scoped.. Thus the discussion is false. > > parameter. Thus we can remove the first parameter then let the > > function directly look at the both two varaibles instead. > > > > I think this is true without this patch, so why that has not been > followed in the first place? One comment, I see in this regard is as > below: > > /* It's legal to not pass a recvpos */ > if (recvpos < last_recvpos) > recvpos = last_recvpos; Sorry. I don't understand this. It is just a part of the ratchet mechanism for the last received lsn to report. regards. -- Kyotaro Horiguchi NTT Open Source Software Center