Search in sources :

Example 86 with HRegion

use of org.apache.hadoop.hbase.regionserver.HRegion in project cdap by caskdata.

the class IncrementSummingScannerTest method testFlushAndCompact.

@Test
public void testFlushAndCompact() throws Exception {
    TableId tableId = TableId.from(NamespaceId.DEFAULT.getNamespace(), "TestFlushAndCompact");
    byte[] familyBytes = Bytes.toBytes("f");
    byte[] columnBytes = Bytes.toBytes("c");
    HRegion region = createRegion(tableId, familyBytes);
    try {
        region.initialize();
        // load an initial set of increments
        long ts = System.currentTimeMillis();
        byte[] row1 = Bytes.toBytes("row1");
        for (int i = 0; i < 50; i++) {
            Put p = new Put(row1);
            p.add(familyBytes, columnBytes, ts, Bytes.toBytes(1L));
            p.setAttribute(HBaseTable.DELTA_WRITE, TRUE);
            ts++;
            region.put(p);
        }
        byte[] row2 = Bytes.toBytes("row2");
        ts = System.currentTimeMillis();
        // start with a full put
        Put row2P = new Put(row2);
        row2P.add(familyBytes, columnBytes, ts++, Bytes.toBytes(10L));
        region.put(row2P);
        for (int i = 0; i < 10; i++) {
            Put p = new Put(row2);
            p.add(familyBytes, columnBytes, ts++, Bytes.toBytes(1L));
            p.setAttribute(HBaseTable.DELTA_WRITE, TRUE);
            region.put(p);
        }
        // force a region flush
        region.flushcache();
        region.waitForFlushesAndCompactions();
        Result r1 = region.get(new Get(row1));
        assertNotNull(r1);
        assertFalse(r1.isEmpty());
        // row1 should have a full put aggregating all 50 incrments
        Cell r1Cell = r1.getColumnLatestCell(familyBytes, columnBytes);
        assertNotNull(r1Cell);
        assertEquals(50L, Bytes.toLong(r1Cell.getValue()));
        Result r2 = region.get(new Get(row2));
        assertNotNull(r2);
        assertFalse(r2.isEmpty());
        // row2 should have a full put aggregating prior put + 10 increments
        Cell r2Cell = r2.getColumnLatestCell(familyBytes, columnBytes);
        assertNotNull(r2Cell);
        assertEquals(20L, Bytes.toLong(r2Cell.getValue()));
        // add 30 more increments to row2
        for (int i = 0; i < 30; i++) {
            Put p = new Put(row2);
            p.add(familyBytes, columnBytes, ts++, Bytes.toBytes(1L));
            p.setAttribute(HBaseTable.DELTA_WRITE, TRUE);
            region.put(p);
        }
        // row2 should now have a full put aggregating prior 20 value + 30 increments
        r2 = region.get(new Get(row2));
        assertNotNull(r2);
        assertFalse(r2.isEmpty());
        r2Cell = r2.getColumnLatestCell(familyBytes, columnBytes);
        assertNotNull(r2Cell);
        assertEquals(50L, Bytes.toLong(r2Cell.getValue()));
        // force another region flush
        region.flushcache();
        region.waitForFlushesAndCompactions();
        // add 100 more increments to row2
        for (int i = 0; i < 100; i++) {
            Put p = new Put(row2);
            p.add(familyBytes, columnBytes, ts++, Bytes.toBytes(1L));
            p.setAttribute(HBaseTable.DELTA_WRITE, TRUE);
            region.put(p);
        }
        // row2 should now have a full put aggregating prior 50 value + 100 increments
        r2 = region.get(new Get(row2));
        assertNotNull(r2);
        assertFalse(r2.isEmpty());
        r2Cell = r2.getColumnLatestCell(familyBytes, columnBytes);
        assertNotNull(r2Cell);
        assertEquals(150L, Bytes.toLong(r2Cell.getValue()));
    } finally {
        region.close();
    }
}
Also used : TableId(co.cask.cdap.data2.util.TableId) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Get(org.apache.hadoop.hbase.client.Get) Cell(org.apache.hadoop.hbase.Cell) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result) HBase10Test(co.cask.cdap.data.hbase.HBase10Test) Test(org.junit.Test)

Example 87 with HRegion

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

the class HBaseFsck method createNewMeta.

/**
   * This borrows code from MasterFileSystem.bootstrap(). Explicitly creates it's own WAL, so be
   * sure to close it as well as the region when you're finished.
   * @param walFactoryID A unique identifier for WAL factory. Filesystem implementations will use
   *          this ID to make a directory inside WAL directory path.
   * @return an open hbase:meta HRegion
   */
private HRegion createNewMeta(String walFactoryID) throws IOException {
    Path rootdir = FSUtils.getRootDir(getConf());
    Configuration c = getConf();
    HRegionInfo metaHRI = new HRegionInfo(HRegionInfo.FIRST_META_REGIONINFO);
    HTableDescriptor metaDescriptor = new FSTableDescriptors(c).get(TableName.META_TABLE_NAME);
    MasterFileSystem.setInfoFamilyCachingForMeta(metaDescriptor, false);
    // The WAL subsystem will use the default rootDir rather than the passed in rootDir
    // unless I pass along via the conf.
    Configuration confForWAL = new Configuration(c);
    confForWAL.set(HConstants.HBASE_DIR, rootdir.toString());
    WAL wal = (new WALFactory(confForWAL, Collections.<WALActionsListener>singletonList(new MetricsWAL()), walFactoryID)).getWAL(metaHRI.getEncodedNameAsBytes(), metaHRI.getTable().getNamespace());
    HRegion meta = HRegion.createHRegion(metaHRI, rootdir, c, metaDescriptor, wal);
    MasterFileSystem.setInfoFamilyCachingForMeta(metaDescriptor, true);
    return meta;
}
Also used : Path(org.apache.hadoop.fs.Path) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) WAL(org.apache.hadoop.hbase.wal.WAL) MetricsWAL(org.apache.hadoop.hbase.regionserver.wal.MetricsWAL) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) MetricsWAL(org.apache.hadoop.hbase.regionserver.wal.MetricsWAL) WALFactory(org.apache.hadoop.hbase.wal.WALFactory) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 88 with HRegion

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

