org.apache.hadoop.hbase.client.ColumnFamilyDescriptor Java Examples

The following examples show how to use org.apache.hadoop.hbase.client.ColumnFamilyDescriptor. 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: BackupSystemTable.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Get backup system table descriptor
 * @return table's descriptor
 */
public static TableDescriptor getSystemTableDescriptor(Configuration conf) {
  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(getTableName(conf));

  ColumnFamilyDescriptorBuilder colBuilder =
      ColumnFamilyDescriptorBuilder.newBuilder(SESSIONS_FAMILY);

  colBuilder.setMaxVersions(1);
  Configuration config = HBaseConfiguration.create();
  int ttl = config.getInt(BackupRestoreConstants.BACKUP_SYSTEM_TTL_KEY,
    BackupRestoreConstants.BACKUP_SYSTEM_TTL_DEFAULT);
  colBuilder.setTimeToLive(ttl);

  ColumnFamilyDescriptor colSessionsDesc = colBuilder.build();
  builder.setColumnFamily(colSessionsDesc);

  colBuilder = ColumnFamilyDescriptorBuilder.newBuilder(META_FAMILY);
  colBuilder.setTimeToLive(ttl);
  builder.setColumnFamily(colBuilder.build());
  return builder.build();
}
 
Example #2
Source File: HBaseOperationContext.java    From atlas with Apache License 2.0 6 votes vote down vote up
public HBaseOperationContext(NamespaceDescriptor namespaceDescriptor, String nameSpace, TableDescriptor tableDescriptor, TableName tableName, ColumnFamilyDescriptor[] columnFamilyDescriptors,
                             ColumnFamilyDescriptor columnFamilyDescriptor, String columnFamily, HBaseAtlasHook.OPERATION operation, UserGroupInformation ugi , String user, String owner,
                             Map<String, String> hbaseConf) {
    this.namespaceDescriptor     = namespaceDescriptor;
    this.nameSpace               = nameSpace;
    this.tableDescriptor         = tableDescriptor;
    this.tableName               = tableName;
    this.columnFamilyDescriptors = columnFamilyDescriptors;
    this.columnFamilyDescriptor  = columnFamilyDescriptor;
    this.columnFamily            = columnFamily;
    this.operation               = operation;
    this.ugi                     = ugi;
    this.user                    = user;
    this.owner                   = owner;
    this.hbaseConf               = hbaseConf;
}
 
Example #3
Source File: TestMinVersions.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testMinVersionsWithKeepDeletedCellsTTL() throws Exception {
  int ttl = 4;
  ColumnFamilyDescriptor cfd =
    ColumnFamilyDescriptorBuilder.newBuilder(c0)
      .setVersionsWithTimeToLive(ttl, 2).build();
  verifyVersionedCellKeyValues(ttl, cfd);

  cfd = ColumnFamilyDescriptorBuilder.newBuilder(c0)
    .setMinVersions(2)
    .setMaxVersions(Integer.MAX_VALUE)
    .setTimeToLive(ttl)
    .setKeepDeletedCells(KeepDeletedCells.TTL)
    .build();
  verifyVersionedCellKeyValues(ttl, cfd);
}
 
Example #4
Source File: TestTimestampFilterSeekHint.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Before
public void prepareRegion() throws IOException {
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder
      .newBuilder(Bytes.toBytes(FAMILY))
      .setBlocksize(1024)
      .setMaxVersions(MAX_VERSIONS)
      .build();
  region = TEST_UTIL
    .createTestRegion("TestTimestampFilterSeekHint" + regionCount++, columnFamilyDescriptor);

  for (long i = 0; i <MAX_VERSIONS - 2; i++) {
    Put p = new Put(RK_BYTES, i);
    p.addColumn(FAMILY_BYTES, QUAL_BYTES, Bytes.toBytes(RandomStringUtils.randomAlphabetic(255)));
    region.put(p);
  }
  region.flush(true);
}
 
