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 1nKdK9-0006C1-Ey for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Feb 2022 09:43:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nKdK8-00089W-8H for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Feb 2022 09:43:40 +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 1nKdK7-00089L-VE for pgsql-hackers@lists.postgresql.org; Thu, 17 Feb 2022 09:43:39 +0000 Received: from mail-yw1-x1134.google.com ([2607:f8b0:4864:20::1134]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nKdK5-0001Cw-Hc for pgsql-hackers@lists.postgresql.org; Thu, 17 Feb 2022 09:43:39 +0000 Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-2d66f95f1d1so25564047b3.0 for ; Thu, 17 Feb 2022 01:43:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=4wHvIa3P6iWU/g6o104djdATSHFyYlRFKvetv+7rtf8=; b=nOP0ItV3xw4ONhbwrktPrkA3cRBTVeZkRbIJ6IeAl74SxVpmyZZ+TBbjbzFwT+Y38T 5Pla/QKyDXPPixdFucF20/WZ6JnW5yITpQ2oxdgZeyCedkJgZmCw75wZDVOy/Bvwbl2N CHmbMH+SQGl7UoatofLBvK8xJCt3e/wChj/4Or9tepvsie6NrWxKOdxyhVDtc/yP/+yK Ge6U8X+ayn+hWubloLxhiP3H/SDJsZjFp/ArlUuCDFOfFMRIg27VGJhqItl5YzlyRyzm 72g9FohBNzLgtAfG09QVJy7kzN6S++U03SKMXQdaCRIgq4YiEuPr9a1F4DcTb0GENH83 eY1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=4wHvIa3P6iWU/g6o104djdATSHFyYlRFKvetv+7rtf8=; b=Enm2iObV3xwpCmUnaTFPRgAyvYTISEjjW7tHXhv/PS5oJoDWhHlkkDfZN8rn99LcwD Jc+2Odz6Wstpjq1KdvZtDoM8eXMH0Cp1RIFwNjE0NL9Jing2ZCtQLzdsXjOPhAp8jCor qvuni70lWzHnW0vteb81YwxIsGyOr8t1d/qmPeLOD2fAM+Wqtw+uG4WaXIbiLIEi3OB+ Esfv3bXEbK+Ho3LDESURNSpDCiL3z7F6x90Fletz7SeqHVvawXyglEnOLP8KiHsNWMjS JLm+K1kuJqf6kDl2R3CPVhJq19zkBXkaorYKvJeRt5ckWPKrheuZkwlNBrNxhJsHIOrg WVQg== X-Gm-Message-State: AOAM532d7kCOAaYWv6fO/nkC+uXJ8dfSetse4SWKjTHcRTCG0fD2zw7G Gg3H4r+n0Jf+MgE2fWD306E4OyYyVdKkVDvTamY= X-Google-Smtp-Source: ABdhPJy4bhce44e6zRsqNIhhwd49oCHks54jb9Gab9TOzT2q8wn9qBLTCApGbAD5ox1sUzC34iK1Xc2b/fbUkfHXFz8= X-Received: by 2002:a81:52cb:0:b0:2d0:c77a:2967 with SMTP id g194-20020a8152cb000000b002d0c77a2967mr1853369ywb.305.1645091015836; Thu, 17 Feb 2022 01:43:35 -0800 (PST) MIME-Version: 1.0 References: <20211217.140309.1173685089580065514.horikyota.ntt@gmail.com> In-Reply-To: From: Amit Kapila Date: Thu, 17 Feb 2022 15:13:24 +0530 Message-ID: Subject: Re: Failed transaction statistics to measure the logical replication progress To: "osumi.takamichi@fujitsu.com" Cc: "tanghy.fnst@fujitsu.com" , Greg Nancarrow , Kyotaro Horiguchi , "vignesh21@gmail.com" , "sawada.mshk@gmail.com" , "houzj.fnst@fujitsu.com" , "pgsql-hackers@lists.postgresql.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jan 4, 2022 at 5:22 PM osumi.takamichi@fujitsu.com wrote: > > On Friday, December 31, 2021 10:12 AM Tang, Haiying/=E5=94=90 =E6=B5=B7= =E8=8B=B1 wrote: > > 4) > > +void > > +pgstat_send_subworker_xact_stats(LogicalRepWorker *repWorker, bool > > +force) { > > + static TimestampTz last_report =3D 0; > > + PgStat_MsgSubWorkerXactEnd msg; > > + > > + if (!force) > > + { > > ... > > + if (!TimestampDifferenceExceeds(last_report, now, > > PGSTAT_STAT_INTERVAL)) > > + return; > > + last_report =3D now; > > + } > > + > > ... > > + if (repWorker->commit_count =3D=3D 0 && repWorker->abort_count = =3D=3D > > 0) > > + return; > > ... > > > > I think it's better to check commit_count and abort_count first, then c= heck if > > reach PGSTAT_STAT_INTERVAL. > > Otherwise if commit_count and abort_count are 0, it is possible that th= e value > > of last_report has been updated but it didn't send stats in fact. In th= is case, > > last_report is not the real time that send last message. > Yeah, agreed. This fix is right in terms of the variable name aspect. > Can't we use pgstat_report_stat() here? Basically, you can update xact completetion counters during apply, and then from pgstat_report_stat(), you can invoke a logical replication worker stats-related function. --=20 With Regards, Amit Kapila.