org.apache.hadoop.hbase.regionserver.HRegion Java Examples

The following examples show how to use org.apache.hadoop.hbase.regionserver.HRegion. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransactionProcessorTest.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
private HRegion updateTtl(HRegion region, byte[] family, long ttl) throws Exception {
  region.close();
  TableDescriptorBuilder tableBuilder =
      TableDescriptorBuilder.newBuilder(region.getTableDescriptor());
  ColumnFamilyDescriptorBuilder cfd =
      ColumnFamilyDescriptorBuilder.newBuilder(tableBuilder.build().getColumnFamily(family));
  if (ttl > 0) {
    cfd.setValue(Bytes.toBytes(TxConstants.PROPERTY_TTL), Bytes.toBytes(String.valueOf(ttl)));
  }
  cfd.setMaxVersions(10);
  tableBuilder.removeColumnFamily(family);
  tableBuilder.addColumnFamily(cfd.build());
  return HRegion
      .openHRegion(region.getRegionInfo(), tableBuilder.build(), region.getWAL(), conf,
        new LocalRegionServerServices(conf, ServerName
            .valueOf(InetAddress.getLocalHost().getHostName(), 0, System.currentTimeMillis())),
        null);
}
 
Example #2
Source File: StatisticsCollector.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public void splitStats(HRegion parent, HRegion left, HRegion right) {
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Collecting stats for split of " + parent.getRegionInfo() + " into " + left.getRegionInfo() + " and " + right.getRegionInfo());
        }
        List<Mutation> mutations = Lists.newArrayListWithExpectedSize(3);
        for (byte[] fam : parent.getStores().keySet()) {
        	statsTable.splitStats(parent, left, right, this, new ImmutableBytesPtr(fam), mutations);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Committing stats for the daughter regions as part of split " + parent.getRegionInfo());
        }
        commitStats(mutations);
    } catch (IOException e) {
        logger.error("Error while capturing stats after split of region "
                + parent.getRegionInfo().getRegionNameAsString(), e);
    }
}
 
Example #3
Source File: TransactionProcessorTest.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
private HRegion createRegion(String tableName, byte[] family, long ttl) throws IOException {
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
  HColumnDescriptor cfd = new HColumnDescriptor(family);
  if (ttl > 0) {
    cfd.setValue(TxConstants.PROPERTY_TTL, String.valueOf(ttl));
  }
  cfd.setMaxVersions(10);
  htd.addFamily(cfd);
  htd.addCoprocessor(TransactionProcessor.class.getName());
  Path tablePath = FSUtils.getTableDir(FSUtils.getRootDir(conf), htd.getTableName());
  FileSystem fs = FileSystem.get(conf);
  assertTrue(fs.mkdirs(tablePath));
  WALFactory walFactory = new WALFactory(conf, null, tableName + ".hlog");
  WAL hLog = walFactory.getWAL(new byte[]{1}, null);
  HRegionInfo regionInfo = new HRegionInfo(TableName.valueOf(tableName));
  HRegionFileSystem regionFS = HRegionFileSystem.createRegionOnFileSystem(conf, fs, tablePath, regionInfo);
  return new HRegion(regionFS, hLog, conf, htd,
      new LocalRegionServerServices(conf, ServerName.valueOf(
          InetAddress.getLocalHost().getHostName(), 0, System.currentTimeMillis())));
}
 
Example #4
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
@Override
public void postFlush(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
  // Record whether the region is empty after a flush
  HRegion region = e.getEnvironment().getRegion();
  // After a flush, if the memstore size is zero and there are no store files for any stores in the region
  // then the region must be empty
  long numStoreFiles = numStoreFilesForRegion(e);
  long memstoreSize = region.getMemstoreSize().get();
  LOG.debug(String.format("Region %s: memstore size = %s, num store files = %s",
                          region.getRegionInfo().getRegionNameAsString(), memstoreSize, numStoreFiles));
  if (memstoreSize == 0 && numStoreFiles == 0) {
    if (compactionState != null) {
      compactionState.persistRegionEmpty(System.currentTimeMillis());
    }
  }
}
 
