]> git.scottworley.com Git - annex-ec/commitdiff
Use more blocks on huge files.
authorScott Worley <scottworley@scottworley.com>
Wed, 18 Mar 2026 09:20:04 +0000 (02:20 -0700)
committerScott Worley <scottworley@scottworley.com>
Wed, 18 Mar 2026 09:20:04 +0000 (02:20 -0700)
Otherwise, during recovery, par2 sometimes fails to read huge blocks
with 'Cannot allocate memory' errors.

annex-ec

index d569fcc301eaae92e0605d618db3a116702b4d45..474175934b16f1b7f3c0b987133d653c777623d5 100755 (executable)
--- a/annex-ec
+++ b/annex-ec
@@ -49,15 +49,17 @@ make_name() {
 
 volumes=()
 redundancy=1
 
 volumes=()
 redundancy=1
+max_block_size=$((128*1024*1024))
 block_size_is_a_multiple_of=4  # par2 requires that this be at least 4
 blocks_per_file=10
 block_size_is_a_multiple_of=4  # par2 requires that this be at least 4
 blocks_per_file=10
-while getopts b:m:r:v: opt;do
+while getopts b:m:r:v:x: opt;do
  case $opt in
   b)    blocks_per_file=$OPTARG;;
   m)    block_size_is_a_multiple_of=$OPTARG;;
   r)    redundancy=$OPTARG;;
   v)    parse_volume_list "$OPTARG";;
  case $opt in
   b)    blocks_per_file=$OPTARG;;
   m)    block_size_is_a_multiple_of=$OPTARG;;
   r)    redundancy=$OPTARG;;
   v)    parse_volume_list "$OPTARG";;
-  *)    echo 'usage: annex-ec [-v remote1,remote2,...] [-r N] file file...' >&2; exit 1;;
+  x)    max_block_size=$OPTARG;;
+  *)    echo 'usage: annex-ec [-v remote1,remote2,...] [-r N] [-b N] [-x N] [-m N] file file...' >&2; exit 1;;
  esac
 done
 shift $((OPTIND - 1))
  esac
 done
 shift $((OPTIND - 1))
@@ -74,7 +76,11 @@ N=$((${#volumes[@]} - redundancy))
 git annex get -- "$@"
 
 max_size=$(find -L "$@" -printf '%s\n' | sort -nr | head -n1)
 git annex get -- "$@"
 
 max_size=$(find -L "$@" -printf '%s\n' | sort -nr | head -n1)
-block_size=$(( ((max_size/(block_size_is_a_multiple_of*blocks_per_file))+1) * block_size_is_a_multiple_of))
+while true;do
+  block_size=$(( ((max_size/(block_size_is_a_multiple_of*blocks_per_file))+1) * block_size_is_a_multiple_of))
+  if (( block_size < max_block_size ));then break;fi
+  blocks_per_file=$((blocks_per_file + 1))
+done
 
 make_name "$@"
 
 
 make_name "$@"