Example #5
Source File: AddColumnAction.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void perform() throws Exception {
  TableDescriptor tableDescriptor = admin.getDescriptor(tableName);
  ColumnFamilyDescriptor columnDescriptor = null;

  while (columnDescriptor == null
      || tableDescriptor.getColumnFamily(columnDescriptor.getName()) != null) {
    columnDescriptor = ColumnFamilyDescriptorBuilder.of(RandomStringUtils.randomAlphabetic(5));
  }

  // Don't try the modify if we're stopping
  if (context.isStopping()) {
    return;
  }

  getLogger().debug("Performing action: Adding " + columnDescriptor + " to " + tableName);

  TableDescriptor modifiedTable = TableDescriptorBuilder.newBuilder(tableDescriptor)
      .setColumnFamily(columnDescriptor).build();
  admin.modifyTable(modifiedTable);
}
 
Example #6
Source File: TestCanaryTool.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasicCanaryWorks() throws Exception {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  Table table = testingUtility.createTable(tableName, new byte[][] { FAMILY });
  // insert some test rows
  for (int i=0; i<1000; i++) {
    byte[] iBytes = Bytes.toBytes(i);
    Put p = new Put(iBytes);
    p.addColumn(FAMILY, COLUMN, iBytes);
    table.put(p);
  }
  ExecutorService executor = new ScheduledThreadPoolExecutor(1);
  CanaryTool.RegionStdOutSink sink = spy(new CanaryTool.RegionStdOutSink());
  CanaryTool canary = new CanaryTool(executor, sink);
  String[] args = { "-writeSniffing", "-t", "10000", tableName.getNameAsString() };
  assertEquals(0, ToolRunner.run(testingUtility.getConfiguration(), canary, args));
  assertEquals("verify no read error count", 0, canary.getReadFailures().size());
  assertEquals("verify no write error count", 0, canary.getWriteFailures().size());
  verify(sink, atLeastOnce()).publishReadTiming(isA(ServerName.class), isA(RegionInfo.class),
    isA(ColumnFamilyDescriptor.class), anyLong());
}
 
Example #7
Source File: IntegrationTestManyRegions.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTableWithRegions() throws Exception {
  ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder
    .newBuilder(Bytes.toBytes("cf"))
    .build();
  TableDescriptor tableDescriptor =
    TableDescriptorBuilder.newBuilder(TABLE_NAME)
      .setColumnFamily(columnFamilyDescriptor)
      .build();

  SplitAlgorithm algo = new RegionSplitter.HexStringSplit();
  byte[][] splits = algo.split(REGION_COUNT);

  LOG.info(String.format("Creating table %s with %d splits.", TABLE_NAME, REGION_COUNT));
  long startTime = System.currentTimeMillis();
  try {
    admin.createTable(tableDescriptor, splits);
    LOG.info(String.format("Pre-split table created successfully in %dms.",
        (System.currentTimeMillis() - startTime)));
  } catch (IOException e) {
    LOG.error("Failed to create table", e);
  }
}
 
Example #8
Source File: UpgradeUtil.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * Synchronize column family properties using the default cf properties for a given table
 * @param tableDesc table descriptor of table to modify
 * @param defaultColFam default column family used as the baseline for property synchronization
 * @param syncedProps Map of properties to be kept in sync as read from the default column family descriptor
 * @return modified table descriptor builder
 */
private static TableDescriptorBuilder syncColFamProperties(TableDescriptor tableDesc, ColumnFamilyDescriptor defaultColFam,
        Map<String, Object> syncedProps) {
    TableDescriptorBuilder tableDescBuilder = TableDescriptorBuilder.newBuilder(tableDesc);
    // Ensure that all column families have necessary properties in sync (including local index cf if present)
    for (ColumnFamilyDescriptor currentColFam: tableDesc.getColumnFamilies()) {
        if (!currentColFam.equals(defaultColFam)) {
            ColumnFamilyDescriptorBuilder colFamDescBuilder = ColumnFamilyDescriptorBuilder.newBuilder(currentColFam);
            for (String prop: MetaDataUtil.SYNCED_DATA_TABLE_AND_INDEX_COL_FAM_PROPERTIES) {
                String existingPropVal = Bytes.toString(currentColFam.getValue(Bytes.toBytes(prop)));
                String expectedPropVal = syncedProps.get(prop).toString();
                if (existingPropVal == null || !existingPropVal.toLowerCase().equals(expectedPropVal.toLowerCase())) {
                    // Need to synchronize this property for the current column family descriptor
                    colFamDescBuilder.setValue(prop, expectedPropVal);
                }
            }
            if (!colFamDescBuilder.equals(ColumnFamilyDescriptorBuilder.newBuilder(currentColFam))) {
                tableDescBuilder.modifyColumnFamily(colFamDescBuilder.build());
            }
        }
    }
    return tableDescBuilder;
}
 
