Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
package org.apache.hadoop.hbase.regionserver;

import static org.apache.hadoop.hbase.regionserver.Store.PRIORITY_USER;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.security.Key;
Expand All @@ -42,7 +45,6 @@
import org.apache.hadoop.hbase.CellComparatorImpl;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.ExtendedCell;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.HConstants;
Expand Down Expand Up @@ -75,27 +77,18 @@
import org.apache.hadoop.hbase.util.CommonFSUtils;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.wal.WALFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Category(MediumTests.class)
@org.junit.jupiter.api.Tag(MediumTests.TAG)
public class TestHMobStore {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestHMobStore.class);

public static final Logger LOG = LoggerFactory.getLogger(TestHMobStore.class);
@Rule
public TestName name = new TestName();
private String name;

private HMobStore store;
private HRegion region;
Expand Down Expand Up @@ -127,8 +120,9 @@ public class TestHMobStore {
/**
* Setup
*/
@Before
public void setUp() throws Exception {
@BeforeEach
public void setUp(TestInfo testInfo) throws Exception {
this.name = testInfo.getTestMethod().get().getName();
qualifiers.add(qf1);
qualifiers.add(qf3);
qualifiers.add(qf5);
Expand Down Expand Up @@ -211,10 +205,11 @@ private void init(Configuration conf, ColumnFamilyDescriptor cfd) throws IOExcep
/**
* Getting data from memstore
*/

@Test
public void testGetFromMemStore() throws IOException {
final Configuration conf = HBaseConfiguration.create();
init(name.getMethodName(), conf, false);
init(name, conf, false);

// Put data in memstore
this.store.add(new KeyValue(row, family, qf1, 1, value), null);
Expand All @@ -234,10 +229,10 @@ public void testGetFromMemStore() throws IOException {
scanner.close();

// Compare
Assert.assertEquals(expected.size(), results.size());
assertEquals(expected.size(), results.size());
for (int i = 0; i < results.size(); i++) {
// Verify the values
Assert.assertEquals(expected.get(i), results.get(i));
assertEquals(expected.get(i), results.get(i));
}
}

Expand All @@ -247,7 +242,7 @@ public void testGetFromMemStore() throws IOException {
@Test
public void testGetFromFiles() throws IOException {
final Configuration conf = TEST_UTIL.getConfiguration();
init(name.getMethodName(), conf, false);
init(name, conf, false);

// Put data in memstore
this.store.add(new KeyValue(row, family, qf1, 1, value), null);
Expand Down Expand Up @@ -277,9 +272,9 @@ public void testGetFromFiles() throws IOException {
scanner.close();

// Compare
Assert.assertEquals(expected.size(), results.size());
assertEquals(expected.size(), results.size());
for (int i = 0; i < results.size(); i++) {
Assert.assertEquals(expected.get(i), results.get(i));
assertEquals(expected.get(i), results.get(i));
}
}

Expand All @@ -289,7 +284,7 @@ public void testGetFromFiles() throws IOException {
@Test
public void testGetReferencesFromFiles() throws IOException {
final Configuration conf = HBaseConfiguration.create();
init(name.getMethodName(), conf, false);
init(name, conf, false);

// Put data in memstore
this.store.add(new KeyValue(row, family, qf1, 1, value), null);
Expand Down Expand Up @@ -320,10 +315,10 @@ public void testGetReferencesFromFiles() throws IOException {
scanner.close();

// Compare
Assert.assertEquals(expected.size(), results.size());
assertEquals(expected.size(), results.size());
for (int i = 0; i < results.size(); i++) {
ExtendedCell cell = results.get(i);
Assert.assertTrue(MobUtils.isMobReferenceCell(cell));
assertTrue(MobUtils.isMobReferenceCell(cell));
}
}

Expand All @@ -335,7 +330,7 @@ public void testGetFromMemStoreAndFiles() throws IOException {

final Configuration conf = HBaseConfiguration.create();

init(name.getMethodName(), conf, false);
init(name, conf, false);

// Put data in memstore
this.store.add(new KeyValue(row, family, qf1, 1, value), null);
Expand Down Expand Up @@ -363,9 +358,9 @@ public void testGetFromMemStoreAndFiles() throws IOException {
scanner.close();

// Compare
Assert.assertEquals(expected.size(), results.size());
assertEquals(expected.size(), results.size());
for (int i = 0; i < results.size(); i++) {
Assert.assertEquals(expected.get(i), results.get(i));
assertEquals(expected.get(i), results.get(i));
}
}

Expand All @@ -377,7 +372,7 @@ public void testMobCellSizeThreshold() throws IOException {
final Configuration conf = HBaseConfiguration.create();
ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(family)
.setMobEnabled(true).setMobThreshold(100).setMaxVersions(4).build();
init(name.getMethodName(), conf, cfd, false);
init(name, conf, cfd, false);

// Put data in memstore
this.store.add(new KeyValue(row, family, qf1, 1, value), null);
Expand Down Expand Up @@ -408,34 +403,34 @@ public void testMobCellSizeThreshold() throws IOException {
scanner.close();

// Compare
Assert.assertEquals(expected.size(), results.size());
assertEquals(expected.size(), results.size());
for (int i = 0; i < results.size(); i++) {
ExtendedCell cell = results.get(i);
// this is not mob reference cell.
Assert.assertFalse(MobUtils.isMobReferenceCell(cell));
Assert.assertEquals(expected.get(i), results.get(i));
Assert.assertEquals(100, store.getColumnFamilyDescriptor().getMobThreshold());
assertFalse(MobUtils.isMobReferenceCell(cell));
assertEquals(expected.get(i), results.get(i));
assertEquals(100, store.getColumnFamilyDescriptor().getMobThreshold());
}
}

@Test
public void testCommitFile() throws Exception {
final Configuration conf = HBaseConfiguration.create();
init(name.getMethodName(), conf, true);
init(name, conf, true);
String targetPathName = MobUtils.formatDate(new Date());
Path targetPath =
new Path(store.getPath(), (targetPathName + Path.SEPARATOR + mobFilePath.getName()));
fs.delete(targetPath, true);
Assert.assertFalse(fs.exists(targetPath));
assertFalse(fs.exists(targetPath));
// commit file
store.commitFile(mobFilePath, targetPath);
Assert.assertTrue(fs.exists(targetPath));
assertTrue(fs.exists(targetPath));
}

@Test
public void testResolve() throws Exception {
final Configuration conf = HBaseConfiguration.create();
init(name.getMethodName(), conf, true);
init(name, conf, true);
String targetPathName = MobUtils.formatDate(currentDate);
Path targetPath = new Path(store.getPath(), targetPathName);
store.commitFile(mobFilePath, targetPath);
Expand All @@ -444,9 +439,9 @@ public void testResolve() throws Exception {
Cell resultCell2 = store.resolve(seekKey2, false).getCell();
Cell resultCell3 = store.resolve(seekKey3, false).getCell();
// compare
Assert.assertEquals(Bytes.toString(value), Bytes.toString(CellUtil.cloneValue(resultCell1)));
Assert.assertEquals(Bytes.toString(value), Bytes.toString(CellUtil.cloneValue(resultCell2)));
Assert.assertEquals(Bytes.toString(value2), Bytes.toString(CellUtil.cloneValue(resultCell3)));
assertEquals(Bytes.toString(value), Bytes.toString(CellUtil.cloneValue(resultCell1)));
assertEquals(Bytes.toString(value), Bytes.toString(CellUtil.cloneValue(resultCell2)));
assertEquals(Bytes.toString(value2), Bytes.toString(CellUtil.cloneValue(resultCell3)));
}

@Test
Expand All @@ -466,9 +461,9 @@ public void testReversedMobStoreScannerGetFilesRead() throws IOException {
private void doTestMobStoreScannerGetFilesRead(boolean reversed) throws IOException {
// Setup: conf, root dir, and MOB store init (mob threshold causes large values to go to MOB).
final Configuration conf = HBaseConfiguration.create();
Path basedir = new Path(DIR + name.getMethodName());
Path basedir = new Path(DIR + name);
CommonFSUtils.setRootDir(conf, basedir);
init(name.getMethodName(), conf, false);
init(name, conf, false);

// Add values above MOB threshold and flush so DefaultMobStoreFlusher creates mob file and refs.
byte[] valueAboveThreshold = Bytes.toBytes("value"); // threshold in setup is 3 bytes
Expand All @@ -493,8 +488,8 @@ private void doTestMobStoreScannerGetFilesRead(boolean reversed) throws IOExcept
}
}
}
Assert.assertTrue("Should have at least one store file and one mob file",
expectedFilePaths.size() >= 2);
assertTrue(expectedFilePaths.size() >= 2,
"Should have at least one store file and one mob file");

// Build scan (optionally reversed) and target columns; get store scanner and verify type.
Scan scan = new Scan();
Expand All @@ -511,18 +506,17 @@ private void doTestMobStoreScannerGetFilesRead(boolean reversed) throws IOExcept

KeyValueScanner kvScanner = store.getScanner(scan, targetCols, 0);
if (reversed) {
Assert.assertTrue("Store scanner should be ReversedMobStoreScanner",
kvScanner instanceof ReversedMobStoreScanner);
assertTrue(kvScanner instanceof ReversedMobStoreScanner,
"Store scanner should be ReversedMobStoreScanner");
} else {
Assert.assertTrue("Store scanner should be MobStoreScanner",
kvScanner instanceof MobStoreScanner);
assertTrue(kvScanner instanceof MobStoreScanner, "Store scanner should be MobStoreScanner");
}

// Before close: getFilesRead must be empty; then drain scanner to resolve MOB refs.
try {
Set<Path> filesReadBeforeClose = kvScanner.getFilesRead();
Assert.assertTrue("Should return empty set before closing", filesReadBeforeClose.isEmpty());
Assert.assertEquals("Should have 0 files before closing", 0, filesReadBeforeClose.size());
assertTrue(filesReadBeforeClose.isEmpty(), "Should return empty set before closing");
assertEquals(0, filesReadBeforeClose.size(), "Should have 0 files before closing");

List<Cell> results = new ArrayList<>();
InternalScanner storeScanner = (InternalScanner) kvScanner;
Expand All @@ -532,27 +526,26 @@ private void doTestMobStoreScannerGetFilesRead(boolean reversed) throws IOExcept

// Still before close: set must remain empty until scanner is closed.
filesReadBeforeClose = kvScanner.getFilesRead();
Assert.assertTrue("Should return empty set before closing even after reading",
filesReadBeforeClose.isEmpty());
assertTrue(filesReadBeforeClose.isEmpty(),
"Should return empty set before closing even after reading");
} finally {
kvScanner.close();
}

// After close: set must contain exactly the expected store + MOB file paths.
Set<Path> filesReadAfterClose = kvScanner.getFilesRead();
Assert.assertEquals("Should have exact file count after closing", expectedFilePaths.size(),
filesReadAfterClose.size());
Assert.assertEquals("Should contain all expected file paths", expectedFilePaths,
filesReadAfterClose);
assertEquals(expectedFilePaths.size(), filesReadAfterClose.size(),
"Should have exact file count after closing");
assertEquals(expectedFilePaths, filesReadAfterClose, "Should contain all expected file paths");
}

/**
* Flush the memstore
*/
private void flush(int storeFilesSize) throws IOException {
flushStore(store, id++);
Assert.assertEquals(storeFilesSize, this.store.getStorefiles().size());
Assert.assertEquals(0, ((AbstractMemStore) this.store.memstore).getActive().getCellsCount());
assertEquals(storeFilesSize, this.store.getStorefiles().size());
assertEquals(0, ((AbstractMemStore) this.store.memstore).getActive().getCellsCount());
}

/**
Expand Down Expand Up @@ -582,7 +575,7 @@ public void testMOBStoreEncryption() throws Exception {
conf.get(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, User.getCurrent().getShortName()),
cfKey))
.build();
init(name.getMethodName(), conf, cfd, false);
init(name, conf, cfd, false);

this.store.add(new KeyValue(row, family, qf1, 1, value), null);
this.store.add(new KeyValue(row, family, qf2, 1, value), null);
Expand All @@ -606,17 +599,17 @@ public void testMOBStoreEncryption() throws Exception {
scanner.next(results);
Collections.sort(results, CellComparatorImpl.COMPARATOR);
scanner.close();
Assert.assertEquals(expected.size(), results.size());
assertEquals(expected.size(), results.size());
for (int i = 0; i < results.size(); i++) {
Assert.assertEquals(expected.get(i), results.get(i));
assertEquals(expected.get(i), results.get(i));
}

// Trigger major compaction
this.store.triggerMajorCompaction();
Optional<CompactionContext> requestCompaction =
this.store.requestCompaction(PRIORITY_USER, CompactionLifeCycleTracker.DUMMY, null);
this.store.compact(requestCompaction.get(), NoLimitThroughputController.INSTANCE, null);
Assert.assertEquals(1, this.store.getStorefiles().size());
assertEquals(1, this.store.getStorefiles().size());

// Check encryption after compaction
checkMobHFileEncrytption(this.store.getStorefiles());
Expand All @@ -626,8 +619,8 @@ private void checkMobHFileEncrytption(Collection<HStoreFile> storefiles) {
HStoreFile storeFile = storefiles.iterator().next();
HFile.Reader reader = storeFile.getReader().getHFileReader();
byte[] encryptionKey = reader.getTrailer().getEncryptionKey();
Assert.assertTrue(null != encryptionKey);
Assert.assertTrue(reader.getFileContext().getEncryptionContext().getCipher().getName()
assertTrue(null != encryptionKey);
assertTrue(reader.getFileContext().getEncryptionContext().getCipher().getName()
.equals(HConstants.CIPHER_AES));
}

Expand Down
Loading