Java Code Examples for org.apache.hadoop.hbase.client.TableDescriptor

The following examples show how to use org.apache.hadoop.hbase.client.TableDescriptor. 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
Source Project: phoenix   Source File: FlappingAlterTableIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNewColumnFamilyInheritsTTLOfEmptyCF() throws Exception {
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
            +"ID1 VARCHAR(15) NOT NULL,\n"
            +"ID2 VARCHAR(15) NOT NULL,\n"
            +"CREATED_DATE DATE,\n"
            +"CREATION_TIME BIGINT,\n"
            +"LAST_USED DATE,\n"
            +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) TTL = 1000";
    Connection conn1 = DriverManager.getConnection(getUrl(), props);
    conn1.createStatement().execute(ddl);
    ddl = "ALTER TABLE " + dataTableFullName + " ADD CF.STRING VARCHAR";
    conn1.createStatement().execute(ddl);
    try (Admin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
        TableDescriptor tableDesc = admin.getDescriptor(TableName.valueOf(dataTableFullName));
        ColumnFamilyDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
        assertEquals(2, columnFamilies.length);
        assertEquals("0", columnFamilies[0].getNameAsString());
        assertEquals(1000, columnFamilies[0].getTimeToLive());
        assertEquals("CF", columnFamilies[1].getNameAsString());
        assertEquals(1000, columnFamilies[1].getTimeToLive());
    }
}
 
Example 2
Source Project: hbase   Source File: TestDeleteMobTable.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteMobTable() throws Exception {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  TableDescriptor tableDescriptor = createTableDescriptor(tableName, true);
  ColumnFamilyDescriptor familyDescriptor = tableDescriptor.getColumnFamily(FAMILY);

  String fileName = null;
  Table table = createTableWithOneFile(tableDescriptor);
  try {
    // the mob file exists
    Assert.assertEquals(1, countMobFiles(tableName, familyDescriptor.getNameAsString()));
    Assert.assertEquals(0, countArchiveMobFiles(tableName, familyDescriptor.getNameAsString()));
    fileName = assertHasOneMobRow(table, tableName, familyDescriptor.getNameAsString());
    Assert.assertFalse(mobArchiveExist(tableName, familyDescriptor.getNameAsString(), fileName));
    Assert.assertTrue(mobTableDirExist(tableName));
  } finally {
    table.close();
    TEST_UTIL.deleteTable(tableName);
  }

  Assert.assertFalse(TEST_UTIL.getAdmin().tableExists(tableName));
  Assert.assertEquals(0, countMobFiles(tableName, familyDescriptor.getNameAsString()));
  Assert.assertEquals(1, countArchiveMobFiles(tableName, familyDescriptor.getNameAsString()));
  Assert.assertTrue(mobArchiveExist(tableName, familyDescriptor.getNameAsString(), fileName));
  Assert.assertFalse(mobTableDirExist(tableName));
}
 
Example 3
Source Project: hbase   Source File: HMaster.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public long deleteColumn(final TableName tableName, final byte[] columnName,
    final long nonceGroup, final long nonce) throws IOException {
  checkInitialized();
  checkTableExists(tableName);

  return modifyTable(tableName, new TableDescriptorGetter() {

    @Override
    public TableDescriptor get() throws IOException {
      TableDescriptor old = getTableDescriptors().get(tableName);

      if (!old.hasColumnFamily(columnName)) {
        throw new InvalidFamilyOperationException("Family '" + Bytes.toString(columnName)
            + "' does not exist, so it cannot be deleted");
      }
      if (old.getColumnFamilyCount() == 1) {
        throw new InvalidFamilyOperationException("Family '" + Bytes.toString(columnName)
            + "' is the only column family in the table, so it cannot be deleted");
      }
      return TableDescriptorBuilder.newBuilder(old).removeColumnFamily(columnName).build();
    }
  }, nonceGroup, nonce, true);
}
 
