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 1sz3gm-003xL5-0w for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Oct 2024 00:39:28 +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 1sz3gi-00ANsF-KN for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Oct 2024 00:39:24 +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 1sz3gi-00ANs7-AK for pgsql-hackers@lists.postgresql.org; Fri, 11 Oct 2024 00:39:24 +0000 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sz3ge-000QdS-Mi for pgsql-hackers@lists.postgresql.org; Fri, 11 Oct 2024 00:39:23 +0000 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2fb18f14242so14482531fa.3 for ; Thu, 10 Oct 2024 17:39:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728607161; x=1729211961; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=NWkVIlpXULbGqWRejL+RH+MF6lRMAbg+D2Mu52Cb4dc=; b=Qsr9Ogu0YWvxmK23PVqXj03agFQ0D5f7wePGyheLKziX8znglrfetQRLWOOd7Ldnay DxQNmAEHyFERr4/uLWz4IzED8/+E4aJYSMqw0fAdgDi1QGRtRkViq94QUE7bN2hiOTU4 /eFr054AqiRar4D7tYzhhkNBLt8IHsnmo6jGFAcotizk/VqDWMZzwd8xUBQhPhpHTl4g bsFzaWo6tB0f7ZXkEvu9F1Gg7ooao1lFLEGgdZVmgETC6d6O7qCk+9XBrer/rhzhtCof 2/28940oBChbrTRRLb5/Mml5Z2lDHXZLPbNmwW490aTnRR8Ptw7vMnf3ETTwd3rJq6A0 wCaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728607161; x=1729211961; h=content-transfer-encoding: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=NWkVIlpXULbGqWRejL+RH+MF6lRMAbg+D2Mu52Cb4dc=; b=JPQIv6sawHAzTHi/4UzniuDG5MVWYqm6+mKpL5J+syii25YEOyqCP5ASUTX8AQIBIF 09LKu5MbzSb1IfZyPtnc93uwymLScjSS/AL/iNx17jYiuyN//1cOim1su2cWs67TtVo+ OoXVoFbXvqOIhL5XsgvTv0LU8UMsS1lXbUon0X/DSLG6VXlu2KKCWU0YRdgI4JhMkpC7 DETfgubgy2GTS5XJGR9RadnvYbk38icYZ68v+h0WJO06oc1UrAcq4apzk8DZKSHmNHGY xkBmYctssh/a6Y/t4oCTerGZinrjIAO8lLqxIndTIR+CR5PijFpGMUKNSEq6kU6OpOfr YkYw== X-Forwarded-Encrypted: i=1; AJvYcCU01Qn/zFXXDh7HT35E3EmQxguPcCBKnZh2Jn0ynpRYU2riohZoGJCK0ptW67yQgqTkbdvGn8YzU6ns6FNz@lists.postgresql.org X-Gm-Message-State: AOJu0Yz/lXZm33E+CNT5AMM2fTGkWvYGG270x7lApseSKzQ2QfDpHq5O 0Rara0UBp99rwrMxlYFpSU3MJf68XsoMW51/vlTI3hdQDLn1r4+NvaYTPsXQRT7YxSZtDaw19GR QvkQIrlaty5EtftbC59Fku0rBY9/RDw== X-Google-Smtp-Source: AGHT+IE89LCWITA9xBPTtekOcWyUowEwb8ANLHNFyKjptGJ+ClnheAVqbzCf/BE6Bk4aVfZUxMZwlHew+Zw39/tBA+k= X-Received: by 2002:a05:6512:3b0f:b0:535:6ad6:2d40 with SMTP id 2adb3069b0e04-539da3b4410mr234696e87.11.1728607160407; Thu, 10 Oct 2024 17:39:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Masahiko Sawada Date: Thu, 10 Oct 2024 17:38:43 -0700 Message-ID: Subject: Re: Add contrib/pg_logicalsnapinspect To: Bertrand Drouvot Cc: Peter Smith , Peter Eisentraut , shveta malik , Amit Kapila , Bharath Rupireddy , pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Oct 10, 2024 at 6:10=E2=80=AFAM Bertrand Drouvot wrote: > > Hi, > > On Thu, Oct 10, 2024 at 12:05:10AM -0700, Masahiko Sawada wrote: > > On Wed, Oct 9, 2024 at 8:32=E2=80=AFPM Bertrand Drouvot > > wrote: > > > So I think that having construct_array_builtin()/deconstruct_array_bu= iltin() > > > taking care of XIDOID is the way to go. If that makes sense to you th= en I'll > > > submit a dedicated patch for it, thoughts? > > > > Your explanation makes sense to me. > > Thanks for sharing your thoughts. > > > I think it can be included in the main pg_logicalinspect patch as this = change > > is a part of it. > > Okay, let's keep the discussion here. Please find attached v13 that takes= care > of your previous remarks and Peter's one ([1]). > > FYI, v13 is splitted into 2 sub-patches (0001 for the discussion related = to > XIDOID and construct_array_builtin() and 0002 for the module itself). Thank you for updating the patch! > > FWIW, the elmbyval and elmalign values that are added in 0001 have been d= educed > from: > > postgres=3D# select typbyval, typalign from pg_type where typname =3D 'xi= d'; > typbyval | typalign > ----------+---------- > t | i > (1 row) +1 The patches mostly look good to me. Here are some minor comments: + sprintf(path, "%s/%s", + PG_LOGICAL_SNAPSHOTS_DIR, + text_to_cstring(filename_t)); + + /* Validate and restore the snapshot to 'ondisk' */ + ValidateAndRestoreSnapshotFile(&ondisk, path, CurrentMemoryContext, false); + + /* Build a tuple descriptor for our result type */ + if (get_call_result_type(fcinfo, NULL, &tupdesc) !=3D TYPEFUNC_COMP= OSITE) + elog(ERROR, "return type must be a row type"); + I think it would be better to check the result type before reading the snapshot file. --- + values[i++] =3D Int64GetDatum((int64) ondisk.checksum); Why is only checksum casted to int64? With that, it can show a checksum value as a non-netagive integer but is it really necessary? For instance, page_header() function in pageinspect shows a page checksum as smallint. ---@@ -0,0 +1,4 @@ +# Generated subdirectories +/log/ +/results/ +/tmp_check/ output_iso and tmp_check_iso should be added. --- /* - * Restore a snapshot into 'builder' if previously one has been stored at = the - * location indicated by 'lsn'. Returns true if successful, false otherwis= e. + * Validate the logical snapshot file and read its contents to 'ondisk'. */ -static bool -SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn) +bool +ValidateAndRestoreSnapshotFile(SnapBuildOnDisk *ondisk, const char *path, + MemoryContext context, bool missing_ok) I think it would be better to add some descriptions of the function arguments, particularly context and missing_ok. The names of all other functions in snapbuild.c have the "SnapBuild" prefix. I think it's better to follow it. How about renaming it to SnapBuildReadSnapshot(), SnapBuildRestoreSnapshot(), or something along those lines? Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com