Java Code Examples for org.apache.hadoop.hbase.TableName

The following examples show how to use org.apache.hadoop.hbase.TableName. These examples are extracted from open source projects. 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
@Test(expected = IllegalArgumentException.class)
public void testScanWithInvalidFilter() throws InitializationException, IOException {
    final String tableName = "nifi";
    final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);

    // Mock an HBase Table so we can verify the put operations later
    final Table table = Mockito.mock(Table.class);
    when(table.getName()).thenReturn(TableName.valueOf(tableName));

    // create the controller service and link it to the test processor
    final MockHBaseClientService service = configureHBaseClientService(runner, table);
    runner.assertValid(service);

    // perform a scan and verify the four rows were returned
    final CollectingResultHandler handler = new CollectingResultHandler();
    final HBaseClientService hBaseClientService = runner.getProcessContext().getProperty(TestProcessor.HBASE_CLIENT_SERVICE)
            .asControllerService(HBaseClientService.class);

    // this should throw IllegalArgumentException
    final String filter = "this is not a filter";
    hBaseClientService.scan(tableName, new ArrayList<Column>(), filter, System.currentTimeMillis(), handler);
}
 
Example 2
Source Project: hbase   Source File: TestRegionSplitter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test creating a pre-split table using the UniformSplit algorithm.
 */
@Test
public void testCreatePresplitTableUniform() throws Exception {
  List<byte[]> expectedBounds = new ArrayList<>(17);
  expectedBounds.add(ArrayUtils.EMPTY_BYTE_ARRAY);
  expectedBounds.add(new byte[] {      0x10, 0, 0, 0, 0, 0, 0, 0});
  expectedBounds.add(new byte[] {      0x20, 0, 0, 0, 0, 0, 0, 0});
  expectedBounds.add(new byte[] {      0x30, 0, 0, 0, 0, 0, 0, 0});
  expectedBounds.add(new byte[] {      0x40, 0, 0, 0, 0, 0, 0, 0});
  expectedBounds.add(new byte[] { 0x50, 0, 0, 0, 0, 0, 0, 0 });
  expectedBounds.add(new byte[] { 0x60, 0, 0, 0, 0, 0, 0, 0 });
  expectedBounds.add(new byte[] { 0x70, 0, 0, 0, 0, 0, 0, 0 });
  expectedBounds.add(new byte[] { (byte) 0x80, 0, 0, 0, 0, 0, 0, 0 });
  expectedBounds.add(new byte[] { (byte) 0x90, 0, 0, 0, 0, 0, 0, 0 });
  expectedBounds.add(new byte[] {(byte)0xa0, 0, 0, 0, 0, 0, 0, 0});
  expectedBounds.add(new byte[] { (byte) 0xb0, 0, 0, 0, 0, 0, 0, 0 });
  expectedBounds.add(new byte[] { (byte) 0xc0, 0, 0, 0, 0, 0, 0, 0 });
  expectedBounds.add(new byte[] { (byte) 0xd0, 0, 0, 0, 0, 0, 0, 0 });
  expectedBounds.add(new byte[] {(byte)0xe0, 0, 0, 0, 0, 0, 0, 0});
  expectedBounds.add(new byte[] { (byte) 0xf0, 0, 0, 0, 0, 0, 0, 0 });
  expectedBounds.add(ArrayUtils.EMPTY_BYTE_ARRAY);

  // Do table creation/pre-splitting and verification of region boundaries
  preSplitTableAndVerify(expectedBounds, UniformSplit.class.getSimpleName(),
      TableName.valueOf(name.getMethodName()));
}
 