Example 4
Source Project: hbase   Source File: TestStoreFileRefresherChore.java    License: Apache License 2.0 6 votes vote down vote up
private HRegion initHRegion(TableDescriptor htd, byte[] startKey, byte[] stopKey, int replicaId)
    throws IOException {
  Configuration conf = TEST_UTIL.getConfiguration();
  Path tableDir = CommonFSUtils.getTableDir(testDir, htd.getTableName());

  RegionInfo info = RegionInfoBuilder.newBuilder(htd.getTableName()).setStartKey(startKey)
      .setEndKey(stopKey).setRegionId(0L).setReplicaId(replicaId).build();
  HRegionFileSystem fs =
      new FailingHRegionFileSystem(conf, tableDir.getFileSystem(conf), tableDir, info);
  final Configuration walConf = new Configuration(conf);
  CommonFSUtils.setRootDir(walConf, tableDir);
  final WALFactory wals = new WALFactory(walConf, "log_" + replicaId);
  ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null);
  HRegion region =
      new HRegion(fs, wals.getWAL(info),
          conf, htd, null);

  region.initialize();

  return region;
}
 
Example 5
Source Project: hbase   Source File: SnapshotScannerHDFSAclController.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void postStartMaster(ObserverContext<MasterCoprocessorEnvironment> c) throws IOException {
  if (!initialized) {
    return;
  }
  try (Admin admin = c.getEnvironment().getConnection().getAdmin()) {
    if (admin.tableExists(PermissionStorage.ACL_TABLE_NAME)) {
      // Check if acl table has 'm' CF, if not, add 'm' CF
      TableDescriptor tableDescriptor = admin.getDescriptor(PermissionStorage.ACL_TABLE_NAME);
      boolean containHdfsAclFamily = Arrays.stream(tableDescriptor.getColumnFamilies()).anyMatch(
        family -> Bytes.equals(family.getName(), SnapshotScannerHDFSAclStorage.HDFS_ACL_FAMILY));
      if (!containHdfsAclFamily) {
        TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor)
            .setColumnFamily(ColumnFamilyDescriptorBuilder
                .newBuilder(SnapshotScannerHDFSAclStorage.HDFS_ACL_FAMILY).build());
        admin.modifyTable(builder.build());
      }
      aclTableInitialized = true;
    } else {
      throw new TableNotFoundException("Table " + PermissionStorage.ACL_TABLE_NAME
          + " is not created yet. Please check if " + getClass().getName()
          + " is configured after " + AccessController.class.getName());
    }
  }
}
 
Example 6
Source Project: hbase   Source File: FSTableDescriptors.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Update table descriptor on the file system
 * @throws IOException Thrown if failed update.
 * @throws NotImplementedException if in read only mode
 */
@VisibleForTesting
Path updateTableDescriptor(TableDescriptor td) throws IOException {
  if (fsreadonly) {
    throw new NotImplementedException("Cannot update a table descriptor - in read only mode");
  }
  TableName tableName = td.getTableName();
  Path tableDir = getTableDir(tableName);
  Path p = writeTableDescriptor(fs, td, tableDir, getTableInfoPath(tableDir));
  if (p == null) {
    throw new IOException("Failed update");
  }
  LOG.info("Updated tableinfo=" + p);
  if (usecache) {
    this.cache.put(td.getTableName(), td);
  }
  return p;
}
 
Example 7
Source Project: hbase   Source File: TestRSGroupsBasics.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNamespaceCreateAndAssign() throws Exception {
  LOG.info("testNamespaceCreateAndAssign");
  String nsName = TABLE_PREFIX + "_foo";
  final TableName tableName = TableName.valueOf(nsName, TABLE_PREFIX + "_testCreateAndAssign");
  RSGroupInfo appInfo = addGroup("appInfo", 1);
  ADMIN.createNamespace(NamespaceDescriptor.create(nsName)
    .addConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP, "appInfo").build());
  final TableDescriptor desc = TableDescriptorBuilder.newBuilder(tableName)
    .setColumnFamily(ColumnFamilyDescriptorBuilder.of("f")).build();
  ADMIN.createTable(desc);
  // wait for created table to be assigned
  TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
    @Override
    public boolean evaluate() throws Exception {
      return getTableRegionMap().get(desc.getTableName()) != null;
    }
  });
  ServerName targetServer = getServerName(appInfo.getServers().iterator().next());
  // verify it was assigned to the right group
  Assert.assertEquals(1, ADMIN.getRegions(targetServer).size());
}
 