Example #5
Source File: TestCoprocessorConfiguration.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegionCoprocessorHostDefaults() throws Exception {
  Configuration conf = new Configuration(CONF);
  HRegion region = mock(HRegion.class);
  when(region.getRegionInfo()).thenReturn(REGIONINFO);
  when(region.getTableDescriptor()).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",
      CoprocessorHost.DEFAULT_COPROCESSORS_ENABLED, systemCoprocessorLoaded.get());
  assertEquals("Table coprocessors loading default was not honored",
      CoprocessorHost.DEFAULT_COPROCESSORS_ENABLED &&
      CoprocessorHost.DEFAULT_USER_COPROCESSORS_ENABLED, tableCoprocessorLoaded.get());
}
 
Example #6
Source File: HbckTableInfo.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRegionEndKeyNotEmpty(byte[] curEndKey) throws IOException {
  errors.reportError(HbckErrorReporter.ERROR_CODE.LAST_REGION_ENDKEY_NOT_EMPTY,
      "Last region should end with an empty key.  Creating a new "
          + "region and regioninfo in HDFS to plug the hole.", getTableInfo());
  TableDescriptor htd = getTableInfo().getTableDescriptor();
  // from curEndKey to EMPTY_START_ROW
  RegionInfo newRegion = RegionInfoBuilder.newBuilder(htd.getTableName())
      .setStartKey(curEndKey)
      .setEndKey(HConstants.EMPTY_START_ROW)
      .build();

  HRegion region = HBaseFsckRepair.createHDFSRegionDir(conf, newRegion, htd);
  LOG.info("Table region end key was not empty.  Created new empty region: " + newRegion
      + " " + region);
  hbck.fixes++;
}
 
Example #7
Source File: MetaDataEndpointImpl.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private PTable buildDeletedTable(byte[] key, ImmutableBytesPtr cacheKey, HRegion region, long clientTimeStamp) throws IOException {
    if (clientTimeStamp == HConstants.LATEST_TIMESTAMP) {
        return null;
    }
    
    Scan scan = newTableRowsScan(key, clientTimeStamp, HConstants.LATEST_TIMESTAMP);
    scan.setFilter(new FirstKeyOnlyFilter());
    scan.setRaw(true);
    RegionScanner scanner = region.getScanner(scan);
    List<KeyValue> results = Lists.<KeyValue>newArrayList();
    scanner.next(results);
    // HBase ignores the time range on a raw scan (HBASE-7362)
    if (!results.isEmpty() && results.get(0).getTimestamp() > clientTimeStamp) {
        KeyValue kv = results.get(0);
        if (kv.isDelete()) {
            Map<ImmutableBytesPtr,PTable> metaDataCache = GlobalCache.getInstance(this.getEnvironment()).getMetaDataCache();
            PTable table = newDeletedTableMarker(kv.getTimestamp());
            metaDataCache.put(cacheKey, table);
            return table;
        }
    }
    return null;
}
 
Example #8
Source File: MetaDataEndpointImpl.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private PTable loadTable(RegionCoprocessorEnvironment env, byte[] key,
    ImmutableBytesPtr cacheKey, long clientTimeStamp, long asOfTimeStamp)
    throws IOException, SQLException {
    HRegion region = env.getRegion();
    Cache<ImmutableBytesPtr,PTable> metaDataCache = GlobalCache.getInstance(this.env).getMetaDataCache();
    PTable table = metaDataCache.getIfPresent(cacheKey);
    // We always cache the latest version - fault in if not in cache
    if (table != null || (table = buildTable(key, cacheKey, region, asOfTimeStamp)) != null) {
        return table;
    }
    // if not found then check if newer table already exists and add delete marker for timestamp
    // found
    if (table == null
            && (table = buildDeletedTable(key, cacheKey, region, clientTimeStamp)) != null) {
        return table;
    }
    return null;
}
 
