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 1omvr5-0007sH-GZ for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Oct 2022 11:42:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1omvr3-0000dJ-Qo for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Oct 2022 11:42:53 +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 1omvr3-0000dA-FJ for pgsql-hackers@lists.postgresql.org; Mon, 24 Oct 2022 11:42:53 +0000 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1omvr0-0001QZ-Vh for pgsql-hackers@lists.postgresql.org; Mon, 24 Oct 2022 11:42:52 +0000 Received: by mail-oi1-x22d.google.com with SMTP id j188so10520762oih.4 for ; Mon, 24 Oct 2022 04:42:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=bDohO9RiGfKj4HVyJEATYDysiMrX2VSndFDCfp378BM=; b=hC0VPyT2tVRgqgRyvQhjBezmAjKfJeuzF48zkBxtd0qSXcCqWaRXg7sRhwlBhYyBKv Dz05PK9KYmxjupG4pOdwLuGofYWc51ekOfzmrP/R0+wsLXp9lw2UmTkUTCEMWH9w6dAR 57LD3uVSd2ZufAwiZldOVKZy8W9rNEf1XiDpe225pa9+uBvMrR3JM58PDc9s2FqjQB0z wVcoWBDlI6ajOpUqQzz/BaDvFmioMM/Ew8DLBbeuWHz//g5zvUiCOMP8GpQroK6GxiXy T8c060G5uYdOV+Q5p3a4BSyAnXyfDvmqom/ByqMNuhAhORL8TRSUSc6+ghH3qe0+BXal ZAXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bDohO9RiGfKj4HVyJEATYDysiMrX2VSndFDCfp378BM=; b=aacEwWELpsSMZRoXU/a7+afSD1a9KSyrZMXyEJATTINJTBtNr5QK+yESMz0L2iqTWa vd7yECH9q/TKTwuOfyB6VWDbZtZyv5IPTi0yy8dxWzaqkvIO7Pelzl1khw0D7AXskULY pUVQfD+AU3tAdjeKUMuSdc0+KhfvnzqXIQOSyhUePMS2x0rVPHp+iDiPJ8gdeYR4nMYW TS1CCQ28fa9urMbjuWL5qONt2R6c2gVFMXTqMW4nS37Rh4MVKDAW0mzlk0yanuykD4dx fcdOAMttkFC8ggkyVNHul1e4z69TnQCiDgBrxi430SdJIvkvRX73jaT8LM+zIMCL1+FF pH4A== X-Gm-Message-State: ACrzQf1nOYLwzBuJX2VwApq1caj/zun8i7jRkGZYRgww9O2Rj86TN/nm tMheiqalLlq3Kjg059fcdPyizSI5bRQiL3Z/UPM= X-Google-Smtp-Source: AMsMyM4D3hry+zwmPsi+kZHIKiP77df8laxsOrDj1e4toikgUTaJhqrAo/toKz1A3687FuudY4kKd7PMcG1GKkkyDE8= X-Received: by 2002:a05:6808:159b:b0:355:2077:77ba with SMTP id t27-20020a056808159b00b00355207777bamr24641036oiw.278.1666611769840; Mon, 24 Oct 2022 04:42:49 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Masahiko Sawada Date: Mon, 24 Oct 2022 20:42:13 +0900 Message-ID: Subject: Re: Perform streaming logical transactions by background workers and parallel apply To: Amit Kapila Cc: "houzj.fnst@fujitsu.com" , "wangw.fnst@fujitsu.com" , Peter Smith , Dilip Kumar , "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 Wed, Oct 12, 2022 at 3:04 PM Amit Kapila wrote: > > On Tue, Oct 11, 2022 at 5:52 AM Masahiko Sawada wrote: > > > > On Fri, Oct 7, 2022 at 2:00 PM Amit Kapila wrote: > > > > > > About your point that having different partition structures for > > > publisher and subscriber, I don't know how common it will be once we > > > have DDL replication. Also, the default value of > > > publish_via_partition_root is false which doesn't seem to indicate > > > that this is a quite common case. > > > > So how can we consider these concurrent issues that could happen only > > when streaming = 'parallel'? Can we restrict some use cases to avoid > > the problem or can we have a safeguard against these conflicts? > > > > Yeah, right now the strategy is to disallow parallel apply for such > cases as you can see in *0003* patch. Tightening the restrictions could work in some cases but there might still be coner cases and it could reduce the usability. I'm not really sure that we can ensure such a deadlock won't happen with the current restrictions. I think we need something safeguard just in case. For example, if the leader apply worker is waiting for a lock acquired by its parallel worker, it cancels the parallel worker's transaction, commits its transaction, and restarts logical replication. Or the leader can log the deadlock to let the user know. > > > We > > could find a new problematic scenario in the future and if it happens, > > logical replication gets stuck, it cannot be resolved only by apply > > workers themselves. > > > > I think users can change streaming option to on/off and internally the > parallel apply worker can detect and restart to allow replication to > proceed. Having said that, I think that would be a bug in the code and > we should try to fix it. We may need to disable parallel apply in the > problematic case. > > The other ideas that occurred to me in this regard are (a) provide a > reloption (say parallel_apply) at table level and we can use that to > bypass various checks like different Unique Key between > publisher/subscriber, constraints/expressions having mutable > functions, Foreign Key (when enabled on subscriber), operations on > Partitioned Table. We can't detect whether those are safe or not > (primarily because of a different structure in publisher and > subscriber) so we prohibit parallel apply but if users use this > option, we can allow it even in those cases. The parallel apply worker is assigned per transaction, right? If so, how can we know which tables are modified in the transaction in advance? and what if two tables whose reloptions are true and false are modified in the same transaction? > (b) While enabling the > parallel option in the subscription, we can try to match all the > table(s) information of the publisher/subscriber. It will be tricky to > make this work because say even if match some trigger function name, > we won't be able to match the function body. The other thing is when > at a later point the table definition is changed on the subscriber, we > need to again validate the information between publisher and > subscriber which I think would be difficult as we would be already in > between processing some message and getting information from the > publisher at that stage won't be possible. Indeed. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com