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.96) (envelope-from ) id 1vsJ9j-00FoWf-1u for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Feb 2026 11:22:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vsJ9i-009tVs-1G for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Feb 2026 11:22:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vsJ9h-009tVd-38 for pgsql-hackers@lists.postgresql.org; Tue, 17 Feb 2026 11:22:14 +0000 Received: from mail-yw1-x112a.google.com ([2607:f8b0:4864:20::112a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vsJ9c-00000001313-1IfF for pgsql-hackers@postgresql.org; Tue, 17 Feb 2026 11:22:13 +0000 Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-79088484065so32984727b3.1 for ; Tue, 17 Feb 2026 03:22:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771327328; cv=none; d=google.com; s=arc-20240605; b=LzrY8pRKJR02Ll+PgoXZJx5rskELPPwIKytKW8HDO6tiHeTflTIJuC6UBGOZ4Ws2Zk GGUBgbuCi+UWK7pF8dUCXaoB+wzPJbmFP4qyWc4rfsLN84akfbMGNSqCzte6Q7RtOauw erOLivVJBBHn6EAmtZscq9nYWUKQb1rSk8ADnag7xfQHdjT3TiBTQsmKfegqJCqDj2c0 ARw+1CE9CJsN5JonurqV7mMD1yxj1wWjjm1BpLQhPlN3pIHP539ToZonM/orllLrQL8p uKZeJtInHAihgIkaXdc23Mxoc11wxHRx8g0KBR/1Ch/6rLpR/0uaakvsjQwz0rGNBjRe 3GeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=9O99esHG8u85/g0dNJlOBgrc7RO0gbq6557IUUV+hJ0=; fh=2OlNetL9z/lJyOAIqcqtY9B4Gy2Syak2y47h3zYdee0=; b=NYE1uM+fE0kZPxxjT/N/2y6My2l7A9BToNs/mHWM3jlTHK6S/U/yXNCncpGc6nj2VU YEyPieKV9QugSfvjNoD/tvV/1hT3yfYT24WptVYy6j1RgG6q+Nrb4fphiaPo1WDq8HFk BfBY30hciK55TXobIcKMaGvWZ31MBF/beH0fUi8A5zKzvTTR5Ajq0BwHKXMUb7Pjg/we gaqeYpPgoqe7Uh47gSSB8mOdLjz/+ajbgMWmPsTHikaUjfx5OPPl4V6TDMRfUUJR0BGZ LeQim7/I5EIFPQ1RycxrKFaOTd/naDjf6zfP+LHhxCfS9ILvx7B70ZNP1X2dlMjGfZ5h BoLQ==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=percona.com; s=google; t=1771327328; x=1771932128; 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=9O99esHG8u85/g0dNJlOBgrc7RO0gbq6557IUUV+hJ0=; b=a28anoEYrkSHaKLRPPp4ezAxYDm7LA4lrVbHbFKvXtx3DmVrCKwQxP/NxK2RqEJNn3 gKG+pFToG0qqj7+ls++SxEUHKTBP8M5gK95ZO8goWzXtgCpr9ulw6LVNy9E7YttOw1ad RvJEpxHalXDjrTYd0KbQGF4s+n5NLWvEJfSCQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771327328; x=1771932128; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=9O99esHG8u85/g0dNJlOBgrc7RO0gbq6557IUUV+hJ0=; b=S1UbdA2QhWl5hY+Z8AhTgQV7nhsPRJRbWH7DiolwwvdvNHaZY/XFSwbWAVsUPxCyrq bAMg8ZUUUZTeumCFZnAbRKwBYEJdTec7FRhPVG+j1QIk6ObjdDPeZ7073qr/FV9QP9CO ZzFRt3/IOcSKhHgZQ0I61kD1lbYdG4SA/MsV4FVfW7hw9bIo8Vnw1sl5Mqupo4Mbuc7n dBM+KJmrGzm4z5rVO+G7tsyBqBgTvXN6nwcV+1LkVLWeqdX1zGhcNShi2+MGdFkeuJNQ AEJUfW56towENZzw/C6eEDSrLZzoiPR/Pu8MtxDZ/LPODQUfZinzA9Df5bLcKrBxNArD JXsQ== X-Forwarded-Encrypted: i=1; AJvYcCXoxnWBZ4DKEhQsU9u08fVoSvREItEh1bfsOll/h7tEbrt8be0k7DCcuvaIW8PU6eayHfcaTGqPudV8lzJN@postgresql.org X-Gm-Message-State: AOJu0Yy7iafLuDcHCd2S0fzZldUEBVY7kyhRwcyPzVHPd1l4v6uyzPKB 5Dtzfpce6gE+XJxFRRLpnLiC9yYj+0hIy7vvmtKT5Osqhkv4bwDd0P9xLvyvNZ9oLFCg/emHUo0 6Mgv67EnpEY4qxgMMpDe4KyZA5MOMfom1FAk/CvQgkaQjouIdHqbx3vxmCyLul3TruhoGNxNSxW oRNS1+RLLVBdxAoYS83Z3QaremFCLTtQ9QDT8aU+07KOfuauWs4ND9aoWJnof1GWvE2FIZKm3kg 1lbGgY536uv3BusM14ZeRpr87YYFgM2qCgLg68isF6FqIAgUII6UnLgmkfgfByRfRg= X-Gm-Gg: AZuq6aJUnE4X1x3cVzPAETVdv0XXcN4iflPVIsrYubpRqsSC2Wuftz2u56zCIVRGLIj 8U2WBcwr9klI9WgtxadlZ36snklE4+4kR296hj2r4zuY8bKmJ9cbf2irG1mvRTw5EnmA5YJ800v 50Jy6yf/SrXSMoUgXVS62JFUsXpnjevasZH2CNQQPDnnEg1/Pv8LV/yj9Pl2hRjR8ImxExnCZSt X+T+i6LvbY8YKPgouNgs2zl+WDXty4dt7H85k1Z8QsGhJKpPYPSfIbFSBFQhCMhHbnlftsckFJF NM9iUwakI9KZAPW4mAZDT9iftDXxzE8yca/SQEhusuta/qdIGqRb8xZ5feCl7WOs7rtW X-Received: by 2002:a05:690c:318:b0:797:ef49:a48c with SMTP id 00721157ae682-797ef49a9bdmr3006567b3.36.1771327328085; Tue, 17 Feb 2026 03:22:08 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Zsolt Parragi Date: Tue, 17 Feb 2026 11:21:56 +0000 X-Gm-Features: AaiRm50m2qIghOfE_Kljzmo80ozhCOAzGAWa9c83Fq3qkhxbsBmPKhY6zBCq7oE Message-ID: Subject: Re: [WIP] Pipelined Recovery To: Imran Zaheer Cc: "Hayato Kuroda (Fujitsu)" , pgsql-hackers Content-Type: text/plain; charset="UTF-8" X-CLOUD-SEC-AV-Sent: true X-CLOUD-SEC-AV-Info: percona,google_mail,monitor X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello! + + SpinLockAcquire(&WalPipelineShm->mutex); + + if (WalPipelineShm->initialized) + { + SpinLockRelease(&WalPipelineShm->mutex); + return; /* Already started */ + } + This doesn't seem to be a good use for a spinlock, as it guards a longer operation. Spinlocks are supposed to guard "a few instructions", not long initialization processes, according to their documentation. Since the code already uses dsm segment, wouldn't it be easier to use something like GetNamedDSMSegment which explicitly supports this use case with an initialization callback? Also see the next two more specific comments about errors and spinlocks. + case WAL_MSG_ERROR: + SpinLockAcquire(&WalPipelineShm->mutex); + ereport(ERROR, + (errcode(WalPipelineShm->error_code), + errmsg("[walpipeline] consumer: received error from the producer: %s", + WalPipelineShm->error_message))); + SpinLockRelease(&WalPipelineShm->mutex); + return NULL; According to the documentation spinlocks are not automatically released on errors, and ereport ERROR stops the code flow so everything after that is dead code. + SpinLockAcquire(&WalPipelineShm->mutex); + elog(LOG, "[walpipeline] producer: exiting: sent=" UINT64_FORMAT " received=" UINT64_FORMAT, + WalPipelineShm->records_sent, WalPipelineShm->records_received); + SpinLockRelease(&WalPipelineShm->mutex); A LOG is not an error, but elog can call palloc, which can cause an out of memory error, and then again we never release the spinlock. + if (msglen > WAL_PIPELINE_MAX_MSG_SIZE) + { + elog(WARNING, "[walpipeline] producer: wal record at %X/%X too large (%zu bytes), skipping", + LSN_FORMAT_ARGS(record->ReadRecPtr), msglen); + pfree(buffer); + return true; + } This doesn't seem like a good idea to me, won't skipping records cause data corruption? + shm_mq_handle *producer_mq_handle; + shm_mq_handle *consumer_mq_handle; Aren't these handles process local, yet stored in WalPipelineShmCtl? +{ name => 'wal_pipeline', type => 'bool', context => 'PGC_SIGHUP', group => 'WAL_RECOVERY', + short_desc => 'Use parallel workers to speedup recovery.', + variable => 'wal_pipeline_enabled', + boot_val => 'false', +}, Is SIGHUP really useful for this feature? It only runs at startup. + elog(FATAL, "[walpipeline] consumer: either pipeline not active, or no record available from pipeline."); + return record; FATAL also stops the codeflow, so that return is never executed. +/* Size of the shared memory queue (can be made configurable) */ +#define WAL_PIPELINE_QUEUE_SIZE (128 * 1024 * 1024) /* 8 MB */ + +/* Maximum size of a single message */ +#define WAL_PIPELINE_MAX_MSG_SIZE (2 * 1024 * 1024) /* 1 MB */ The comments about the sizes seem to be off. if (reachedRecoveryTarget) { + if (wal_pipeline_enabled) + WalPipeline_Stop(); What if we didn't reach the recovery target, shouldn't we stop the pipelines then? + /* Send shutdown message if queue is available */ + if (consumer_mq_handle) + WalPipeline_SendShutdown(); +} This seems wrong, WalPipeline_SendShutdown checks for the producer handle inside it instead? What's the exact contract, who should call these methods? By looking at the code I'm not sure if this shutdown logic works as intended.