Example #9
Source File: TestMasterRegionFlush.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
  conf = HBaseConfiguration.create();
  region = mock(HRegion.class);
  HStore store = mock(HStore.class);
  when(store.getStorefilesCount()).thenReturn(1);
  when(region.getStores()).thenReturn(Collections.singletonList(store));
  when(region.getRegionInfo())
    .thenReturn(RegionInfoBuilder.newBuilder(TableName.valueOf("hbase:local")).build());
  flushCalled = new AtomicInteger(0);
  memstoreHeapSize = new AtomicLong(0);
  memstoreOffHeapSize = new AtomicLong(0);
  when(region.getMemStoreHeapSize()).thenAnswer(invocation -> memstoreHeapSize.get());
  when(region.getMemStoreOffHeapSize()).thenAnswer(invocation -> memstoreOffHeapSize.get());
  when(region.flush(anyBoolean())).thenAnswer(invocation -> {
    assertTrue(invocation.getArgument(0));
    memstoreHeapSize.set(0);
    memstoreOffHeapSize.set(0);
    flushCalled.incrementAndGet();
    return null;
  });
}
 
Example #10
Source File: TestRegionObserverScannerOpenHook.java    From hbase with Apache License 2.0 6 votes vote down vote up
HRegion initHRegion(byte[] tableName, String callingMethod, Configuration conf,
    byte[]... families) throws IOException {
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(TableName.valueOf(tableName));
  for (byte[] family : families) {
    tableDescriptor.setColumnFamily(
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family));
  }
  ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null);
  RegionInfo info = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
  Path path = new Path(DIR + callingMethod);
  WAL wal = HBaseTestingUtility.createWal(conf, path, info);
  HRegion r = HRegion.createHRegion(info, path, conf, tableDescriptor, wal);
  // this following piece is a hack. currently a coprocessorHost
  // is secretly loaded at OpenRegionHandler. we don't really
  // start a region server here, so just manually create cphost
  // and set it to region.
  RegionCoprocessorHost host = new RegionCoprocessorHost(r, null, conf);
  r.setCoprocessorHost(host);
  return r;
}
 
Example #11
Source File: WALRecoveryRegionPostOpenIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private void moveRegionAndWait(MiniHBaseCluster miniHBaseCluster,HRegion destRegion, HRegionServer destRegionServer) throws IOException, InterruptedException {
    HMaster master = miniHBaseCluster.getMaster();
    getUtility().getHBaseAdmin().move(
            destRegion.getRegionInfo().getEncodedNameAsBytes(),
            Bytes.toBytes(destRegionServer.getServerName().getServerName()));
    while (true) {
        ServerName currentRegionServerName =
                master.getAssignmentManager().getRegionStates().getRegionServerOfRegion(destRegion.getRegionInfo());
        if (currentRegionServerName != null && currentRegionServerName.equals(destRegionServer.getServerName())) {
            getUtility().assertRegionOnServer(
                    destRegion.getRegionInfo(), currentRegionServerName, 200);
            break;
        }
        Thread.sleep(10);
    }
}
 
Example #12
Source File: AbstractTestLogRolling.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that logs are deleted
 */
@Test
public void testLogRolling() throws Exception {
  this.tableName = getName();
  // TODO: Why does this write data take for ever?
  startAndWriteData();
  RegionInfo region = server.getRegions(TableName.valueOf(tableName)).get(0).getRegionInfo();
  final WAL log = server.getWAL(region);
  LOG.info("after writing there are " + AbstractFSWALProvider.getNumRolledLogFiles(log) + " log files");
  assertLogFileSize(log);

  // flush all regions
  for (HRegion r : server.getOnlineRegionsLocalContext()) {
    r.flush(true);
  }

  // Now roll the log
  log.rollWriter();

  int count = AbstractFSWALProvider.getNumRolledLogFiles(log);
  LOG.info("after flushing all regions and rolling logs there are " + count + " log files");
  assertTrue(("actual count: " + count), count <= 2);
  assertLogFileSize(log);
}
 
