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 1pDhCH-0003P9-Q7 for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Jan 2023 07:31:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pDhCG-0008IH-Lm for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Jan 2023 07:31:24 +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 1pDhCG-0008I8-D2 for pgsql-hackers@lists.postgresql.org; Fri, 06 Jan 2023 07:31:24 +0000 Received: from mail-yb1-xb33.google.com ([2607:f8b0:4864:20::b33]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pDhCD-0001Qk-OS for pgsql-hackers@lists.postgresql.org; Fri, 06 Jan 2023 07:31:23 +0000 Received: by mail-yb1-xb33.google.com with SMTP id 203so1007318yby.10 for ; Thu, 05 Jan 2023 23:31:21 -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=TTN6M6T2htJIm2bDcqY1863c2q2CcC+IPayGfYQkf9c=; b=fc/uTkNNP7AP5kty4003engOlaXdUhA2b6Zjo7qfrJXlNBhW1HlDlv6fJiOHPCfZqL Wr53S/NlqsWTQC9kJyQHaYEH6fpNTDLpOCndlAXzu1THY7IBBGRSB4eRHVLFv7Hn4OJ0 iseRTX/vWttb/lecAbBNTEZZfQ4QMBQxKgwWCQZp0jBOyZVtxPojKxWX27JJMhq34vqR sXJrbNFkmAtte6hv3vJn+MbFwDRPMVPjaO48JhPgPWKKofjrkzGpJz9JlZ88ieyjVaLR RcsQXXp2PgOKeTbGmJQBA7D2iGxXHKskfB2igXS0QmtZ2EmwsohMV4jpWtTMI+SFxG/U IP3A== 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=TTN6M6T2htJIm2bDcqY1863c2q2CcC+IPayGfYQkf9c=; b=W5M15caTAuJr9VOfKu4oxYFXOWdPGWyX40QP5enb/8nhZ7hTth5TSM4/phGGWhDkAl 2PzNVIMZ0zbY8Oi9re9LVxpG1NwrdHVlTk95pFKVPuvaTw1dhNbKB4q5r1yyIqIT89TY +WowxPSCsi/2/VsA8HH50nZHM53ovxEhVY/DYMcnMxatFle3K8ulTX/wC4xqRi71g8LU WVeAen2Tjw4Jyrb7fkjeJQPAfkyDVT++dJI5Ee+GWuj6pVlXDtCyrcZyda8dM5C4k9mh ig9qZy/DowTsSUqO9iyNpjzkKXujEE479LZ8Ncy54l/wxw1vrGKTNu62QvQ0xEwNYpd4 zH7Q== X-Gm-Message-State: AFqh2kp5itlfSXr0FF1mCOyAnld/6Q/zNtEPTtKSmHESuchKkdo8QsvL tRLCgh/wGgjgCoCM7ldbQaNCNCGddZ5Fz4a36cg= X-Google-Smtp-Source: AMrXdXsCI4v7FDb2ump3RMUXf6QkX7UUgxyz4CgpcJNCFeqPg8hnoBBfmoa7Wfnc1205mbIpIzR/WxxzczTsZEs4LgY= X-Received: by 2002:a25:3d6:0:b0:73a:4455:b5 with SMTP id 205-20020a2503d6000000b0073a445500b5mr5321541ybd.266.1672990279624; Thu, 05 Jan 2023 23:31:19 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Dilip Kumar Date: Fri, 6 Jan 2023 13:01:02 +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:59 PM Dilip Kumar wrote: > > > > 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. > But anyway it is not a performance-critical path so if you think the current way looks cleaner then I am fine with that too. -- Regards, Dilip Kumar EnterpriseDB: http://www.enterprisedb.com