Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1j9FNO-0002SO-Cc for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Mar 2020 21:46:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j9FNN-0003MW-4u for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Mar 2020 21:46:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j9FNM-0003MP-Sb for pgsql-hackers@lists.postgresql.org; Tue, 03 Mar 2020 21:46:52 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j9FNK-0005gQ-0b for pgsql-hackers@postgresql.org; Tue, 03 Mar 2020 21:46:52 +0000 Received: by mail-wm1-x341.google.com with SMTP id 6so5020600wmi.5 for ; Tue, 03 Mar 2020 13:46:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=A1wbzbT6tPOOgQPSyGiYXXrSNJLauVjzSic/mtSo2o8=; b=CbKvg+NefQ/w8OcikrWrGNH10l3joobtMCXlrh9+ya1poRVUpdIjCXBoUU8z3fsXH1 46QDgQR6ywiTtKXEIe1G7U0J0qv9nyhs2GOaZWM6qRYxw3A5J6Fkg/bZkkCQUtnnMPi4 YkOfT2bcwZC3NUECv+lKBo9T3swcr3KQmYhTaG/rTte/vni85sECZA9M2XEdxC0Y8uIK cRzHS2lzKfGo5FJ4elQZQAlfBceXiDz2vHIQxTj6jNP4sA9gIaC9i2/dqseI6zD2DBFR 1C2fDhJNFeEGvxKHvuIBdwCpwpm8WOrLmJEslW/ODyRY0NSuAmgDhOOPa6tlwWRiM3YV dLQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=A1wbzbT6tPOOgQPSyGiYXXrSNJLauVjzSic/mtSo2o8=; b=JYa+wY8vdC3Grc8qYQOCl6Oc2IKtg2FdsRAsQQIvsAtk9tKksrnI9pJYNWq6AWe6TO bSEYMGxkLSSho2mHWgxKjcGZlczkTjtXigZ2fMGHctQUogJbLCgaTkAqgZ1Jd+mp3Pw+ 9SBRL9ze/0gpDJ/+PKle+57HrcAuwxxPZwu08NO0pxW0o/PiWvFhMz+woSCH8DFsfkkR wkZIW3uWIK5k5ck9hMi+elgoikhxPUADwrpkB7yN7eMYdbvlDBN6surOhHonXb8D6Xi3 /hY/4fHvP6bJ11rPn6RngOUb+73hZYhbEI7C5Dqob9+XQxu2kNim4eCVgiKViax1crYp LGrg== X-Gm-Message-State: ANhLgQ2k9KeBmQIkrS7wT/GdIsnIlEm3PSfHJxBP+znVVyZJqYSWvFYn 6haP7ltdc8+rVc8WUjoHZZNinw== X-Google-Smtp-Source: ADFU+vvqUSAvWqyE9DaEVsc9BL1sSyCTqyGX3gASvoIOFWOvGH5t+nN7jAYYQ+pnuHu4X8LJt2binQ== X-Received: by 2002:a1c:1b13:: with SMTP id b19mr541588wmb.91.1583272009222; Tue, 03 Mar 2020 13:46:49 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id o27sm37241265wro.27.2020.03.03.13.46.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 13:46:48 -0800 (PST) Date: Tue, 3 Mar 2020 22:46:46 +0100 From: Tomas Vondra To: Dilip Kumar Cc: Amit Kapila , Michael Paquier , Peter Eisentraut , PostgreSQL Hackers Subject: Re: PATCH: logical_work_mem and logical streaming of large in-progress transactions Message-ID: <20200303214646.6adway2z5wnapjem@development> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, I started looking at this patch series again, hoping to get it moving for PG13. There's been a tremendous amount of work done since I last worked on it, and a lot was discussed on this thread, so it'll take a while to get familiar with the new code ... The first thing I realized that WAL-logging of assignments in v12 does both the "old" logging (using dedicated message) and "new" with toplevel-XID embedded in the first message. Yes, the patch was wrong, because it eliminated all calls to ProcArrayApplyXidAssignment() and so it was trivial to crash the replica due to KnownAssignedXids overflow. But I don't think re-introducing XLOG_XACT_ASSIGNMENT message is the right fix. I actually proposed doing this (having both ways to log assignments) so that there's no regression risk with (wal_level < logical). But IIRC Andres objected to it, argumenting that we should not log the same piece of information in two very different ways at the same time (IIRC it was discussed on the FOSDEM dev meeting, so I don't have a link to share). And I do agree with him ... The question is, why couldn't the replica use the same assignment info we already write for logical decoding? The main challenge is that now the assignment can be sent in many different xlog messages, from a bunch of resource managers (essentially, any xlog message with a xid can have embedded XID of the toplevel xact). So the handling would either need to happen in every rmgr, or we need to move it before we call the rmgr. For exampple, we might do this e.g. in StartupXLOG() I think, per the attached patch (FWIW this particular fix was written by Masahiko Sawada, not me). This does the trick for me - I'm no longer able to reproduce the KnownAssignedXids overflow. The one difference is that we used to call ProcArrayApplyXidAssignment for larger groups of XIDs, as sent in the assignment message. Now we call it for each individual assignment. I don't know if this is an issue, but I suppose we might introduce some sort of local caching (accumulate the assignments into a local array, call the function only when we have enough of them). Aside from that, I think there's a minor bug in xact.c - the patch adds a "assigned" field to TransactionStateData, but then it fails to add a default value into TopTransactionStateData. We probably interpret NULL as false, but then there's nothing for the pointer. I suspect it might leave some random garbage there, leading to strange things later. Another thing I noticed is LogicalDecodingProcessRecord() extracts the toplevel XID using a macro txid = XLogRecGetTopXid(record); but then it just starts accessing the fields directly again in the ReorderBufferAssignChild call. I think we should do this instead: ReorderBufferAssignChild(ctx->reorder, txid, XLogRecGetXid(record), buf.origptr); regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services