Example 3
Source Project: Flink-CEPplus   Source File: HBaseRowInputFormat.java    License: Apache License 2.0 6 votes vote down vote up
private void connectToTable() {

		if (this.conf == null) {
			this.conf = HBaseConfiguration.create();
		}

		try {
			Connection conn = ConnectionFactory.createConnection(conf);
			super.table = (HTable) conn.getTable(TableName.valueOf(tableName));
		} catch (TableNotFoundException tnfe) {
			LOG.error("The table " + tableName + " not found ", tnfe);
			throw new RuntimeException("HBase table '" + tableName + "' not found.", tnfe);
		} catch (IOException ioe) {
			LOG.error("Exception while creating connection to HBase.", ioe);
			throw new RuntimeException("Cannot create connection to HBase.", ioe);
		}
	}
 
Example 4
private void createTable(Admin admin, TableName tableName, boolean setVersion,
    boolean acl) throws IOException {
  if (!admin.tableExists(tableName)) {
    TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
      new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
    ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY_NAME);
    if (setVersion) {
      familyDescriptor.setMaxVersions(DEFAULT_TABLES_COUNT);
    }
    tableDescriptor.setColumnFamily(familyDescriptor);
    admin.createTable(tableDescriptor);
    if (acl) {
      LOG.info("Granting permissions for user " + USER.getShortName());
      Permission.Action[] actions = { Permission.Action.READ };
      try {
        AccessControlClient.grant(ConnectionFactory.createConnection(getConf()), tableName,
            USER.getShortName(), null, null, actions);
      } catch (Throwable e) {
        LOG.error(HBaseMarkers.FATAL, "Error in granting permission for the user " +
            USER.getShortName(), e);
        throw new IOException(e);
      }
    }
  }
}
 
Example 5
Source Project: hbase   Source File: HMaster.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Check hbase:namespace table is assigned. If not, startup will hang looking for the ns table
 * <p/>
 * This is for rolling upgrading, later we will migrate the data in ns table to the ns family of
 * meta table. And if this is a new cluster, this method will return immediately as there will be
 * no namespace table/region.
 * @return True if namespace table is up/online.
 */
private boolean waitForNamespaceOnline() throws IOException {
  TableState nsTableState =
    MetaTableAccessor.getTableState(getConnection(), TableName.NAMESPACE_TABLE_NAME);
  if (nsTableState == null || nsTableState.isDisabled()) {
    // this means we have already migrated the data and disabled or deleted the namespace table,
    // or this is a new deploy which does not have a namespace table from the beginning.
    return true;
  }
  List<RegionInfo> ris =
    this.assignmentManager.getRegionStates().getRegionsOfTable(TableName.NAMESPACE_TABLE_NAME);
  if (ris.isEmpty()) {
    // maybe this will not happen any more, but anyway, no harm to add a check here...
    return true;
  }
  // Else there are namespace regions up in meta. Ensure they are assigned before we go on.
  for (RegionInfo ri : ris) {
    if (!isRegionOnline(ri)) {
      return false;
    }
  }
  return true;
}
 
Example 6
Source Project: phoenix-omid   Source File: HBaseSyncPostCommitter.java    License: Apache License 2.0 6 votes vote down vote up
private void addShadowCell(HBaseCellId cell, HBaseTransaction tx, SettableFuture<Void> updateSCFuture,
                           Map<TableName,List<Mutation>> mutations) throws IOException, InterruptedException {
    Put put = new Put(cell.getRow());
    put.addColumn(cell.getFamily(),
            CellUtils.addShadowCellSuffixPrefix(cell.getQualifier(), 0, cell.getQualifier().length),
            cell.getTimestamp(),
            Bytes.toBytes(tx.getCommitTimestamp()));

    TableName table = cell.getTable().getHTable().getName();
    List<Mutation> tableMutations = mutations.get(table);
    if (tableMutations == null) {
        ArrayList<Mutation> newList = new ArrayList<>();
        newList.add(put);
        mutations.put(table, newList);
    } else {
        tableMutations.add(put);
        if (tableMutations.size() > MAX_BATCH_SIZE) {
            flushMutations(table, tableMutations);
            mutations.remove(table);
        }
    }
}
 
