summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2019-07-01 15:36:58 -0400
committerRandolph Tan <randolph@10gen.com>2019-07-12 14:04:54 -0400
commit86380492129440f1d150b804810207b079ee8285 (patch)
treef9aff688fbd1ad0c0adc4ddd6823cc03463448d1 /src
parentb583a5704eaf895facadaf470ddd9cf2bfe6270e (diff)
downloadmongo-86380492129440f1d150b804810207b079ee8285.tar.gz
SERVER-41632 Fix division by zero in shell collStats helper
(cherry picked from commit 83a0d0d890e375dfafe0e464f3f56fbdedf5189e)
Diffstat (limited to 'src')
-rw-r--r--src/mongo/shell/collection.js10
-rw-r--r--src/mongo/shell/utils_sh.js4
2 files changed, 10 insertions, 4 deletions
diff --git a/src/mongo/shell/collection.js b/src/mongo/shell/collection.js
index 81c4d7dae5e..3d8b66451ff 100644
--- a/src/mongo/shell/collection.js
+++ b/src/mongo/shell/collection.js
@@ -1224,8 +1224,8 @@ DBCollection.prototype.getShardDistribution = function() {
numChunks += chunks.length;
- var estChunkData = shardStats.size / chunks.length;
- var estChunkCount = Math.floor(shardStats.count / chunks.length);
+ var estChunkData = (chunks.length == 0) ? 0 : shardStats.size / chunks.length;
+ var estChunkCount = (chunks.length == 0) ? 0 : Math.floor(shardStats.count / chunks.length);
print(" data : " + sh._dataFormat(shardStats.size) + " docs : " + shardStats.count +
" chunks : " + chunks.length);
@@ -1239,8 +1239,10 @@ DBCollection.prototype.getShardDistribution = function() {
for (var shard in stats.shards) {
var shardStats = stats.shards[shard];
- var estDataPercent = Math.floor(shardStats.size / stats.size * 10000) / 100;
- var estDocPercent = Math.floor(shardStats.count / stats.count * 10000) / 100;
+ var estDataPercent =
+ (stats.size == 0) ? 0 : (Math.floor(shardStats.size / stats.size * 10000) / 100);
+ var estDocPercent =
+ (stats.count == 0) ? 0 : (Math.floor(shardStats.count / stats.count * 10000) / 100);
print(" Shard " + shard + " contains " + estDataPercent + "% data, " + estDocPercent +
"% docs in cluster, " + "avg obj size on shard : " +
diff --git a/src/mongo/shell/utils_sh.js b/src/mongo/shell/utils_sh.js
index f77455fd130..5c40d2aacf1 100644
--- a/src/mongo/shell/utils_sh.js
+++ b/src/mongo/shell/utils_sh.js
@@ -25,6 +25,10 @@ sh._getConfigDB = function() {
};
sh._dataFormat = function(bytes) {
+ if (bytes == null) {
+ return "0B";
+ }
+
if (bytes < 1024)
return Math.floor(bytes) + "B";
if (bytes < 1024 * 1024)