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 1pDhAg-0003Fn-0v for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Jan 2023 07:29:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pDhAd-0005Nb-Un for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Jan 2023 07:29:43 +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 1pDhAd-0005NP-FA for pgsql-hackers@lists.postgresql.org; Fri, 06 Jan 2023 07:29:43 +0000 Received: from mail-yw1-x1131.google.com ([2607:f8b0:4864:20::1131]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pDhAa-0006OA-EA for pgsql-hackers@lists.postgresql.org; Fri, 06 Jan 2023 07:29:42 +0000 Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-4b718cab0e4so12021507b3.9 for ; Thu, 05 Jan 2023 23:29:40 -0800 (PST) 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=5ESsXT73sjXm4xyMOhKV1l/B7xoWUHd4eYIjxILsvF0=; b=e4fhSTT88sR5s7ngFQNGWP32GrpQR7TvvjWHZXx63kZUNcLg79CE61aixb9nnizeUT HNPhYdPXN8sQxCyMEbUU0FchhNXJdwl2DfNsNmIKcrthLSCfHmUj86yNqMraJwCB8VkM 4LGSx0jmc2yGb0MPO94hHXG3u52Bx77PE7rFyRIIMWcCrKbl7IB/QhvqnxomSMNeenAX mCalsWsqA79tuE7NaRmSB8+7EFHRZBRl8VpgzRTqLf2m3ZDM5NQTzr5podabgTxiOw3L fcFUN7R1Ygr4Y7LjUqyK3eIJbOpSYje1vDUmQim5IvJvekHaJ4wMMG3Fis17bLBCDdEa JBhg== 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=5ESsXT73sjXm4xyMOhKV1l/B7xoWUHd4eYIjxILsvF0=; b=1ITyMmcGYh06+crLMMDlb6/ZjUbq/v3kQ9F43ElbrNv3vf/McNcdb4+HZSi7buuvh3 hm/ySOTMQbKKyFAxCBQGCGaY8boQyEWglOIaP4HYxSiDv+aQIBaM1WMk2uBavcVDoq9t lX85fo79wgLWzKw3LoGcZrVLNDEQkhkAzTwxGN3sIY4/B3JpBe3lqBkobCdfwkr/23rf nq91gTAOG90nELAku36RYS6WnTg11L+ou9yRYNwbuUi6xYr0jTy99KXWBxSuJtIToY1Y SGTV46tbdyrZWUXLKc14YG2Qu2rxfaBQO95BUJ3FjfKywNuF1GxTD1rvn+msoZJh107D Gi4Q== X-Gm-Message-State: AFqh2koJ7vCquYIZYuj6fg4WhM2r6W4VZP3uT+2JJBQBwKrV0SGVhdN3 hLA03TIjSD0jHwiNjV9fVxjVu7EaZ6SDV6RtKMQ= X-Google-Smtp-Source: AMrXdXs8oRJm4U91KfWqz829nZbMCTHLIY8ETZvulYIcZYm9HbIL2UxHd4YuwfmhZLkpHEU8MOh9EqOlW7VxDvrpIdk= X-Received: by 2002:a81:7487:0:b0:3d4:f914:442 with SMTP id p129-20020a817487000000b003d4f9140442mr366000ywc.226.1672990179575; Thu, 05 Jan 2023 23:29:39 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Dilip Kumar Date: Fri, 6 Jan 2023 12:59:22 +0530 Message-ID: Subject: Re: Perform streaming logical transactions by background workers and parallel apply To: Amit Kapila Cc: "houzj.fnst@fujitsu.com" , Masahiko Sawada , "wangw.fnst@fujitsu.com" , Peter Smith , "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 Fri, Jan 6, 2023 at 12:05 PM Amit Kapila wrote: > > > Yeah, I also don't think sending extra eight bytes with stream_start > message is worth it. But it is fine to mention the same in the > comments. Right. > > 2. > > > > + * XXX Additionally, we also stop the worker if the leader apply worker > > + * serialize part of the transaction data due to a send timeout. This is > > + * because the message could be partially written to the queue and there > > + * is no way to clean the queue other than resending the message until it > > + * succeeds. Instead of trying to send the data which anyway would have > > + * been serialized and then letting the parallel apply worker deal with > > + * the spurious message, we stop the worker. > > + */ > > + if (winfo->serialize_changes || > > + list_length(ParallelApplyWorkerPool) > > > + (max_parallel_apply_workers_per_subscription / 2)) > > > > IMHO this reason (XXX Additionally, we also stop the worker if the > > leader apply worker serialize part of the transaction data due to a > > send timeout) for stopping the worker looks a bit hackish to me. It > > may be a rare case so I am not talking about the performance but the > > reasoning behind stopping is not good. Ideally we should be able to > > clean up the message queue and reuse the worker. > > > > TBH, I don't know what is the better way to deal with this with the > current infrastructure. I thought we can do this as a separate > enhancement in the future. Okay. > > 3. > > + else if (shmq_res == SHM_MQ_WOULD_BLOCK) > > + { > > + /* Replay the changes from the file, if any. */ > > + if (pa_has_spooled_message_pending()) > > + { > > + pa_spooled_messages(); > > + } > > > > I think we do not need this pa_has_spooled_message_pending() function. > > Because this function is just calling pa_get_fileset_state() which is > > acquiring mutex and getting filestate then if the filestate is not > > FS_EMPTY then we call pa_spooled_messages() that will again call > > pa_get_fileset_state() which will again acquire mutex. I think when > > the state is FS_SERIALIZE_IN_PROGRESS it will frequently call > > pa_get_fileset_state() consecutively 2 times, and I think we can > > easily achieve the same behavior with just one call. > > > > This is just to keep the code easy to follow. As this would be a rare > case, so thought of giving preference to code clarity. I think the code will be simpler with just one function no? I mean instead of calling pa_has_spooled_message_pending() in if condition what if we directly call pa_spooled_messages();, this is anyway fetching the file_state and if the filestate is EMPTY then it can return false, and if it returns false we can execute the code which is there in else condition. We might need to change the name of the function though. -- Regards, Dilip Kumar EnterpriseDB: http://www.enterprisedb.com