add defense to selectNewPathForShard

This commit is contained in:
Mike McCandless 2016-07-29 11:51:33 -04:00
parent ed5e5db188
commit 37e0e63a65

View File

@ -187,7 +187,7 @@ public final class ShardPath {
// TODO - do we need something more extensible? Yet, this does the job for now... // TODO - do we need something more extensible? Yet, this does the job for now...
final NodeEnvironment.NodePath[] paths = env.nodePaths(); final NodeEnvironment.NodePath[] paths = env.nodePaths();
NodeEnvironment.NodePath bestPath = null; NodeEnvironment.NodePath bestPath = null;
BigInteger maxUsableBytes = BigInteger.valueOf(-1); BigInteger maxUsableBytes = BigInteger.valueOf(Long.MIN_VALUE);
for (NodeEnvironment.NodePath nodePath : paths) { for (NodeEnvironment.NodePath nodePath : paths) {
FileStore fileStore = nodePath.fileStore; FileStore fileStore = nodePath.fileStore;
@ -199,7 +199,7 @@ public final class ShardPath {
if (count != null) { if (count != null) {
usableBytes = usableBytes.subtract(estShardSizeInBytes.multiply(BigInteger.valueOf(count))); usableBytes = usableBytes.subtract(estShardSizeInBytes.multiply(BigInteger.valueOf(count)));
} }
if (usableBytes.compareTo(maxUsableBytes) > 0) { if (bestPath == null || usableBytes.compareTo(maxUsableBytes) > 0) {
maxUsableBytes = usableBytes; maxUsableBytes = usableBytes;
bestPath = nodePath; bestPath = nodePath;
} }