Example 7
Source Project: hbase   Source File: TestScannersFromClientSide.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testReadExpiredDataForRawScan() throws IOException {
  TableName tableName = name.getTableName();
  long ts = System.currentTimeMillis() - 10000;
  byte[] value = Bytes.toBytes("expired");
  try (Table table = TEST_UTIL.createTable(tableName, FAMILY)) {
    table.put(new Put(ROW).addColumn(FAMILY, QUALIFIER, ts, value));
    assertArrayEquals(value, table.get(new Get(ROW)).getValue(FAMILY, QUALIFIER));
    TEST_UTIL.getAdmin().modifyColumnFamily(tableName,
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY)
        .setTimeToLive(5));
    try (ResultScanner scanner = table.getScanner(FAMILY)) {
      assertNull(scanner.next());
    }
    try (ResultScanner scanner = table.getScanner(new Scan().setRaw(true))) {
      assertArrayEquals(value, scanner.next().getValue(FAMILY, QUALIFIER));
      assertNull(scanner.next());
    }
  }
}
 
Example 8
Source Project: kylin   Source File: StorageCleanJobHbaseUtilTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws IOException {
    HBaseAdmin hBaseAdmin = mock(HBaseAdmin.class);
    HTableDescriptor[] hds = new HTableDescriptor[2];
    HTableDescriptor d1 = mock(HTableDescriptor.class);
    HTableDescriptor d2 = mock(HTableDescriptor.class);
    hds[0] = d1;
    hds[1] = d2;
    when(d1.getValue("KYLIN_HOST")).thenReturn("../examples/test_metadata/");
    when(d2.getValue("KYLIN_HOST")).thenReturn("../examples/test_metadata/");
    when(d1.getTableName()).thenReturn(TableName.valueOf("KYLIN_J9TE08D9IA"));
    String toBeDel = "to-be-del";
    when(d2.getTableName()).thenReturn(TableName.valueOf(toBeDel));
    when(hBaseAdmin.listTables("KYLIN_.*")).thenReturn(hds);

    when(hBaseAdmin.tableExists(toBeDel)).thenReturn(true);
    when(hBaseAdmin.isTableEnabled(toBeDel)).thenReturn(false);
    StorageCleanJobHbaseUtil.cleanUnusedHBaseTables(hBaseAdmin, true, 100000, 1);

    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(hBaseAdmin).deleteTable(captor.capture());
    assertEquals(Lists.newArrayList(toBeDel), captor.getAllValues());
}
 
Example 9
Source Project: hbase   Source File: SchemaResource.java    License: Apache License 2.0 6 votes vote down vote up
private Response update(final TableSchemaModel model, final boolean replace,
    final UriInfo uriInfo) {
  try {
    TableName name = TableName.valueOf(tableResource.getName());
    Admin admin = servlet.getAdmin();
    if (replace || !admin.tableExists(name)) {
      return replace(name, model, uriInfo, admin);
    } else {
      return update(name, model, uriInfo, admin);
    }
  } catch (Exception e) {
    servlet.getMetrics().incrementFailedPutRequests(1);
    // Avoid re-unwrapping the exception
    if (e instanceof WebApplicationException) {
      throw (WebApplicationException) e;
    }
    return processException(e);
  }
}
 
Example 10
Source Project: hbase   Source File: TestRegionReplicasWithModifyTable.java    License: Apache License 2.0 6 votes vote down vote up
private static void enableReplicationByModification(final TableName tableName,
    boolean withReplica, int initialReplicaCount, int enableReplicaCount, int splitCount)
    throws IOException, InterruptedException {
  HTableDescriptor htd = new HTableDescriptor(tableName);
  if (withReplica) {
    htd.setRegionReplication(initialReplicaCount);
  }
  if (splitCount > 0) {
    byte[][] splits = getSplits(splitCount);
    table = HTU.createTable(htd, new byte[][] { f }, splits,
      new Configuration(HTU.getConfiguration()));

  } else {
    table = HTU.createTable(htd, new byte[][] { f }, (byte[][]) null,
      new Configuration(HTU.getConfiguration()));
  }
  HBaseTestingUtility.setReplicas(HTU.getAdmin(), table.getName(), enableReplicaCount);
}
 