the class TestCoprocessorInterface method initHRegion.

Region initHRegion(TableName tableName, String callingMethod, Configuration conf, Class<?>[] implClasses, byte[][] families) throws IOException {
    HTableDescriptor htd = new HTableDescriptor(tableName);
    for (byte[] family : families) {
        htd.addFamily(new HColumnDescriptor(family));
    }
    HRegionInfo info = new HRegionInfo(tableName, null, null, false);
    Path path = new Path(DIR + callingMethod);
    Region r = HBaseTestingUtility.createRegionAndWAL(info, path, conf, htd);
    // this following piece is a hack.
    RegionCoprocessorHost host = new RegionCoprocessorHost(r, null, conf);
    ((HRegion) r).setCoprocessorHost(host);
    for (Class<?> implClass : implClasses) {
        host.load(implClass, Coprocessor.PRIORITY_USER, conf);
        Coprocessor c = host.findCoprocessor(implClass.getName());
        assertNotNull(c);
    }
    // Here we have to call pre and postOpen explicitly.
    host.preOpen();
    host.postOpen();
    return r;
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Path(org.apache.hadoop.fs.Path) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Coprocessor(org.apache.hadoop.hbase.Coprocessor) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) RegionCoprocessorHost(org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Region(org.apache.hadoop.hbase.regionserver.Region) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 89 with HRegion

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

the class TestSplitOrMergeStatus method waitForMergable.

private void waitForMergable(Admin admin, TableName t) throws InterruptedException, IOException {
    // Wait for the Regions to be mergeable
    MiniHBaseCluster miniCluster = TEST_UTIL.getMiniHBaseCluster();
    int mergeable = 0;
    while (mergeable < 2) {
        Thread.sleep(100);
        admin.majorCompact(t);
        mergeable = 0;
        for (JVMClusterUtil.RegionServerThread regionThread : miniCluster.getRegionServerThreads()) {
            for (Region region : regionThread.getRegionServer().getOnlineRegions(t)) {
                mergeable += ((HRegion) region).isMergeable() ? 1 : 0;
            }
        }
    }
}
Also used : HRegion(org.apache.hadoop.hbase.regionserver.HRegion) JVMClusterUtil(org.apache.hadoop.hbase.util.JVMClusterUtil) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Region(org.apache.hadoop.hbase.regionserver.Region)

Example 90 with HRegion

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

the class TestCoprocessorConfiguration method testRegionCoprocessorHostDefaults.

@Test
public void testRegionCoprocessorHostDefaults() throws Exception {
    Configuration conf = new Configuration(CONF);
    HRegion region = mock(HRegion.class);
    when(region.getRegionInfo()).thenReturn(REGIONINFO);
    when(region.getTableDesc()).thenReturn(TABLEDESC);
    RegionServerServices rsServices = mock(RegionServerServices.class);
    systemCoprocessorLoaded.set(false);
    tableCoprocessorLoaded.set(false);
    new RegionCoprocessorHost(region, rsServices, conf);
    assertEquals("System coprocessors loading default was not honored", systemCoprocessorLoaded.get(), CoprocessorHost.DEFAULT_COPROCESSORS_ENABLED);
    assertEquals("Table coprocessors loading default was not honored", tableCoprocessorLoaded.get(), CoprocessorHost.DEFAULT_COPROCESSORS_ENABLED && CoprocessorHost.DEFAULT_USER_COPROCESSORS_ENABLED);
}
Also used : HRegion(org.apache.hadoop.hbase.regionserver.HRegion) RegionServerServices(org.apache.hadoop.hbase.regionserver.RegionServerServices) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) RegionCoprocessorHost(org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost) Test(org.junit.Test)

Aggregations

HRegion (org.apache.hadoop.hbase.regionserver.HRegion)148 Test (org.junit.Test)88 Put (org.apache.hadoop.hbase.client.Put)56 Path (org.apache.hadoop.fs.Path)40 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)40 Scan (org.apache.hadoop.hbase.client.Scan)37 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)36 Cell (org.apache.hadoop.hbase.Cell)35 TableId (co.cask.cdap.data2.util.TableId)32 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)28 IOException (java.io.IOException)26 WAL (org.apache.hadoop.hbase.wal.WAL)25 FileSystem (org.apache.hadoop.fs.FileSystem)24 ArrayList (java.util.ArrayList)22 TableName (org.apache.hadoop.hbase.TableName)22 Configuration (org.apache.hadoop.conf.Configuration)21 Result (org.apache.hadoop.hbase.client.Result)21 Region (org.apache.hadoop.hbase.regionserver.Region)21 MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)19 RegionScanner (org.apache.hadoop.hbase.regionserver.RegionScanner)19