Example #9
Source File: TestCoprocessorTableEndpoint.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testDynamicCoprocessorTableEndpoint() throws Throwable {
  final TableName tableName = TableName.valueOf(name.getMethodName());

  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
  ColumnFamilyDescriptor familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(TEST_FAMILY);

  tableDescriptor.setColumnFamily(familyDescriptor);
  createTable(tableDescriptor);

  tableDescriptor.setCoprocessor(ColumnAggregationEndpoint.class.getName());
  updateTable(tableDescriptor);

  verifyTable(tableName);
}
 
Example #10
Source File: TestExpiredMobFileCleaner.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void init() throws Exception {
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(tableName);
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder
      .newBuilder(Bytes.toBytes(family))
      .setMobEnabled(true)
      .setMobThreshold(3L)
      .setMaxVersions(4)
      .build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);

  admin = TEST_UTIL.getAdmin();
  admin.createTable(tableDescriptorBuilder.build());
  table = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())
          .getBufferedMutator(tableName);
}
 
Example #11
Source File: MultiHfileOutputFormat.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * Serialize column family to compression algorithm map to configuration.
 * Invoked while configuring the MR job for incremental load.
 *
 * @param table to read the properties from
 * @param conf to persist serialized values into
 * @throws IOException
 *           on failure to read column family descriptors
 */
@edu.umd.cs.findbugs.annotations.SuppressWarnings(
    value="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
@VisibleForTesting
static String configureCompression(TableDescriptor tableDescriptor)
    throws UnsupportedEncodingException {

    StringBuilder compressionConfigValue = new StringBuilder();
    if(tableDescriptor == null){
        // could happen with mock table instance
        return compressionConfigValue.toString();
    }
    ColumnFamilyDescriptor[] families = tableDescriptor.getColumnFamilies();
    int i = 0;
    for (ColumnFamilyDescriptor familyDescriptor : families) {
        if (i++ > 0) {
            compressionConfigValue.append('&');
        }
        compressionConfigValue.append(URLEncoder.encode(
                familyDescriptor.getNameAsString(), "UTF-8"));
        compressionConfigValue.append('=');
        compressionConfigValue.append(URLEncoder.encode(
                familyDescriptor.getCompressionType().getName(), "UTF-8"));
    }
    return compressionConfigValue.toString();
}
 
Example #12
Source File: TestHRegionServerBulkLoad.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a table with given table name and specified number of column
 * families if the table does not already exist.
 */
public void setupTable(TableName table, int cfs) throws IOException {
  try {
    LOG.info("Creating table " + table);
    TableDescriptorBuilder tableDescriptorBuilder =
      TableDescriptorBuilder.newBuilder(table);

    tableDescriptorBuilder.setCoprocessor(MyObserver.class.getName());
    MyObserver.sleepDuration = this.sleepDuration;
    for (int i = 0; i < 10; i++) {
      ColumnFamilyDescriptor columnFamilyDescriptor =
        ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family(i))).build();
      tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
    }

    UTIL.getAdmin().createTable(tableDescriptorBuilder.build());
  } catch (TableExistsException tee) {
    LOG.info("Table " + table + " already exists");
  }
}
 
