You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by wi...@apache.org on 2017/09/12 17:28:32 UTC

[couchdb] branch master updated: Do not crash when free space cannot be calculated (#803)

This is an automated email from the ASF dual-hosted git repository.

willholley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/master by this push:
     new ef8a934  Do not crash when free space cannot be calculated (#803)
ef8a934 is described below

commit ef8a934c1ca67092b06f0cee2e01871013bae4e5
Author: Will Holley <wi...@gmail.com>
AuthorDate: Tue Sep 12 18:28:29 2017 +0100

    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
---
 src/couch/src/couch_compaction_daemon.erl | 44 ++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/src/couch/src/couch_compaction_daemon.erl b/src/couch/src/couch_compaction_daemon.erl
index 8f95eb2..024b867 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.

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].