Example 8
Source Project: hbase   Source File: TestDeleteMobTable.java    License: Apache License 2.0 6 votes vote down vote up
private Table createTableWithOneFile(TableDescriptor tableDescriptor) throws IOException {
  Table table = TEST_UTIL.createTable(tableDescriptor, null);
  try {
    // insert data
    byte[] value = generateMobValue(10);
    byte[] row = Bytes.toBytes("row");
    Put put = new Put(row);
    put.addColumn(FAMILY, QF, EnvironmentEdgeManager.currentTime(), value);
    table.put(put);

    // create an hfile
    TEST_UTIL.getAdmin().flush(tableDescriptor.getTableName());
  } catch (IOException e) {
    table.close();
    throw e;
  }
  return table;
}
 
Example 9
Source Project: atlas   Source File: HBaseAtlasCoprocessor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void postCloneSnapshot(ObserverContext<MasterCoprocessorEnvironment> observerContext, SnapshotDescription snapshot, TableDescriptor tableDescriptor) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> HBaseAtlasCoprocessor.postCloneSnapshot()");
    }

    try {
        activatePluginClassLoader();
        implMasterObserver.postCloneSnapshot(observerContext,snapshot,tableDescriptor);
    } finally {
        deactivatePluginClassLoader();
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== HBaseAtlasCoprocessor.postCloneSnapshot()");
    }
}
 
Example 10
Source Project: hbase   Source File: TestRegionSplitPolicy.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateDefault() throws IOException {
  conf.setLong(HConstants.HREGION_MAX_FILESIZE, 1234L);
  TableDescriptor td = TableDescriptorBuilder.newBuilder(TABLENAME).build();
  doReturn(td).when(mockRegion).getTableDescriptor();
  // Using a default HTD, should pick up the file size from
  // configuration.
  ConstantSizeRegionSplitPolicy policy =
    (ConstantSizeRegionSplitPolicy) RegionSplitPolicy.create(mockRegion, conf);
  assertWithinJitter(1234L, policy.getDesiredMaxFileSize());

  // If specified in HTD, should use that
  td = TableDescriptorBuilder.newBuilder(TABLENAME).setMaxFileSize(9999L).build();
  doReturn(td).when(mockRegion).getTableDescriptor();
  policy = (ConstantSizeRegionSplitPolicy) RegionSplitPolicy.create(mockRegion, conf);
  assertWithinJitter(9999L, policy.getDesiredMaxFileSize());
}
 
Example 11
Source Project: hbase   Source File: RestoreTool.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get table descriptor
 * @param tableName is the table backed up
 * @return {@link TableDescriptor} saved in backup image of the table
 */
TableDescriptor getTableDesc(TableName tableName) throws IOException {
  Path tableInfoPath = this.getTableInfoPath(tableName);
  SnapshotDescription desc = SnapshotDescriptionUtils.readSnapshotInfo(fs, tableInfoPath);
  SnapshotManifest manifest = SnapshotManifest.open(conf, fs, tableInfoPath, desc);
  TableDescriptor tableDescriptor = manifest.getTableDescriptor();
  if (!tableDescriptor.getTableName().equals(tableName)) {
    LOG.error("couldn't find Table Desc for table: " + tableName + " under tableInfoPath: "
            + tableInfoPath.toString());
    LOG.error("tableDescriptor.getNameAsString() = "
            + tableDescriptor.getTableName().getNameAsString());
    throw new FileNotFoundException("couldn't find Table Desc for table: " + tableName
        + " under tableInfoPath: " + tableInfoPath.toString());
  }
  return tableDescriptor;
}
 