Example #13
Source File: TestAccessController.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testTableModify() throws Exception {
  AccessTestAction modifyTable = new AccessTestAction() {
    @Override
    public Object run() throws Exception {
      TableDescriptorBuilder tableDescriptorBuilder =
        TableDescriptorBuilder.newBuilder(TEST_TABLE);
      ColumnFamilyDescriptor columnFamilyDescriptor =
        ColumnFamilyDescriptorBuilder.newBuilder(TEST_FAMILY).build();
      tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
      columnFamilyDescriptor = ColumnFamilyDescriptorBuilder
        .newBuilder(Bytes.toBytes("fam_" + User.getCurrent().getShortName())).build();
      tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
      ACCESS_CONTROLLER.preModifyTable(ObserverContextImpl.createAndPrepare(CP_ENV),
          TEST_TABLE,
          null,  // not needed by AccessController
          tableDescriptorBuilder.build());
      return null;
    }
  };

  verifyAllowed(modifyTable, SUPERUSER, USER_ADMIN, USER_CREATE, USER_OWNER, USER_GROUP_CREATE,
    USER_GROUP_ADMIN);
  verifyDenied(modifyTable, USER_RW, USER_RO, USER_NONE, USER_GROUP_READ, USER_GROUP_WRITE);
}
 
Example #14
Source File: HMaster.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public long modifyColumn(final TableName tableName, final ColumnFamilyDescriptor descriptor,
    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(descriptor.getName())) {
        throw new InvalidFamilyOperationException("Family '" + descriptor.getNameAsString()
            + "' does not exist, so it cannot be modified");
      }

      return TableDescriptorBuilder.newBuilder(old).modifyColumnFamily(descriptor).build();
    }
  }, nonceGroup, nonce, true);
}
 
Example #15
Source File: SetPropertyIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetPropertyAndAddColumnForDefaultColumnFamily() throws Exception {
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    conn.setAutoCommit(false);
    String ddl = "CREATE TABLE " + dataTableFullName +
            "  (a_string varchar not null, col1 integer" +
            "  CONSTRAINT pk PRIMARY KEY (a_string)) " + tableDDLOptions;
    try {
        conn.createStatement().execute(ddl);
        conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " ADD col2 integer IN_MEMORY=true");
        try (Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
            ColumnFamilyDescriptor[] columnFamilies = admin.getDescriptor(TableName.valueOf(dataTableFullName))
                    .getColumnFamilies();
            assertEquals(1, columnFamilies.length);
            assertEquals("0", columnFamilies[0].getNameAsString());
            assertTrue(columnFamilies[0].isInMemory());
        }
    } finally {
        conn.close();
    }
}
 
Example #16
Source File: TestHMobStore.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void init(String methodName, Configuration conf, ColumnFamilyDescriptor cfd,
    boolean testStore) throws IOException {
  TableDescriptor td =
      TableDescriptorBuilder.newBuilder(TableName.valueOf(table)).setColumnFamily(cfd).build();

  //Setting up tje Region and Store
  Path basedir = new Path(DIR + methodName);
  Path tableDir = CommonFSUtils.getTableDir(basedir, td.getTableName());
  String logName = "logs";
  Path logdir = new Path(basedir, logName);
  FileSystem fs = FileSystem.get(conf);
  fs.delete(logdir, true);

  RegionInfo info = RegionInfoBuilder.newBuilder(td.getTableName()).build();
  ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null);
  final Configuration walConf = new Configuration(conf);
  CommonFSUtils.setRootDir(walConf, basedir);
  final WALFactory wals = new WALFactory(walConf, methodName);
  region = new HRegion(tableDir, wals.getWAL(info), fs, conf, info, td, null);
  region.setMobFileCache(new MobFileCache(conf));
  store = new HMobStore(region, cfd, conf, false);
  if (testStore) {
    init(conf, cfd);
  }
}
 
