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 1j9uj0-0002r5-Pf for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Mar 2020 17:55:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j9uiz-0003od-EI for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Mar 2020 17:55:57 +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 1j9uiz-0003oW-5M for pgsql-hackers@lists.postgresql.org; Thu, 05 Mar 2020 17:55:57 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j9uiw-0002XU-18 for pgsql-hackers@postgresql.org; Thu, 05 Mar 2020 17:55:56 +0000 Received: by mail-wm1-x344.google.com with SMTP id p9so7385847wmc.2 for ; Thu, 05 Mar 2020 09:55:53 -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=ycJ+0piBAcaWusuCeTSwGlOb8Y3OP9O/svpEt7jv+Fw=; b=m+rEwmTtBqJg5HPaP3ibx/e+lXkGBDjliv7rlHDj/zkvII9Q1AjNYd+kXxKafVM+6z jytrXwcTIf7Cy7YMevbbEQRTq3S4AZ/WNvmWF9910sl51s6YjBYnSDnvfrkI6oeyK+Ur e9TMQ5Rn1rIGhXL68CEoHlK5i9L3yhuMLKkSviVDxP+qWZw3oaR0PVEorgPHRAF+b0eG 5cqL8/PoNMfenX5F/RzqOe+v7mx9wKcWcv33Ok1z3HhMGOyLlbRRsurK07AXTygDzoB4 Tevzz43Zn4uXvTkkBeyeR3DZPGsUCXA3mZR0C5G7xRjrmg2cFWHTMX6v+x2p3BUOXNlf +gXA== 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=ycJ+0piBAcaWusuCeTSwGlOb8Y3OP9O/svpEt7jv+Fw=; b=eqg8vx5vKWZ4TejKRhW46Lpy0P+C6mwqOXJQrLA/8TFN1NPwfzINlsfkMVog8oMm4Y oqVt3hivhzJONXYO9HxmvOSvsK/XNrgQ6ixhs4jdFQ3KwJxf1pyLcteGmZNzkO9A8S6h yvShYx1BL/YpOHEyP8aS80J8yd5EKV0O1QTYStGz19BqwatPzDVy50rSrCkevTTNjxqd FGk0v6NhbH0utAurvpHKIl0yT+6pQFh+6gkrXFVyfVkuePCnKCSYSZaKCIHg6XoGZe++ aglU5q4H2YC3LzQHD9pDM4JY8U8LAfc1SYaqaHandezMAGo5ZGzPxOoQ/5egIqWJ+EdQ h5gg== X-Gm-Message-State: ANhLgQ3ftYsh60GUzF3VUfNR+iy3ACLLBpcWgBz65Y8mfYMRVPrqrfIm ZeO4C94MHtt5XYzHUTxOwnkhOw== X-Google-Smtp-Source: ADFU+vs2kDeREUS5k86iWmZSEzIfVaiw84RBVe0pRAKwEi/0SuySKjHaP0NTfAJevzw15UCLLR3zlg== X-Received: by 2002:a1c:9802:: with SMTP id a2mr10875173wme.117.1583430953169; Thu, 05 Mar 2020 09:55:53 -0800 (PST) Received: from localhost (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id x17sm5300464wrt.31.2020.03.05.09.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 09:55:52 -0800 (PST) Date: Thu, 5 Mar 2020 18:55:47 +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: <20200305175547.lx7m7oynnkqppsfm@development> References: <20200303214646.6adway2z5wnapjem@development> 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 On Wed, Mar 04, 2020 at 09:13:49AM +0530, Dilip Kumar wrote: >On Wed, Mar 4, 2020 at 3:16 AM Tomas Vondra > wrote: >> >> Hi, >> >> I started looking at this patch series again, hoping to get it moving >> for PG13. > >Nice. > > 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). > >Thanks for the pointers, I will think over these points. > >> >> 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. > >Actually, we will never access that field for the >TopTransactionStateData, right? >See below code, we have a check that only if IsSubTransaction(), then >we access the "assigned" filed. > >+bool >+IsSubTransactionAssignmentPending(void) >+{ >+ if (!XLogLogicalInfoActive()) >+ return false; >+ >+ /* we need to be in a transaction state */ >+ if (!IsTransactionState()) >+ return false; >+ >+ /* it has to be a subtransaction */ >+ if (!IsSubTransaction()) >+ return false; >+ >+ /* the subtransaction has to have a XID assigned */ >+ if (!TransactionIdIsValid(GetCurrentTransactionIdIfAny())) >+ return false; >+ >+ /* and it needs to have 'assigned' */ >+ return !CurrentTransactionState->assigned; >+ >+} > The problem is not with the "assigned" field, really. AFAICS we probably initialize it to false because we interpret NULL as false. My concern was that we essentially leave the last pointer not initialized. That seems like a bug, not sure if it breaks something in practice. >> >> 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); > >Make sense. I will change this in the patch. > +1, thanks regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services