Example 12
Source Project: hbase   Source File: IntegrationTestBackupRestore.java    License: Apache License 2.0 6 votes vote down vote up
private void createTable(TableName tableName) throws Exception {
  long startTime, endTime;

  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);

  TableDescriptor desc = builder.build();
  ColumnFamilyDescriptorBuilder cbuilder =
      ColumnFamilyDescriptorBuilder.newBuilder(COLUMN_NAME.getBytes(Charset.defaultCharset()));
  ColumnFamilyDescriptor[] columns = new ColumnFamilyDescriptor[] { cbuilder.build() };
  LOG.info("Creating table {} with {} splits.", tableName,
    regionsCountPerServer * regionServerCount);
  startTime = System.currentTimeMillis();
  HBaseTestingUtility.createPreSplitLoadTestTable(util.getConfiguration(), desc, columns,
    regionsCountPerServer);
  util.waitTableAvailable(tableName);
  endTime = System.currentTimeMillis();
  LOG.info("Pre-split table created successfully in {}ms.", (endTime - startTime));
}
 
Example 13
Source Project: phoenix   Source File: SetPropertyIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSetHTableAndHColumnProperties() throws Exception {
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
            +"ID1 VARCHAR(15) NOT NULL,\n"
            +"ID2 VARCHAR(15) NOT NULL,\n"
            +"CREATED_DATE DATE,\n"
            +"CREATION_TIME BIGINT,\n"
            +"LAST_USED DATE,\n"
            +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + generateDDLOptions("SALT_BUCKETS = 8");
    Connection conn1 = DriverManager.getConnection(getUrl(), props);
    conn1.createStatement().execute(ddl);
    ddl = "ALTER TABLE " + dataTableFullName + " SET COMPACTION_ENABLED = FALSE, REPLICATION_SCOPE = 1";
    conn1.createStatement().execute(ddl);
    try (Admin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
        TableDescriptor tableDesc = admin.getDescriptor(TableName.valueOf(dataTableFullName));
        ColumnFamilyDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
        assertEquals(1, columnFamilies.length);
        assertEquals("0", columnFamilies[0].getNameAsString());
        assertEquals(1, columnFamilies[0].getScope());
        assertEquals(false, tableDesc.isCompactionEnabled());
    }
}
 
Example 14
Source Project: hbase   Source File: MasterProcedureTestingUtility.java    License: Apache License 2.0 6 votes vote down vote up
public static void validateColumnFamilyDeletion(final HMaster master, final TableName tableName,
    final String family) throws IOException {
  // verify htd
  TableDescriptor htd = master.getTableDescriptors().get(tableName);
  assertTrue(htd != null);
  assertFalse(htd.hasColumnFamily(Bytes.toBytes(family)));

  // verify fs
  final FileSystem fs = master.getMasterFileSystem().getFileSystem();
  final Path tableDir =
    CommonFSUtils.getTableDir(master.getMasterFileSystem().getRootDir(), tableName);
  for (Path regionDir : FSUtils.getRegionDirs(fs, tableDir)) {
    final Path familyDir = new Path(regionDir, family);
    assertFalse(family + " family dir should not exist", fs.exists(familyDir));
  }
}
 
Example 15
Source Project: hbase   Source File: SnapshotTestingUtils.java    License: Apache License 2.0 6 votes vote down vote up
private SnapshotBuilder createSnapshot(final String snapshotName, final String tableName,
    final int numRegions, final int version) throws IOException {
  TableDescriptor htd = createHtd(tableName);
  RegionData[] regions = createTable(htd, numRegions);

  SnapshotProtos.SnapshotDescription desc = SnapshotProtos.SnapshotDescription.newBuilder()
    .setTable(htd.getTableName().getNameAsString())
    .setName(snapshotName)
    .setVersion(version)
    .build();

  Path workingDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(desc, rootDir, conf);
  FileSystem workingFs = workingDir.getFileSystem(conf);
  SnapshotDescriptionUtils.writeSnapshotInfo(desc, workingDir, workingFs);
  return new SnapshotBuilder(conf, fs, rootDir, htd, desc, regions);
}
 
Example 16
@Override
public TableDescriptor preCreateTableRegionsInfos(
    ObserverContext<MasterCoprocessorEnvironment> ctx, TableDescriptor desc)
    throws IOException {
  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(desc);
  for (ColumnFamilyDescriptor cfd : desc.getColumnFamilies()) {
    builder.modifyColumnFamily(
        ColumnFamilyDescriptorBuilder.newBuilder(cfd).setMaxVersions(1).build());
  }
  return builder.build();
}
 
