From b1941b200d6b4fa6a7891421c0a1e212cad3d6eb Mon Sep 17 00:00:00 2001 From: Xiao Chen Date: Wed, 15 Nov 2017 16:43:25 -0800 Subject: [PATCH] HADOOP-15023. ValueQueue should also validate (int) (lowWatermark * numValues) > 0 on construction. --- .../java/org/apache/hadoop/crypto/key/kms/ValueQueue.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/kms/ValueQueue.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/kms/ValueQueue.java index 8411ffbf23..1ddd8a3c67 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/kms/ValueQueue.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/kms/ValueQueue.java @@ -224,6 +224,9 @@ public ValueQueue(final int numValues, final float lowWatermark, Preconditions.checkArgument(numValues > 0, "\"numValues\" must be > 0"); Preconditions.checkArgument(((lowWatermark > 0)&&(lowWatermark <= 1)), "\"lowWatermark\" must be > 0 and <= 1"); + final int watermarkValue = (int) (numValues * lowWatermark); + Preconditions.checkArgument(watermarkValue > 0, + "(int) (\"numValues\" * \"lowWatermark\") must be > 0"); Preconditions.checkArgument(expiry > 0, "\"expiry\" must be > 0"); Preconditions.checkArgument(numFillerThreads > 0, "\"numFillerThreads\" must be > 0"); @@ -243,8 +246,7 @@ public LinkedBlockingQueue load(String keyName) throws Exception { LinkedBlockingQueue keyQueue = new LinkedBlockingQueue(); - refiller.fillQueueForKey(keyName, keyQueue, - (int)(lowWatermark * numValues)); + refiller.fillQueueForKey(keyName, keyQueue, watermarkValue); return keyQueue; } });