Skip to content

Commit 3212f09

Browse files
committed
HBASE-30000 testCompactionWithCorruptBlock fails on branch-2.5 (#7962)
Signed-off-by: Charles Connell <cconnell@apache.org> Signed-off-by: Xiao Liu <liuxiaocs@apache.org> Signed-off-by: Duo Zhang <zhangduo@apache.org>
1 parent 413233d commit 3212f09

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import static org.mockito.Mockito.spy;
4141
import static org.mockito.Mockito.when;
4242

43+
import java.io.File;
44+
import java.io.FileOutputStream;
4345
import java.io.IOException;
4446
import java.io.InputStream;
4547
import java.io.OutputStream;
@@ -52,6 +54,7 @@
5254
import java.util.concurrent.CountDownLatch;
5355
import java.util.concurrent.TimeUnit;
5456
import java.util.zip.GZIPInputStream;
57+
import java.util.zip.GZIPOutputStream;
5558
import org.apache.hadoop.conf.Configuration;
5659
import org.apache.hadoop.fs.FSDataOutputStream;
5760
import org.apache.hadoop.fs.FileStatus;
@@ -93,6 +96,7 @@
9396
import org.junit.Assume;
9497
import org.junit.Before;
9598
import org.junit.ClassRule;
99+
import org.junit.Ignore;
96100
import org.junit.Rule;
97101
import org.junit.Test;
98102
import org.junit.experimental.categories.Category;
@@ -156,7 +160,10 @@ public void setUp() throws Exception {
156160
ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).setMaxVersions(65536).build();
157161
builder.setColumnFamily(familyDescriptor);
158162
}
159-
if (name.getMethodName().equals("testCompactionWithCorruptBlock")) {
163+
if (
164+
name.getMethodName().equals("testCompactionWithCorruptBlock")
165+
|| name.getMethodName().equals("generateHFileForCorruptBlockTest")
166+
) {
160167
UTIL.getConfiguration().setBoolean("hbase.hstore.validate.read_fully", true);
161168
ColumnFamilyDescriptor familyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(FAMILY)
162169
.setCompressionType(Compression.Algorithm.GZ).build();
@@ -382,9 +389,38 @@ public void testCompactionWithCorruptResult() throws Exception {
382389
assertTrue(fs.exists(tmpPath));
383390
}
384391

392+
/**
393+
* Generates the HFile used by {@link #testCompactionWithCorruptBlock()}. Run this method to
394+
* regenerate the test resource file after changes to the HFile format. The output file must then
395+
* be hand-edited to corrupt the first data block (zero out the GZip magic bytes at offset 33)
396+
* before being placed into the test resources directory.
397+
*/
398+
@Ignore("Not a test; utility for regenerating testCompactionWithCorruptBlock resource file")
399+
@Test
400+
public void generateHFileForCorruptBlockTest() throws Exception {
401+
createStoreFile(r, Bytes.toString(FAMILY));
402+
createStoreFile(r, Bytes.toString(FAMILY));
403+
HStore store = r.getStore(FAMILY);
404+
405+
Collection<HStoreFile> storeFiles = store.getStorefiles();
406+
DefaultCompactor tool = (DefaultCompactor) store.storeEngine.getCompactor();
407+
CompactionRequestImpl request = new CompactionRequestImpl(storeFiles);
408+
List<Path> paths = tool.compact(request, NoLimitThroughputController.INSTANCE, null);
409+
410+
FileSystem fs = store.getFileSystem();
411+
Path hfilePath = paths.get(0);
412+
File outFile = new File("/tmp/TestCompaction_HFileWithCorruptBlock.gz");
413+
try (InputStream in = fs.open(hfilePath);
414+
GZIPOutputStream gzOut = new GZIPOutputStream(new FileOutputStream(outFile))) {
415+
IOUtils.copyBytes(in, gzOut, 4096);
416+
}
417+
LoggerFactory.getLogger(TestCompaction.class)
418+
.info("Wrote HFile to {}. Now hex-edit offset 33 (0x21): zero out bytes 1f 8b.", outFile);
419+
}
420+
385421
/**
386422
* This test uses a hand-modified HFile, which is loaded in from the resources' path. That file
387-
* was generated from the test support code in this class and then edited to corrupt the
423+
* was generated from {@link #generateHFileForCorruptBlockTest()} and then edited to corrupt the
388424
* GZ-encoded block by zeroing-out the first two bytes of the GZip header, the "standard
389425
* declaration" of {@code 1f 8b}, found at offset 33 in the file. I'm not sure why, but it seems
390426
* that in this test context we do not enforce CRC checksums. Thus, this corruption manifests in

0 commit comments

Comments
 (0)