Example 17
Source Project: hbase   Source File: MasterCoprocessorHost.java    License: Apache License 2.0 5 votes vote down vote up
public void preCloneSnapshot(final SnapshotDescription snapshot,
    final TableDescriptor hTableDescriptor) throws IOException {
  execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
    @Override
    public void call(MasterObserver observer) throws IOException {
      observer.preCloneSnapshot(this, snapshot, hTableDescriptor);
    }
  });
}
 
Example 18
Source Project: hbase   Source File: TestNamespaceReplication.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  TestReplicationBase.setUpBeforeClass();

  connection1 = ConnectionFactory.createConnection(CONF1);
  connection2 = ConnectionFactory.createConnection(CONF2);
  admin1 = connection1.getAdmin();
  admin2 = connection2.getAdmin();

  admin1.createNamespace(NamespaceDescriptor.create(ns1).build());
  admin1.createNamespace(NamespaceDescriptor.create(ns2).build());
  admin2.createNamespace(NamespaceDescriptor.create(ns1).build());
  admin2.createNamespace(NamespaceDescriptor.create(ns2).build());

  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tabAName);
  builder.setColumnFamily(ColumnFamilyDescriptorBuilder
    .newBuilder(f1Name).setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build());
  builder.setColumnFamily(ColumnFamilyDescriptorBuilder
    .newBuilder(f2Name).setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build());
  TableDescriptor tabA = builder.build();
  admin1.createTable(tabA);
  admin2.createTable(tabA);

  builder = TableDescriptorBuilder.newBuilder(tabBName);
  builder.setColumnFamily(ColumnFamilyDescriptorBuilder
    .newBuilder(f1Name).setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build());
  builder.setColumnFamily(ColumnFamilyDescriptorBuilder
    .newBuilder(f2Name).setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build());
  TableDescriptor tabB = builder.build();
  admin1.createTable(tabB);
  admin2.createTable(tabB);
}
 
Example 19
Source Project: hbase   Source File: SecureTestUtil.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void postCompletedCreateTableAction(
    final ObserverContext<MasterCoprocessorEnvironment> ctx,
    TableDescriptor desc, RegionInfo[] regions) throws IOException {
  // the AccessController test, some times calls only and directly the
  // postCompletedCreateTableAction()
  if (tableCreationLatch != null) {
    tableCreationLatch.countDown();
  }
}
 
Example 20
Source Project: hbase   Source File: TestMergeTableRegionsProcedure.java    License: Apache License 2.0 5 votes vote down vote up
private List<RegionInfo> createTable(final TableName tableName) throws Exception {
  TableDescriptor desc = TableDescriptorBuilder.newBuilder(tableName)
    .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).build();
  byte[][] splitRows = new byte[initialRegionCount - 1][];
  for (int i = 0; i < splitRows.length; ++i) {
    splitRows[i] = Bytes.toBytes(String.format("%d", i));
  }
  admin.createTable(desc, splitRows);
  return assertRegionCount(tableName, initialRegionCount);
}
 
Example 21
public SpliceHRegion(final Path tableDir, final WAL wal, final FileSystem fs,
                     final Configuration confParam, final RegionInfo regionInfo,
                     final TableDescriptor htd, final RegionServerServices rsServices,
                     Set<String> compactedFilesPaths) throws IOException{

    super(tableDir, wal, fs, confParam, regionInfo, htd, rsServices);
    openHRegion(null);
    setCompactedFiles(compactedFilesPaths);
}
 
Example 22
Source Project: hbase   Source File: MasterCoprocessorHost.java    License: Apache License 2.0 5 votes vote down vote up
public void postCloneSnapshot(final SnapshotDescription snapshot,
    final TableDescriptor hTableDescriptor) throws IOException {
  execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
    @Override
    public void call(MasterObserver observer) throws IOException {
      observer.postCloneSnapshot(this, snapshot, hTableDescriptor);
    }
  });
}
 
