You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by li...@apache.org on 2013/10/31 19:18:20 UTC
svn commit: r1537574 -
/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java
Author: liyin
Date: Thu Oct 31 18:18:19 2013
New Revision: 1537574
URL: http://svn.apache.org/r1537574
Log:
[HBASE-8805] Added a test to verify that the compaction properties behave as expected when changed online
Author: gauravm
Summary: I wanted to verify that the compaction properties when changed online, behave as expected, and cause a change in the compaction algorithm (and not only test if the values are changing. Previous tests were geared towards that).
Test Plan: Unit Test
Reviewers: aaiyer, liyintang, adela, fan, manukranthk, rshroff, arjen
Reviewed By: fan
CC: hbase-eng@
Differential Revision: https://phabricator.fb.com/D1031643
Task ID: 2842041
Modified:
hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java
Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java?rev=1537574&r1=1537573&r2=1537574&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java (original)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java Thu Oct 31 18:18:19 2013
@@ -587,8 +587,12 @@ public class TestCompaction extends HBas
}
private void createStoreFile(final HRegion region) throws IOException {
+ createStoreFile(region, null);
+ }
+
+ private void createStoreFile(final HRegion region, String column) throws IOException {
HRegionIncommon loader = new HRegionIncommon(region);
- addContent(loader, Bytes.toString(COLUMN_FAMILY));
+ addContent(loader, Bytes.toString(COLUMN_FAMILY), column);
loader.flushcache();
}
@@ -636,4 +640,83 @@ public class TestCompaction extends HBas
fail("testCompactionWithCorruptResult failed since no exception was" +
"thrown while completing a corrupt file");
}
+
+ /**
+ * This test is to verify that the compaction related online configuration
+ * changes actually cause the desired behaviour in compaction, not just
+ * changing of the values. We will change a bunch of compaction properties in
+ * an online fashion, and verify that they cause the desired change in
+ * compaction behavior.
+ */
+ public void testOnlineConfigurationChange() throws IOException {
+ // Creating two files of the same size (say, 'x').
+ createStoreFile(r, "abc");
+ createStoreFile(r, "def");
+
+ Store store = r.getStore(COLUMN_FAMILY);
+ List<StoreFile> storeFiles = store.getStorefiles();
+ // Check that we wouldn't get to do a compaction, because we just have
+ // two files.
+ r.compactStores();
+ assertEquals(storeFiles, store.getStorefiles());
+
+ // Now set the minimum number of files for compaction to 2.
+ conf.setInt(HConstants.HSTORE_COMPACTION_PREFIX + "min", 2);
+ HRegionServer.configurationManager.notifyAllObservers(conf);
+ r.compactStores();
+ assertNotSame(storeFiles, store.getStorefiles());
+
+ // Check that we only have one store file.
+ assertEquals(1, store.getStorefiles().size());
+
+ // We now have one file of size roughly 2x.
+ // Creating two more files of size x each.
+ createStoreFile(r, "ghi");
+ createStoreFile(r, "jkl");
+ storeFiles = store.getStorefiles();
+ assertEquals(3, storeFiles.size());
+ long firstFileSizeBeforeCompaction = storeFiles.get(0).getReader().length();
+
+ // We now have 3 files, of sizes 2x, x and x each.
+ // If we were compact regularly, it would get compacted into one file of
+ // size 4x roughly. We will reduce the max number of files to be
+ // compacted, and set the compaction ratio to be > 2, so that the
+ // first two files (of sizes 2x and x), get compacted.
+ conf.setInt(HConstants.HSTORE_COMPACTION_PREFIX + "max", 2);
+ conf.setFloat(HConstants.HSTORE_COMPACTION_PREFIX + "ratio", 2.5f);
+ HRegionServer.configurationManager.notifyAllObservers(conf);
+ r.compactStores();
+ storeFiles = store.getStorefiles();
+ assertEquals(2, storeFiles.size());
+
+ // Verify that the first file in the new set of store files is
+ // bigger than the first file in the old set of store files.
+ assertTrue(storeFiles.get(0).getReader().length() >
+ firstFileSizeBeforeCompaction);
+ firstFileSizeBeforeCompaction = storeFiles.get(0).getReader().length();
+
+ // We will try to compact but nothing will happen, since the files are of
+ // sizes 3x and x respectively, and we have just set the compaction ratio to
+ // 2.5.
+ r.compactStores();
+ storeFiles = store.getStorefiles();
+ // Check that nothing has changed.
+ assertEquals(2, storeFiles.size());
+ assertEquals(firstFileSizeBeforeCompaction,
+ storeFiles.get(0).getReader().length());
+
+ // Now change the min compact size, below which, we don't check the
+ // compaction ratio.
+ conf.setLong(HConstants.HSTORE_COMPACTION_PREFIX + "min.size",
+ 2 * firstFileSizeBeforeCompaction);
+ HRegionServer.configurationManager.notifyAllObservers(conf);
+ r.compactStores();
+ storeFiles = store.getStorefiles();
+
+ // We should have just one massive file,
+ assertEquals(1, storeFiles.size());
+ // whose size will be bigger than the previous biggest file.
+ assertTrue(storeFiles.get(0).getReader().length() >
+ firstFileSizeBeforeCompaction);
+ }
}