Search in sources :

Example 31 with MultiVersionConcurrencyControl

use of org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl in project hbase by apache.

the class CompressedWALTestBase method doTest.

public void doTest(TableName tableName) throws Exception {
    NavigableMap<byte[], Integer> scopes = new TreeMap<>(Bytes.BYTES_COMPARATOR);
    scopes.put(tableName.getName(), 0);
    RegionInfo regionInfo = RegionInfoBuilder.newBuilder(tableName).build();
    final int total = 1000;
    final byte[] row = Bytes.toBytes("row");
    final byte[] family = Bytes.toBytes("family");
    final byte[] value = VALUE;
    final WALFactory wals = new WALFactory(TEST_UTIL.getConfiguration(), tableName.getNameAsString());
    // Write the WAL
    final WAL wal = wals.getWAL(regionInfo);
    MultiVersionConcurrencyControl mvcc = new MultiVersionConcurrencyControl();
    for (int i = 0; i < total; i++) {
        WALEdit kvs = new WALEdit();
        kvs.add(new KeyValue(row, family, Bytes.toBytes(i), value));
        wal.appendData(regionInfo, new WALKeyImpl(regionInfo.getEncodedNameAsBytes(), tableName, System.currentTimeMillis(), mvcc, scopes), kvs);
    }
    wal.sync();
    final Path walPath = AbstractFSWALProvider.getCurrentFileName(wal);
    wals.shutdown();
    // Confirm the WAL can be read back
    WAL.Reader reader = wals.createReader(TEST_UTIL.getTestFileSystem(), walPath);
    int count = 0;
    WAL.Entry entry = new WAL.Entry();
    while (reader.next(entry) != null) {
        count++;
        List<Cell> cells = entry.getEdit().getCells();
        assertTrue("Should be one KV per WALEdit", cells.size() == 1);
        for (Cell cell : cells) {
            assertTrue("Incorrect row", Bytes.equals(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(), row, 0, row.length));
            assertTrue("Incorrect family", Bytes.equals(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength(), family, 0, family.length));
            assertTrue("Incorrect value", Bytes.equals(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength(), value, 0, value.length));
        }
    }
    assertEquals("Should have read back as many KVs as written", total, count);
    reader.close();
}
Also used : Path(org.apache.hadoop.fs.Path) KeyValue(org.apache.hadoop.hbase.KeyValue) MultiVersionConcurrencyControl(org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TreeMap(java.util.TreeMap) Cell(org.apache.hadoop.hbase.Cell)

Aggregations

MultiVersionConcurrencyControl (org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl)31 TreeMap (java.util.TreeMap)25 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)25 Path (org.apache.hadoop.fs.Path)20 Test (org.junit.Test)20 KeyValue (org.apache.hadoop.hbase.KeyValue)19 TableName (org.apache.hadoop.hbase.TableName)14 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)14 WALEdit (org.apache.hadoop.hbase.wal.WALEdit)12 WALKeyImpl (org.apache.hadoop.hbase.wal.WALKeyImpl)12 WAL (org.apache.hadoop.hbase.wal.WAL)11 IOException (java.io.IOException)10 Cell (org.apache.hadoop.hbase.Cell)8 Configuration (org.apache.hadoop.conf.Configuration)7 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)5 List (java.util.List)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 FileSystem (org.apache.hadoop.fs.FileSystem)4 WALFactory (org.apache.hadoop.hbase.wal.WALFactory)4 Method (java.lang.reflect.Method)3