Example #17
Source File: HMobStore.java    From hbase with Apache License 2.0 6 votes vote down vote up
public HMobStore(final HRegion region, final ColumnFamilyDescriptor family,
    final Configuration confParam, boolean warmup) throws IOException {
  super(region, family, confParam, warmup);
  this.family = family;
  this.mobFileCache = region.getMobFileCache();
  this.homePath = MobUtils.getMobHome(conf);
  this.mobFamilyPath = MobUtils.getMobFamilyPath(conf, this.getTableName(),
      family.getNameAsString());
  List<Path> locations = new ArrayList<>(2);
  locations.add(mobFamilyPath);
  TableName tn = region.getTableDescriptor().getTableName();
  locations.add(HFileArchiveUtil.getStoreArchivePath(conf, tn, MobUtils.getMobRegionInfo(tn)
      .getEncodedName(), family.getNameAsString()));
  map.put(tn, locations);
  List<Tag> tags = new ArrayList<>(2);
  tags.add(MobConstants.MOB_REF_TAG);
  Tag tableNameTag = new ArrayBackedTag(TagType.MOB_TABLE_NAME_TAG_TYPE,
      getTableName().getName());
  tags.add(tableNameTag);
  this.refCellTags = TagUtil.fromList(tags);
}
 
Example #18
Source File: TestMasterQuotasObserver.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void createTable(Admin admin, TableName tn) throws Exception {
  // Create a table
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(tn);
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("F1")).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  admin.createTable(tableDescriptorBuilder.build());
}
 
Example #19
Source File: HFileOutputFormat2.java    From hbase with Apache License 2.0 5 votes vote down vote up
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value =
  "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
@VisibleForTesting
static String serializeColumnFamilyAttribute(Function<ColumnFamilyDescriptor, String> fn,
      List<TableDescriptor> allTables)
    throws UnsupportedEncodingException {
  StringBuilder attributeValue = new StringBuilder();
  int i = 0;
  for (TableDescriptor tableDescriptor : allTables) {
    if (tableDescriptor == null) {
      // could happen with mock table instance
      // CODEREVIEW: Can I set an empty string in conf if mock table instance?
      return "";
    }
    for (ColumnFamilyDescriptor familyDescriptor : tableDescriptor.getColumnFamilies()) {
      if (i++ > 0) {
        attributeValue.append('&');
      }
      attributeValue.append(URLEncoder.encode(
        Bytes.toString(combineTableNameSuffix(tableDescriptor.getTableName().getName(),
          familyDescriptor.getName())), "UTF-8"));
      attributeValue.append('=');
      attributeValue.append(URLEncoder.encode(fn.apply(familyDescriptor), "UTF-8"));
    }
  }
  // Get rid of the last ampersand
  return attributeValue.toString();
}
 
Example #20
Source File: TestHFileOutputFormat2.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void setupMockColumnFamiliesForBloomType(Table table,
    Map<String, BloomType> familyToDataBlockEncoding) throws IOException {
  TableDescriptorBuilder mockTableDescriptor =
    TableDescriptorBuilder.newBuilder(TABLE_NAMES[0]);
  for (Entry<String, BloomType> entry : familyToDataBlockEncoding.entrySet()) {
    ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder
      .newBuilder(Bytes.toBytes(entry.getKey()))
      .setMaxVersions(1)
      .setBloomFilterType(entry.getValue())
      .setBlockCacheEnabled(false)
      .setTimeToLive(0).build();
    mockTableDescriptor.setColumnFamily(columnFamilyDescriptor);
  }
  Mockito.doReturn(mockTableDescriptor).when(table).getDescriptor();
}
 
Example #21
Source File: CanaryTool.java    From hbase with Apache License 2.0 5 votes vote down vote up
public void publishReadFailure(ServerName serverName, RegionInfo region,
    ColumnFamilyDescriptor column, Exception e) {
  incReadFailureCount();
  incFailuresCountDetails(serverName, region);
  LOG.error("Read from {} on serverName={}, columnFamily={} failed",
      region.getRegionNameAsString(), serverName,
      column.getNameAsString(), e);
}
 
Example #22
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Converts an TableDescriptor to TableSchema
 * @param htd the TableDescriptor
 * @return Convert the current {@link TableDescriptor} into a pb TableSchema instance.
 */
