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 1sTh9k-001SPV-Lf for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jul 2024 12:19:44 +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 1sTh9i-000FB9-VS for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jul 2024 12:19:42 +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 1sTh9i-000FAk-Lr for pgsql-hackers@lists.postgresql.org; Tue, 16 Jul 2024 12:19:42 +0000 Received: from mail-yw1-x112e.google.com ([2607:f8b0:4864:20::112e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sTh9g-002PTh-DN for pgsql-hackers@lists.postgresql.org; Tue, 16 Jul 2024 12:19:41 +0000 Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-65f8b0df1f0so29078227b3.2 for ; Tue, 16 Jul 2024 05:19:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1721132378; x=1721737178; darn=lists.postgresql.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=ap9IXQUhoO71XzbbjPqVFrfrSkrZcB54dS02h0ZCzro=; b=YwSl9Y1TudTJrp7gLpP2C/sVbxZIUIQI3ZerDesOvmV3F1GuiltkqQAOG5FzS+/B5n qjVeUZNsIu+0MDDXr3NorR61BWkK6VxLStn1Ki0/s9U4kRe6noQB0K5AmBtMWhH0WD1z H9ir6bUF6/jG7QVqLkceAKoPOLqpBkOxcDnsw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721132378; x=1721737178; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ap9IXQUhoO71XzbbjPqVFrfrSkrZcB54dS02h0ZCzro=; b=qpS27iRQPRd50Upq6MRTXnUI/KsVIgkM93WnMJCiqgjL5kmP2QuLYOgIf/cLdkNdoz wqSLrkuvXnkLgCEpxiuMo2+IXo2rwRJ6TU++Z1fIDjVLVnZ+N/qV3vEP0GgfYjHUzEg/ O4d8YvwwTms5VFBF/bBvcHqPsL56+mlsaHwW9BOM60MglefsM6XfCt1183HfKim7jQBi 3C/Bp5O0Dp07JlOvedsodCIj4nycICYOH0JaKJiC+5FTbWFgilP2Bn3SM13q0mU2WT9A lGLT9uvqeoZbMFDpUMvgTNj6TE7eTmhIzgMyxPVNykEXhiNv+bAT3FouWOObxgkWvWEP 0ztQ== X-Gm-Message-State: AOJu0YyZCHRXZRG8LEd3uc01m1E1crURl+4hxGAgDg7RSW0BaI4eimTd Adxx+YeBwBHSUh0AlicCoFpGGKIiiDHc21bp98/64PYmF0NlZTdKyC+2AHE7kw== X-Google-Smtp-Source: AGHT+IHRMMJkeVUytISoSDh8GNefOJYS7dKCMoCK+5kJ5NrviNCtPsUfQlHdEtXlWIJ1in07wspf9A== X-Received: by 2002:a81:9e07:0:b0:64b:ead:3e3f with SMTP id 00721157ae682-6637fd640d9mr19953927b3.22.1721132378471; Tue, 16 Jul 2024 05:19:38 -0700 (PDT) Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id 00721157ae682-65fc4451f3dsm11409737b3.115.2024.07.16.05.19.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jul 2024 05:19:38 -0700 (PDT) Date: Tue, 16 Jul 2024 05:19:35 -0700 From: Noah Misch To: Nazir Bilal Yavuz Cc: PostgreSQL Hackers Subject: Re: Use read streams in CREATE DATABASE command when the strategy is wal_log Message-ID: <20240716121935.fa.nmisch@google.com> References: <20240711235209.f6.nmisch@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jul 16, 2024 at 02:11:20PM +0300, Nazir Bilal Yavuz wrote: > On Fri, 12 Jul 2024 at 02:52, Noah Misch wrote: > > On Tue, Apr 16, 2024 at 02:12:19PM +0300, Nazir Bilal Yavuz wrote: > > > --- a/src/backend/storage/aio/read_stream.c > > > +++ b/src/backend/storage/aio/read_stream.c > > > @@ -549,7 +549,7 @@ read_stream_begin_relation(int flags, > > > { > > > stream->ios[i].op.rel = rel; > > > stream->ios[i].op.smgr = RelationGetSmgr(rel); > > > - stream->ios[i].op.smgr_persistence = 0; > > > + stream->ios[i].op.smgr_persistence = rel->rd_rel->relpersistence; > > > > Does the following comment in ReadBuffersOperation need an update? > > > > /* > > * The following members should be set by the caller. If only smgr is > > * provided without rel, then smgr_persistence can be set to override the > > * default assumption of RELPERSISTENCE_PERMANENT. > > */ > > I believe it does not need to be updated but I renamed > 'ReadBuffersOperation.smgr_persistence' as > 'ReadBuffersOperation.persistence'. So, this comment is updated as > well. I think that rename suits better because persistence does not > need to come from smgr, it could come from relation, too. Do you think > it is a good idea? If it is, does it need a separate commit? The rename is good. I think the comment implies "persistence" is unused when rel!=NULL. That implication is true before the patch but false after the patch. > > > @@ -4667,19 +4698,31 @@ RelationCopyStorageUsingBuffer(RelFileLocator srclocator, > > > > > /* Iterate over each block of the source relation file. */ > > > for (blkno = 0; blkno < nblocks; blkno++) > > > { > > > CHECK_FOR_INTERRUPTS(); > > > > > > /* Read block from source relation. */ > > > - srcBuf = ReadBufferWithoutRelcache(srclocator, forkNum, blkno, > > > - RBM_NORMAL, bstrategy_src, > > > - permanent); > > > + srcBuf = read_stream_next_buffer(src_stream, NULL); > > > LockBuffer(srcBuf, BUFFER_LOCK_SHARE); > > > > I think this should check for read_stream_next_buffer() returning > > InvalidBuffer. pg_prewarm doesn't, but the other callers do, and I think the > > other callers are a better model. LockBuffer() doesn't check the > > InvalidBuffer case, so let's avoid the style of using a > > read_stream_next_buffer() return value without checking. > > There is an assert in the LockBuffer which checks for the > InvalidBuffer. If that is not enough, we may add an if check for > InvalidBuffer but what should we do in this case? It should not > happen, so erroring out may be a good idea. I like this style from read_stream_reset(): while ((buffer = read_stream_next_buffer(stream, NULL)) != InvalidBuffer) { ... } That is, don't iterate over block numbers. Drain the stream until empty. If the stream returns a number of blocks higher or lower than we expected, we won't detect that, and that's okay. It's not a strong preference, so I'm open to arguments against that from you or others. A counterargument could be that read_stream_reset() doesn't know the buffer count, so it has no choice. The counterargument could say that callers knowing the block count should use the pg_prewarm() style, and others should use the read_stream_reset() style.