summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Lehnardt <jan@apache.org>2018-03-09 11:37:26 +0100
committerJan Lehnardt <jan@apache.org>2018-03-09 13:47:35 +0100
commit6f294c1645e1a8b28258a98ee401f06101990da3 (patch)
treed61b63e80b032f37f62a714aa97f9d253852537a
parent1b21587c16ffab621def35888cf4558defd59b06 (diff)
downloadcouchdb-6f294c1645e1a8b28258a98ee401f06101990da3.tar.gz
fix: compaction daemon symlink resolution and log level #1097
-rw-r--r--src/couch/src/couch_compaction_daemon.erl44
1 files changed, 37 insertions, 7 deletions
diff --git a/src/couch/src/couch_compaction_daemon.erl b/src/couch/src/couch_compaction_daemon.erl
index 200c3fd76..5c278aaf6 100644
--- a/src/couch/src/couch_compaction_daemon.erl
+++ b/src/couch/src/couch_compaction_daemon.erl
@@ -519,9 +519,9 @@ free_space(Path) ->
free_space_rec(_Path, []) ->
undefined;
-free_space_rec(Path, [{MountPoint0, Total, Usage} | Rest]) ->
- case abs_path(MountPoint0) of
- {ok, MountPoint} ->
+free_space_rec(Path0, [{MountPoint, Total, Usage} | Rest]) ->
+ case abs_path(Path0) of
+ {ok, Path} ->
case MountPoint =:= string:substr(Path, 1, length(MountPoint)) of
false ->
free_space_rec(Path, Rest);
@@ -529,10 +529,10 @@ free_space_rec(Path, [{MountPoint0, Total, Usage} | Rest]) ->
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)
+ couch_log:debug("Compaction daemon - unable to calculate free space"
+ " for `~s`: `~s` for mount mount `~p`",
+ [Path0, Reason, MountPoint]),
+ free_space_rec(Path0, Rest)
end.
abs_path(Path0) ->
@@ -557,3 +557,33 @@ abs_path2(Path0) ->
_ ->
{ok, Path ++ "/"}
end.
+
+
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+
+free_space_rec_test() ->
+ ?assertEqual(undefined, free_space_rec("", [])),
+ ?assertEqual(51200, free_space_rec("/tmp/", [{"/", 100, 50}])),
+ ?assertEqual(51200, free_space_rec("/tmp/", [
+ {"/floop", 200, 25},
+ {"/run", 0, 0},
+ {"/", 100, 50}
+ ])),
+ ?assertEqual(undefined, free_space_rec("/flopp/", [{"/", 300, 75}])),
+ ?assertEqual(undefined, free_space_rec("/flopp/", [
+ {"/floop", 200, 25},
+ {"/run", 0, 0},
+ {"/", 100, 50}
+ ])),
+ ok.
+
+abs_path2_test() ->
+ ?assertEqual({ok, "/a/"}, abs_path2("/a")),
+ ?assertEqual({ok, "/a/"}, abs_path2("/a/")),
+
+ ?assertEqual({ok, "/a/b/"}, abs_path2("/a/b")),
+ ?assertEqual({ok, "/a/b/"}, abs_path2("/a/b")),
+ ok.
+
+-endif.