Example 11
Source Project: hbase   Source File: TestTableInputFormat.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void configure(JobConf job) {
  try {
    Connection connection = ConnectionFactory.createConnection(job);
    Table exampleTable = connection.getTable(TableName.valueOf(("exampleDeprecatedTable")));
    // mandatory
    initializeTable(connection, exampleTable.getName());
    byte[][] inputColumns = new byte [][] { Bytes.toBytes("columnA"),
      Bytes.toBytes("columnB") };
    // optional
    Scan scan = new Scan();
    for (byte[] family : inputColumns) {
      scan.addFamily(family);
    }
    Filter exampleFilter =
      new RowFilter(CompareOperator.EQUAL, new RegexStringComparator("aa.*"));
    scan.setFilter(exampleFilter);
    setScan(scan);
  } catch (IOException exception) {
    throw new RuntimeException("Failed to configure for job.", exception);
  }
}
 
Example 12
Source Project: phoenix-tephra   Source File: DataJanitorStateTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void beforeTest() throws Exception {
  pruneStateTable = TableName.valueOf(conf.get(TxConstants.TransactionPruning.PRUNE_STATE_TABLE,
                                               TxConstants.TransactionPruning.DEFAULT_PRUNE_STATE_TABLE));
  HTable table = createTable(pruneStateTable.getName(), new byte[][]{DataJanitorState.FAMILY}, false,
                             // Prune state table is a non-transactional table, hence no transaction co-processor
                             Collections.<String>emptyList());
  table.close();
  connection = HConnectionManager.createConnection(conf);

  dataJanitorState =
    new DataJanitorState(new DataJanitorState.TableSupplier() {
      @Override
      public HTableInterface get() throws IOException {
        return connection.getTable(pruneStateTable);
      }
    });

}
 
Example 13
Source Project: pinpoint   Source File: ParallelResultScanner.java    License: Apache License 2.0 6 votes vote down vote up
public ParallelResultScanner(TableName tableName, HbaseAccessor hbaseAccessor, ExecutorService executor, Scan originalScan, AbstractRowKeyDistributor keyDistributor, int numParallelThreads) throws IOException {
    if (hbaseAccessor == null) {
        throw new NullPointerException("hbaseAccessor");
    }
    if (executor == null) {
        throw new NullPointerException("executor");
    }
    if (originalScan == null) {
        throw new NullPointerException("originalScan");
    }
    this.keyDistributor = Objects.requireNonNull(keyDistributor, "keyDistributor");

    final ScanTaskConfig scanTaskConfig = new ScanTaskConfig(tableName, hbaseAccessor, keyDistributor, originalScan.getCaching());
    final Scan[] splitScans = splitScans(originalScan);

    this.scanTasks = createScanTasks(scanTaskConfig, splitScans, numParallelThreads);
    this.nextResults = new Result[scanTasks.size()];
    for (ScanTask scanTask : scanTasks) {
        executor.execute(scanTask);
    }
}
 
Example 14
Source Project: eagle   Source File: HBaseEntitySchemaManager.java    License: Apache License 2.0 6 votes vote down vote up
private void createTable(EntityDefinition entityDefinition) throws IOException {
    String tableName = entityDefinition.getTable();
    if (admin.tableExists(tableName)) {
        LOG.info("Table {} already exists", tableName);
    } else {
        HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(tableName));

        // Adding column families to table descriptor
        HColumnDescriptor columnDescriptor = new HColumnDescriptor(entityDefinition.getColumnFamily());
        columnDescriptor.setBloomFilterType(BloomType.ROW);
        //columnDescriptor.setCompressionType(Compression.Algorithm.SNAPPY);
        columnDescriptor.setMaxVersions(DEFAULT_MAX_VERSIONS);

        tableDescriptor.addFamily(columnDescriptor);

        // Execute the table through admin
        admin.createTable(tableDescriptor);
        LOG.info("Successfully create Table {}", tableName);
    }
}
 
