浏览代码

_cat/allocation to return no value for `disk.total` when not available (e.g. non data nodes) instead of `-1b`

Closes #5948
javanna 11 年之前
父节点
当前提交
aa4dc092da
共有 1 个文件被更改,包括 11 次插入7 次删除
  1. 11 7
      src/main/java/org/elasticsearch/rest/action/cat/RestAllocationAction.java

+ 11 - 7
src/main/java/org/elasticsearch/rest/action/cat/RestAllocationAction.java

@@ -123,19 +123,23 @@ public class RestAllocationAction extends AbstractCatAction {
                 shardCount = allocs.lget();
             }
 
-            long used = nodeStats.getFs().getTotal().getTotal().bytes() - nodeStats.getFs().getTotal().getAvailable().bytes();
-            long avail = nodeStats.getFs().getTotal().getAvailable().bytes();
-
+            ByteSizeValue total = nodeStats.getFs().getTotal().getTotal();
+            ByteSizeValue avail = nodeStats.getFs().getTotal().getAvailable();
+            //if we don't know how much we use (non data nodes), it means 0
+            long used = 0;
             short diskPercent = -1;
-            if (used >= 0 && avail >= 0) {
-                diskPercent = (short) (used * 100 / (used + avail));
+            if (total.bytes() > 0) {
+                used = total.bytes() - avail.bytes();
+                if (used >= 0 && avail.bytes() >= 0) {
+                    diskPercent = (short) (used * 100 / (used + avail.bytes()));
+                }
             }
 
             table.startRow();
             table.addCell(shardCount);
             table.addCell(used < 0 ? null : new ByteSizeValue(used));
-            table.addCell(avail < 0 ? null : new ByteSizeValue(avail));
-            table.addCell(nodeStats.getFs().getTotal().getTotal());
+            table.addCell(avail.bytes() < 0 ? null : avail);
+            table.addCell(total.bytes() < 0 ? null : total);
             table.addCell(diskPercent < 0 ? null : diskPercent);
             table.addCell(node.getHostName());
             table.addCell(node.getHostAddress());