diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java index d012863..1345fe5 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java @@ -393,28 +393,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); @@ -567,6 +551,17 @@ 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 = minimum versions "); + } setValue(HConstants.VERSIONS, Integer.toString(maxVersions)); cachedMaxVersions = maxVersions; return this; @@ -753,6 +748,24 @@ 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 (this.getMaxVersions() == 0) { + // only for the first time of initialization + // setMinVersion() while maxVersion has not been set yet + // setMaxVersion to Default to avoid throw errors + this.setMaxVersions(DEFAULT_VERSIONS); + } + if (minVersions > this.getMaxVersions()) { + throw new IllegalArgumentException("Set MinVersion to " + minVersions + + " while maxVersion is " + this.getMaxVersions() + + ". Minimum versions must be <= maximum versions "); + } + } return setValue(MIN_VERSIONS, Integer.toString(minVersions)); }