Example 15
Source Project: bigdata-tutorial   Source File: HBaseSimpleDemo.java    License: Apache License 2.0 6 votes vote down vote up
public Boolean createTable(String tableName, String familyName) throws Exception {
	HBaseAdmin admin = new HBaseAdmin(hconn);
	if (admin.tableExists(tableName)) {
		LOGGER.warn(">>>> Table {} exists!", tableName);
		admin.close();
		return false;
	}
	HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(tableName));
	tableDesc.addFamily(new HColumnDescriptor(familyName));
	admin.createTable(tableDesc);
	LOGGER.info(">>>> Table {} create success!", tableName);

	admin.close();
	return true;

}
 
Example 16
Source Project: hbase   Source File: TestReplicaWithCluster.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testReplicaGetWithPrimaryDown() throws IOException {
  // Create table then get the single region for our new table.
  HTableDescriptor hdt = HTU.createTableDescriptor(TableName.valueOf("testCreateDeleteTable"),
    HColumnDescriptor.DEFAULT_MIN_VERSIONS, 3, HConstants.FOREVER,
    HColumnDescriptor.DEFAULT_KEEP_DELETED);
  hdt.setRegionReplication(NB_SERVERS);
  hdt.addCoprocessor(RegionServerStoppedCopro.class.getName());
  try {
    Table table = HTU.createTable(hdt, new byte[][] { f }, null);

    Put p = new Put(row);
    p.addColumn(f, row, row);
    table.put(p);

    // Flush so it can be picked by the replica refresher thread
    HTU.flush(table.getName());

    // Sleep for some time until data is picked up by replicas
    try {
      Thread.sleep(2 * REFRESH_PERIOD);
    } catch (InterruptedException e1) {
      LOG.error(e1.toString(), e1);
    }

    // But if we ask for stale we will get it
    Get g = new Get(row);
    g.setConsistency(Consistency.TIMELINE);
    Result r = table.get(g);
    Assert.assertTrue(r.isStale());
  } finally {
    HTU.getAdmin().disableTable(hdt.getTableName());
    HTU.deleteTable(hdt.getTableName());
  }
}
 
Example 17
Source Project: datacollector   Source File: HBaseProcessor2_0.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void createTable() throws IOException, InterruptedException {
  hbaseConnectionHelper.getUGI().doAs((PrivilegedExceptionAction<Void>) () -> {
    Connection connection = ConnectionFactory.createConnection(hbaseConnectionHelper.getHBaseConfiguration());
    table = connection.getTable(TableName.valueOf(hBaseLookupConfig.hBaseConnectionConfig.tableName));
    return null;
  });
}
 
Example 18
Source Project: hbase   Source File: RawAsyncHBaseAdmin.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Void> truncateTable(TableName tableName, boolean preserveSplits) {
  return this.<TruncateTableRequest, TruncateTableResponse> procedureCall(tableName,
    RequestConverter.buildTruncateTableRequest(tableName, preserveSplits, ng.getNonceGroup(),
      ng.newNonce()), (s, c, req, done) -> s.truncateTable(c, req, done),
    (resp) -> resp.getProcId(), new TruncateTableProcedureBiConsumer(tableName));
}
 
Example 19
Source Project: BigData   Source File: Data2HBase.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 创建表
 *
 * @param admin
 * @param tableNameString
 * @param columnFamily
 * @throws IOException
 */
