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 1neqKj-0000Fr-Ct for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Apr 2022 03:39:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1neqKi-0002kn-7G for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Apr 2022 03:39:48 +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 1neqKh-0002ke-Sd for pgsql-hackers@lists.postgresql.org; Thu, 14 Apr 2022 03:39:47 +0000 Received: from mail-yb1-xb30.google.com ([2607:f8b0:4864:20::b30]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1neqKe-0007kR-Pg for pgsql-hackers@postgresql.org; Thu, 14 Apr 2022 03:39:47 +0000 Received: by mail-yb1-xb30.google.com with SMTP id x200so7164209ybe.13 for ; Wed, 13 Apr 2022 20:39:44 -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=mMhIak0VYRPsRikLqvh1OuNLueCq2yuPV0rEJHgV+7I=; b=mGdYN5oYS0oH7ZMAGEAd+kM7damffm7RzEvmO8SlIgRydiN6pb8JCj/pLm/a19D7Yx rkmw/mIvY8MDlDcwcinJYCGRbyYH/GXvimRujVS3WzTP/gPLJ/vPnC2SDzMUdxdqUwNQ RQBojm7EkIFs4Ep4meJA6Ve25mrpwnRA4eXQ2AXF1D5fRhmQUWL0I5SrRRSKELXV8+hR Ij8hm8TvCEZxfhUJ0kFJOO7fprimEufn5Tub3ocISDhEj9shmaqWeiUyyQCAflpJOYlg VUdNIO/fiI6AK67lqBt+L0QoO4V+pRl1hiEMsBuc0YmYhs/8ODFIk0opCW5avNoygnO1 YMDQ== 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=mMhIak0VYRPsRikLqvh1OuNLueCq2yuPV0rEJHgV+7I=; b=ZdPoOXn1OKLqMxuknrY3zZ2TTzTqNN/uaDA3ollCaJYe7yyxDZQt5VUn8LwJmmDr3V ubVutFMipaToJHH6vVcKsnFhlndF1VEDvhnvAaCHfrXgFCOLn/oTzeBlz/brr4XXGe+m DRtw+s4Zm9Vp5gPYrY5J5j0QHwxw1Dpe/PrbxcUub8NKtS4/gC/5ZAETr2kPYLhbovRD r5Ka854tFxrtXylgzZjx7/T2G2DIdPc3zm2WU3D07jhyJcAnCOKZ3F6vJgM8QleL32fU cfmbGQxEUlClUBcS62E8Qn75nrmiEevW9queqkAZVIOkmBRDEmnxWf0qyL1NStr5C6S7 sEFQ== X-Gm-Message-State: AOAM533rNjw3L2TPsueCMSk08DIZPe1c5b6lDiIxMT88F+FZmakM4cQH MXz5nq2PWifdPiwv6iR2lOFqh2OTO9KpCyPiy9w= X-Google-Smtp-Source: ABdhPJzFScbmW6WTF+H5v0lG4mCehUnoW4bwWIOj9Q4lmUTZVhfV0Kzt2ExhTBegF4KFkuKIwmqBNpaBdDzEvFDIuOA= X-Received: by 2002:a25:d217:0:b0:641:1cf7:5b2f with SMTP id j23-20020a25d217000000b006411cf75b2fmr460447ybg.349.1649907582043; Wed, 13 Apr 2022 20:39:42 -0700 (PDT) MIME-Version: 1.0 References: <202201120041.p24wvsfcsope@alvherre.pgsql> <78b8d385-57cb-9a3f-cfe5-9f300f15eced@enterprisedb.com> <822a8e40-287c-59ff-0ea9-35eb759f4fe6@enterprisedb.com> <2b8471f9-3849-c91f-ef82-9181d4bca0a7@enterprisedb.com> <16e83ce3-8415-b732-37b2-c3329a2c13a1@enterprisedb.com> <3162f7f0-86ac-e3a9-dc55-0a660cb9bab1@enterprisedb.com> <369ae611-8822-f499-87cd-58ad0d60c60c@enterprisedb.com> In-Reply-To: From: Amit Kapila Date: Thu, 14 Apr 2022 09:09:31 +0530 Message-ID: Subject: Re: Column Filtering in Logical Replication To: Masahiko Sawada , Petr Jelinek Cc: Tomas Vondra , "houzj.fnst@fujitsu.com" , Peter Eisentraut , Alvaro Herrera , Justin Pryzby , Rahila Syed , Peter Smith , pgsql-hackers , "shiy.fnst@fujitsu.com" Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Apr 14, 2022 at 8:32 AM Masahiko Sawada wrote: > > On Wed, Apr 13, 2022 at 6:45 PM Amit Kapila wrote: > > > > On Wed, Apr 13, 2022 at 1:41 PM Masahiko Sawada wrote: > > > > > > I've looked at this issue and had the same analysis. Also, I could > > > reproduce this issue with the steps shared by Amit. > > > > > > As I mentioned in another thread[1], the fact that the tablesync > > > worker doesn't check the return value from > > > wait_for_worker_state_change() seems a bug to me. So my initial > > > thought of the solution is that we can have the tablesync worker check > > > the return value and exit if it's false. That way, the apply worker > > > can restart and request to launch the tablesync worker again. What do > > > you think? > > > > > > > I think that will fix this symptom but I am not sure if that would be > > the best way to deal with this because we have a mechanism where the > > sync worker can continue even if we don't do anything as a result of > > wait_for_worker_state_change() provided apply worker restarts. > > I think we can think this is a separate issue. That is, if tablesync > worker can start streaming changes even without waiting for the apply > worker to set SUBREL_STATE_CATCHUP, do we really need the wait? I'm > not sure it's really safe. If it's safe, the tablesync worker will no > longer need to wait there. > As per my understanding, it is safe, whatever is streamed by tablesync worker will be skipped later by apply worker. The wait here avoids streaming the same data both by the apply worker and table sync worker which I think is good even if it is not a must. > > > > The other part of the puzzle is the below check in the code: > > /* > > * If we reached the sync worker limit per subscription, just exit > > * silently as we might get here because of an otherwise harmless race > > * condition. > > */ > > if (nsyncworkers >= max_sync_workers_per_subscription) > > > > It is not clear to me why this check is there, if this wouldn't be > > there, the user would have got either a WARNING to increase the > > max_logical_replication_workers or the apply worker would have been > > restarted. Do you have any idea about this? > > Yeah, I'm also puzzled with this check. It seems that this function > doesn't work well when the apply worker is not running and some > tablesync workers are running. I initially thought that the apply > worker calls to this function as many as tables that needs to be > synced, but it checks the max_sync_workers_per_subscription limit > before calling to logicalrep_worker_launch(). So I'm not really sure > we need this check. > I just hope that the original author Petr J. responds to this point. I have added him to this email. This will help us to find the best solution for this problem. Note: I'll be away for the remaining week, so will join the discussion next week unless we reached the conclusion by that time. -- With Regards, Amit Kapila.