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 1syRpF-00GsJ1-64 for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Oct 2024 08:13:41 +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 1syRoF-00FYLz-T2 for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Oct 2024 08:12:39 +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 1syRoF-00FYLr-EZ for pgsql-hackers@lists.postgresql.org; Wed, 09 Oct 2024 08:12:39 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1syRoA-0007jM-TK for pgsql-hackers@lists.postgresql.org; Wed, 09 Oct 2024 08:12:38 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-42cb60aff1eso66930915e9.0 for ; Wed, 09 Oct 2024 01:12:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728461555; x=1729066355; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=K6Xn4V7BI2FPll+hzcVEZpdTlSGvSBHJ7vYgmivdn14=; b=JLmU8Tju58LrjBaC6MMoGP+WLEbvHo0+Xk7vM0R7Ch6jipPNI9Rs20lzC9Ko23X1OR KRzdP5MUwzY7o6IM/yUPCgYZoG5yP7/W8n0tB3iMi7zFIi/gHSNezPBt9s+tK8D5fU+U NfEivfTLA8OmgPmIPl6m5pOLv+g1mtlfA9GEmzsS3WHE6w2nv/oWJJQ5/gUjaSjfVZ/K ld0qX0ZWbtpn+0a1KdRAFYxfByq8+dE/Otr1Li5RGeOLtxHIynso2aLoPK/HEPPQ/i99 IAVF4tdPNBO0f+26L5G3OYkpEbHfhueX1hH+CWsChodlOAgfnxw6WBBXsSQe6ys++Mza 5aSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728461555; x=1729066355; h=in-reply-to:content-transfer-encoding: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=K6Xn4V7BI2FPll+hzcVEZpdTlSGvSBHJ7vYgmivdn14=; b=lBWOy1jGs0fPYsGiqY2i+5kxieRTAYrwOq3OZ4xwHIErFyKV7V9K6wLS7g/roHgN/R kM81x5bkDlBXP/X3iAOPJUoNlAChslRL5lwaB+7I4+QV4itPvBCjHzs7G1hyk64ZS7J/ fgkmh5QL5ph2mI0C0ukJmd+LZOiGI0cXWqdWRCrRWGXaqsI11vnsI64vEHtNukKvOYMO Yzb0AxN+8/29x/Z3YJ1H8wqsJlzm1wChRARKrA9Xbo0l3Y8L6SSc+0vC5PqpTaxqeX7e quUrPp6P8FmCaGez3s7RlabvtCgwuDsQOBaHmjLNPAl8PKw08pYSvWtuBCHENzSLGg/E GX5g== X-Forwarded-Encrypted: i=1; AJvYcCW2+V3SK39uJyBTC61XTlBYLvkJKuI3FUw4vyXso8XF80vhuVEHOEKfSqQQboLQYOaAJyHUzzidHOiiLP9W@lists.postgresql.org X-Gm-Message-State: AOJu0YyhrKw7QNsLdW6YG9lDgWtTDVwwR38+z1pmEc//O+wxHG5N+QkQ BM04ig1iWy2NJZkxOBQZHxmxpMd7ZyEpVilcsXE4oHg/bhoNGORTVv4eDA== X-Google-Smtp-Source: AGHT+IF0lhRPKLr17V7/WF5HccgRr1FxqDE7wYRqAAAmXo1hzjRCT3xdkfAAD1P2egNpXpKftd5thQ== X-Received: by 2002:a05:6000:180f:b0:37c:c892:a98c with SMTP id ffacd0b85a97d-37d3ab01a50mr824458f8f.56.1728461554703; Wed, 09 Oct 2024 01:12:34 -0700 (PDT) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-236-134-5.eu-west-3.compute.amazonaws.com. [15.236.134.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4304efc1cd3sm24212165e9.1.2024.10.09.01.12.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 01:12:33 -0700 (PDT) Date: Wed, 9 Oct 2024 08:12:32 +0000 From: Bertrand Drouvot To: Masahiko Sawada Cc: Peter Smith , Peter Eisentraut , shveta malik , Amit Kapila , Bharath Rupireddy , pgsql-hackers@lists.postgresql.org Subject: Re: Add contrib/pg_logicalsnapinspect Message-ID: References: <6dd0f118-ce86-4b98-af2c-1319e1593a15@eisentraut.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Tue, Oct 08, 2024 at 10:52:11AM -0700, Masahiko Sawada wrote: > On Tue, Oct 8, 2024 at 9:25 AM Bertrand Drouvot > wrote: > > Thank you for updating the patch! I have some comments on v12 patch: Thanks for looking at it! > --- > + if (ondisk.builder.committed.xcnt > 0) > + { > + Datum *arrayelems; > + int narrayelems = 0; > + > + arrayelems = (Datum *) > palloc(ondisk.builder.committed.xcnt * sizeof(Datum)); > + > + for (; narrayelems < ondisk.builder.committed.xcnt; > narrayelems++) > + arrayelems[narrayelems] = > Int64GetDatum((int64) ondisk.builder.committed.xip[narrayelems]); > + > + values[i++] = > PointerGetDatum(construct_array_builtin(arrayelems, narrayelems, > INT8OID)); > + } > > Since committed_xip and catchange_xip are xid[], we should use > TransactionIdGetDatum() and XIDOID instead. I ended up using INT8OID because XIDOID is not part of the switch in construct_array_builtin() and so leads to: " ERROR: type 28 not supported by construct_array_builtin() " One option could be (did not test it) to add this switch in construct_array_builtin(): + case XIDOID: + elmlen = sizeof(TransactionId); + elmbyval = true; + elmalign = TYPALIGN_INT; + break; I think that could make sense and would probably need a dedicated patch for that, thoughts? > I think that it would be cleaner if we pass > ondisk.builder.committed.xcnt instead of construct_array_builtin to > construct_array_buildin(). That is, we can rewrite it as follows: > > for (int j = 0; j < ondisk.builder.committed.xcnt; j++) > arrayelems[j] = TransactionIdGetDatum(ondisk.builder.committed.xip[j]); > > values[i++] = PointerGetDatum(construct_array_builtin(arrayelems, > ondisk.builder.committed.xcnt, XIDOID)); Fine by me. Will do that in v13 with TransactionIdGetDatum/XIDOID or Int64GetDatum/INT8OID once we decide what to do with the above remark linked to construct_array_builtin(). > --- > +# Test the pg_logicalinspect functions: that needs some permutation to > +# ensure that we are creating multiple logical snapshots and that one of them > +# contains ongoing catalogs changes. > > If we use prepared transactions modifying catalog changes, can we > write the normal (i.e. not isolation check) tests? It would be easier > to write and add tests. > Not sure about this one. I think that the test is simple enough and mainly inspired by what can be found in the test_decoding module. We could still add "normal" (REGRESS) tests in the future should we add features to the pg_logicalinspect module that would require new tests. For example, test_decoding is using both kind of tests, what do you think? > --- > + tuple = heap_form_tuple(tupdesc, values, nulls); > + > + MemoryContextReset(context); > + > + PG_RETURN_DATUM(HeapTupleGetDatum(tuple)); > > I think we don't necessarily need to reset the memory context here. > Rather, I think we can just pass CurrentMemoryContext to > ValidateAndRestoreSnapshotFile() instead of passing the separate new > memory context. Yeah, we should be in a short-lived memory context here (ExprContext or such), so that's fine by me (will do in v13). > --- > + fd = OpenTransientFile(path, O_RDONLY | PG_BINARY); > + > + if (fd < 0) > + ereport(ERROR, > + (errcode_for_file_access(), > + errmsg("could not open file \"%s\": > %m", path))); > + > + context = AllocSetContextCreate(CurrentMemoryContext, > + > "logicalsnapshot inspect context", > + > ALLOCSET_DEFAULT_SIZES); > + > + /* Validate and restore the snapshot to 'ondisk' */ > + ValidateAndRestoreSnapshotFile(&ondisk, path, fd, context); > > It's a bit odd to me that this function opens a snapshot file and > passes both the file descriptor and file path. The file path is used > mostly only for error reporting in ValidateAndRestoreSnapshotFile(). Right. > I guess it would be cleaner if we pass the file path to > ValidateAndRestoreSnapshotFile() which opens and validates the > snapshot file. Since SnapBuildRestore() wants to get false if the > specified file doesn't exist, we can also add missing_ok argument to > ValidateAndRestoreSnapshotFile(). That is, the function will be like: > > void > ValidateAndRestoreSnapshotFile(SnapBuildOnDisk *ondisk, const char > *path, MemoryContext context, bool missing_ok) > { > : > fd = OpenTransientFile(path, O_RDONLY | PG_BINARY); > > if (fd < 0) > { > if (missing_ok && errno == ENOENT) > return false; > else > ereport(ERROR, > (errcode_for_file_access(), > errmsg("could not open file \"%s\": %m", path))); > } Yeah, it makes sense to move the OpenTransientFile() call in ValidateAndRestoreSnapshotFile(), will do in v13. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com