private static void createTable(Connection connection, String tableNameString, String columnFamily) throws IOException {
    Admin admin = connection.getAdmin();
    TableName tableName = TableName.valueOf(tableNameString); //d2h (data to HBase)
    HTableDescriptor table = new HTableDescriptor(tableName);
    HColumnDescriptor family = new HColumnDescriptor(columnFamily);
    table.addFamily(family);
    //判断表是否已经存在
    if (admin.tableExists(tableName)) {
        admin.disableTable(tableName);
        admin.deleteTable(tableName);
    }
    admin.createTable(table);
}
 
Example 20
Source Project: hbase   Source File: TestAsyncTableRpcPriority.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testScanSystemTable() throws IOException, InterruptedException {
  try (ResultScanner scanner =
    conn.getTable(TableName.valueOf(SYSTEM_NAMESPACE_NAME_STR, name.getMethodName()))
      .getScanner(new Scan().setCaching(1).setMaxResultSize(1))) {
    assertNotNull(scanner.next());
    Thread.sleep(1000);
  }
  Thread.sleep(1000);
  // open, next, several renew lease, and then close
  verify(stub, atLeast(4)).scan(assertPriority(SYSTEMTABLE_QOS), any(ScanRequest.class), any());
}
 
Example 21
Source Project: hbase   Source File: RegionSplitter.java    License: Apache License 2.0 5 votes vote down vote up
static void createPresplitTable(TableName tableName, SplitAlgorithm splitAlgo,
        String[] columnFamilies, Configuration conf)
throws IOException, InterruptedException {
  final int splitCount = conf.getInt("split.count", 0);
  Preconditions.checkArgument(splitCount > 1, "Split count must be > 1");

  Preconditions.checkArgument(columnFamilies.length > 0,
      "Must specify at least one column family. ");
  LOG.debug("Creating table " + tableName + " with " + columnFamilies.length
      + " column families.  Presplitting to " + splitCount + " regions");

  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
  for (String cf : columnFamilies) {
    builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(cf));
  }
  try (Connection connection = ConnectionFactory.createConnection(conf)) {
    Admin admin = connection.getAdmin();
    try {
      Preconditions.checkArgument(!admin.tableExists(tableName),
        "Table already exists: " + tableName);
      admin.createTable(builder.build(), splitAlgo.split(splitCount));
    } finally {
      admin.close();
    }
    LOG.debug("Table created!  Waiting for regions to show online in META...");
    if (!conf.getBoolean("split.verify", true)) {
      // NOTE: createTable is synchronous on the table, but not on the regions
      int onlineRegions = 0;
      while (onlineRegions < splitCount) {
        onlineRegions = MetaTableAccessor.getRegionCount(connection, tableName);
        LOG.debug(onlineRegions + " of " + splitCount + " regions online...");
        if (onlineRegions < splitCount) {
          Thread.sleep(10 * 1000); // sleep
        }
      }
    }
    LOG.debug("Finished creating table with " + splitCount + " regions");
  }
}
 
Example 22
Source Project: hbase   Source File: TestBackupBoundaryTests.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Verify that full backup fails on a single table that does not exist.
 *
 * @throws Exception if doing the full backup fails
 */
@Test(expected = IOException.class)
public void testFullBackupSingleDNE() throws Exception {
  LOG.info("test full backup fails on a single table that does not exist");
  List<TableName> tables = toList("tabledne");
  fullTableBackup(tables);
}
 
Example 23
Source Project: hbase   Source File: TestAdmin2.java    License: Apache License 2.0 5 votes vote down vote up
private void createTableWithDefaultConf(TableName TABLENAME) throws IOException {
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(TABLENAME);
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("value")).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);

  ADMIN.createTable(tableDescriptorBuilder.build());
}
 