public static TableSchema toTableSchema(TableDescriptor htd) {
  TableSchema.Builder builder = TableSchema.newBuilder();
  builder.setTableName(toProtoTableName(htd.getTableName()));
  for (Map.Entry<Bytes, Bytes> e : htd.getValues().entrySet()) {
    BytesBytesPair.Builder aBuilder = BytesBytesPair.newBuilder();
    aBuilder.setFirst(UnsafeByteOperations.unsafeWrap(e.getKey().get()));
    aBuilder.setSecond(UnsafeByteOperations.unsafeWrap(e.getValue().get()));
    builder.addAttributes(aBuilder.build());
  }
  for (ColumnFamilyDescriptor hcd : htd.getColumnFamilies()) {
    builder.addColumnFamilies(toColumnFamilySchema(hcd));
  }
  return builder.build();
}
 
Example #23
Source File: MetaDataUtil.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public static Map<String, Object> getSyncedProps(ColumnFamilyDescriptor defaultCFDesc) {
    Map<String, Object> syncedProps = new HashMap<>();
    if (defaultCFDesc != null) {
        for (String propToKeepInSync: SYNCED_DATA_TABLE_AND_INDEX_COL_FAM_PROPERTIES) {
            syncedProps.put(propToKeepInSync, Bytes.toString(
                    defaultCFDesc.getValue(Bytes.toBytes(propToKeepInSync))));
        }
    }
    return syncedProps;
}
 
Example #24
Source File: SetPropertyIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetHColumnPropertyForTableWithOnlyPKCols1() throws Exception {
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    conn.setAutoCommit(false);
    try {
        String ddl = "create table " + dataTableFullName + " ("
                + " id char(1) NOT NULL,"
                + " col1 integer NOT NULL,"
                + " col2 bigint NOT NULL,"
                + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)"
                + " ) " + generateDDLOptions("TTL=86400, SALT_BUCKETS = 4, DEFAULT_COLUMN_FAMILY='XYZ'");
        conn.createStatement().execute(ddl);
        ddl = "ALTER TABLE " + dataTableFullName + " SET IN_MEMORY=true";
        conn.createStatement().execute(ddl);
        conn.commit();
        try (Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
            TableDescriptor tableDesc = admin.getDescriptor(TableName.valueOf(dataTableFullName));
            ColumnFamilyDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
            assertEquals(1, columnFamilies.length);
            assertEquals(true, columnFamilies[0].isInMemory());
            assertEquals("XYZ", columnFamilies[0].getNameAsString());
        }
    } finally {
        conn.close();
    }
}
 
Example #25
Source File: ExpiredMobFileCleaner.java    From hbase with Apache License 2.0 5 votes vote down vote up
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="REC_CATCH_EXCEPTION",
    justification="Intentional")
@Override
public int run(String[] args) throws Exception {
  if (args.length != 2) {
    printUsage();
    return 1;
  }
  String tableName = args[0];
  String familyName = args[1];
  TableName tn = TableName.valueOf(tableName);
  Connection connection = ConnectionFactory.createConnection(getConf());
  Admin admin = connection.getAdmin();
  try {
    TableDescriptor htd = admin.getDescriptor(tn);
    ColumnFamilyDescriptor family = htd.getColumnFamily(Bytes.toBytes(familyName));
    if (family == null || !family.isMobEnabled()) {
      throw new IOException("Column family " + familyName + " is not a MOB column family");
    }
    if (family.getMinVersions() > 0) {
      throw new IOException(
          "The minVersions of the column family is not 0, could not be handled by this cleaner");
    }
    cleanExpiredMobFiles(tableName, family);
    return 0;
  } finally {
    admin.close();
    try {
      connection.close();
    } catch (IOException e) {
      LOG.error("Failed to close the connection.", e);
    }
  }
}
 
