summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Holley <willholley@gmail.com>2017-09-12 18:28:29 +0100
committerGitHub <noreply@github.com>2017-09-12 18:28:29 +0100
commitef8a934c1ca67092b06f0cee2e01871013bae4e5 (patch)
tree55973db1327d4bd6f001c39b16efaf65213f5e7d
parentcf00dc26447ed44d3a8be0d77e4923367b02bb6b (diff)
downloadcouchdb-ef8a934c1ca67092b06f0cee2e01871013bae4e5.tar.gz
Do not crash when free space cannot be calculated (#803)
If the compaction daemon cannot calculate the free space for a volume, do not crash CouchDB. Instead, log a warning that free space could not be calculated and continue. Compaction of the database is not necessarily prevented - just that the disk space for this specific volume won't be taken into account when deciding whether to automatically compact or not. This is primarily to cope with edge cases arising from ERL-343, whereby disksup:get_disk_data() returns invalid paths for volumes containing whitespace. Fixes #732
-rw-r--r--src/couch/src/couch_compaction_daemon.erl44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/couch/src/couch_compaction_daemon.erl b/src/couch/src/couch_compaction_daemon.erl
index 8f95eb21e..024b867d0 100644
--- a/src/couch/src/couch_compaction_daemon.erl
+++ b/src/couch/src/couch_compaction_daemon.erl
@@ -509,34 +509,46 @@ free_space(Path) ->
length(filename:split(PathA)) > length(filename:split(PathB))
end,
disksup:get_disk_data()),
- free_space_rec(abs_path(Path), DiskData).
+ {ok, AbsPath} = abs_path(Path),
+ free_space_rec(AbsPath, DiskData).
free_space_rec(_Path, []) ->
undefined;
free_space_rec(Path, [{MountPoint0, Total, Usage} | Rest]) ->
- MountPoint = abs_path(MountPoint0),
- case MountPoint =:= string:substr(Path, 1, length(MountPoint)) of
- false ->
- free_space_rec(Path, Rest);
- true ->
- trunc(Total - (Total * (Usage / 100))) * 1024
+ case abs_path(MountPoint0) of
+ {ok, MountPoint} ->
+ case MountPoint =:= string:substr(Path, 1, length(MountPoint)) of
+ false ->
+ free_space_rec(Path, Rest);
+ true ->
+ trunc(Total - (Total * (Usage / 100))) * 1024
+ end;
+ {error, Reason} ->
+ couch_log:warning("Compaction daemon - unable to calculate free space"
+ " for `~s`: `~s`",
+ [MountPoint0, Reason]),
+ free_space_rec(Path, Rest)
end.
abs_path(Path0) ->
- {ok, Info} = file:read_link_info(Path0),
- case Info#file_info.type of
- symlink ->
- {ok, Path} = file:read_link(Path0),
- abs_path(Path);
- _ ->
- abs_path2(Path0)
+ case file:read_link_info(Path0) of
+ {ok, Info} ->
+ case Info#file_info.type of
+ symlink ->
+ {ok, Path} = file:read_link(Path0),
+ abs_path(Path);
+ _ ->
+ abs_path2(Path0)
+ end;
+ {error, Reason} ->
+ {error, Reason}
end.
abs_path2(Path0) ->
Path = filename:absname(Path0),
case lists:last(Path) of
$/ ->
- Path;
+ {ok, Path};
_ ->
- Path ++ "/"
+ {ok, Path ++ "/"}
end.