Map data pull over brick's nginx: X-Accel-Buffering: no on map files (buffered, nginx's 1 GB temp file cap ended every bigger download there); each attempt resumes from the part on disk (curl's --retry kept its first offset); a file that can't be written is skipped, not the whole run
This commit is contained in:
1 parent
62045be0f7
commit
5c023619ec
2 files changed
+21
-9
No files matched your search
@@ -921,6 +921,10 @@ module Maptool
|
|||||||
get "/api/sync/maps/file" do
|
get "/api/sync/maps/file" do
|
||||||
require_sync_token!
|
require_sync_token!
|
||||||
path = App.map_sync_files[params[:path].to_s] or halt 404
|
path = App.map_sync_files[params[:path].to_s] or halt 404
|
||||||
|
# Straight through brick's nginx: buffered, it spools the response to
|
||||||
|
# a temp file capped at 1 GB (proxy_max_temp_file_size) and a bigger
|
||||||
|
# file's download ended there.
|
||||||
|
headers "X-Accel-Buffering" => "no"
|
||||||
send_file path
|
send_file path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+17
-9
@@ -45,20 +45,28 @@ while IFS=$'\t' read -r size mtime path; do
|
|||||||
local_file="$DATA/$path"
|
local_file="$DATA/$path"
|
||||||
[ -f "$local_file" ] && [ "$(stat -c '%s %Y' "$local_file")" = "$size $mtime" ] && continue
|
[ -f "$local_file" ] && [ "$(stat -c '%s %Y' "$local_file")" = "$size $mtime" ] && continue
|
||||||
|
|
||||||
mkdir -p "$(dirname "$local_file")"
|
|
||||||
part="$local_file.part"
|
part="$local_file.part"
|
||||||
|
# One file that can't be written (a directory the container owns) is
|
||||||
|
# that file's failure, not the whole run's.
|
||||||
|
if ! mkdir -p "$(dirname "$local_file")" || ! touch "$part.version" 2>/dev/null; then
|
||||||
|
echo "pull-maps: can't write $local_file, skipping" >&2
|
||||||
|
failed=$((failed + 1))
|
||||||
|
continue
|
||||||
|
fi
|
||||||
# A partial download of another version of the file starts over.
|
# A partial download of another version of the file starts over.
|
||||||
[ "$(cat "$part.version" 2>/dev/null)" = "$size $mtime" ] || rm -f "$part"
|
[ "$(cat "$part.version" 2>/dev/null)" = "$size $mtime" ] && [ "$(stat -c %s "$part" 2>/dev/null || echo 0)" -le "$size" ] || rm -f "$part"
|
||||||
echo "$size $mtime" > "$part.version"
|
echo "$size $mtime" > "$part.version"
|
||||||
echo "pull-maps: $path ($((size / 1048576)) MB)"
|
echo "pull-maps: $path ($((size / 1048576)) MB)"
|
||||||
# Into a temp file, renamed when complete: the app and Valhalla keep
|
# Into a temp file, renamed when complete: the app and Valhalla keep
|
||||||
# reading the old copy until restarted.
|
# reading the old copy until restarted. Each attempt resumes from what's
|
||||||
if [ "$(stat -c %s "$part" 2>/dev/null || echo -1)" != "$size" ]; then
|
# there (curl's own --retry keeps its first offset); --speed-*: a
|
||||||
# --speed-*: a connection that went dead (Wi-Fi switched, proxy gone)
|
# connection that went dead (Wi-Fi switched) is dropped after a minute.
|
||||||
# is dropped after a minute without data and the retry resumes.
|
stalls=0
|
||||||
curl -fsS --retry 10 --retry-all-errors --retry-delay 5 --speed-limit 1024 --speed-time 60 -C - -o "$part" -H "@$auth" \
|
while have=$(stat -c %s "$part" 2>/dev/null || echo 0); [ "$have" -lt "$size" ] && [ "$stalls" -lt 5 ]; do
|
||||||
--get --data-urlencode "path=$path" "$server/api/sync/maps/file" || true
|
curl -fsS --retry 3 --retry-delay 5 --speed-limit 1024 --speed-time 60 -C - -o "$part" -H "@$auth" \
|
||||||
fi
|
--get --data-urlencode "path=$path" "$server/api/sync/maps/file" || sleep 5
|
||||||
|
[ "$(stat -c %s "$part" 2>/dev/null || echo 0)" -gt "$have" ] && stalls=0 || stalls=$((stalls + 1))
|
||||||
|
done
|
||||||
if [ "$(stat -c %s "$part" 2>/dev/null || echo -1)" = "$size" ]; then
|
if [ "$(stat -c %s "$part" 2>/dev/null || echo -1)" = "$size" ]; then
|
||||||
touch -d "@$mtime" "$part"
|
touch -d "@$mtime" "$part"
|
||||||
mv "$part" "$local_file"
|
mv "$part" "$local_file"
|
||||||
|
|||||||
Reference in new issue
Block a user