Example #26
Source File: TestNamespaceAuditor.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testStatePreserve() throws Exception {
  final String nsp1 = prefix + "_testStatePreserve";
  NamespaceDescriptor nspDesc = NamespaceDescriptor.create(nsp1)
      .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "20")
      .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "10").build();
  ADMIN.createNamespace(nspDesc);
  TableName tableOne = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table1");
  TableName tableTwo = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table2");
  TableName tableThree = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table3");
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("fam1")).build();
  TableDescriptorBuilder tableDescOne = TableDescriptorBuilder
    .newBuilder(tableOne);
  tableDescOne.setColumnFamily(columnFamilyDescriptor);
  TableDescriptorBuilder tableDescTwo = TableDescriptorBuilder
    .newBuilder(tableTwo);
  tableDescTwo.setColumnFamily(columnFamilyDescriptor);
  TableDescriptorBuilder tableDescThree = TableDescriptorBuilder
    .newBuilder(tableThree);
  tableDescThree.setColumnFamily(columnFamilyDescriptor);

  ADMIN.createTable(tableDescOne.build(), Bytes.toBytes("1"), Bytes.toBytes("1000"), 3);
  ADMIN.createTable(tableDescTwo.build(), Bytes.toBytes("1"), Bytes.toBytes("1000"), 3);
  ADMIN.createTable(tableDescThree.build(), Bytes.toBytes("1"), Bytes.toBytes("1000"), 4);
  ADMIN.disableTable(tableThree);
  deleteTable(tableThree);
  // wait for chore to complete
  UTIL.waitFor(1000, new Waiter.Predicate<Exception>() {
    @Override
    public boolean evaluate() throws Exception {
      return (getNamespaceState(nsp1).getTables().size() == 2);
    }
  });
  NamespaceTableAndRegionInfo before = getNamespaceState(nsp1);
  killActiveMaster();
  NamespaceTableAndRegionInfo after = getNamespaceState(nsp1);
  assertEquals("Expected: " + before.getTables() + " Found: " + after.getTables(), before
      .getTables().size(), after.getTables().size());
}
 
Example #27
Source File: MobUtils.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Get list of Mob column families (if any exists)
 * @param htd table descriptor
 * @return list of Mob column families
 */
public static List<ColumnFamilyDescriptor> getMobColumnFamilies(TableDescriptor htd) {

  List<ColumnFamilyDescriptor> fams = new ArrayList<ColumnFamilyDescriptor>();
  ColumnFamilyDescriptor[] hcds = htd.getColumnFamilies();
  for (ColumnFamilyDescriptor hcd : hcds) {
    if (hcd.isMobEnabled()) {
      fams.add(hcd);
    }
  }
  return fams;
}
 
Example #28
Source File: MobUtils.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether this table has mob-enabled columns.
 * @param htd The current table descriptor.
 * @return Whether this table has mob-enabled columns.
 */
public static boolean hasMobColumns(TableDescriptor htd) {
  ColumnFamilyDescriptor[] hcds = htd.getColumnFamilies();
  for (ColumnFamilyDescriptor hcd : hcds) {
    if (hcd.isMobEnabled()) {
      return true;
    }
  }
  return false;
}
 
Example #29
Source File: TableDescriptorChecker.java    From hbase with Apache License 2.0 5 votes vote down vote up
private static void checkReplicationScope(final ColumnFamilyDescriptor cfd) throws IOException {
  // check replication scope
  WALProtos.ScopeType scop = WALProtos.ScopeType.valueOf(cfd.getScope());
  if (scop == null) {
    String message =
        "Replication scope for column family " + cfd.getNameAsString() + " is " + cfd.getScope() +
            " which is invalid.";

    LOG.error(message);
    throw new DoNotRetryIOException(message);
  }
}
 
Example #30
Source File: AcidGuaranteesTestTool.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void createTableIfMissing(Admin admin, boolean useMob) throws IOException {
  if (!admin.tableExists(TABLE_NAME)) {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TABLE_NAME);
    Stream.of(FAMILIES).map(ColumnFamilyDescriptorBuilder::of)
        .forEachOrdered(builder::setColumnFamily);
    admin.createTable(builder.build());
  }
  ColumnFamilyDescriptor cfd = admin.getDescriptor(TABLE_NAME).getColumnFamilies()[0];
  if (cfd.isMobEnabled() != useMob) {
    admin.modifyColumnFamily(TABLE_NAME, ColumnFamilyDescriptorBuilder.newBuilder(cfd)
        .setMobEnabled(useMob).setMobThreshold(4).build());
  }
}