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 1nY9Az-0003gl-Ui for pgsql-hackers@arkaria.postgresql.org; Sat, 26 Mar 2022 16:22:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nY9Ay-0001Am-9M for pgsql-hackers@arkaria.postgresql.org; Sat, 26 Mar 2022 16:22:04 +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 1nY9Ax-0001Ac-Qc for pgsql-hackers@lists.postgresql.org; Sat, 26 Mar 2022 16:22:04 +0000 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nY9Au-0001Ti-6Z for pgsql-hackers@lists.postgresql.org; Sat, 26 Mar 2022 16:22:03 +0000 Received: by mail-io1-xd36.google.com with SMTP id h63so12233768iof.12 for ; Sat, 26 Mar 2022 09:21:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=dyzQFc1HDzZFEvJlxi73kMT8ukOeaAzuohos09q4noc=; b=OvFY2o6gE2UhMvbkStzimDcUdbn460kaQ8YUzcmbdS59Ty3oLArMMwoQXgl6vpxh7o +ySUMsUX6/XBhmlgdo0LWLVEwqI2K8W+DEwr7nv2I9w7YrLmxFWZC7W0MYKBpX2ZdUxL VCcqwUrl+DWsOMEOEKgVMm2AXu0cSV0Z6JdE8O+eKXOOYZfa3pZJQjYIsWpXHrB9MhHg a7D3JgBE79+wCwyh60HtInH1w6Nu7/a0l6mJm5n1ow3ZmcEGcGuq5uviNw/XA01NF6Fm ov47skUEkoTJ2oh77zgg9kuFVPvEG0njwo92lvUdVOQF04aLvoyu/YbMZr6RlgOpYeSu zGhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=dyzQFc1HDzZFEvJlxi73kMT8ukOeaAzuohos09q4noc=; b=o4asQE6qFq2tlmzCg8tiiIzGxPH+2VVAK95aT1RY00kir5oyLBDxMhz+TXfX+ev62j LbgY4Ty5qXfGByuT1m3L/sCdZ9bLYN43OyD//zhIhsiJ6k5YepG9mayAdFB5YFOYxaup 3aHhd8osdGBMfO3h1KxBQP5RjPj4B40L7YpyhSdBnOuGZ6IyzaPHXpB3z3IQnJ0139X0 hlfgoL8LVWwYr7fg39x+aT2vcfkQy5hqNJ+h3bqSkTOl3PiXiepOsUbRyaFCU0noShOa FLpLsml0MsinScQnkELhVfXB+Jc8YgiFqGxVoPpv78o6qXMXzhTl/UBovMKnDC0ft6iC gzuQ== X-Gm-Message-State: AOAM531ATeRiT2hCXfkUi1h3x8CBy9G6ogs+uka2NAtyMOp+AJrhGAeQ JB66efapeNnz3PFIyatLyZEMlw== X-Google-Smtp-Source: ABdhPJwmCJ9II+dEQMtCojnyVz6PmOWrRAOM2MtJedMIhSKsdots6iSCj9VDau3EuEtCZ1Odn3P9ZQ== X-Received: by 2002:a05:6638:3592:b0:319:99da:3323 with SMTP id v18-20020a056638359200b0031999da3323mr8888035jal.58.1648311717873; Sat, 26 Mar 2022 09:21:57 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id n35-20020a056602342300b006115627b87csm470189ioz.55.2022.03.26.09.21.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Mar 2022 09:21:57 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 9789F800BC8; Sat, 26 Mar 2022 11:21:56 -0500 (CDT) Date: Sat, 26 Mar 2022 11:21:56 -0500 From: Justin Pryzby To: Georgios Cc: pgsql-hackers@lists.postgresql.org, Rachel Heaton Subject: Re: Add LZ4 compression in pg_dump Message-ID: <20220326162156.GI28503@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk LZ4F_HEADER_SIZE_MAX isn't defined in old LZ4. I ran into that on an ubuntu LTS, so I don't think it's so old that it shouldn't be handled more gracefully. LZ4 should either have an explicit version check, or else shouldn't depend on that feature (or should define a safe fallback version if the library header doesn't define it). https://packages.ubuntu.com/liblz4-1 0003: typo: of legacy => or legacy There are a large number of ifdefs being added here - it'd be nice to minimize that. basebackup was organized to use separate files, which is one way. $ git grep -c 'ifdef .*LZ4' src/bin/pg_dump/compress_io.c src/bin/pg_dump/compress_io.c:19 In last year's CF entry, I had made a union within CompressorState. LZ4 doesn't need z_streamp (and ztsd will need ZSTD_outBuffer, ZSTD_inBuffer, ZSTD_CStream). 0002: I wonder if you're able to re-use any of the basebackup parsing stuff from commit ffd53659c. You're passing both the compression method *and* level. I think there should be a structure which includes both. In the future, that can also handle additional options. I hope to re-use these same things for wal_compression=method:level. You renamed this: |- COMPR_ALG_LIBZ |-} CompressionAlgorithm; |+ COMPRESSION_GZIP, |+} CompressionMethod; ..But I don't think that's an improvement. If you were to change it, it should say something like PGDUMP_COMPRESS_ZLIB, since there are other compression structs and typedefs. zlib is not idential to gzip, which uses a different header, so in WriteDataToArchive(), LIBZ is correct, and GZIP is incorrect. The cf* changes in pg_backup_archiver could be split out into a separate commit. It's strictly a code simplification - not just preparation for more compression algorithms. The commit message should "See also: bf9aa490db24b2334b3595ee33653bf2fe39208c". The changes in 0002 for cfopen_write seem insufficient: |+ if (compressionMethod == COMPRESSION_NONE) |+ fp = cfopen(path, mode, compressionMethod, 0); | else | { | #ifdef HAVE_LIBZ | char *fname; | | fname = psprintf("%s.gz", path); |- fp = cfopen(fname, mode, compression); |+ fp = cfopen(fname, mode, compressionMethod, compressionLevel); | free_keep_errno(fname); | #else The only difference between the LIBZ and uncompressed case is the file extension, and it'll be the only difference with LZ4 too. So I suggest to first handle the file extension, and the rest of the code path is not conditional on the compression method. I don't think cfopen_write even needs HAVE_LIBZ - can't you handle that in cfopen_internal() ? This patch rejects -Z0, which ought to be accepted: ./src/bin/pg_dump/pg_dump -h /tmp regression -Fc -Z0 |wc pg_dump: error: can only specify -Z/--compress [LEVEL] when method is set Your 0003 patch shouldn't reference LZ4: +#ifndef HAVE_LIBLZ4 + if (*compressionMethod == COMPRESSION_LZ4) + supports_compression = false; +#endif The 0004 patch renames zlibOutSize to outsize - I think the patch series should be constructed such as to minimize the size of the method-specific patches. I say this anticipating also adding support for zstd. The preliminary patches should have all the boring stuff. It would help for reviewing to keep the patches split up, or to enumerate all the boring things that are being renamed (like change OutputContext to cfp, rename zlibOutSize, ...). 0004: The include should use and not "lz4.h" freebsd/cfbot is failing. I suggested off-list to add an 0099 patch to change LZ4 to the default, to exercise it more on CI. -- Justin