Example 24
Source Project: hbase   Source File: ThriftAdmin.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void modifyColumnFamily(TableName tableName, ColumnFamilyDescriptor columnFamily)
    throws IOException {
  TTableName tTableName = ThriftUtilities.tableNameFromHBase(tableName);
  TColumnFamilyDescriptor tColumnFamilyDescriptor = ThriftUtilities
      .columnFamilyDescriptorFromHBase(columnFamily);
  try {
    client.modifyColumnFamily(tTableName, tColumnFamilyDescriptor);
  } catch (TException e) {
    throw new IOException(e);
  }
}
 
Example 25
Source Project: hbase   Source File: TestAddToSerialReplicationPeer.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEnablingTable() throws Exception {
  TableName tableName = createTable();
  try (Table table = UTIL.getConnection().getTable(tableName)) {
    for (int i = 0; i < 100; i++) {
      table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
    }
  }
  RegionInfo region = UTIL.getAdmin().getRegions(tableName).get(0);
  HRegionServer rs = UTIL.getOtherRegionServer(UTIL.getRSForFirstRegionInTable(tableName));
  moveRegionAndArchiveOldWals(region, rs);
  TableStateManager tsm = UTIL.getMiniHBaseCluster().getMaster().getTableStateManager();
  tsm.setTableState(tableName, TableState.State.ENABLING);
  Thread t = new Thread(() -> {
    try {
      addPeer(true);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  });
  t.start();
  Thread.sleep(5000);
  // we will wait on the disabling table so the thread should still be alive.
  assertTrue(t.isAlive());
  tsm.setTableState(tableName, TableState.State.ENABLED);
  t.join();
  try (Table table = UTIL.getConnection().getTable(tableName)) {
    for (int i = 0; i < 100; i++) {
      table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
    }
  }
  waitUntilReplicationDone(100);
  checkOrder(100);
}
 
Example 26
Source Project: hbase   Source File: SpaceQuotaHelperForTests.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Removes all quotas defined in the HBase quota table.
 */
void removeAllQuotas(Connection conn) throws IOException {
  // Wait for the quota table to be created
  if (!conn.getAdmin().tableExists(QuotaUtil.QUOTA_TABLE_NAME)) {
    waitForQuotaTable(conn);
  } else {
    // Or, clean up any quotas from previous test runs.
    QuotaRetriever scanner = QuotaRetriever.open(conn.getConfiguration());
    try {
      for (QuotaSettings quotaSettings : scanner) {
        final String namespace = quotaSettings.getNamespace();
        final TableName tableName = quotaSettings.getTableName();
        final String userName = quotaSettings.getUserName();
        if (namespace != null) {
          LOG.debug("Deleting quota for namespace: " + namespace);
          QuotaUtil.deleteNamespaceQuota(conn, namespace);
        } else if (tableName != null) {
          LOG.debug("Deleting quota for table: " + tableName);
          QuotaUtil.deleteTableQuota(conn, tableName);
        } else if (userName != null) {
          LOG.debug("Deleting quota for user: " + userName);
          QuotaUtil.deleteUserQuota(conn, userName);
        }
      }
    } finally {
      if (scanner != null) {
        scanner.close();
      }
    }
  }
}
 
Example 27
Source Project: hbase   Source File: TestAsyncTableRpcPriority.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testScan() throws IOException, InterruptedException {
  try (ResultScanner scanner = conn.getTable(TableName.valueOf(name.getMethodName()))
    .getScanner(new Scan().setCaching(1).setMaxResultSize(1).setPriority(19))) {
    assertNotNull(scanner.next());
    Thread.sleep(1000);
  }
  Thread.sleep(1000);
  // open, next, several renew lease, and then close
  verify(stub, atLeast(4)).scan(assertPriority(19), any(ScanRequest.class), any());
}
 
Example 28
Source Project: hbase   Source File: TestMultiRowRangeFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testReverseMultiRowRangeFilterWithinTable() throws IOException {
  tableName = TableName.valueOf(name.getMethodName());
  Table ht = TEST_UTIL.createTable(tableName, family);
  generateRows(numRows, ht, family, qf, value);

  Scan scan = new Scan();
  scan.setReversed(true);
  List<RowRange> ranges = Arrays.asList(
      new RowRange(Bytes.toBytes(20), true, Bytes.toBytes(30), true),
      new RowRange(Bytes.toBytes(50), true, Bytes.toBytes(60), true)
  );
  MultiRowRangeFilter filter = new MultiRowRangeFilter(ranges);
  scan.setFilter(filter);

  List<Integer> expectedResults = new ArrayList<>();
  for (int i = 60; i >= 50; i--) {
    expectedResults.add(i);
  }
  for (int i = 30; i >= 20; i--) {
    expectedResults.add(i);
  }

  List<Cell> results = getResults(ht, scan);
  List<Integer> actualResults = new ArrayList<>();
  StringBuilder sb = new StringBuilder();
  for (Cell result : results) {
    int observedValue = Bytes.toInt(
        result.getRowArray(), result.getRowOffset(), result.getRowLength());
    actualResults.add(observedValue);
    if (sb.length() > 0) {
      sb.append(", ");
    }
    sb.append(observedValue);
  }
  assertEquals("Saw results: " + sb.toString(), 22, results.size());
}
 
Example 29
Source Project: hbase   Source File: MasterCoprocessorHost.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Invoked just before a split
 * @param tableName the table where the region belongs to
 * @param splitRow the split point
 * @param user the user
 * @throws IOException
 */
public void preSplitRegionAction(
    final TableName tableName,
    final byte[] splitRow,
    final User user) throws IOException {
  execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) {
    @Override
    public void call(MasterObserver observer) throws IOException {
      observer.preSplitRegionAction(this, tableName, splitRow);
    }
  });
}
 
