Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v670P-00H0Hx-Es for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Oct 2025 12:41:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v670N-00H1AT-08 for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Oct 2025 12:41:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v670M-00H1AL-MQ for pgsql-hackers@lists.postgresql.org; Tue, 07 Oct 2025 12:41:23 +0000 Received: from mail-vk1-xa30.google.com ([2607:f8b0:4864:20::a30]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v670L-000rOB-0P for pgsql-hackers@postgresql.org; Tue, 07 Oct 2025 12:41:23 +0000 Received: by mail-vk1-xa30.google.com with SMTP id 71dfb90a1353d-54bd3158f7bso4676201e0c.0 for ; Tue, 07 Oct 2025 05:41:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759840879; x=1760445679; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=OX9aOTNOA9N1y+jXrPsHaMsUPOfO2a2aE6fcJaRsSc4=; b=P9xnEDmtcygWeaVxDrWGOl2zBCby2iWCX8x/xdsVDiGyWdSElwIyXZ3J6Y1pvTxDW/ 5F16P7JbN9WihtD/cTCqMWR13C7gUwqb951alrvvkmpPV7GWlhkpyJG4GXeuh+lykGe8 sXnkozQWnKOHcBw6NSHfG446Kj8baUE8AHMjhVTOhDeHP4/0w+bZeHUud4ANZEWnDTyE 9JdVILmtvGwmSNpu3A+tRo3n0EE5cDDV/niAU4sJAgPNYdZpfrFwMFuT9DxniFU/db0I sMQNgmL1qmRkbw+EKy1lBGRuQmPCDpwS3mWlWLGNCLHyriU4yeYhYW2swHsP+AvQQWOy RY1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759840879; x=1760445679; 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=OX9aOTNOA9N1y+jXrPsHaMsUPOfO2a2aE6fcJaRsSc4=; b=pQJxEWjjAd9B06MoJoNTSo5iynX/GNokEMN5pffV90/tKLhP7w7URa4sEwHze7GSUI QAhDuT1s6swOnRFRNClHCxtjc/TifXiQs0kvOsuLV384Ei3pm8mux0m1d+9u5GHTnvyB zyTh4IxgtWnjHygKshi+jHViDauoqL8xL1dOLjizauGws2U7H7heKub9KErbGXzBcO76 8XQ85MX2tUSTuEqpx7/BMG2bktI4llSXyUcSjniby6FLvOW5NeMTxTikK9sZx4o6o897 5Fo/+JoMGxl/E1IlzayvMd6aXWvxVnmg6t0c/k9NlGoklVqncLzgB1dGY9IgBvjRsn3X Az6w== X-Gm-Message-State: AOJu0Yz4muaEUPgVs7cy2mkvydyU/2WBRKVCHbTSZAHTGnTPWfhk7hrM cpfK6q7VY+qd4lCck77vnhvuRlqmpPrv7KcmWQMTwK4F4mhX/+X7eNODcolpgAp0kpWMDM2sU9x rE9p9G/b4HacMRcaNGu58wQtxFPIpjz0rYw== X-Gm-Gg: ASbGncssz8EG448vNKJU3qmsz8X20xpF6YiMn8HoqhbhExVS4+CLWvpEg0pVxFajgWw KyOOXGk1p/+cItn219e1eEmek9DV9oqJ/iYDRQt4I29DkmN40iceC/dbBGn9rJkf4AsLUj1a3v8 kqINjLBnbPn36T0KBgWP96LkWYARj5VB6tR2Rkq0Yp4UiPveCyDLOBOn3qGaWVpNHLH7/iapDT9 fb7aAsqvspAQjqCHe4RbV/ps/VWSmE6 X-Google-Smtp-Source: AGHT+IFcBmZ2RjVCEU79fHh2uS8XauAcmw4bpjB/jwPXHsSdBNU5RLkJB4d8KPzDES8NX7nLnBRI4nYwdJT015zfyq4= X-Received: by 2002:a05:6102:5cc5:b0:52e:68:770a with SMTP id ada2fe7eead31-5d41d10bca9mr5770913137.24.1759840878849; Tue, 07 Oct 2025 05:41:18 -0700 (PDT) MIME-Version: 1.0 References: <6899c044-4a82-49be-8117-e6f669765f7e@app.fastmail.com> <165530.1752362320@sss.pgh.pa.us> <02a7cd37-e2fc-4212-8b19-f8c239c95fb8@app.fastmail.com> <96f00bf1-cc9d-4520-9d02-9e14e7767c88@app.fastmail.com> <30c2aa7d-dd6c-4b68-a2e4-f217a1a34acf@app.fastmail.com> <0b4d402a-9ac2-4aa8-acf8-8231dbe579ea@app.fastmail.com> <3095599.1758644879@sss.pgh.pa.us> <0dc6a2cc-5216-4dc1-9dd2-430cafc6095b@app.fastmail.com> <52CC167F-763B-4ECA-B0B4-DAB381816828@gmail.com> <9186C6D0-F7A9-482A-9183-89E530B57E36@gmail.com> <1073593.1759423179@sss.pgh.pa.us> <4bd5e6c4-6fa7-44bb-869d-59a32a331fa8@app.fastmail.com> In-Reply-To: <4bd5e6c4-6fa7-44bb-869d-59a32a331fa8@app.fastmail.com> From: Matheus Alcantara Date: Tue, 7 Oct 2025 09:40:51 -0300 X-Gm-Features: AS18NWDhZDkRid1FcE5SsuGtjvazfro0Ln2wwOUIt4oun9O5aes85cR52qI7ZBA Message-ID: Subject: Re: Optimize LISTEN/NOTIFY To: Joel Jacobson , Tom Lane Cc: pgsql-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 Oct 6, 2025 at 5:11 PM -03, Joel Jacobson wrote: > The patch is now using dshash. I've been looking at code in launcher.c > when implementing it. The function init_channel_hash() ended up being > very similar to launcher.c's logicalrep_launcher_attach_dshmem(). > Hi, This is not a complete review, I just read the v9 patch and summarized some points. 1. You may want to add ChannelEntry and ChannelHashKey to typedefs.list to get pgindent do the right job on indentation. 2. The ListCell* variables are normally named as lc + ListCell *p; 3. This block on ChannelHashRemoveListener() seems contradictory. You early return if channel_hash == NULL and then call init_channel_hash that it will early return if channel_hash != NULL. So if channel_hash != NULL I don't think that we need to call init_channel_hash()? + if (channel_hash == NULL) + return; + + init_channel_hash(); A similar check also exists on SignalBackends() if (channel_hash == NULL) ... else { // channel_hash is != NULL, so init_channel_hash will early // return. init_channel_hash(); ... } 4. The ChannelHashRemoveListener() release lock logic could be simplified to something like the following, what do you think? + if (entry->num_listeners == 0) + { + dsa_free(channel_dsa, entry->listeners_array); + dshash_delete_entry(channel_hash, entry); + } + break; + } + } + + /* Not found in list */ + dshash_release_lock(channel_hash, entry); 5. You may want to use list_member() on GetPendingNotifyChannels() to avoid the inner loop to check for duplicate channel names. 6. s/beind/behind + /* Need to signal if a backend has fallen too far beind */ 7. I'm wondering if we could add some TAP tests for this? I think that adding a case to ensure that we can grown the dshash correctly and also we manage multiple backends to the same channel properly. This CF [1] has some examples of how TAP tests can be created to test LISTEN/NOTIFY [1] https://commitfest.postgresql.org/patch/6095/ -- Matheus Alcantara