diff --git a/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java b/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java index dca442d..fdf29bc 100644 --- a/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java +++ b/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java @@ -371,28 +371,12 @@ public class HColumnDescriptor implements WritableComparable isLegalFamilyName(familyName); this.name = familyName; - if (maxVersions <= 0) { - // TODO: Allow maxVersion of 0 to be the way you say "Keep all versions". - // Until there is support, consider 0 or < 0 -- a configuration error. - throw new IllegalArgumentException("Maximum versions must be positive"); - } - - if (minVersions > 0) { - if (timeToLive == HConstants.FOREVER) { - throw new IllegalArgumentException("Minimum versions requires TTL."); - } - if (minVersions >= maxVersions) { - throw new IllegalArgumentException("Minimum versions must be < " - + "maximum versions."); - } - } - + setTimeToLive(timeToLive); setMaxVersions(maxVersions); setMinVersions(minVersions); setKeepDeletedCells(keepDeletedCells); setInMemory(inMemory); setBlockCacheEnabled(blockCacheEnabled); - setTimeToLive(timeToLive); setCompressionType(Compression.Algorithm. valueOf(compression.toUpperCase())); setEncodeOnDisk(encodeOnDisk); @@ -540,6 +524,15 @@ public class HColumnDescriptor implements WritableComparable * @return this (for chained invocation) */ public HColumnDescriptor setMaxVersions(int maxVersions) { + if (maxVersions <= 0) { + // TODO: Allow maxVersion of 0 to be the way you say "Keep all versions". + // Until there is support, consider 0 or < 0 -- a configuration error. + throw new IllegalArgumentException("Maximum versions must be positive"); + } + else if (maxVersions <=this.getMinVersions()) { + throw new IllegalArgumentException("Maximum versions must be > " + + "minimum versions " + this.getMinVersions()); + } setValue(HConstants.VERSIONS, Integer.toString(maxVersions)); cachedMaxVersions = maxVersions; return this; @@ -726,6 +719,17 @@ public class HColumnDescriptor implements WritableComparable * @return this (for chained invocation) */ public HColumnDescriptor setMinVersions(int minVersions) { + + if (minVersions > 0) { + if (this.getTimeToLive() == HConstants.FOREVER) { + //set to DEFAULT instead of throw exception here. + this.setTimeToLive(DEFAULT_TTL); + } + if (minVersions >= this.getMaxVersions()) { + throw new IllegalArgumentException("Minimum versions must be < " + + "maximum versions " + this.getMaxVersions()); + } + } return setValue(MIN_VERSIONS, Integer.toString(minVersions)); }