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 1nljwj-0002F3-QJ for pgsql-hackers@arkaria.postgresql.org; Tue, 03 May 2022 04:15:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nljwi-0005MU-GY for pgsql-hackers@arkaria.postgresql.org; Tue, 03 May 2022 04:15:32 +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 1nljwi-0005ML-5h for pgsql-hackers@lists.postgresql.org; Tue, 03 May 2022 04:15:32 +0000 Received: from mail-yw1-x1135.google.com ([2607:f8b0:4864:20::1135]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nljwb-0005UR-Nc for pgsql-hackers@lists.postgresql.org; Tue, 03 May 2022 04:15:31 +0000 Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-2ebf4b91212so168209917b3.8 for ; Mon, 02 May 2022 21:15:25 -0700 (PDT) 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; bh=L+4xShGmiroJ0wsO+R/HN62CEskSbeGPnz1OJVu9JT4=; b=mFawCq2qYh7yCLQ8zhb5MwR1xwRlzP+0/1R+T+hoyIr1wVHeojM1ba8fb/5oFVy2pR slHbMZIxKzB1Y0RyReL3WaxBOL0cigNoiqJAKDWsSCWHO59w5Isyg2j0g8u9Uuxdh9mS h3Nq5avg7Tffqlq+59nGaxym1oJcyrN/P3pxpEhIvx206V7gAdPkYqqAbMiI/jK+JQrN RBinFFNh7Kd6H++/g/uKsaaDHOdHqKYHemQUw5SdcmLueNvuP+lmxeg8MWEosZ4lfYNq MS/jeZSshIgn4SDtPjUzarzX5uNMdIFCyZHYQhUJiJgB8ky9EA3X+8sJiotZAm+z2S9j sgFA== 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; bh=L+4xShGmiroJ0wsO+R/HN62CEskSbeGPnz1OJVu9JT4=; b=Yev0/g7hq8IZmlqL6/KTnukdZUdUpjdYkv6+Gt7KcYYsQnTrbHu3PqY1xZSI2CxzzM 4iLm75DgAv9xPBq+tv9v7huNUvtevjbfYvnLYV63Kk2BWE5OpEPfph9rfQHR8jLivrZh K1X9XC0lhkBcdPeqjkmPnkiNlKgzq6hBYxrKvWq3wH8QCxHMh2765LPoZ03vIwKEzomH H+dOcJUNxpLS+u9djAK+pJL2/hBk2mDUoL7XDB/g8H3WZCoDCrD4P+bvnjbcH0ufCx5S 1FBUxAdtkPm+AbOBuC2AwWGmGTtcH1DMxiOMEs6DH6BwZsn+8bKvf0c0TXUnX+Kz+gvV /5NQ== X-Gm-Message-State: AOAM532XnfR6j2d92x09yaiXOemGfD87cFsf7JDp+BOpo3c8attwEKh7 3h7Oj+7ixNCOKykpwZpnU6vY1PJSyA19dkZo1bI= X-Google-Smtp-Source: ABdhPJykSOkNuf29+f2S9DL90vZj9gpKTN3nxpEJM8gpZSAy0Y7DuGal0t0DzJujV+9xikyTTciWrxSuAcd+7gYjHdw= X-Received: by 2002:a81:1108:0:b0:2f7:bf11:3fb9 with SMTP id 8-20020a811108000000b002f7bf113fb9mr14085401ywr.305.1651551324974; Mon, 02 May 2022 21:15:24 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Tue, 3 May 2022 09:45:14 +0530 Message-ID: Subject: Re: Perform streaming logical transactions by background workers and parallel apply To: Masahiko Sawada Cc: "houzj.fnst@fujitsu.com" , "shiy.fnst@fujitsu.com" , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, May 2, 2022 at 5:06 PM Masahiko Sawada wrote: > > On Mon, May 2, 2022 at 6:09 PM Amit Kapila wrote: > > > > On Mon, May 2, 2022 at 11:47 AM Masahiko Sawada wrote: > > > > > > > > > Are you planning to support "Transaction dependency" Amit mentioned in > > > his first mail in this patch? IIUC since the background apply worker > > > applies the streamed changes as soon as receiving them from the main > > > apply worker, a conflict that doesn't happen in the current streaming > > > logical replication could happen. > > > > > > > This patch seems to be waiting for stream_stop to finish, so I don't > > see how the issues related to "Transaction dependency" can arise? What > > type of conflict/issues you have in mind? > > Suppose we set both publisher and subscriber: > > On publisher: > create table test (i int); > insert into test values (0); > create publication test_pub for table test; > > On subscriber: > create table test (i int primary key); > create subscription test_sub connection '...' publication test_pub; -- > value 0 is replicated via initial sync > > Now, both 'test' tables have value 0. > > And suppose two concurrent transactions are executed on the publisher > in following order: > > TX-1: > begin; > insert into test select generate_series(0, 10000); -- changes will be streamed; > > TX-2: > begin; > delete from test where c = 0; > commit; > > TX-1: > commit; > > With the current streaming logical replication, these changes will be > applied successfully since the deletion is applied before the > (streamed) insertion. Whereas with the apply bgworker, it fails due to > an unique constraint violation since the insertion is applied first. > I've confirmed that it happens with v5 patch. > Good point but I am not completely sure if doing transaction dependency tracking for such cases is really worth it. I feel for such concurrent cases users can anyway now also get conflicts, it is just a matter of timing. One more thing to check transaction dependency, we might need to spill the data for streaming transactions in which case we might lose all the benefits of doing it via a background worker. Do we see any simple way to avoid this? -- With Regards, Amit Kapila.