diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java index 542d9281243..480aff919e1 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java @@ -568,6 +568,9 @@ public class HColumnDescriptor implements WritableComparable * @return this (for chained invocation) */ public HColumnDescriptor setValue(byte[] key, byte[] value) { + if (Bytes.compareTo(Bytes.toBytes(HConstants.VERSIONS), key) == 0) { + cachedMaxVersions = UNINITIALIZED; + } values.put(new ImmutableBytesWritable(key), new ImmutableBytesWritable(value)); return this; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptorDefaultVersions.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptorDefaultVersions.java index 17ad36d4ed6..4660bbbeec0 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptorDefaultVersions.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptorDefaultVersions.java @@ -134,6 +134,19 @@ public class TestHColumnDescriptorDefaultVersions { admin.deleteTable(TABLE_NAME); } } + + @Test + public void testHColumnDescriptorCachedMaxVersions() throws Exception { + HColumnDescriptor hcd = new HColumnDescriptor(FAMILY); + hcd.setMaxVersions(5); + // Verify the max version + assertEquals(5, hcd.getMaxVersions()); + + // modify the max version + hcd.setValue(Bytes.toBytes(HConstants.VERSIONS), Bytes.toBytes("8")); + // Verify the max version + assertEquals(8, hcd.getMaxVersions()); + } private void verifyHColumnDescriptor(int expected, final TableName tableName, final byte[]... families) throws IOException {