Example 23
Source Project: hbase   Source File: RegionReplicaReplicationEndpoint.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * returns true if the specified entry must be replicated. We should always replicate meta
 * operations (e.g. flush) and use the user HTD flag to decide whether or not replicate the
 * memstore.
 */
private boolean requiresReplication(Optional<TableDescriptor> tableDesc,
    Entry entry) {
  // empty edit does not need to be replicated
  if (entry.getEdit().isEmpty() || !tableDesc.isPresent()) {
    return false;
  }
  // meta edits (e.g. flush) must be always replicated
  return entry.getEdit().isMetaEdit() || tableDesc.get().hasRegionMemStoreReplication();
}
 
Example 24
Source Project: hbase   Source File: TestFileArchiverNotifierImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSnapshotSizePersistence() throws IOException {
  final Admin admin = TEST_UTIL.getAdmin();
  final TableName tn = TableName.valueOf(testName.getMethodName());
  if (admin.tableExists(tn)) {
    admin.disableTable(tn);
    admin.deleteTable(tn);
  }
  TableDescriptor desc = TableDescriptorBuilder.newBuilder(tn).setColumnFamily(
      ColumnFamilyDescriptorBuilder.of(QuotaTableUtil.QUOTA_FAMILY_USAGE)).build();
  admin.createTable(desc);

  FileArchiverNotifierImpl notifier = new FileArchiverNotifierImpl(conn, conf, fs, tn);
  List<SnapshotWithSize> snapshotsWithSizes = new ArrayList<>();
  try (Table table = conn.getTable(tn)) {
    // Writing no values will result in no records written.
    verify(table, () -> {
      notifier.persistSnapshotSizes(table, snapshotsWithSizes);
      assertEquals(0, count(table));
    });

    verify(table, () -> {
      snapshotsWithSizes.add(new SnapshotWithSize("ss1", 1024L));
      snapshotsWithSizes.add(new SnapshotWithSize("ss2", 4096L));
      notifier.persistSnapshotSizes(table, snapshotsWithSizes);
      assertEquals(2, count(table));
      assertEquals(1024L, extractSnapshotSize(table, tn, "ss1"));
      assertEquals(4096L, extractSnapshotSize(table, tn, "ss2"));
    });
  }
}
 
Example 25
Source Project: hbase   Source File: RemoveColumnAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void perform() throws Exception {
  TableDescriptor tableDescriptor = admin.getDescriptor(tableName);
  ColumnFamilyDescriptor[] columnDescriptors = tableDescriptor.getColumnFamilies();

  if (columnDescriptors.length <= (protectedColumns == null ? 1 : protectedColumns.size())) {
    return;
  }

  int index = random.nextInt(columnDescriptors.length);
  while(protectedColumns != null &&
        protectedColumns.contains(columnDescriptors[index].getNameAsString())) {
    index = random.nextInt(columnDescriptors.length);
  }
  byte[] colDescName = columnDescriptors[index].getName();
  getLogger().debug("Performing action: Removing " + Bytes.toString(colDescName)+ " from "
      + tableName.getNameAsString());

  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor);
  builder.removeColumnFamily(colDescName);

  // Don't try the modify if we're stopping
  if (context.isStopping()) {
    return;
  }
  admin.modifyTable(builder.build());
}
 
Example 26
Source Project: hbase   Source File: HBaseTestingUtility.java    License: 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, boolean initialize)
    throws IOException {
  ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null);
  WAL wal = createWal(conf, rootDir, info);
  return HRegion.createHRegion(info, rootDir, conf, htd, wal, initialize);
}
 
