Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pKjZy-0005Th-UK for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Jan 2023 17:28:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pKjZx-00016q-OD for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Jan 2023 17:28:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pKjZx-00016h-CP for pgsql-hackers@lists.postgresql.org; Wed, 25 Jan 2023 17:28:57 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pKjZu-0005db-AZ for pgsql-hackers@lists.postgresql.org; Wed, 25 Jan 2023 17:28:56 +0000 Received: by mail-wr1-x42c.google.com with SMTP id z5so17796903wrt.6 for ; Wed, 25 Jan 2023 09:28:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=R6XdkqT2oYoMucjdWdyTc6jPlCKTVK7S0/eNrqDZTDU=; b=mG0GecZPBk3OESK4lJlR1muudVkkxh6KPfRFUMwtBWbAVn7leRH3RUR617j2cDCRV/ 9UCGpYAdlUBlBnoRjLgoHIMcQCZ8qlbTcIgpDf5Y/DQ8bipOP45vgvftJv3huVj52BWl 3AmhWoqwJJ+CqzZYgqWG44zdFskGxGXFCv4RymeVFGH65JlASgRdYxLhVyi0m1vd40aK IopokyoV9gFv5UYB8cEiZjxKE63z6VXVVdiOx1YhicrQhqTPtRMHhYnL5XOO92oc8JZd RMGPf6aJWv+wcqBfdPwn3TsdUHuVRDFgmGmCHLSoUt7YVBK7iro2KcB/uyTJIZt5T3co 0mbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=R6XdkqT2oYoMucjdWdyTc6jPlCKTVK7S0/eNrqDZTDU=; b=IugLHxygaBmo6diSqGJfwMAtrHRCUUv6gVYgITRIoKumkEWEi1ZrcWp9YUMdQ1AwIO I+RukWfQnukwjawZez3cO9ahUcnXWaJ8TccAqkMnNxcSXUa8YHw57Fbp7/kiyegidSX4 Al59IQN/D/jCC02uGbSruVmlxKTiHz4N2P+ZYPGy54s+q1XaHmPtu8CPTOirnafemkfv ZP+L+d1qnNRR0tLAk0P7SwvzK0Q7LOidtxrIE+NX+2AawHeBSbMxSX42i8rMHi+Bw94Q Kf0gvz+v1vNGFARqvYeIKtr5oyokuPQtFOSKWVKbQoJTi41q4LI8DhEN+iMf+da6Xt/Q WTaw== X-Gm-Message-State: AFqh2kp4JkyLvl+YkGrSGvws9AqwX0fxl8FO8QwALGPsZrS3oSEfu3KB RSaquXI4ulNKa/vGKUJKH27j8VF6vwwSnyDq+DLfF3ciRP8gLxSAOZSSw1pkdS+W+ThLCDiC00O PSbrfcbBIhuZGS0GEuwzV+PFidRlkXyeMDHU8PRE6430KvAQu5Rjf9O1h+4HY98jZFNfUxqRiTE S2YngkVjg+v2RhiKW0I87hVhciyIGN6Lma4V5Z9i85a6qCjppgZ8RiaANRxARSbX2M3OKRzN5Mr rPJiJ+qCBf4oPwvIOVnwcgqIc23+lR+OeWranb4RyIYHBTPpc8HntStuSTa X-Google-Smtp-Source: AMrXdXvSRsJxBl0dieAvRUPeF2yA4eWl/LfaUfbdRxLksmAGnKVgXqYwi0TPfGLB+Wt+lgRBMWL1Zg== X-Received: by 2002:a05:6000:781:b0:2be:3ccd:7f34 with SMTP id bu1-20020a056000078100b002be3ccd7f34mr20378735wrb.37.1674667731260; Wed, 25 Jan 2023 09:28:51 -0800 (PST) Received: from [10.137.0.17] (static-84-42-175-93.bb.vodafone.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id j26-20020a5d453a000000b002bdf3809f59sm4962442wra.38.2023.01.25.09.28.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Jan 2023 09:28:50 -0800 (PST) Message-ID: <15b255d0-8868-a020-f6a9-7324f82a28b6@enterprisedb.com> Date: Wed, 25 Jan 2023 18:28:49 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: Add LZ4 compression in pg_dump To: gkokolatos@pm.me, Justin Pryzby Cc: Michael Paquier , pgsql-hackers@lists.postgresql.org, Rachel Heaton References: <6ab89d42-0345-b96e-02d4-68e171cdbe03@enterprisedb.com> <7zu6GYFi72jByVk2SEe_nd8r1DHhwA35vSntAE9sAfiMX9Lfk6bwimkwmu7GDgYaEvL27SE4qF1uK4_LHWQM4H-SXOwkMAI-GV8PKGmED_E=@pm.me> <20230123180014.GX13860@telsasoft.com> <20230125014203.GL13860@telsasoft.com> <-myGeDiZ-ePDRyi18026Iu2HTTfmwfjWaJn4OWJ2F3oglZUfJTOQ7FARPW7gYxE4vK3b0HpwYoiHR45nfOWReRvvJZfCBfJzPP5iJyn4muk=@pm.me> Content-Language: en-US From: Tomas Vondra In-Reply-To: <-myGeDiZ-ePDRyi18026Iu2HTTfmwfjWaJn4OWJ2F3oglZUfJTOQ7FARPW7gYxE4vK3b0HpwYoiHR45nfOWReRvvJZfCBfJzPP5iJyn4muk=@pm.me> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/25/23 16:37, gkokolatos@pm.me wrote: > > > > > > ------- Original Message ------- > On Wednesday, January 25th, 2023 at 2:42 AM, Justin Pryzby wrote: > > >> >> >> On Tue, Jan 24, 2023 at 03:56:20PM +0000, gkokolatos@pm.me wrote: >> >>> On Monday, January 23rd, 2023 at 7:00 PM, Justin Pryzby pryzby@telsasoft.com wrote: >>> >>>> On Mon, Jan 23, 2023 at 05:31:55PM +0000, gkokolatos@pm.me wrote: >>>> >>>>> Please find attached v23 which reintroduces the split. >>>>> >>>>> 0001 is reworked to have a reduced footprint than before. Also in an attempt >>>>> to facilitate the readability, 0002 splits the API's and the uncompressed >>>>> implementation in separate files. >>>> >>>> Thanks for updating the patch. Could you address the review comments I >>>> sent here ? >>>> https://www.postgresql.org/message-id/20230108194524.GA27637%40telsasoft.com >>> >>> Please find v24 attached. >> >> >> Thanks for updating the patch. >> >> In 001, RestoreArchive() does: >> >>> -#ifndef HAVE_LIBZ >>> - if (AH->compression_spec.algorithm == PG_COMPRESSION_GZIP && >>> - AH->PrintTocDataPtr != NULL) >>> + supports_compression = false; >>> + if (AH->compression_spec.algorithm == PG_COMPRESSION_NONE || >>> + AH->compression_spec.algorithm == PG_COMPRESSION_GZIP) >>> + supports_compression = true; >>> + >>> + if (AH->PrintTocDataPtr != NULL) >>> { >>> for (te = AH->toc->next; te != AH->toc; te = te->next) >>> { >>> if (te->hadDumper && (te->reqs & REQ_DATA) != 0) >>> - pg_fatal("cannot restore from compressed archive (compression not supported in this installation)"); >>> + { >>> +#ifndef HAVE_LIBZ >>> + if (AH->compression_spec.algorithm == PG_COMPRESSION_GZIP) >>> + supports_compression = false; >>> +#endif >>> + if (supports_compression == false) >>> + pg_fatal("cannot restore from compressed archive (compression not supported in this installation)"); >>> + } >>> } >>> } >>> -#endif >> >> >> This first checks if the algorithm is implemented, and then checks if >> the algorithm is supported by the current build - that confused me for a >> bit. It seems unnecessary to check for unimplemented algorithms before >> looping. That also requires referencing both GZIP and LZ4 in two >> places. > > I am not certain that it is unnecessary, at least not in the way that is > described. The idea is that new compression methods can be added, without > changing the archive's version number. It is very possible that it is > requested to restore an archive compressed with a method not implemented > in the current binary. The first check takes care of that and sets > supports_compression only for the supported versions. It is possible to > enter the loop with supports_compression already set to false, for example > because the archive was compressed with ZSTD, triggering the fatal error. > > Of course, one can throw the error before entering the loop, yet I think > that it does not help the readability of the code. IMHO it is easier to > follow if the error is thrown once during that check. > Actually, I don't understand why 0001 moves the check into the loop. I mean, why not check HAVE_LIBZ before the loop? >> >> I think it could be written to avoid the need to change for added >> compression algorithms: >> >> + if (te->hadDumper && (te->reqs & REQ_DATA) != 0) >> >> + { >> + /* Check if the compression algorithm is supported */ >> + pg_compress_specification spec; >> + parse_compress_specification(AH->compression_spec.algorithm, NULL, &spec); >> >> + if (spec->parse_error != NULL) >> >> + pg_fatal(spec->parse_error); >> >> + } > > I am not certain how that would work in the example with ZSTD above. > If I am not wrong, parse_compress_specification() will not throw an error > if the codebase supports ZSTD, yet this specific pg_dump binary will not > support it because ZSTD is not implemented. parse_compress_specification() > is not aware of that and should not be aware of it, should it? > Not sure. What happens in a similar situation now? That is, when trying to deal with an archive gzip-compressed in a build without libz? regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company