HBASE-14688 Cleanup MOB tests
This commit is contained in:
parent
e04e7402cd
commit
c91bfff586
|
@ -1845,7 +1845,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
|
||||||
|
|
||||||
//
|
//
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide an existing table name to truncate.
|
* Provide an existing table name to truncate.
|
||||||
* Scans the table and issues a delete for each row read.
|
* Scans the table and issues a delete for each row read.
|
||||||
|
@ -2141,7 +2141,10 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
|
||||||
* Return the number of rows in the given table.
|
* Return the number of rows in the given table.
|
||||||
*/
|
*/
|
||||||
public int countRows(final Table table) throws IOException {
|
public int countRows(final Table table) throws IOException {
|
||||||
Scan scan = new Scan();
|
return countRows(table, new Scan());
|
||||||
|
}
|
||||||
|
|
||||||
|
public int countRows(final Table table, final Scan scan) throws IOException {
|
||||||
ResultScanner results = table.getScanner(scan);
|
ResultScanner results = table.getScanner(scan);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (@SuppressWarnings("unused") Result res : results) {
|
for (@SuppressWarnings("unused") Result res : results) {
|
||||||
|
|
|
@ -19,11 +19,16 @@
|
||||||
package org.apache.hadoop.hbase.mob;
|
package org.apache.hadoop.hbase.mob;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.Cell;
|
import org.apache.hadoop.hbase.Cell;
|
||||||
import org.apache.hadoop.hbase.CellUtil;
|
import org.apache.hadoop.hbase.CellUtil;
|
||||||
import org.apache.hadoop.hbase.KeyValue;
|
import org.apache.hadoop.hbase.KeyValue;
|
||||||
|
import org.apache.hadoop.hbase.client.Result;
|
||||||
|
import org.apache.hadoop.hbase.client.ResultScanner;
|
||||||
|
import org.apache.hadoop.hbase.client.Scan;
|
||||||
|
import org.apache.hadoop.hbase.client.Table;
|
||||||
import org.apache.hadoop.hbase.regionserver.StoreFile;
|
import org.apache.hadoop.hbase.regionserver.StoreFile;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -73,15 +78,30 @@ public class MobTestUtil {
|
||||||
/**
|
/**
|
||||||
* Compare two Cells only for their row family qualifier value
|
* Compare two Cells only for their row family qualifier value
|
||||||
*/
|
*/
|
||||||
public static void assertCellEquals(Cell firstKeyValue,
|
public static void assertCellEquals(Cell firstKeyValue, Cell secondKeyValue) {
|
||||||
Cell secondKeyValue) {
|
Assert.assertArrayEquals(CellUtil.cloneRow(firstKeyValue),
|
||||||
Assert.assertEquals(Bytes.toString(CellUtil.cloneRow(firstKeyValue)),
|
CellUtil.cloneRow(secondKeyValue));
|
||||||
Bytes.toString(CellUtil.cloneRow(secondKeyValue)));
|
Assert.assertArrayEquals(CellUtil.cloneFamily(firstKeyValue),
|
||||||
Assert.assertEquals(Bytes.toString(CellUtil.cloneFamily(firstKeyValue)),
|
CellUtil.cloneFamily(secondKeyValue));
|
||||||
Bytes.toString(CellUtil.cloneFamily(secondKeyValue)));
|
Assert.assertArrayEquals(CellUtil.cloneQualifier(firstKeyValue),
|
||||||
Assert.assertEquals(Bytes.toString(CellUtil.cloneQualifier(firstKeyValue)),
|
CellUtil.cloneQualifier(secondKeyValue));
|
||||||
Bytes.toString(CellUtil.cloneQualifier(secondKeyValue)));
|
Assert.assertArrayEquals(CellUtil.cloneValue(firstKeyValue),
|
||||||
Assert.assertEquals(Bytes.toString(CellUtil.cloneValue(firstKeyValue)),
|
CellUtil.cloneValue(secondKeyValue));
|
||||||
Bytes.toString(CellUtil.cloneValue(secondKeyValue)));
|
}
|
||||||
}
|
|
||||||
|
public static void assertCellsValue(Table table, Scan scan,
|
||||||
|
byte[] expectedValue, int expectedCount) throws IOException {
|
||||||
|
ResultScanner results = table.getScanner(scan);
|
||||||
|
int count = 0;
|
||||||
|
for (Result res : results) {
|
||||||
|
List<Cell> cells = res.listCells();
|
||||||
|
for(Cell cell : cells) {
|
||||||
|
// Verify the value
|
||||||
|
Assert.assertArrayEquals(expectedValue, CellUtil.cloneValue(cell));
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
results.close();
|
||||||
|
Assert.assertEquals(expectedCount, count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
import org.apache.hadoop.hbase.Cell;
|
import org.apache.hadoop.hbase.Cell;
|
||||||
import org.apache.hadoop.hbase.HBaseConfiguration;
|
import org.apache.hadoop.hbase.HBaseConfiguration;
|
||||||
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
import org.apache.hadoop.hbase.KeyValue;
|
import org.apache.hadoop.hbase.KeyValue;
|
||||||
import org.apache.hadoop.hbase.KeyValue.Type;
|
import org.apache.hadoop.hbase.KeyValue.Type;
|
||||||
import org.apache.hadoop.hbase.io.hfile.CacheConfig;
|
import org.apache.hadoop.hbase.io.hfile.CacheConfig;
|
||||||
|
@ -43,10 +44,9 @@ import org.junit.experimental.categories.Category;
|
||||||
@Category(SmallTests.class)
|
@Category(SmallTests.class)
|
||||||
public class TestCachedMobFile extends TestCase{
|
public class TestCachedMobFile extends TestCase{
|
||||||
static final Log LOG = LogFactory.getLog(TestCachedMobFile.class);
|
static final Log LOG = LogFactory.getLog(TestCachedMobFile.class);
|
||||||
private Configuration conf = HBaseConfiguration.create();
|
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||||
|
private Configuration conf = TEST_UTIL.getConfiguration();
|
||||||
private CacheConfig cacheConf = new CacheConfig(conf);
|
private CacheConfig cacheConf = new CacheConfig(conf);
|
||||||
private static final String TABLE = "tableName";
|
|
||||||
private static final String FAMILY = "familyName";
|
|
||||||
private static final String FAMILY1 = "familyName1";
|
private static final String FAMILY1 = "familyName1";
|
||||||
private static final String FAMILY2 = "familyName2";
|
private static final String FAMILY2 = "familyName2";
|
||||||
private static final long EXPECTED_REFERENCE_ZERO = 0;
|
private static final long EXPECTED_REFERENCE_ZERO = 0;
|
||||||
|
@ -56,13 +56,11 @@ public class TestCachedMobFile extends TestCase{
|
||||||
@Test
|
@Test
|
||||||
public void testOpenClose() throws Exception {
|
public void testOpenClose() throws Exception {
|
||||||
String caseName = getName();
|
String caseName = getName();
|
||||||
FileSystem fs = FileSystem.get(conf);
|
Path testDir = TEST_UTIL.getDataTestDir();
|
||||||
Path testDir = FSUtils.getRootDir(conf);
|
FileSystem fs = testDir.getFileSystem(conf);
|
||||||
Path outputDir = new Path(new Path(testDir, TABLE),
|
|
||||||
FAMILY);
|
|
||||||
HFileContext meta = new HFileContextBuilder().withBlockSize(8*1024).build();
|
HFileContext meta = new HFileContextBuilder().withBlockSize(8*1024).build();
|
||||||
StoreFile.Writer writer = new StoreFile.WriterBuilder(conf, cacheConf, fs)
|
StoreFile.Writer writer = new StoreFile.WriterBuilder(conf, cacheConf, fs)
|
||||||
.withOutputDir(outputDir).withFileContext(meta).build();
|
.withOutputDir(testDir).withFileContext(meta).build();
|
||||||
MobTestUtil.writeStoreFile(writer, caseName);
|
MobTestUtil.writeStoreFile(writer, caseName);
|
||||||
CachedMobFile cachedMobFile = CachedMobFile.create(fs, writer.getPath(), conf, cacheConf);
|
CachedMobFile cachedMobFile = CachedMobFile.create(fs, writer.getPath(), conf, cacheConf);
|
||||||
Assert.assertEquals(EXPECTED_REFERENCE_ZERO, cachedMobFile.getReferenceCount());
|
Assert.assertEquals(EXPECTED_REFERENCE_ZERO, cachedMobFile.getReferenceCount());
|
||||||
|
@ -79,17 +77,15 @@ public class TestCachedMobFile extends TestCase{
|
||||||
@Test
|
@Test
|
||||||
public void testCompare() throws Exception {
|
public void testCompare() throws Exception {
|
||||||
String caseName = getName();
|
String caseName = getName();
|
||||||
FileSystem fs = FileSystem.get(conf);
|
Path testDir = TEST_UTIL.getDataTestDir();
|
||||||
Path testDir = FSUtils.getRootDir(conf);
|
FileSystem fs = testDir.getFileSystem(conf);
|
||||||
Path outputDir1 = new Path(new Path(testDir, TABLE),
|
Path outputDir1 = new Path(testDir, FAMILY1);
|
||||||
FAMILY1);
|
|
||||||
HFileContext meta = new HFileContextBuilder().withBlockSize(8 * 1024).build();
|
HFileContext meta = new HFileContextBuilder().withBlockSize(8 * 1024).build();
|
||||||
StoreFile.Writer writer1 = new StoreFile.WriterBuilder(conf, cacheConf, fs)
|
StoreFile.Writer writer1 = new StoreFile.WriterBuilder(conf, cacheConf, fs)
|
||||||
.withOutputDir(outputDir1).withFileContext(meta).build();
|
.withOutputDir(outputDir1).withFileContext(meta).build();
|
||||||
MobTestUtil.writeStoreFile(writer1, caseName);
|
MobTestUtil.writeStoreFile(writer1, caseName);
|
||||||
CachedMobFile cachedMobFile1 = CachedMobFile.create(fs, writer1.getPath(), conf, cacheConf);
|
CachedMobFile cachedMobFile1 = CachedMobFile.create(fs, writer1.getPath(), conf, cacheConf);
|
||||||
Path outputDir2 = new Path(new Path(testDir, TABLE),
|
Path outputDir2 = new Path(testDir, FAMILY2);
|
||||||
FAMILY2);
|
|
||||||
StoreFile.Writer writer2 = new StoreFile.WriterBuilder(conf, cacheConf, fs)
|
StoreFile.Writer writer2 = new StoreFile.WriterBuilder(conf, cacheConf, fs)
|
||||||
.withOutputDir(outputDir2)
|
.withOutputDir(outputDir2)
|
||||||
.withFileContext(meta)
|
.withFileContext(meta)
|
||||||
|
@ -105,12 +101,11 @@ public class TestCachedMobFile extends TestCase{
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadKeyValue() throws Exception {
|
public void testReadKeyValue() throws Exception {
|
||||||
FileSystem fs = FileSystem.get(conf);
|
Path testDir = TEST_UTIL.getDataTestDir();
|
||||||
Path testDir = FSUtils.getRootDir(conf);
|
FileSystem fs = testDir.getFileSystem(conf);
|
||||||
Path outputDir = new Path(new Path(testDir, TABLE), "familyname");
|
|
||||||
HFileContext meta = new HFileContextBuilder().withBlockSize(8 * 1024).build();
|
HFileContext meta = new HFileContextBuilder().withBlockSize(8 * 1024).build();
|
||||||
StoreFile.Writer writer = new StoreFile.WriterBuilder(conf, cacheConf, fs)
|
StoreFile.Writer writer = new StoreFile.WriterBuilder(conf, cacheConf, fs)
|
||||||
.withOutputDir(outputDir).withFileContext(meta).build();
|
.withOutputDir(testDir).withFileContext(meta).build();
|
||||||
String caseName = getName();
|
String caseName = getName();
|
||||||
MobTestUtil.writeStoreFile(writer, caseName);
|
MobTestUtil.writeStoreFile(writer, caseName);
|
||||||
CachedMobFile cachedMobFile = CachedMobFile.create(fs, writer.getPath(), conf, cacheConf);
|
CachedMobFile cachedMobFile = CachedMobFile.create(fs, writer.getPath(), conf, cacheConf);
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.mob;
|
package org.apache.hadoop.hbase.mob;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.Cell;
|
import org.apache.hadoop.hbase.Cell;
|
||||||
|
@ -26,9 +25,7 @@ import org.apache.hadoop.hbase.CellUtil;
|
||||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||||
import org.apache.hadoop.hbase.MasterNotRunningException;
|
|
||||||
import org.apache.hadoop.hbase.TableName;
|
import org.apache.hadoop.hbase.TableName;
|
||||||
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
|
|
||||||
import org.apache.hadoop.hbase.client.*;
|
import org.apache.hadoop.hbase.client.*;
|
||||||
import org.apache.hadoop.hbase.testclassification.LargeTests;
|
import org.apache.hadoop.hbase.testclassification.LargeTests;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
|
@ -64,127 +61,67 @@ public class TestDefaultMobStoreFlusher {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFlushNonMobFile() throws InterruptedException {
|
public void testFlushNonMobFile() throws Exception {
|
||||||
String TN = "testFlushNonMobFile";
|
TableName tn = TableName.valueOf("testFlushNonMobFile");
|
||||||
TableName tn = TableName.valueOf(TN);
|
HTableDescriptor desc = new HTableDescriptor(tn);
|
||||||
Table table = null;
|
HColumnDescriptor hcd = new HColumnDescriptor(family);
|
||||||
HBaseAdmin admin = null;
|
hcd.setMaxVersions(4);
|
||||||
|
desc.addFamily(hcd);
|
||||||
|
|
||||||
try {
|
testFlushFile(desc);
|
||||||
HTableDescriptor desc = new HTableDescriptor(tn);
|
|
||||||
HColumnDescriptor hcd = new HColumnDescriptor(family);
|
|
||||||
hcd.setMaxVersions(4);
|
|
||||||
desc.addFamily(hcd);
|
|
||||||
|
|
||||||
admin = TEST_UTIL.getHBaseAdmin();
|
|
||||||
admin.createTable(desc);
|
|
||||||
table = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())
|
|
||||||
.getTable(TableName.valueOf(TN));
|
|
||||||
|
|
||||||
//Put data
|
|
||||||
Put put0 = new Put(row1);
|
|
||||||
put0.addColumn(family, qf1, 1, value1);
|
|
||||||
table.put(put0);
|
|
||||||
|
|
||||||
//Put more data
|
|
||||||
Put put1 = new Put(row2);
|
|
||||||
put1.addColumn(family, qf2, 1, value2);
|
|
||||||
table.put(put1);
|
|
||||||
|
|
||||||
//Flush
|
|
||||||
admin.flush(tn);
|
|
||||||
|
|
||||||
Scan scan = new Scan();
|
|
||||||
scan.addColumn(family, qf1);
|
|
||||||
scan.setMaxVersions(4);
|
|
||||||
ResultScanner scanner = table.getScanner(scan);
|
|
||||||
|
|
||||||
//Compare
|
|
||||||
Result result = scanner.next();
|
|
||||||
int size = 0;
|
|
||||||
while (result != null) {
|
|
||||||
size++;
|
|
||||||
List<Cell> cells = result.getColumnCells(family, qf1);
|
|
||||||
// Verify the cell size
|
|
||||||
Assert.assertEquals(1, cells.size());
|
|
||||||
// Verify the value
|
|
||||||
Assert.assertEquals(Bytes.toString(value1),
|
|
||||||
Bytes.toString(CellUtil.cloneValue(cells.get(0))));
|
|
||||||
result = scanner.next();
|
|
||||||
}
|
|
||||||
scanner.close();
|
|
||||||
Assert.assertEquals(1, size);
|
|
||||||
admin.close();
|
|
||||||
} catch (MasterNotRunningException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} catch (ZooKeeperConnectionException e2) {
|
|
||||||
e2.printStackTrace();
|
|
||||||
} catch (IOException e3) {
|
|
||||||
e3.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFlushMobFile() throws InterruptedException {
|
public void testFlushMobFile() throws Exception {
|
||||||
String TN = "testFlushMobFile";
|
TableName tn = TableName.valueOf("testFlushMobFile");
|
||||||
TableName tn = TableName.valueOf(TN);
|
HTableDescriptor desc = new HTableDescriptor(tn);
|
||||||
Table table = null;
|
HColumnDescriptor hcd = new HColumnDescriptor(family);
|
||||||
Admin admin = null;
|
hcd.setMobEnabled(true);
|
||||||
|
hcd.setMobThreshold(3L);
|
||||||
|
hcd.setMaxVersions(4);
|
||||||
|
desc.addFamily(hcd);
|
||||||
|
|
||||||
try {
|
testFlushFile(desc);
|
||||||
HTableDescriptor desc = new HTableDescriptor(tn);
|
|
||||||
HColumnDescriptor hcd = new HColumnDescriptor(family);
|
|
||||||
hcd.setMobEnabled(true);
|
|
||||||
hcd.setMobThreshold(3L);
|
|
||||||
hcd.setMaxVersions(4);
|
|
||||||
desc.addFamily(hcd);
|
|
||||||
|
|
||||||
Connection c = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
|
|
||||||
admin = c.getAdmin();
|
|
||||||
admin.createTable(desc);
|
|
||||||
table = c.getTable(TableName.valueOf(TN));
|
|
||||||
|
|
||||||
//put data
|
|
||||||
Put put0 = new Put(row1);
|
|
||||||
put0.addColumn(family, qf1, 1, value1);
|
|
||||||
table.put(put0);
|
|
||||||
|
|
||||||
//put more data
|
|
||||||
Put put1 = new Put(row2);
|
|
||||||
put1.addColumn(family, qf2, 1, value2);
|
|
||||||
table.put(put1);
|
|
||||||
|
|
||||||
//flush
|
|
||||||
admin.flush(tn);
|
|
||||||
|
|
||||||
//Scan
|
|
||||||
Scan scan = new Scan();
|
|
||||||
scan.addColumn(family, qf1);
|
|
||||||
scan.setMaxVersions(4);
|
|
||||||
ResultScanner scanner = table.getScanner(scan);
|
|
||||||
|
|
||||||
//Compare
|
|
||||||
Result result = scanner.next();
|
|
||||||
int size = 0;
|
|
||||||
while (result != null) {
|
|
||||||
size++;
|
|
||||||
List<Cell> cells = result.getColumnCells(family, qf1);
|
|
||||||
// Verify the the cell size
|
|
||||||
Assert.assertEquals(1, cells.size());
|
|
||||||
// Verify the value
|
|
||||||
Assert.assertEquals(Bytes.toString(value1),
|
|
||||||
Bytes.toString(CellUtil.cloneValue(cells.get(0))));
|
|
||||||
result = scanner.next();
|
|
||||||
}
|
|
||||||
scanner.close();
|
|
||||||
Assert.assertEquals(1, size);
|
|
||||||
admin.close();
|
|
||||||
} catch (MasterNotRunningException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} catch (ZooKeeperConnectionException e2) {
|
|
||||||
e2.printStackTrace();
|
|
||||||
} catch (IOException e3) {
|
|
||||||
e3.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void testFlushFile(HTableDescriptor htd) throws Exception {
|
||||||
|
Table table = null;
|
||||||
|
try {
|
||||||
|
table = TEST_UTIL.createTable(htd, null);
|
||||||
|
|
||||||
|
//put data
|
||||||
|
Put put0 = new Put(row1);
|
||||||
|
put0.addColumn(family, qf1, 1, value1);
|
||||||
|
table.put(put0);
|
||||||
|
|
||||||
|
//put more data
|
||||||
|
Put put1 = new Put(row2);
|
||||||
|
put1.addColumn(family, qf2, 1, value2);
|
||||||
|
table.put(put1);
|
||||||
|
|
||||||
|
//flush
|
||||||
|
TEST_UTIL.flush(htd.getTableName());
|
||||||
|
|
||||||
|
//Scan
|
||||||
|
Scan scan = new Scan();
|
||||||
|
scan.addColumn(family, qf1);
|
||||||
|
scan.setMaxVersions(4);
|
||||||
|
ResultScanner scanner = table.getScanner(scan);
|
||||||
|
|
||||||
|
//Compare
|
||||||
|
int size = 0;
|
||||||
|
for (Result result: scanner) {
|
||||||
|
size++;
|
||||||
|
List<Cell> cells = result.getColumnCells(family, qf1);
|
||||||
|
// Verify the cell size
|
||||||
|
Assert.assertEquals(1, cells.size());
|
||||||
|
// Verify the value
|
||||||
|
Assert.assertArrayEquals(value1, CellUtil.cloneValue(cells.get(0)));
|
||||||
|
}
|
||||||
|
scanner.close();
|
||||||
|
Assert.assertEquals(1, size);
|
||||||
|
} finally {
|
||||||
|
table.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
|
||||||
import org.apache.hadoop.fs.FileStatus;
|
import org.apache.hadoop.fs.FileStatus;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
|
@ -124,7 +123,7 @@ public class TestExpiredMobFileCleaner {
|
||||||
public void testCleaner() throws Exception {
|
public void testCleaner() throws Exception {
|
||||||
init();
|
init();
|
||||||
|
|
||||||
Path mobDirPath = getMobFamilyPath(TEST_UTIL.getConfiguration(), tableName, family);
|
Path mobDirPath = MobUtils.getMobFamilyPath(TEST_UTIL.getConfiguration(), tableName, family);
|
||||||
|
|
||||||
byte[] dummyData = makeDummyData(600);
|
byte[] dummyData = makeDummyData(600);
|
||||||
long ts = System.currentTimeMillis() - 3 * secondsOfDay() * 1000; // 3 days before
|
long ts = System.currentTimeMillis() - 3 * secondsOfDay() * 1000; // 3 days before
|
||||||
|
@ -158,11 +157,6 @@ public class TestExpiredMobFileCleaner {
|
||||||
assertEquals("After cleanup without delay 2", secondFile, lastFile);
|
assertEquals("After cleanup without delay 2", secondFile, lastFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path getMobFamilyPath(Configuration conf, TableName tableName, String familyName) {
|
|
||||||
Path p = new Path(MobUtils.getMobRegionPath(conf, tableName), familyName);
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int secondsOfDay() {
|
private int secondsOfDay() {
|
||||||
return 24 * 3600;
|
return 24 * 3600;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.mob;
|
package org.apache.hadoop.hbase.mob;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.Cell;
|
|
||||||
import org.apache.hadoop.hbase.CellUtil;
|
|
||||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||||
|
@ -32,7 +29,6 @@ import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
|
||||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
|
@ -117,19 +113,6 @@ public class TestMobDataBlockEncoding {
|
||||||
|
|
||||||
Scan scan = new Scan();
|
Scan scan = new Scan();
|
||||||
scan.setMaxVersions(4);
|
scan.setMaxVersions(4);
|
||||||
|
MobTestUtil.assertCellsValue(table, scan, value, 3);
|
||||||
ResultScanner results = table.getScanner(scan);
|
|
||||||
int count = 0;
|
|
||||||
for (Result res : results) {
|
|
||||||
List<Cell> cells = res.listCells();
|
|
||||||
for(Cell cell : cells) {
|
|
||||||
// Verify the value
|
|
||||||
Assert.assertEquals(Bytes.toString(value),
|
|
||||||
Bytes.toString(CellUtil.cloneValue(cell)));
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
results.close();
|
|
||||||
Assert.assertEquals(3, count);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,17 +47,14 @@ public class TestMobFile extends TestCase {
|
||||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||||
private Configuration conf = TEST_UTIL.getConfiguration();
|
private Configuration conf = TEST_UTIL.getConfiguration();
|
||||||
private CacheConfig cacheConf = new CacheConfig(conf);
|
private CacheConfig cacheConf = new CacheConfig(conf);
|
||||||
private final String TABLE = "tableName";
|
|
||||||
private final String FAMILY = "familyName";
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadKeyValue() throws Exception {
|
public void testReadKeyValue() throws Exception {
|
||||||
FileSystem fs = FileSystem.get(conf);
|
Path testDir = TEST_UTIL.getDataTestDir();
|
||||||
Path testDir = FSUtils.getRootDir(conf);
|
FileSystem fs = testDir.getFileSystem(conf);
|
||||||
Path outputDir = new Path(new Path(testDir, TABLE), FAMILY);
|
|
||||||
HFileContext meta = new HFileContextBuilder().withBlockSize(8*1024).build();
|
HFileContext meta = new HFileContextBuilder().withBlockSize(8*1024).build();
|
||||||
StoreFile.Writer writer = new StoreFile.WriterBuilder(conf, cacheConf, fs)
|
StoreFile.Writer writer = new StoreFile.WriterBuilder(conf, cacheConf, fs)
|
||||||
.withOutputDir(outputDir)
|
.withOutputDir(testDir)
|
||||||
.withFileContext(meta)
|
.withFileContext(meta)
|
||||||
.build();
|
.build();
|
||||||
String caseName = getName();
|
String caseName = getName();
|
||||||
|
@ -106,12 +103,11 @@ public class TestMobFile extends TestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetScanner() throws Exception {
|
public void testGetScanner() throws Exception {
|
||||||
FileSystem fs = FileSystem.get(conf);
|
Path testDir = TEST_UTIL.getDataTestDir();
|
||||||
Path testDir = FSUtils.getRootDir(conf);
|
FileSystem fs = testDir.getFileSystem(conf);
|
||||||
Path outputDir = new Path(new Path(testDir, TABLE), FAMILY);
|
|
||||||
HFileContext meta = new HFileContextBuilder().withBlockSize(8*1024).build();
|
HFileContext meta = new HFileContextBuilder().withBlockSize(8*1024).build();
|
||||||
StoreFile.Writer writer = new StoreFile.WriterBuilder(conf, cacheConf, fs)
|
StoreFile.Writer writer = new StoreFile.WriterBuilder(conf, cacheConf, fs)
|
||||||
.withOutputDir(outputDir)
|
.withOutputDir(testDir)
|
||||||
.withFileContext(meta)
|
.withFileContext(meta)
|
||||||
.build();
|
.build();
|
||||||
MobTestUtil.writeStoreFile(writer, getName());
|
MobTestUtil.writeStoreFile(writer, getName());
|
||||||
|
|
|
@ -413,8 +413,8 @@ public class TestMobCompactor {
|
||||||
result = table.get(get);
|
result = table.get(get);
|
||||||
cell = result.getColumnLatestCell(hcd1.getName(), Bytes.toBytes(qf1));
|
cell = result.getColumnLatestCell(hcd1.getName(), Bytes.toBytes(qf1));
|
||||||
// the ref name is the new file
|
// the ref name is the new file
|
||||||
Path mobFamilyPath = new Path(
|
Path mobFamilyPath =
|
||||||
MobUtils.getMobRegionPath(TEST_UTIL.getConfiguration(), tableName), hcd1.getNameAsString());
|
MobUtils.getMobFamilyPath(TEST_UTIL.getConfiguration(), tableName, hcd1.getNameAsString());
|
||||||
List<Path> paths = new ArrayList<Path>();
|
List<Path> paths = new ArrayList<Path>();
|
||||||
if (fs.exists(mobFamilyPath)) {
|
if (fs.exists(mobFamilyPath)) {
|
||||||
FileStatus[] files = fs.listStatus(mobFamilyPath);
|
FileStatus[] files = fs.listStatus(mobFamilyPath);
|
||||||
|
@ -495,13 +495,7 @@ public class TestMobCompactor {
|
||||||
Scan scan = new Scan();
|
Scan scan = new Scan();
|
||||||
// Do not retrieve the mob data when scanning
|
// Do not retrieve the mob data when scanning
|
||||||
scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE));
|
scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE));
|
||||||
ResultScanner results = table.getScanner(scan);
|
return TEST_UTIL.countRows(table, scan);
|
||||||
int count = 0;
|
|
||||||
for (Result res : results) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
results.close();
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -532,8 +526,7 @@ public class TestMobCompactor {
|
||||||
*/
|
*/
|
||||||
private int countFiles(TableName tableName, boolean isMobFile, String familyName)
|
private int countFiles(TableName tableName, boolean isMobFile, String familyName)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Path mobDirPath = MobUtils.getMobFamilyPath(
|
Path mobDirPath = MobUtils.getMobFamilyPath(conf, tableName, familyName);
|
||||||
MobUtils.getMobRegionPath(conf, tableName), familyName);
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if (fs.exists(mobDirPath)) {
|
if (fs.exists(mobDirPath)) {
|
||||||
FileStatus[] files = fs.listStatus(mobDirPath);
|
FileStatus[] files = fs.listStatus(mobDirPath);
|
||||||
|
@ -553,8 +546,7 @@ public class TestMobCompactor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean verifyEncryption(TableName tableName, String familyName) throws IOException {
|
private boolean verifyEncryption(TableName tableName, String familyName) throws IOException {
|
||||||
Path mobDirPath = MobUtils.getMobFamilyPath(MobUtils.getMobRegionPath(conf, tableName),
|
Path mobDirPath = MobUtils.getMobFamilyPath(conf, tableName, familyName);
|
||||||
familyName);
|
|
||||||
boolean hasFiles = false;
|
boolean hasFiles = false;
|
||||||
if (fs.exists(mobDirPath)) {
|
if (fs.exists(mobDirPath)) {
|
||||||
FileStatus[] files = fs.listStatus(mobDirPath);
|
FileStatus[] files = fs.listStatus(mobDirPath);
|
||||||
|
@ -579,8 +571,7 @@ public class TestMobCompactor {
|
||||||
* @return the number of the HFileLink
|
* @return the number of the HFileLink
|
||||||
*/
|
*/
|
||||||
private int countHFileLinks(String familyName) throws IOException {
|
private int countHFileLinks(String familyName) throws IOException {
|
||||||
Path mobDirPath = MobUtils.getMobFamilyPath(
|
Path mobDirPath = MobUtils.getMobFamilyPath(conf, tableName, familyName);
|
||||||
MobUtils.getMobRegionPath(conf, tableName), familyName);
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if (fs.exists(mobDirPath)) {
|
if (fs.exists(mobDirPath)) {
|
||||||
FileStatus[] files = fs.listStatus(mobDirPath);
|
FileStatus[] files = fs.listStatus(mobDirPath);
|
||||||
|
@ -601,8 +592,7 @@ public class TestMobCompactor {
|
||||||
* @return the number of files large than the size
|
* @return the number of files large than the size
|
||||||
*/
|
*/
|
||||||
private int countLargeFiles(int size, TableName tableName, String familyName) throws IOException {
|
private int countLargeFiles(int size, TableName tableName, String familyName) throws IOException {
|
||||||
Path mobDirPath = MobUtils.getMobFamilyPath(MobUtils.getMobRegionPath(conf, tableName),
|
Path mobDirPath = MobUtils.getMobFamilyPath(conf, tableName, familyName);
|
||||||
familyName);
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if (fs.exists(mobDirPath)) {
|
if (fs.exists(mobDirPath)) {
|
||||||
FileStatus[] files = fs.listStatus(mobDirPath);
|
FileStatus[] files = fs.listStatus(mobDirPath);
|
||||||
|
@ -729,8 +719,8 @@ public class TestMobCompactor {
|
||||||
// Do not retrieve the mob data when scanning
|
// Do not retrieve the mob data when scanning
|
||||||
scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE));
|
scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE));
|
||||||
ResultScanner results = table.getScanner(scan);
|
ResultScanner results = table.getScanner(scan);
|
||||||
Path mobFamilyPath = new Path(MobUtils.getMobRegionPath(TEST_UTIL.getConfiguration(),
|
Path mobFamilyPath = MobUtils.getMobFamilyPath(TEST_UTIL.getConfiguration(),
|
||||||
tableName), familyName);
|
tableName, familyName);
|
||||||
List<Path> actualFilePaths = new ArrayList<>();
|
List<Path> actualFilePaths = new ArrayList<>();
|
||||||
List<Path> expectFilePaths = new ArrayList<>();
|
List<Path> expectFilePaths = new ArrayList<>();
|
||||||
for (Result res : results) {
|
for (Result res : results) {
|
||||||
|
|
|
@ -104,8 +104,27 @@ public class TestPartitionedMobCompactor {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCompactionSelectWithAllFiles() throws Exception {
|
public void testCompactionSelectWithAllFiles() throws Exception {
|
||||||
resetConf();
|
|
||||||
String tableName = "testCompactionSelectWithAllFiles";
|
String tableName = "testCompactionSelectWithAllFiles";
|
||||||
|
testCompactionAtMergeSize(tableName, MobConstants.DEFAULT_MOB_COMPACTION_MERGEABLE_THRESHOLD,
|
||||||
|
CompactionType.ALL_FILES, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompactionSelectWithPartFiles() throws Exception {
|
||||||
|
String tableName = "testCompactionSelectWithPartFiles";
|
||||||
|
testCompactionAtMergeSize(tableName, 4000, CompactionType.PART_FILES, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompactionSelectWithForceAllFiles() throws Exception {
|
||||||
|
String tableName = "testCompactionSelectWithForceAllFiles";
|
||||||
|
testCompactionAtMergeSize(tableName, Long.MAX_VALUE, CompactionType.ALL_FILES, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testCompactionAtMergeSize(final String tableName,
|
||||||
|
final long mergeSize, final CompactionType type, final boolean isForceAllFiles)
|
||||||
|
throws Exception {
|
||||||
|
resetConf();
|
||||||
init(tableName);
|
init(tableName);
|
||||||
int count = 10;
|
int count = 10;
|
||||||
// create 10 mob files.
|
// create 10 mob files.
|
||||||
|
@ -113,7 +132,6 @@ public class TestPartitionedMobCompactor {
|
||||||
// create 10 del files
|
// create 10 del files
|
||||||
createStoreFiles(basePath, family, qf, count, Type.Delete);
|
createStoreFiles(basePath, family, qf, count, Type.Delete);
|
||||||
listFiles();
|
listFiles();
|
||||||
long mergeSize = MobConstants.DEFAULT_MOB_COMPACTION_MERGEABLE_THRESHOLD;
|
|
||||||
List<String> expectedStartKeys = new ArrayList<>();
|
List<String> expectedStartKeys = new ArrayList<>();
|
||||||
for(FileStatus file : mobFiles) {
|
for(FileStatus file : mobFiles) {
|
||||||
if(file.getLen() < mergeSize) {
|
if(file.getLen() < mergeSize) {
|
||||||
|
@ -122,90 +140,33 @@ public class TestPartitionedMobCompactor {
|
||||||
expectedStartKeys.add(startKey);
|
expectedStartKeys.add(startKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
testSelectFiles(tableName, CompactionType.ALL_FILES, false, expectedStartKeys);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCompactionSelectWithPartFiles() throws Exception {
|
|
||||||
resetConf();
|
|
||||||
String tableName = "testCompactionSelectWithPartFiles";
|
|
||||||
init(tableName);
|
|
||||||
int count = 10;
|
|
||||||
// create 10 mob files.
|
|
||||||
createStoreFiles(basePath, family, qf, count, Type.Put);
|
|
||||||
// create 10 del files
|
|
||||||
createStoreFiles(basePath, family, qf, count, Type.Delete);
|
|
||||||
listFiles();
|
|
||||||
long mergeSize = 4000;
|
|
||||||
List<String> expectedStartKeys = new ArrayList<>();
|
|
||||||
for(FileStatus file : mobFiles) {
|
|
||||||
if(file.getLen() < 4000) {
|
|
||||||
String fileName = file.getPath().getName();
|
|
||||||
String startKey = fileName.substring(0, 32);
|
|
||||||
expectedStartKeys.add(startKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// set the mob compaction mergeable threshold
|
// set the mob compaction mergeable threshold
|
||||||
conf.setLong(MobConstants.MOB_COMPACTION_MERGEABLE_THRESHOLD, mergeSize);
|
conf.setLong(MobConstants.MOB_COMPACTION_MERGEABLE_THRESHOLD, mergeSize);
|
||||||
testSelectFiles(tableName, CompactionType.PART_FILES, false, expectedStartKeys);
|
testSelectFiles(tableName, type, isForceAllFiles, expectedStartKeys);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCompactionSelectWithForceAllFiles() throws Exception {
|
|
||||||
resetConf();
|
|
||||||
String tableName = "testCompactionSelectWithForceAllFiles";
|
|
||||||
init(tableName);
|
|
||||||
int count = 10;
|
|
||||||
// create 10 mob files.
|
|
||||||
createStoreFiles(basePath, family, qf, count, Type.Put);
|
|
||||||
// create 10 del files
|
|
||||||
createStoreFiles(basePath, family, qf, count, Type.Delete);
|
|
||||||
listFiles();
|
|
||||||
long mergeSize = 4000;
|
|
||||||
List<String> expectedStartKeys = new ArrayList<>();
|
|
||||||
for(FileStatus file : mobFiles) {
|
|
||||||
String fileName = file.getPath().getName();
|
|
||||||
String startKey = fileName.substring(0, 32);
|
|
||||||
expectedStartKeys.add(startKey);
|
|
||||||
}
|
|
||||||
// set the mob compaction mergeable threshold
|
|
||||||
conf.setLong(MobConstants.MOB_COMPACTION_MERGEABLE_THRESHOLD, mergeSize);
|
|
||||||
testSelectFiles(tableName, CompactionType.ALL_FILES, true, expectedStartKeys);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCompactDelFilesWithDefaultBatchSize() throws Exception {
|
public void testCompactDelFilesWithDefaultBatchSize() throws Exception {
|
||||||
resetConf();
|
|
||||||
String tableName = "testCompactDelFilesWithDefaultBatchSize";
|
String tableName = "testCompactDelFilesWithDefaultBatchSize";
|
||||||
init(tableName);
|
testCompactDelFilesAtBatchSize(tableName, MobConstants.DEFAULT_MOB_COMPACTION_BATCH_SIZE,
|
||||||
// create 20 mob files.
|
MobConstants.DEFAULT_MOB_DELFILE_MAX_COUNT);
|
||||||
createStoreFiles(basePath, family, qf, 20, Type.Put);
|
|
||||||
// create 13 del files
|
|
||||||
createStoreFiles(basePath, family, qf, 13, Type.Delete);
|
|
||||||
listFiles();
|
|
||||||
testCompactDelFiles(tableName, 1, 13, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCompactDelFilesWithSmallBatchSize() throws Exception {
|
public void testCompactDelFilesWithSmallBatchSize() throws Exception {
|
||||||
resetConf();
|
|
||||||
String tableName = "testCompactDelFilesWithSmallBatchSize";
|
String tableName = "testCompactDelFilesWithSmallBatchSize";
|
||||||
init(tableName);
|
testCompactDelFilesAtBatchSize(tableName, 4, MobConstants.DEFAULT_MOB_DELFILE_MAX_COUNT);
|
||||||
// create 20 mob files.
|
|
||||||
createStoreFiles(basePath, family, qf, 20, Type.Put);
|
|
||||||
// create 13 del files
|
|
||||||
createStoreFiles(basePath, family, qf, 13, Type.Delete);
|
|
||||||
listFiles();
|
|
||||||
|
|
||||||
// set the mob compaction batch size
|
|
||||||
conf.setInt(MobConstants.MOB_COMPACTION_BATCH_SIZE, 4);
|
|
||||||
testCompactDelFiles(tableName, 1, 13, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCompactDelFilesChangeMaxDelFileCount() throws Exception {
|
public void testCompactDelFilesChangeMaxDelFileCount() throws Exception {
|
||||||
resetConf();
|
|
||||||
String tableName = "testCompactDelFilesWithSmallBatchSize";
|
String tableName = "testCompactDelFilesWithSmallBatchSize";
|
||||||
|
testCompactDelFilesAtBatchSize(tableName, 4, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testCompactDelFilesAtBatchSize(String tableName, int batchSize,
|
||||||
|
int delfileMaxCount) throws Exception {
|
||||||
|
resetConf();
|
||||||
init(tableName);
|
init(tableName);
|
||||||
// create 20 mob files.
|
// create 20 mob files.
|
||||||
createStoreFiles(basePath, family, qf, 20, Type.Put);
|
createStoreFiles(basePath, family, qf, 20, Type.Put);
|
||||||
|
@ -214,10 +175,10 @@ public class TestPartitionedMobCompactor {
|
||||||
listFiles();
|
listFiles();
|
||||||
|
|
||||||
// set the max del file count
|
// set the max del file count
|
||||||
conf.setInt(MobConstants.MOB_DELFILE_MAX_COUNT, 5);
|
conf.setInt(MobConstants.MOB_DELFILE_MAX_COUNT, delfileMaxCount);
|
||||||
// set the mob compaction batch size
|
// set the mob compaction batch size
|
||||||
conf.setInt(MobConstants.MOB_COMPACTION_BATCH_SIZE, 2);
|
conf.setInt(MobConstants.MOB_COMPACTION_BATCH_SIZE, batchSize);
|
||||||
testCompactDelFiles(tableName, 4, 13, false);
|
testCompactDelFiles(tableName, 1, 13, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,7 +24,6 @@ import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||||
import org.apache.hadoop.hbase.HRegionInfo;
|
|
||||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||||
import org.apache.hadoop.hbase.TableName;
|
import org.apache.hadoop.hbase.TableName;
|
||||||
import org.apache.hadoop.hbase.client.*;
|
import org.apache.hadoop.hbase.client.*;
|
||||||
|
@ -74,132 +73,110 @@ public class TestDeleteMobTable {
|
||||||
return mobVal;
|
return mobVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private HTableDescriptor createTableDescriptor(TableName tableName, boolean hasMob) {
|
||||||
public void testDeleteMobTable() throws Exception {
|
HTableDescriptor htd = new HTableDescriptor(tableName);
|
||||||
byte[] tableName = Bytes.toBytes("testDeleteMobTable");
|
|
||||||
TableName tn = TableName.valueOf(tableName);
|
|
||||||
HTableDescriptor htd = new HTableDescriptor(tn);
|
|
||||||
HColumnDescriptor hcd = new HColumnDescriptor(FAMILY);
|
HColumnDescriptor hcd = new HColumnDescriptor(FAMILY);
|
||||||
hcd.setMobEnabled(true);
|
if (hasMob) {
|
||||||
hcd.setMobThreshold(0);
|
hcd.setMobEnabled(true);
|
||||||
|
hcd.setMobThreshold(0);
|
||||||
|
}
|
||||||
htd.addFamily(hcd);
|
htd.addFamily(hcd);
|
||||||
HBaseAdmin admin = null;
|
return htd;
|
||||||
Table table = null;
|
}
|
||||||
try {
|
|
||||||
admin = TEST_UTIL.getHBaseAdmin();
|
|
||||||
admin.createTable(htd);
|
|
||||||
table = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration()).getTable(tn);
|
|
||||||
byte[] value = generateMobValue(10);
|
|
||||||
|
|
||||||
|
private Table createTableWithOneFile(HTableDescriptor htd) throws IOException {
|
||||||
|
Table table = TEST_UTIL.createTable(htd, null);
|
||||||
|
try {
|
||||||
|
// insert data
|
||||||
|
byte[] value = generateMobValue(10);
|
||||||
byte[] row = Bytes.toBytes("row");
|
byte[] row = Bytes.toBytes("row");
|
||||||
Put put = new Put(row);
|
Put put = new Put(row);
|
||||||
put.addColumn(FAMILY, QF, EnvironmentEdgeManager.currentTime(), value);
|
put.addColumn(FAMILY, QF, EnvironmentEdgeManager.currentTime(), value);
|
||||||
table.put(put);
|
table.put(put);
|
||||||
|
|
||||||
admin.flush(tn);
|
// create an hfile
|
||||||
|
TEST_UTIL.getHBaseAdmin().flush(htd.getTableName());
|
||||||
|
} catch (IOException e) {
|
||||||
|
table.close();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteMobTable() throws Exception {
|
||||||
|
TableName tn = TableName.valueOf("testDeleteMobTable");
|
||||||
|
HTableDescriptor htd = createTableDescriptor(tn, true);
|
||||||
|
HColumnDescriptor hcd = htd.getFamily(FAMILY);
|
||||||
|
|
||||||
|
String fileName = null;
|
||||||
|
Table table = createTableWithOneFile(htd);
|
||||||
|
try {
|
||||||
// the mob file exists
|
// the mob file exists
|
||||||
Assert.assertEquals(1, countMobFiles(tn, hcd.getNameAsString()));
|
Assert.assertEquals(1, countMobFiles(tn, hcd.getNameAsString()));
|
||||||
Assert.assertEquals(0, countArchiveMobFiles(tn, hcd.getNameAsString()));
|
Assert.assertEquals(0, countArchiveMobFiles(tn, hcd.getNameAsString()));
|
||||||
String fileName = assertHasOneMobRow(table, tn, hcd.getNameAsString());
|
fileName = assertHasOneMobRow(table, tn, hcd.getNameAsString());
|
||||||
Assert.assertFalse(mobArchiveExist(tn, hcd.getNameAsString(), fileName));
|
Assert.assertFalse(mobArchiveExist(tn, hcd.getNameAsString(), fileName));
|
||||||
Assert.assertTrue(mobTableDirExist(tn));
|
Assert.assertTrue(mobTableDirExist(tn));
|
||||||
table.close();
|
|
||||||
|
|
||||||
admin.disableTable(tn);
|
|
||||||
admin.deleteTable(tn);
|
|
||||||
|
|
||||||
Assert.assertFalse(admin.tableExists(tn));
|
|
||||||
Assert.assertEquals(0, countMobFiles(tn, hcd.getNameAsString()));
|
|
||||||
Assert.assertEquals(1, countArchiveMobFiles(tn, hcd.getNameAsString()));
|
|
||||||
Assert.assertTrue(mobArchiveExist(tn, hcd.getNameAsString(), fileName));
|
|
||||||
Assert.assertFalse(mobTableDirExist(tn));
|
|
||||||
} finally {
|
} finally {
|
||||||
if (admin != null) {
|
table.close();
|
||||||
admin.close();
|
TEST_UTIL.deleteTable(tn);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Assert.assertFalse(TEST_UTIL.getHBaseAdmin().tableExists(tn));
|
||||||
|
Assert.assertEquals(0, countMobFiles(tn, hcd.getNameAsString()));
|
||||||
|
Assert.assertEquals(1, countArchiveMobFiles(tn, hcd.getNameAsString()));
|
||||||
|
Assert.assertTrue(mobArchiveExist(tn, hcd.getNameAsString(), fileName));
|
||||||
|
Assert.assertFalse(mobTableDirExist(tn));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteNonMobTable() throws Exception {
|
public void testDeleteNonMobTable() throws Exception {
|
||||||
byte[] tableName = Bytes.toBytes("testDeleteNonMobTable");
|
TableName tn = TableName.valueOf("testDeleteNonMobTable");
|
||||||
TableName tn = TableName.valueOf(tableName);
|
HTableDescriptor htd = createTableDescriptor(tn, false);
|
||||||
HTableDescriptor htd = new HTableDescriptor(tn);
|
HColumnDescriptor hcd = htd.getFamily(FAMILY);
|
||||||
HColumnDescriptor hcd = new HColumnDescriptor(FAMILY);
|
|
||||||
htd.addFamily(hcd);
|
Table table = createTableWithOneFile(htd);
|
||||||
HBaseAdmin admin = null;
|
|
||||||
Table table = null;
|
|
||||||
try {
|
try {
|
||||||
admin = TEST_UTIL.getHBaseAdmin();
|
|
||||||
admin.createTable(htd);
|
|
||||||
table = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration()).getTable(tn);
|
|
||||||
byte[] value = generateMobValue(10);
|
|
||||||
|
|
||||||
byte[] row = Bytes.toBytes("row");
|
|
||||||
Put put = new Put(row);
|
|
||||||
put.addColumn(FAMILY, QF, EnvironmentEdgeManager.currentTime(), value);
|
|
||||||
table.put(put);
|
|
||||||
|
|
||||||
admin.flush(tn);
|
|
||||||
table.close();
|
|
||||||
|
|
||||||
// the mob file doesn't exist
|
// the mob file doesn't exist
|
||||||
Assert.assertEquals(0, countMobFiles(tn, hcd.getNameAsString()));
|
Assert.assertEquals(0, countMobFiles(tn, hcd.getNameAsString()));
|
||||||
Assert.assertEquals(0, countArchiveMobFiles(tn, hcd.getNameAsString()));
|
Assert.assertEquals(0, countArchiveMobFiles(tn, hcd.getNameAsString()));
|
||||||
Assert.assertFalse(mobTableDirExist(tn));
|
Assert.assertFalse(mobTableDirExist(tn));
|
||||||
|
|
||||||
admin.disableTable(tn);
|
|
||||||
admin.deleteTable(tn);
|
|
||||||
|
|
||||||
Assert.assertFalse(admin.tableExists(tn));
|
|
||||||
Assert.assertEquals(0, countMobFiles(tn, hcd.getNameAsString()));
|
|
||||||
Assert.assertEquals(0, countArchiveMobFiles(tn, hcd.getNameAsString()));
|
|
||||||
Assert.assertFalse(mobTableDirExist(tn));
|
|
||||||
} finally {
|
} finally {
|
||||||
if (admin != null) {
|
table.close();
|
||||||
admin.close();
|
TEST_UTIL.deleteTable(tn);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Assert.assertFalse(TEST_UTIL.getHBaseAdmin().tableExists(tn));
|
||||||
|
Assert.assertEquals(0, countMobFiles(tn, hcd.getNameAsString()));
|
||||||
|
Assert.assertEquals(0, countArchiveMobFiles(tn, hcd.getNameAsString()));
|
||||||
|
Assert.assertFalse(mobTableDirExist(tn));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMobFamilyDelete() throws Exception {
|
public void testMobFamilyDelete() throws Exception {
|
||||||
TableName tn = TableName.valueOf("testMobFamilyDelete");
|
TableName tn = TableName.valueOf("testMobFamilyDelete");
|
||||||
HTableDescriptor htd = new HTableDescriptor(tn);
|
HTableDescriptor htd = createTableDescriptor(tn, true);
|
||||||
HColumnDescriptor hcd = new HColumnDescriptor(FAMILY);
|
HColumnDescriptor hcd = htd.getFamily(FAMILY);
|
||||||
hcd.setMobEnabled(true);
|
|
||||||
hcd.setMobThreshold(0);
|
|
||||||
htd.addFamily(hcd);
|
|
||||||
htd.addFamily(new HColumnDescriptor(Bytes.toBytes("family2")));
|
htd.addFamily(new HColumnDescriptor(Bytes.toBytes("family2")));
|
||||||
HBaseAdmin admin = null;
|
|
||||||
Table table = null;
|
Table table = createTableWithOneFile(htd);
|
||||||
try {
|
try {
|
||||||
admin = TEST_UTIL.getHBaseAdmin();
|
|
||||||
admin.createTable(htd);
|
|
||||||
table = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration()).getTable(tn);
|
|
||||||
byte[] value = generateMobValue(10);
|
|
||||||
byte[] row = Bytes.toBytes("row");
|
|
||||||
Put put = new Put(row);
|
|
||||||
put.addColumn(FAMILY, QF, EnvironmentEdgeManager.currentTime(), value);
|
|
||||||
table.put(put);
|
|
||||||
admin.flush(tn);
|
|
||||||
// the mob file exists
|
// the mob file exists
|
||||||
Assert.assertEquals(1, countMobFiles(tn, hcd.getNameAsString()));
|
Assert.assertEquals(1, countMobFiles(tn, hcd.getNameAsString()));
|
||||||
Assert.assertEquals(0, countArchiveMobFiles(tn, hcd.getNameAsString()));
|
Assert.assertEquals(0, countArchiveMobFiles(tn, hcd.getNameAsString()));
|
||||||
String fileName = assertHasOneMobRow(table, tn, hcd.getNameAsString());
|
String fileName = assertHasOneMobRow(table, tn, hcd.getNameAsString());
|
||||||
Assert.assertFalse(mobArchiveExist(tn, hcd.getNameAsString(), fileName));
|
Assert.assertFalse(mobArchiveExist(tn, hcd.getNameAsString(), fileName));
|
||||||
Assert.assertTrue(mobTableDirExist(tn));
|
Assert.assertTrue(mobTableDirExist(tn));
|
||||||
admin.deleteColumnFamily(tn, FAMILY);
|
|
||||||
|
TEST_UTIL.getHBaseAdmin().deleteColumnFamily(tn, FAMILY);
|
||||||
|
|
||||||
Assert.assertEquals(0, countMobFiles(tn, hcd.getNameAsString()));
|
Assert.assertEquals(0, countMobFiles(tn, hcd.getNameAsString()));
|
||||||
Assert.assertEquals(1, countArchiveMobFiles(tn, hcd.getNameAsString()));
|
Assert.assertEquals(1, countArchiveMobFiles(tn, hcd.getNameAsString()));
|
||||||
Assert.assertTrue(mobArchiveExist(tn, hcd.getNameAsString(), fileName));
|
Assert.assertTrue(mobArchiveExist(tn, hcd.getNameAsString(), fileName));
|
||||||
Assert.assertFalse(mobColumnFamilyDirExist(tn));
|
Assert.assertFalse(mobColumnFamilyDirExist(tn, hcd.getNameAsString()));
|
||||||
} finally {
|
} finally {
|
||||||
table.close();
|
table.close();
|
||||||
if (admin != null) {
|
|
||||||
admin.close();
|
|
||||||
}
|
|
||||||
TEST_UTIL.deleteTable(tn);
|
TEST_UTIL.deleteTable(tn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,9 +186,8 @@ public class TestDeleteMobTable {
|
||||||
Path mobFileDir = MobUtils.getMobFamilyPath(TEST_UTIL.getConfiguration(), tn, familyName);
|
Path mobFileDir = MobUtils.getMobFamilyPath(TEST_UTIL.getConfiguration(), tn, familyName);
|
||||||
if (fs.exists(mobFileDir)) {
|
if (fs.exists(mobFileDir)) {
|
||||||
return fs.listStatus(mobFileDir).length;
|
return fs.listStatus(mobFileDir).length;
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int countArchiveMobFiles(TableName tn, String familyName)
|
private int countArchiveMobFiles(TableName tn, String familyName)
|
||||||
|
@ -221,9 +197,8 @@ public class TestDeleteMobTable {
|
||||||
MobUtils.getMobRegionInfo(tn).getEncodedName(), familyName);
|
MobUtils.getMobRegionInfo(tn).getEncodedName(), familyName);
|
||||||
if (fs.exists(storePath)) {
|
if (fs.exists(storePath)) {
|
||||||
return fs.listStatus(storePath).length;
|
return fs.listStatus(storePath).length;
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean mobTableDirExist(TableName tn) throws IOException {
|
private boolean mobTableDirExist(TableName tn) throws IOException {
|
||||||
|
@ -232,12 +207,9 @@ public class TestDeleteMobTable {
|
||||||
return fs.exists(tableDir);
|
return fs.exists(tableDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean mobColumnFamilyDirExist(TableName tn) throws IOException {
|
private boolean mobColumnFamilyDirExist(TableName tn, String familyName) throws IOException {
|
||||||
FileSystem fs = TEST_UTIL.getTestFileSystem();
|
FileSystem fs = TEST_UTIL.getTestFileSystem();
|
||||||
Path tableDir = FSUtils.getTableDir(MobUtils.getMobHome(TEST_UTIL.getConfiguration()), tn);
|
Path mobFamilyDir = MobUtils.getMobFamilyPath(TEST_UTIL.getConfiguration(), tn, familyName);
|
||||||
HRegionInfo mobRegionInfo = MobUtils.getMobRegionInfo(tn);
|
|
||||||
Path mobFamilyDir = new Path(tableDir, new Path(mobRegionInfo.getEncodedName(),
|
|
||||||
Bytes.toString(FAMILY)));
|
|
||||||
return fs.exists(mobFamilyDir);
|
return fs.exists(mobFamilyDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,8 +228,7 @@ public class TestDeleteMobTable {
|
||||||
ResultScanner rs = table.getScanner(scan);
|
ResultScanner rs = table.getScanner(scan);
|
||||||
Result r = rs.next();
|
Result r = rs.next();
|
||||||
Assert.assertNotNull(r);
|
Assert.assertNotNull(r);
|
||||||
byte[] value = r.getValue(FAMILY, QF);
|
String fileName = MobUtils.getMobFileName(r.getColumnLatestCell(FAMILY, QF));
|
||||||
String fileName = Bytes.toString(value, Bytes.SIZEOF_INT, value.length - Bytes.SIZEOF_INT);
|
|
||||||
Path filePath = new Path(
|
Path filePath = new Path(
|
||||||
MobUtils.getMobFamilyPath(TEST_UTIL.getConfiguration(), tn, familyName), fileName);
|
MobUtils.getMobFamilyPath(TEST_UTIL.getConfiguration(), tn, familyName), fileName);
|
||||||
FileSystem fs = TEST_UTIL.getTestFileSystem();
|
FileSystem fs = TEST_UTIL.getTestFileSystem();
|
||||||
|
|
|
@ -278,8 +278,7 @@ public class TestMobStoreCompaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int countMobFiles() throws IOException {
|
private int countMobFiles() throws IOException {
|
||||||
Path mobDirPath = new Path(MobUtils.getMobRegionPath(conf, htd.getTableName()),
|
Path mobDirPath = MobUtils.getMobFamilyPath(conf, htd.getTableName(), hcd.getNameAsString());
|
||||||
hcd.getNameAsString());
|
|
||||||
if (fs.exists(mobDirPath)) {
|
if (fs.exists(mobDirPath)) {
|
||||||
FileStatus[] files = UTIL.getTestFileSystem().listStatus(mobDirPath);
|
FileStatus[] files = UTIL.getTestFileSystem().listStatus(mobDirPath);
|
||||||
return files.length;
|
return files.length;
|
||||||
|
@ -289,8 +288,7 @@ public class TestMobStoreCompaction {
|
||||||
|
|
||||||
private long countMobCellsInMetadata() throws IOException {
|
private long countMobCellsInMetadata() throws IOException {
|
||||||
long mobCellsCount = 0;
|
long mobCellsCount = 0;
|
||||||
Path mobDirPath = new Path(MobUtils.getMobRegionPath(conf, htd.getTableName()),
|
Path mobDirPath = MobUtils.getMobFamilyPath(conf, htd.getTableName(), hcd.getNameAsString());
|
||||||
hcd.getNameAsString());
|
|
||||||
Configuration copyOfConf = new Configuration(conf);
|
Configuration copyOfConf = new Configuration(conf);
|
||||||
copyOfConf.setFloat(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0f);
|
copyOfConf.setFloat(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0f);
|
||||||
CacheConfig cacheConfig = new CacheConfig(copyOfConf);
|
CacheConfig cacheConfig = new CacheConfig(copyOfConf);
|
||||||
|
@ -357,9 +355,16 @@ public class TestMobStoreCompaction {
|
||||||
|
|
||||||
private int countRows() throws IOException {
|
private int countRows() throws IOException {
|
||||||
Scan scan = new Scan();
|
Scan scan = new Scan();
|
||||||
// Do not retrieve the mob data when scanning
|
|
||||||
InternalScanner scanner = region.getScanner(scan);
|
InternalScanner scanner = region.getScanner(scan);
|
||||||
|
try {
|
||||||
|
return countRows(scanner);
|
||||||
|
} finally {
|
||||||
|
scanner.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int countRows(InternalScanner scanner) throws IOException {
|
||||||
|
// Do not retrieve the mob data when scanning
|
||||||
int scannedCount = 0;
|
int scannedCount = 0;
|
||||||
List<Cell> results = new ArrayList<Cell>();
|
List<Cell> results = new ArrayList<Cell>();
|
||||||
boolean hasMore = true;
|
boolean hasMore = true;
|
||||||
|
@ -368,8 +373,6 @@ public class TestMobStoreCompaction {
|
||||||
scannedCount += results.size();
|
scannedCount += results.size();
|
||||||
results.clear();
|
results.clear();
|
||||||
}
|
}
|
||||||
scanner.close();
|
|
||||||
|
|
||||||
return scannedCount;
|
return scannedCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,8 +426,7 @@ public class TestMobStoreCompaction {
|
||||||
Configuration copyOfConf = new Configuration(conf);
|
Configuration copyOfConf = new Configuration(conf);
|
||||||
copyOfConf.setFloat(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0f);
|
copyOfConf.setFloat(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0f);
|
||||||
CacheConfig cacheConfig = new CacheConfig(copyOfConf);
|
CacheConfig cacheConfig = new CacheConfig(copyOfConf);
|
||||||
Path mobDirPath = new Path(MobUtils.getMobRegionPath(conf, htd.getTableName()),
|
Path mobDirPath = MobUtils.getMobFamilyPath(conf, htd.getTableName(), hcd.getNameAsString());
|
||||||
hcd.getNameAsString());
|
|
||||||
List<StoreFile> sfs = new ArrayList<>();
|
List<StoreFile> sfs = new ArrayList<>();
|
||||||
int numDelfiles = 0;
|
int numDelfiles = 0;
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
@ -436,6 +438,7 @@ public class TestMobStoreCompaction {
|
||||||
numDelfiles++;
|
numDelfiles++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List scanners = StoreFileScanner.getScannersForStoreFiles(sfs, false, true, false, false,
|
List scanners = StoreFileScanner.getScannersForStoreFiles(sfs, false, true, false, false,
|
||||||
HConstants.LATEST_TIMESTAMP);
|
HConstants.LATEST_TIMESTAMP);
|
||||||
Scan scan = new Scan();
|
Scan scan = new Scan();
|
||||||
|
@ -446,12 +449,10 @@ public class TestMobStoreCompaction {
|
||||||
CellComparator.COMPARATOR);
|
CellComparator.COMPARATOR);
|
||||||
StoreScanner scanner = new StoreScanner(scan, scanInfo, ScanType.COMPACT_DROP_DELETES, null,
|
StoreScanner scanner = new StoreScanner(scan, scanInfo, ScanType.COMPACT_DROP_DELETES, null,
|
||||||
scanners, 0L, HConstants.LATEST_TIMESTAMP);
|
scanners, 0L, HConstants.LATEST_TIMESTAMP);
|
||||||
List<Cell> results = new ArrayList<>();
|
try {
|
||||||
boolean hasMore = true;
|
size += countRows(scanner);
|
||||||
while (hasMore) {
|
} finally {
|
||||||
hasMore = scanner.next(results);
|
scanner.close();
|
||||||
size += results.size();
|
|
||||||
results.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// assert the number of the existing del files
|
// assert the number of the existing del files
|
||||||
|
|
|
@ -44,6 +44,7 @@ import org.apache.hadoop.hbase.client.Table;
|
||||||
import org.apache.hadoop.hbase.io.hfile.CorruptHFileException;
|
import org.apache.hadoop.hbase.io.hfile.CorruptHFileException;
|
||||||
import org.apache.hadoop.hbase.io.hfile.TestHFile;
|
import org.apache.hadoop.hbase.io.hfile.TestHFile;
|
||||||
import org.apache.hadoop.hbase.mob.MobConstants;
|
import org.apache.hadoop.hbase.mob.MobConstants;
|
||||||
|
import org.apache.hadoop.hbase.mob.MobTestUtil;
|
||||||
import org.apache.hadoop.hbase.mob.MobUtils;
|
import org.apache.hadoop.hbase.mob.MobUtils;
|
||||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
|
@ -196,12 +197,12 @@ public class TestMobStoreScanner {
|
||||||
table.put(put4);
|
table.put(put4);
|
||||||
Result result = rs.next();
|
Result result = rs.next();
|
||||||
Cell cell = result.getColumnLatestCell(family, qf1);
|
Cell cell = result.getColumnLatestCell(family, qf1);
|
||||||
Assert.assertEquals("value1", Bytes.toString(CellUtil.cloneValue(cell)));
|
Assert.assertArrayEquals(value1, CellUtil.cloneValue(cell));
|
||||||
|
|
||||||
admin.flush(tn);
|
admin.flush(tn);
|
||||||
result = rs.next();
|
result = rs.next();
|
||||||
cell = result.getColumnLatestCell(family, qf1);
|
cell = result.getColumnLatestCell(family, qf1);
|
||||||
Assert.assertEquals("value2", Bytes.toString(CellUtil.cloneValue(cell)));
|
Assert.assertArrayEquals(value2, CellUtil.cloneValue(cell));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -213,7 +214,7 @@ public class TestMobStoreScanner {
|
||||||
get.setAttribute(MobConstants.EMPTY_VALUE_ON_MOBCELL_MISS, Bytes.toBytes(true));
|
get.setAttribute(MobConstants.EMPTY_VALUE_ON_MOBCELL_MISS, Bytes.toBytes(true));
|
||||||
Result result = table.get(get);
|
Result result = table.get(get);
|
||||||
Cell cell = result.getColumnLatestCell(family, qf1);
|
Cell cell = result.getColumnLatestCell(family, qf1);
|
||||||
Assert.assertEquals(0, CellUtil.cloneValue(cell).length);
|
Assert.assertEquals(0, cell.getValueLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -249,8 +250,7 @@ public class TestMobStoreScanner {
|
||||||
|
|
||||||
private Path getFlushedMobFile(Configuration conf, FileSystem fs, TableName table, String family)
|
private Path getFlushedMobFile(Configuration conf, FileSystem fs, TableName table, String family)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Path regionDir = MobUtils.getMobRegionPath(conf, table);
|
Path famDir = MobUtils.getMobFamilyPath(conf, table, family);
|
||||||
Path famDir = new Path(regionDir, family);
|
|
||||||
FileStatus[] hfFss = fs.listStatus(famDir);
|
FileStatus[] hfFss = fs.listStatus(famDir);
|
||||||
for (FileStatus hfs : hfFss) {
|
for (FileStatus hfs : hfFss) {
|
||||||
if (!hfs.isDirectory()) {
|
if (!hfs.isDirectory()) {
|
||||||
|
@ -262,7 +262,17 @@ public class TestMobStoreScanner {
|
||||||
|
|
||||||
private void testGetFromFiles(boolean reversed) throws Exception {
|
private void testGetFromFiles(boolean reversed) throws Exception {
|
||||||
TableName tn = TableName.valueOf("testGetFromFiles" + reversed);
|
TableName tn = TableName.valueOf("testGetFromFiles" + reversed);
|
||||||
setUp(defaultThreshold, tn);
|
testGet(tn, reversed, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testGetFromMemStore(boolean reversed) throws Exception {
|
||||||
|
TableName tn = TableName.valueOf("testGetFromMemStore" + reversed);
|
||||||
|
testGet(tn, reversed, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testGet(TableName tableName, boolean reversed, boolean doFlush)
|
||||||
|
throws Exception {
|
||||||
|
setUp(defaultThreshold, tableName);
|
||||||
long ts1 = System.currentTimeMillis();
|
long ts1 = System.currentTimeMillis();
|
||||||
long ts2 = ts1 + 1;
|
long ts2 = ts1 + 1;
|
||||||
long ts3 = ts1 + 2;
|
long ts3 = ts1 + 2;
|
||||||
|
@ -274,55 +284,13 @@ public class TestMobStoreScanner {
|
||||||
put1.addColumn(family, qf3, ts1, value);
|
put1.addColumn(family, qf3, ts1, value);
|
||||||
table.put(put1);
|
table.put(put1);
|
||||||
|
|
||||||
admin.flush(tn);
|
if (doFlush) {
|
||||||
|
admin.flush(tableName);
|
||||||
|
}
|
||||||
|
|
||||||
Scan scan = new Scan();
|
Scan scan = new Scan();
|
||||||
setScan(scan, reversed, false);
|
setScan(scan, reversed, false);
|
||||||
|
MobTestUtil.assertCellsValue(table, scan, value, 3);
|
||||||
ResultScanner results = table.getScanner(scan);
|
|
||||||
int count = 0;
|
|
||||||
for (Result res : results) {
|
|
||||||
List<Cell> cells = res.listCells();
|
|
||||||
for(Cell cell : cells) {
|
|
||||||
// Verify the value
|
|
||||||
Assert.assertEquals(Bytes.toString(value),
|
|
||||||
Bytes.toString(CellUtil.cloneValue(cell)));
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
results.close();
|
|
||||||
Assert.assertEquals(3, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testGetFromMemStore(boolean reversed) throws Exception {
|
|
||||||
setUp(defaultThreshold, TableName.valueOf("testGetFromMemStore" + reversed));
|
|
||||||
long ts1 = System.currentTimeMillis();
|
|
||||||
long ts2 = ts1 + 1;
|
|
||||||
long ts3 = ts1 + 2;
|
|
||||||
byte [] value = generateMobValue((int)defaultThreshold+1);;
|
|
||||||
|
|
||||||
Put put1 = new Put(row1);
|
|
||||||
put1.addColumn(family, qf1, ts3, value);
|
|
||||||
put1.addColumn(family, qf2, ts2, value);
|
|
||||||
put1.addColumn(family, qf3, ts1, value);
|
|
||||||
table.put(put1);
|
|
||||||
|
|
||||||
Scan scan = new Scan();
|
|
||||||
setScan(scan, reversed, false);
|
|
||||||
|
|
||||||
ResultScanner results = table.getScanner(scan);
|
|
||||||
int count = 0;
|
|
||||||
for (Result res : results) {
|
|
||||||
List<Cell> cells = res.listCells();
|
|
||||||
for(Cell cell : cells) {
|
|
||||||
// Verify the value
|
|
||||||
Assert.assertEquals(Bytes.toString(value),
|
|
||||||
Bytes.toString(CellUtil.cloneValue(cell)));
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
results.close();
|
|
||||||
Assert.assertEquals(3, count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testGetReferences(boolean reversed) throws Exception {
|
private void testGetReferences(boolean reversed) throws Exception {
|
||||||
|
@ -426,8 +394,8 @@ public class TestMobStoreScanner {
|
||||||
|
|
||||||
// Get the files in the mob path
|
// Get the files in the mob path
|
||||||
Path mobFamilyPath;
|
Path mobFamilyPath;
|
||||||
mobFamilyPath = new Path(MobUtils.getMobRegionPath(TEST_UTIL.getConfiguration(), tn),
|
mobFamilyPath = MobUtils.getMobFamilyPath(
|
||||||
hcd.getNameAsString());
|
TEST_UTIL.getConfiguration(), tn, hcd.getNameAsString());
|
||||||
FileSystem fs = FileSystem.get(TEST_UTIL.getConfiguration());
|
FileSystem fs = FileSystem.get(TEST_UTIL.getConfiguration());
|
||||||
FileStatus[] files = fs.listStatus(mobFamilyPath);
|
FileStatus[] files = fs.listStatus(mobFamilyPath);
|
||||||
|
|
||||||
|
@ -458,19 +426,7 @@ public class TestMobStoreScanner {
|
||||||
// Scan from archive
|
// Scan from archive
|
||||||
Scan scan = new Scan();
|
Scan scan = new Scan();
|
||||||
setScan(scan, reversed, false);
|
setScan(scan, reversed, false);
|
||||||
ResultScanner results = table.getScanner(scan);
|
MobTestUtil.assertCellsValue(table, scan, value, 3);
|
||||||
int count = 0;
|
|
||||||
for (Result res : results) {
|
|
||||||
List<Cell> cells = res.listCells();
|
|
||||||
for(Cell cell : cells) {
|
|
||||||
// Verify the value
|
|
||||||
Assert.assertEquals(Bytes.toString(value),
|
|
||||||
Bytes.toString(CellUtil.cloneValue(cell)));
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
results.close();
|
|
||||||
Assert.assertEquals(3, count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -478,12 +434,9 @@ public class TestMobStoreScanner {
|
||||||
*/
|
*/
|
||||||
private static void assertNotMobReference(Cell cell, byte[] row, byte[] family,
|
private static void assertNotMobReference(Cell cell, byte[] row, byte[] family,
|
||||||
byte[] value) throws IOException {
|
byte[] value) throws IOException {
|
||||||
Assert.assertEquals(Bytes.toString(row),
|
Assert.assertArrayEquals(row, CellUtil.cloneRow(cell));
|
||||||
Bytes.toString(CellUtil.cloneRow(cell)));
|
Assert.assertArrayEquals(family, CellUtil.cloneFamily(cell));
|
||||||
Assert.assertEquals(Bytes.toString(family),
|
Assert.assertArrayEquals(value, CellUtil.cloneValue(cell));
|
||||||
Bytes.toString(CellUtil.cloneFamily(cell)));
|
|
||||||
Assert.assertTrue(Bytes.toString(value).equals(
|
|
||||||
Bytes.toString(CellUtil.cloneValue(cell))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -491,20 +444,15 @@ public class TestMobStoreScanner {
|
||||||
*/
|
*/
|
||||||
private static void assertIsMobReference(Cell cell, byte[] row, byte[] family,
|
private static void assertIsMobReference(Cell cell, byte[] row, byte[] family,
|
||||||
byte[] value, TableName tn) throws IOException {
|
byte[] value, TableName tn) throws IOException {
|
||||||
Assert.assertEquals(Bytes.toString(row),
|
Assert.assertArrayEquals(row, CellUtil.cloneRow(cell));
|
||||||
Bytes.toString(CellUtil.cloneRow(cell)));
|
Assert.assertArrayEquals(family, CellUtil.cloneFamily(cell));
|
||||||
Assert.assertEquals(Bytes.toString(family),
|
Assert.assertFalse(Bytes.equals(value, CellUtil.cloneValue(cell)));
|
||||||
Bytes.toString(CellUtil.cloneFamily(cell)));
|
|
||||||
Assert.assertFalse(Bytes.toString(value).equals(
|
|
||||||
Bytes.toString(CellUtil.cloneValue(cell))));
|
|
||||||
byte[] referenceValue = CellUtil.cloneValue(cell);
|
byte[] referenceValue = CellUtil.cloneValue(cell);
|
||||||
String fileName = Bytes.toString(referenceValue, Bytes.SIZEOF_INT,
|
String fileName = MobUtils.getMobFileName(cell);
|
||||||
referenceValue.length - Bytes.SIZEOF_INT);
|
|
||||||
int valLen = Bytes.toInt(referenceValue, 0, Bytes.SIZEOF_INT);
|
int valLen = Bytes.toInt(referenceValue, 0, Bytes.SIZEOF_INT);
|
||||||
Assert.assertEquals(value.length, valLen);
|
Assert.assertEquals(value.length, valLen);
|
||||||
Path mobFamilyPath;
|
Path mobFamilyPath = MobUtils.getMobFamilyPath(
|
||||||
mobFamilyPath = new Path(MobUtils.getMobRegionPath(TEST_UTIL.getConfiguration(),
|
TEST_UTIL.getConfiguration(), tn, hcd.getNameAsString());
|
||||||
tn), hcd.getNameAsString());
|
|
||||||
Path targetPath = new Path(mobFamilyPath, fileName);
|
Path targetPath = new Path(mobFamilyPath, fileName);
|
||||||
FileSystem fs = FileSystem.get(TEST_UTIL.getConfiguration());
|
FileSystem fs = FileSystem.get(TEST_UTIL.getConfiguration());
|
||||||
Assert.assertTrue(fs.exists(targetPath));
|
Assert.assertTrue(fs.exists(targetPath));
|
||||||
|
|
|
@ -131,7 +131,7 @@ public class BaseTestHBaseFsck {
|
||||||
Bytes.toBytes("00"), Bytes.toBytes("50"), Bytes.toBytes("A0"), Bytes.toBytes("A5"),
|
Bytes.toBytes("00"), Bytes.toBytes("50"), Bytes.toBytes("A0"), Bytes.toBytes("A5"),
|
||||||
Bytes.toBytes("B0"), Bytes.toBytes("B5"), Bytes.toBytes("C0"), Bytes.toBytes("C5") };
|
Bytes.toBytes("B0"), Bytes.toBytes("B5"), Bytes.toBytes("C0"), Bytes.toBytes("C5") };
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new region in META.
|
* Create a new region in META.
|
||||||
*/
|
*/
|
||||||
|
@ -633,8 +633,7 @@ public class BaseTestHBaseFsck {
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
Path getFlushedMobFile(FileSystem fs, TableName table) throws IOException {
|
Path getFlushedMobFile(FileSystem fs, TableName table) throws IOException {
|
||||||
Path regionDir = MobUtils.getMobRegionPath(conf, table);
|
Path famDir = MobUtils.getMobFamilyPath(conf, table, FAM_STR);
|
||||||
Path famDir = new Path(regionDir, FAM_STR);
|
|
||||||
|
|
||||||
// keep doing this until we get a legit hfile
|
// keep doing this until we get a legit hfile
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
Loading…
Reference in New Issue