Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.5x speed increase by using cmp instead of crc32 #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions zfs-inplace-rebalancing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,51 +137,46 @@ function rebalance() {
# Linux

# file attributes
original_checksum=$(lsattr "${file_path}")
original_perms=$(lsattr "${file_path}")
# remove anything after the last space
original_checksum=${original_checksum% *}
original_perms=${original_perms% *}
# file permissions, owner, group, size, modification time
original_checksum="${original_checksum} $(stat -c "%A %U %G %s %Y" "${file_path}")"
# file content
original_checksum="${original_checksum} $(cksum "${file_path}")"
original_perms="${original_perms} $(stat -c "%A %U %G %s %Y" "${file_path}")"


# file attributes
copy_checksum=$(lsattr "${tmp_file_path}")
copy_perms=$(lsattr "${tmp_file_path}")
# remove anything after the last space
copy_checksum=${copy_checksum% *}
copy_perms=${copy_perms% *}
# file permissions, owner, group, size, modification time
copy_checksum="${copy_checksum} $(stat -c "%A %U %G %s %Y" "${tmp_file_path}")"
# file content
copy_checksum="${copy_checksum} $(cksum "${file_path}")"
# remove the temporary extension
copy_checksum=${copy_checksum%"${tmp_extension}"}
copy_perms="${copy_perms} $(stat -c "%A %U %G %s %Y" "${tmp_file_path}")"
elif [[ "${OSName}" == "darwin"* ]] || [[ "${OSName}" == "freebsd"* ]]; then
# Mac OS
# FreeBSD

# note: no lsattr on Mac OS or FreeBSD

# file permissions, owner, group size, modification time
original_checksum="$(stat -f "%Sp %Su %Sg %z %m" "${file_path}")"
# file content
original_checksum="${original_checksum} $(cksum "${file_path}")"
original_perms="$(stat -f "%Sp %Su %Sg %z %m" "${file_path}")"

# file permissions, owner, group size, modification time
copy_checksum="$(stat -f "%Sp %Su %Sg %z %m" "${tmp_file_path}")"
# file content
copy_checksum="${copy_checksum} $(cksum "${file_path}")"
# remove the temporary extension
copy_checksum=${copy_checksum%"${tmp_extension}"}
copy_perms="$(stat -f "%Sp %Su %Sg %z %m" "${tmp_file_path}")"
else
echo "Unsupported OS type: $OSTYPE"
exit 1
fi

if [[ "${original_checksum}" == "${copy_checksum}"* ]]; then
color_echo "${Green}" "Checksum OK"
if [[ "${original_perms}" == "${copy_perms}"* ]] && cmp -s "${file_path}" "${tmp_file_path}"; then
color_echo "${Green}" "Attribute and permission check OK"
else
color_echo "${Red}" "Checksum FAILED: ${original_checksum} != ${copy_checksum}"
color_echo "${Red}" "Attribute and permission check FAILED: ${original_perms} != ${copy_perms}"
exit 1
fi

if cmp -s "${file_path}" "${tmp_file_path}"; then
color_echo "${Green}" "File content check OK"
else
color_echo "${Red}" "File content check FAILED"
exit 1
fi
fi
Expand Down
Loading