Example #13
Source File: TestCoprocessorConfiguration.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegionCoprocessorHostAllDisabled() throws Exception {
  Configuration conf = new Configuration(CONF);
  conf.setBoolean(CoprocessorHost.COPROCESSORS_ENABLED_CONF_KEY, false);
  HRegion region = mock(HRegion.class);
  when(region.getRegionInfo()).thenReturn(REGIONINFO);
  when(region.getTableDescriptor()).thenReturn(TABLEDESC);
  RegionServerServices rsServices = mock(RegionServerServices.class);
  systemCoprocessorLoaded.set(false);
  tableCoprocessorLoaded.set(false);
  new RegionCoprocessorHost(region, rsServices, conf);
  assertFalse("System coprocessors should not have been loaded",
    systemCoprocessorLoaded.get());
  assertFalse("Table coprocessors should not have been loaded",
    tableCoprocessorLoaded.get());
}
 
Example #14
Source File: HBaseTestingUtility.java    From hbase with Apache License 2.0 6 votes vote down vote up
public void verifyNumericRows(HRegion region, final byte[] f, int startRow, int endRow,
    final boolean present) throws IOException {
  for (int i = startRow; i < endRow; i++) {
    String failMsg = "Failed verification of row :" + i;
    byte[] data = Bytes.toBytes(String.valueOf(i));
    Result result = region.get(new Get(data));

    boolean hasResult = result != null && !result.isEmpty();
    assertEquals(failMsg + result, present, hasResult);
    if (!present) continue;

    assertTrue(failMsg, result.containsColumn(f, null));
    assertEquals(failMsg, 1, result.getColumnCells(f, null).size());
    Cell cell = result.getColumnLatestCell(f, null);
    assertTrue(failMsg,
      Bytes.equals(data, 0, data.length, cell.getValueArray(), cell.getValueOffset(),
        cell.getValueLength()));
  }
}
 
Example #15
Source File: HBaseTestingUtility.java    From hbase with Apache License 2.0 6 votes vote down vote up
public HRegion createLocalHRegionWithInMemoryFlags(TableName tableName, byte[] startKey,
  byte[] stopKey, boolean isReadOnly, Durability durability, WAL wal, boolean[] compactedMemStore,
  byte[]... families) throws IOException {
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
  tableDescriptor.setReadOnly(isReadOnly);
  int i = 0;
  for (byte[] family : families) {
    ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family);
    if (compactedMemStore != null && i < compactedMemStore.length) {
      familyDescriptor.setInMemoryCompaction(MemoryCompactionPolicy.BASIC);
    } else {
      familyDescriptor.setInMemoryCompaction(MemoryCompactionPolicy.NONE);

    }
    i++;
    // Set default to be three versions.
    familyDescriptor.setMaxVersions(Integer.MAX_VALUE);
    tableDescriptor.setColumnFamily(familyDescriptor);
  }
  tableDescriptor.setDurability(durability);
  RegionInfo info = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName())
    .setStartKey(startKey).setEndKey(stopKey).build();
  return createLocalHRegion(info, tableDescriptor, wal);
}
 
Example #16
Source File: TransactionProcessorTest.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
private HRegion createRegion(String tableName, byte[] family, long ttl) throws IOException {
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
  HColumnDescriptor cfd = new HColumnDescriptor(family);
  if (ttl > 0) {
    cfd.setValue(TxConstants.PROPERTY_TTL, String.valueOf(ttl));
  }
  cfd.setMaxVersions(10);
  htd.addFamily(cfd);
  htd.addCoprocessor(TransactionProcessor.class.getName());
  Path tablePath = FSUtils.getTableDir(FSUtils.getRootDir(conf), htd.getTableName());
  FileSystem fs = FileSystem.get(conf);
  assertTrue(fs.mkdirs(tablePath));
  WALFactory walFactory = new WALFactory(conf, null, tableName + ".hlog");
  WAL hLog = walFactory.getWAL(new byte[]{1}, null);
  HRegionInfo regionInfo = new HRegionInfo(TableName.valueOf(tableName));
  HRegionFileSystem regionFS = HRegionFileSystem.createRegionOnFileSystem(conf, fs, tablePath, regionInfo);
  return new HRegion(regionFS, hLog, conf, htd,
      new LocalRegionServerServices(conf, ServerName.valueOf(
          InetAddress.getLocalHost().getHostName(), 0, System.currentTimeMillis())));
}
 
