Add ability to recompress send streams with new compression algorithm

As new compression algorithms are added to ZFS, it could be useful for 
people to recompress data with new algorithms. There is currently no 
mechanism to do this aside from copying the data manually into a new 
filesystem with the new algorithm enabled. This tool allows the 
transformation to happen through zfs send, allowing it to be done 
efficiently to remote systems and in an incremental fashion.

A new zstream command is added that decompresses WRITE records and 
then recompresses them with a provided algorithm, and then re-emits 
the modified send stream. It may also be possible to re-compress 
embedded block pointers, but that was not attempted for the initial 
version.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Paul Dagnelie <pcd@delphix.com>
Closes #14106
This commit is contained in:
Paul Dagnelie
2022-11-10 15:23:46 -08:00
committed by GitHub
parent e9ab9e512c
commit 9f4ede63d2
7 changed files with 451 additions and 6 deletions
+6 -6
View File
@@ -838,12 +838,12 @@ tests = ['recv_dedup', 'recv_dedup_encrypted_zvol', 'rsend_001_pos',
'rsend_026_neg', 'rsend_027_pos', 'rsend_028_neg', 'rsend_029_neg',
'rsend_030_pos', 'send-c_verify_ratio', 'send-c_verify_contents',
'send-c_props', 'send-c_incremental', 'send-c_volume',
'send-c_zstreamdump', 'send-c_lz4_disabled', 'send-c_recv_lz4_disabled',
'send-c_mixed_compression', 'send-c_stream_size_estimate',
'send-c_embedded_blocks', 'send-c_resume', 'send-cpL_varied_recsize',
'send-c_recv_dedup', 'send-L_toggle', 'send_encrypted_hierarchy',
'send_encrypted_props', 'send_encrypted_truncated_files',
'send_freeobjects', 'send_realloc_files',
'send-c_zstream_recompress', 'send-c_zstreamdump', 'send-c_lz4_disabled',
'send-c_recv_lz4_disabled', 'send-c_mixed_compression',
'send-c_stream_size_estimate', 'send-c_embedded_blocks', 'send-c_resume',
'send-cpL_varied_recsize', 'send-c_recv_dedup', 'send-L_toggle',
'send_encrypted_hierarchy', 'send_encrypted_props',
'send_encrypted_truncated_files', 'send_freeobjects', 'send_realloc_files',
'send_realloc_encrypted_files', 'send_spill_block', 'send_holds',
'send_hole_birth', 'send_mixed_raw', 'send-wR_encrypted_zvol',
'send_partial_dataset', 'send_invalid', 'send_doall',
@@ -0,0 +1,58 @@
#!/bin/ksh -p
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
#
# Copyright (c) 2022 by Delphix. All rights reserved.
#
. $STF_SUITE/tests/functional/rsend/rsend.kshlib
. $STF_SUITE/include/math.shlib
#
# Description:
# Verify compression features show up in zstream dump
#
# Strategy:
# 1. Create a compressed send stream
# 2. Recompress the stream with a different algorithm
# 3. Verify it can be received correctly
# 4. Verify the contents match the original filesystem
# 5. Create an uncompressed send stream
# 6. Compress the send stream
# 7. Verify that the stream is smaller when compressed
#
verify_runnable "both"
log_assert "Verify zstream recompress correctly modifies send streams."
log_onexit cleanup_pool $POOL2
typeset sendfs=$POOL2/fs
typeset recvfs=$POOL2/fs2
log_must zfs create -o compress=lz4 $sendfs
typeset dir=$(get_prop mountpoint $sendfs)
write_compressible $dir 16m
log_must zfs snapshot $sendfs@snap
log_must eval "zfs send -c $sendfs@snap | zstream recompress gzip-1 | zfs recv $recvfs"
typeset recvdir=$(get_prop mountpoint $recvfs)
log_must diff -r $dir $recvdir
log_must eval "zfs send $sendfs@snap >$BACKDIR/uncompressed"
log_must zstream recompress gzip-1 <$BACKDIR/uncompressed >$BACKDIR/compressed
typeset uncomp_size=$(wc -c $BACKDIR/uncompressed | awk '{print $1}')
typeset comp_size=$(wc -c $BACKDIR/compressed | awk '{print $1}')
[[ "$uncomp_size" -gt "$comp_size" ]] || log_fail "recompressed stream was not smaller"
log_pass "zstream recompress correctly modifies send streams."