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 1pK9Jh-000411-1y for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Jan 2023 02:45:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pK9Jf-000778-V9 for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Jan 2023 02:45:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pK9Jf-00076w-KC for pgsql-hackers@lists.postgresql.org; Tue, 24 Jan 2023 02:45:43 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pK9Jc-0000ez-Ts for pgsql-hackers@postgresql.org; Tue, 24 Jan 2023 02:45:42 +0000 Received: by mail-pj1-x1031.google.com with SMTP id m3-20020a17090a414300b00229ef93c5b0so12059179pjg.2 for ; Mon, 23 Jan 2023 18:45:40 -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=yH6DDwRYtxZEZy+3myTgmlZZDs7IQNOFQ/1ltpULL1g=; b=XDiqF9IOknZX2yeiQI4oTR6rBSnRQQoCZrZFHcIgpjWAElth4UgymO6qSvRz5B7o1E HFI7cothH+2Il/TYRX5jO1ewBsF2AMUXuHpfnDEeRQ3HR8dGPpG+h3uZOJ404H8gBBgI 4fsUPtMtpSLOrc5k7fLOg1y7QZMSwY9KR1fMF+ySCVxlZKKz37iY6fz1ssEaCAIeBcmI pUPhYiXW9mmInT3isNVH1eYlC5k3KWoVB2aXEN8teCZM6YwQT1358iUwLtKRLy/nauit 998f2AXaTu2nUZrv0fuAfNGnBCZTpITkQYzMtiyGrxioqB1siCyMmTSUD1Bpy8byamQj cyZw== 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=yH6DDwRYtxZEZy+3myTgmlZZDs7IQNOFQ/1ltpULL1g=; b=PnTjaIzQ9f+mYEAbsmu3DHqT6t9+Xyxv2AgqnRuFkekzYDhltL3ErAO5WObB9Hw66q fmAwbzF0C99KvC0VwDCw1oPbNzgL1ZatJPTRp3Z0gfPuufd5RkRXNjEK4vXyeePakjpj aMo74MZAsarUYE6Gi9LNHr8yyqAkqxEdNMXLXzDM1RsVm8Pw6cPWzDZIODXvNBhXWdr1 itgSXwLhGyFGG86ucGdg17JnIBFOAUlmA34y7Yn7YYmbFhOKkWAZugwWKAVFhmRFMFpS Su2UvfK/wRa9u9309c2ylJ8NsL4dApb1xn9i3ANdQtbJi128/KA9ClOKJk2Ai1Q+6JLj 2ZOA== X-Gm-Message-State: AFqh2kqMtznEVpIiPF0yRAfdGktBcoX4ZxajSS3FNdB6ypFvGSV6qGz8 lOWQUknXsLc3DRWld+UNkDg= X-Google-Smtp-Source: AMrXdXtsD/f3OD8BDmrKDoNEGoTn/X54Q8fhBehnAl3OKC4uumtv8cZp9jwJPevtE0Hqb6fmxrMHow== X-Received: by 2002:a17:90b:1b4f:b0:226:d23b:8037 with SMTP id nv15-20020a17090b1b4f00b00226d23b8037mr28602391pjb.33.1674528339836; Mon, 23 Jan 2023 18:45:39 -0800 (PST) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id z4-20020a17090a6d0400b0022bbad75af4sm344344pjj.2.2023.01.23.18.45.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 23 Jan 2023 18:45:39 -0800 (PST) Date: Tue, 24 Jan 2023 11:45:35 +0900 (JST) Message-Id: <20230124.114535.1107425862791533999.horikyota.ntt@gmail.com> To: osumi.takamichi@fujitsu.com Cc: smithpb2250@gmail.com, vignesh21@gmail.com, kuroda.hayato@fujitsu.com, shveta.malik@gmail.com, dilipbalaut@gmail.com, amit.kapila16@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: 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 > Attached the updated patch v19. + maybe_delay_apply(TransactionId xid, TimestampTz finish_ts) I look this spelling strange. How about maybe_apply_delay()? 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? 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 parameter. Thus we can remove the first parameter then let the function directly look at the both two varaibles instead. regards. -- Kyotaro Horiguchi NTT Open Source Software Center