Example #17
Source File: TestRegionStateStore.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testVisitMetaForRegionExistingRegion() throws Exception {
  final TableName tableName = TableName.valueOf("testVisitMetaForRegion");
  UTIL.createTable(tableName, "cf");
  final List<HRegion> regions = UTIL.getHBaseCluster().getRegions(tableName);
  final String encodedName = regions.get(0).getRegionInfo().getEncodedName();
  final RegionStateStore regionStateStore = UTIL.getHBaseCluster().getMaster().
    getAssignmentManager().getRegionStateStore();
  final AtomicBoolean visitorCalled = new AtomicBoolean(false);
  regionStateStore.visitMetaForRegion(encodedName, new RegionStateStore.RegionStateVisitor() {
    @Override
    public void visitRegionState(Result result, RegionInfo regionInfo, RegionState.State state,
      ServerName regionLocation, ServerName lastHost, long openSeqNum) {
      assertEquals(encodedName, regionInfo.getEncodedName());
      visitorCalled.set(true);
    }
  });
  assertTrue("Visitor has not been called.", visitorCalled.get());
}
 
Example #18
Source File: HBaseTestingUtility.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Create a region with it's own WAL. Be sure to call
 * {@link HBaseTestingUtility#closeRegionAndWAL(HRegion)} to clean up all resources.
 */
public static HRegion createRegionAndWAL(final RegionInfo info, final Path rootDir,
    final Configuration conf, final TableDescriptor htd, MobFileCache mobFileCache)
    throws IOException {
  HRegion region = createRegionAndWAL(info, rootDir, conf, htd, false);
  region.setMobFileCache(mobFileCache);
  region.initialize();
  return region;
}
 
Example #19
Source File: TransactionProcessorTest.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
private HRegion updateTtl(HRegion region, byte[] family, long ttl) throws Exception {
  region.close();
  HTableDescriptor htd = region.getTableDesc();
  HColumnDescriptor cfd = htd.getFamily(family);
  if (ttl > 0) {
    cfd.setValue(TxConstants.PROPERTY_TTL, String.valueOf(ttl));
  }
  cfd.setMaxVersions(10);
  return HRegion.openHRegion(region.getRegionInfo(), htd, region.getWAL(), conf,
                             new LocalRegionServerServices(conf, ServerName.valueOf(
                               InetAddress.getLocalHost().getHostName(), 0, System.currentTimeMillis())), null);
}
 
Example #20
Source File: SnapshotManifest.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a 'manifest' for the specified region, by reading directly from the HRegion object.
 * This is used by the "online snapshot" when the table is enabled.
 */
public void addRegion(final HRegion region) throws IOException {
  // Get the ManifestBuilder/RegionVisitor
  RegionVisitor visitor = createRegionVisitor(desc);

  // Visit the region and add it to the manifest
  addRegion(region, visitor);
}
 
Example #21
Source File: MiniHBaseCluster.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Call flushCache on all regions of the specified table.
 */
public void flushcache(TableName tableName) throws IOException {
  for (JVMClusterUtil.RegionServerThread t : this.hbaseCluster.getRegionServers()) {
    for (HRegion r : t.getRegionServer().getOnlineRegionsLocalContext()) {
      if (r.getTableDescriptor().getTableName().equals(tableName)) {
        executeFlush(r);
      }
    }
  }
}
 
Example #22
Source File: TransactionProcessorTest.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
private void scanAndAssert(HRegion region, List<Cell> expected, Scan scan) throws Exception {
  try (RegionScanner regionScanner = region.getScanner(scan)) {
    List<Cell> results = Lists.newArrayList();
    while (regionScanner.next(results)) { }
    assertEquals(expected, results);
  }
}
 
Example #23
Source File: TestWALRecoveryCaching.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Set<ServerName> getServersForTable(MiniHBaseCluster cluster, byte[] table)
    throws Exception {
  List<HRegion> indexRegions = cluster.getRegions(table);
  Set<ServerName> indexServers = new HashSet<ServerName>();
  for (HRegion region : indexRegions) {
    indexServers.add(cluster.getServerHoldingRegion(region.getRegionName()));
  }
  return indexServers;
}
 
Example #24
Source File: TestWALSplitToHFile.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testDifferentRootDirAndWALRootDir() throws Exception {
  // Change wal root dir and reset the configuration
  Path walRootDir = UTIL.createWALRootDir();
  this.conf = HBaseConfiguration.create(UTIL.getConfiguration());

  FileSystem walFs = CommonFSUtils.getWALFileSystem(this.conf);
  this.oldLogDir = new Path(walRootDir, HConstants.HREGION_OLDLOGDIR_NAME);
  String serverName =
      ServerName.valueOf(TEST_NAME.getMethodName() + "-manual", 16010, System.currentTimeMillis())
          .toString();
  this.logName = AbstractFSWALProvider.getWALDirectoryName(serverName);
  this.logDir = new Path(walRootDir, logName);
  this.wals = new WALFactory(conf, TEST_NAME.getMethodName());

  Pair<TableDescriptor, RegionInfo> pair = setupTableAndRegion();
  TableDescriptor td = pair.getFirst();
  RegionInfo ri = pair.getSecond();

  WAL wal = createWAL(walFs, walRootDir, logName);
  HRegion region = HRegion.openHRegion(this.conf, this.fs, rootDir, ri, td, wal);
  writeData(td, region);

  // Now close the region without flush
  region.close(true);
  wal.shutdown();
  // split the log
  WALSplitter.split(walRootDir, logDir, oldLogDir, FileSystem.get(this.conf), this.conf, wals);

  WAL wal2 = createWAL(walFs, walRootDir, logName);
  HRegion region2 = HRegion.openHRegion(this.conf, this.fs, rootDir, ri, td, wal2);
  Result result2 = region2.get(new Get(ROW));
  assertEquals(td.getColumnFamilies().length, result2.size());
  for (ColumnFamilyDescriptor cfd : td.getColumnFamilies()) {
    assertTrue(Bytes.equals(VALUE1, result2.getValue(cfd.getName(), QUALIFIER)));
  }
}
 
Example #25
Source File: TestFavoredStochasticLoadBalancer.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void compactTable(TableName tableName) throws IOException {
  for(JVMClusterUtil.RegionServerThread t : cluster.getRegionServerThreads()) {
    for(HRegion region : t.getRegionServer().getRegions(tableName)) {
      region.compact(true);
    }
  }
}
 
Example #26
Source File: PerRegionIndexWriteCache.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * @param region
 * @param table
 * @param collection
 */
public void addEdits(HRegion region, HTableInterfaceReference table,
    Collection<Mutation> collection) {
  Multimap<HTableInterfaceReference, Mutation> edits = cache.get(region);
  if (edits == null) {
    edits = ArrayListMultimap.<HTableInterfaceReference, Mutation> create();
    cache.put(region, edits);
  }
  edits.putAll(table, collection);
}
 
Example #27
Source File: TestCompactedHFilesDischarger.java    From hbase with Apache License 2.0 5 votes vote down vote up
protected void startScannerThreads() throws InterruptedException {
  // Start parallel scan threads
  ScanThread[] scanThreads = new ScanThread[3];
  for (int i = 0; i < 3; i++) {
    scanThreads[i] = new ScanThread((HRegion) region);
  }
  for (ScanThread thread : scanThreads) {
    thread.start();
  }
  while (counter.get() != 3) {
    Thread.sleep(100);
  }
}
 
Example #28
Source File: TestFromClientSide3.java    From hbase with Apache License 2.0 5 votes vote down vote up
private static <T extends RegionObserver> T find(final TableName tableName,
        Class<T> clz) throws IOException, InterruptedException {
  HRegion region = find(tableName);
  Coprocessor cp = region.getCoprocessorHost().findCoprocessor(clz.getName());
  assertTrue("The cp instance should be " + clz.getName()
          + ", current instance is " + cp.getClass().getName(), clz.isInstance(cp));
  return clz.cast(cp);
}
 
Example #29
Source File: TestCoprocessorInterface.java    From hbase with Apache License 2.0 5 votes vote down vote up
HRegion reopenRegion(final HRegion closedRegion, Class<?> ... implClasses)
    throws IOException {
  //RegionInfo info = new RegionInfo(tableName, null, null, false);
  HRegion r = HRegion.openHRegion(closedRegion, null);

  // this following piece is a hack. currently a coprocessorHost
  // is secretly loaded at OpenRegionHandler. we don't really
  // start a region server here, so just manually create cphost
  // and set it to region.
  Configuration conf = TEST_UTIL.getConfiguration();
  RegionCoprocessorHost host = new RegionCoprocessorHost(r,
      Mockito.mock(RegionServerServices.class), conf);
  r.setCoprocessorHost(host);

  for (Class<?> implClass : implClasses) {
    host.load((Class<? extends RegionCoprocessor>) implClass, Coprocessor.PRIORITY_USER, conf);
  }
  // we need to manually call pre- and postOpen here since the
  // above load() is not the real case for CP loading. A CP is
  // expected to be loaded by default from 1) configuration; or 2)
  // HTableDescriptor. If it's loaded after HRegion initialized,
  // the pre- and postOpen() won't be triggered automatically.
  // Here we have to call pre and postOpen explicitly.
  host.preOpen();
  host.postOpen();
  return r;
}
 
Example #30
Source File: TestSimpleRegionNormalizerOnCluster.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * create a table with 5 regions, having region sizes so as to provoke a split
 * of the largest region.
 * <ul>
 *   <li>total table size: 12</li>
 *   <li>average region size: 2.4</li>
 *   <li>split threshold: 2.4 * 2 = 4.8</li>
 * </ul>
 */
private static int createTableBegsSplit(final TableName tableName,
    final boolean normalizerEnabled, final boolean isMergeEnabled)
  throws IOException {
  final List<HRegion> generatedRegions = generateTestData(tableName, 1, 1, 2, 3, 5);
  assertEquals(5, MetaTableAccessor.getRegionCount(TEST_UTIL.getConnection(), tableName));
  admin.flush(tableName);

  final TableDescriptor td = TableDescriptorBuilder.newBuilder(admin.getDescriptor(tableName))
    .setNormalizationEnabled(normalizerEnabled)
    .setMergeEnabled(isMergeEnabled)
    .build();
  admin.modifyTable(td);

  // make sure relatively accurate region statistics are available for the test table. use
  // the last/largest region as clue.
  TEST_UTIL.waitFor(TimeUnit.MINUTES.toMillis(1), new ExplainingPredicate<IOException>() {
    @Override public String explainFailure() {
      return "expected largest region to be >= 4mb.";
    }
    @Override public boolean evaluate() {
      return generatedRegions.stream()
        .mapToDouble(val -> getRegionSizeMB(master, val.getRegionInfo()))
        .allMatch(val -> val > 0)
        && getRegionSizeMB(master, generatedRegions.get(4).getRegionInfo()) >= 4.0;
    }
  });
  return 5;
}