Example 27
Source Project: hbase   Source File: IntegrationTestDDLMasterFailover.java    License: Apache License 2.0 5 votes vote down vote up
@Override
void perform() throws IOException {
  TableDescriptor selected = selectTable(disabledTables);
  ColumnFamilyDescriptor cfd = selectFamily(selected);
  if (selected == null || cfd == null) {
    return;
  }

  Admin admin = connection.getAdmin();
  try {
    if (selected.getColumnFamilyCount() < 2) {
      LOG.info("No enough column families to delete in table " + selected.getTableName());
      return;
    }
    TableName tableName = selected.getTableName();
    LOG.info("Deleting column family: " + cfd + " from table: " + tableName);
    admin.deleteColumnFamily(tableName, cfd.getName());
    // assertion
    TableDescriptor freshTableDesc = admin.getDescriptor(tableName);
    Assert.assertFalse("Column family: " + cfd + " was not added",
        freshTableDesc.hasColumnFamily(cfd.getName()));
    Assert.assertTrue(
      "After delete column family, Table: " + tableName + " is not disabled",
      admin.isTableDisabled(tableName));
    disabledTables.put(tableName, freshTableDesc);
    LOG.info("Deleted column family: " + cfd + " from table: " + tableName);
  } catch (Exception e) {
    LOG.warn("Caught exception in action: " + this.getClass());
    throw e;
  } finally {
    admin.close();
  }
}
 
Example 28
Source Project: hbase   Source File: TestWALSplitToHFile.java    License: Apache License 2.0 5 votes vote down vote up
private Pair<TableDescriptor, RegionInfo> setupTableAndRegion() throws IOException {
  final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
  final TableDescriptor td = createBasic3FamilyTD(tableName);
  final RegionInfo ri = RegionInfoBuilder.newBuilder(tableName).build();
  final Path tableDir = CommonFSUtils.getTableDir(this.rootDir, tableName);
  deleteDir(tableDir);
  FSTableDescriptors.createTableDescriptorForTableDirectory(fs, tableDir, td, false);
  HRegion region = HBaseTestingUtility.createRegionAndWAL(ri, rootDir, this.conf, td);
  HBaseTestingUtility.closeRegionAndWAL(region);
  return new Pair<>(td, ri);
}
 
Example 29
Source Project: hbase   Source File: TestMobStoreCompaction.java    License: Apache License 2.0 5 votes vote down vote up
private static HRegion setMobThreshold(HRegion region, byte[] cfName, long modThreshold) {
  ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder
          .newBuilder(region.getTableDescriptor().getColumnFamily(cfName))
          .setMobThreshold(modThreshold)
          .build();
  TableDescriptor td = TableDescriptorBuilder
          .newBuilder(region.getTableDescriptor())
          .removeColumnFamily(cfName)
          .setColumnFamily(cfd)
          .build();
  region.setTableDescriptor(td);
  return region;
}
 
Example 30
Source Project: hbase   Source File: RSGroupInfoManagerImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void removeRSGroup(String groupName) throws IOException {
  RSGroupInfo rsGroupInfo = getRSGroupInfo(groupName);
  int serverCount = rsGroupInfo.getServers().size();
  if (serverCount > 0) {
    throw new ConstraintException("RSGroup " + groupName + " has " + serverCount +
        " servers; you must remove these servers from the RSGroup before" +
        " the RSGroup can be removed.");
  }
  for (TableDescriptor td : masterServices.getTableDescriptors().getAll().values()) {
    if (td.getRegionServerGroup().map(groupName::equals).orElse(false)) {
      throw new ConstraintException("RSGroup " + groupName + " is already referenced by " +
          td.getTableName() + "; you must remove all the tables from the rsgroup before " +
          "the rsgroup can be removed.");
    }
  }
  for (NamespaceDescriptor ns : masterServices.getClusterSchema().getNamespaces()) {
    String nsGroup = ns.getConfigurationValue(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP);
    if (nsGroup != null && nsGroup.equals(groupName)) {
      throw new ConstraintException(
          "RSGroup " + groupName + " is referenced by namespace: " + ns.getName());
    }
  }
  Map<String, RSGroupInfo> rsGroupMap = holder.groupName2Group;
  if (!rsGroupMap.containsKey(groupName) || groupName.equals(RSGroupInfo.DEFAULT_GROUP)) {
    throw new ConstraintException(
      "Group " + groupName + " does not exist or is a reserved " + "group");
  }
  Map<String, RSGroupInfo> newGroupMap = Maps.newHashMap(rsGroupMap);
  newGroupMap.remove(groupName);
  flushConfig(newGroupMap);
}