|
35 | 35 | import org.apache.hadoop.hbase.HConstants; |
36 | 36 | import org.apache.hadoop.hbase.HTableDescriptor; |
37 | 37 | import org.apache.hadoop.hbase.TableName; |
38 | | -import org.apache.hadoop.hbase.Waiter.Predicate; |
| 38 | +import org.apache.hadoop.hbase.Waiter; |
| 39 | +import org.apache.hadoop.hbase.client.CompactionState; |
39 | 40 | import org.apache.hadoop.hbase.client.Put; |
40 | 41 | import org.apache.hadoop.hbase.client.Table; |
41 | 42 | import org.apache.hadoop.hbase.io.crypto.Encryption; |
@@ -133,27 +134,14 @@ public void testCFKeyRotation() throws Exception { |
133 | 134 |
|
134 | 135 | // And major compact |
135 | 136 | TEST_UTIL.getAdmin().majorCompact(htd.getTableName()); |
136 | | - final List<Path> updatePaths = findCompactedStorefilePaths(htd.getTableName()); |
137 | | - TEST_UTIL.waitFor(30000, 1000, true, new Predicate<Exception>() { |
| 137 | + // waiting for the major compaction to complete |
| 138 | + TEST_UTIL.waitFor(30000, new Waiter.Predicate<IOException>() { |
138 | 139 | @Override |
139 | | - public boolean evaluate() throws Exception { |
140 | | - // When compaction has finished, all of the original files will be |
141 | | - // gone |
142 | | - boolean found = false; |
143 | | - for (Path path: updatePaths) { |
144 | | - found = TEST_UTIL.getTestFileSystem().exists(path); |
145 | | - if (found) { |
146 | | - LOG.info("Found " + path); |
147 | | - break; |
148 | | - } |
149 | | - } |
150 | | - return !found; |
| 140 | + public boolean evaluate() throws IOException { |
| 141 | + return TEST_UTIL.getAdmin().getCompactionState(htd.getTableName()) == |
| 142 | + CompactionState.NONE; |
151 | 143 | } |
152 | 144 | }); |
153 | | - |
154 | | - // Verify we have store file(s) with only the new key |
155 | | - Thread.sleep(1000); |
156 | | - waitForCompaction(htd.getTableName()); |
157 | 145 | List<Path> pathsAfterCompaction = findStorefilePaths(htd.getTableName()); |
158 | 146 | assertTrue(pathsAfterCompaction.size() > 0); |
159 | 147 | for (Path path: pathsAfterCompaction) { |
@@ -210,33 +198,6 @@ public void testMasterKeyRotation() throws Exception { |
210 | 198 | } |
211 | 199 | } |
212 | 200 |
|
213 | | - private static void waitForCompaction(TableName tableName) |
214 | | - throws IOException, InterruptedException { |
215 | | - boolean compacted = false; |
216 | | - for (Region region : TEST_UTIL.getRSForFirstRegionInTable(tableName) |
217 | | - .getRegions(tableName)) { |
218 | | - for (HStore store : ((HRegion) region).getStores()) { |
219 | | - compacted = false; |
220 | | - while (!compacted) { |
221 | | - if (store.getStorefiles() != null) { |
222 | | - while (store.getStorefilesCount() != 1) { |
223 | | - Thread.sleep(100); |
224 | | - } |
225 | | - for (HStoreFile storefile : store.getStorefiles()) { |
226 | | - if (!storefile.isCompactedAway()) { |
227 | | - compacted = true; |
228 | | - break; |
229 | | - } |
230 | | - Thread.sleep(100); |
231 | | - } |
232 | | - } else { |
233 | | - break; |
234 | | - } |
235 | | - } |
236 | | - } |
237 | | - } |
238 | | - } |
239 | | - |
240 | 201 | private static List<Path> findStorefilePaths(TableName tableName) throws Exception { |
241 | 202 | List<Path> paths = new ArrayList<>(); |
242 | 203 | for (Region region : TEST_UTIL.getRSForFirstRegionInTable(tableName) |
|
0 commit comments