Example 30
Source Project: phoenix-tephra   Source File: InvalidListPruneTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void startMiniCluster() throws Exception {
  // Setup the configuration to start HBase cluster with the invalid list pruning enabled
  conf = HBaseConfiguration.create();
  conf.setBoolean(TxConstants.TransactionPruning.PRUNE_ENABLE, true);
  // Flush prune data to table quickly, so that tests don't need have to wait long to see updates
  conf.setLong(TxConstants.TransactionPruning.PRUNE_FLUSH_INTERVAL, 0L);
  AbstractHBaseTableTest.startMiniCluster();

  TransactionStateStorage txStateStorage = new InMemoryTransactionStateStorage();
  TransactionManager txManager = new TransactionManager(conf, txStateStorage, new TxMetricsCollector());
  txManager.startAndWait();

  // Do some transactional data operations
  txDataTable1 = TableName.valueOf("invalidListPruneTestTable1");
  HTable hTable = createTable(txDataTable1.getName(), new byte[][]{family}, false,
                              Collections.singletonList(TestTransactionProcessor.class.getName()));
  try (TransactionAwareHTable txTable = new TransactionAwareHTable(hTable, TxConstants.ConflictDetection.ROW)) {
    TransactionContext txContext = new TransactionContext(new InMemoryTxSystemClient(txManager), txTable);
    txContext.start();
    for (int i = 0; i < MAX_ROWS; ++i) {
      txTable.put(new Put(Bytes.toBytes(i)).add(family, qualifier, Bytes.toBytes(i)));
    }
    txContext.finish();
  }

  testUtil.flush(txDataTable1);
  txManager.stopAndWait();

  pruneStateTable = TableName.valueOf(conf.get(TxConstants.TransactionPruning.PRUNE_STATE_TABLE,
                                               TxConstants.TransactionPruning.DEFAULT_PRUNE_STATE_TABLE));
  connection = HConnectionManager.createConnection(conf);
  dataJanitorState =
    new DataJanitorState(new DataJanitorState.TableSupplier() {
      @Override
      public HTableInterface get() throws IOException {
        return connection.getTable(pruneStateTable);
      }
    });
}