From 9a91f5ac818b078526962e5c64183a2541a064b4 Mon Sep 17 00:00:00 2001 From: tedyu Date: Mon, 23 Nov 2015 20:13:00 -0800 Subject: [PATCH] HBASE-14737 Clear cachedMaxVersions when HColumnDescriptor#setValue(VERSIONS, value) is called (Pankaj Kumar) --- .../org/apache/hadoop/hbase/HColumnDescriptor.java | 3 +++ .../hbase/TestHColumnDescriptorDefaultVersions.java | 13 +++++++++++++ 2 files changed, 16 insertions(+) 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 4daf6efdd81..2c103089011 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 @@ -439,6 +439,9 @@ public class HColumnDescriptor implements Comparable { * @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 Bytes(key), new Bytes(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 94df71f11c7..8d0557f757f 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 @@ -133,6 +133,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 {