Java Code Examples for org.apache.hadoop.hbase.client.ColumnFamilyDescriptor#getNameAsString()

The following examples show how to use org.apache.hadoop.hbase.client.ColumnFamilyDescriptor#getNameAsString() . 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: MergeTableRegionsProcedure.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Create reference file(s) to parent region hfiles in the <code>mergeDir</code>
 * @param regionFs merge parent region file system
 * @param mergeDir the temp directory in which we are accumulating references.
 */
private void mergeStoreFiles(final MasterProcedureEnv env, final HRegionFileSystem regionFs,
    final Path mergeDir) throws IOException {
  final TableDescriptor htd = env.getMasterServices().getTableDescriptors().get(getTableName());
  for (ColumnFamilyDescriptor hcd : htd.getColumnFamilies()) {
    String family = hcd.getNameAsString();
    final Collection<StoreFileInfo> storeFiles = regionFs.getStoreFiles(family);
    if (storeFiles != null && storeFiles.size() > 0) {
      for (StoreFileInfo storeFileInfo : storeFiles) {
        // Create reference file(s) to parent region file here in mergedDir.
        // As this procedure is running on master, use CacheConfig.DISABLED means
        // don't cache any block.
        regionFs.mergeStoreFile(mergedRegion, family, new HStoreFile(
            storeFileInfo, hcd.getBloomFilterType(), CacheConfig.DISABLED), mergeDir);
      }
    }
  }
}
 
Example 2
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 3
Source File: EncryptionUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Helper to create an encyption context.
 *
 * @param conf The current configuration.
 * @param family The current column descriptor.
 * @return The created encryption context.
 * @throws IOException if an encryption key for the column cannot be unwrapped
 */
public static Encryption.Context createEncryptionContext(Configuration conf,
  ColumnFamilyDescriptor family) throws IOException {
  Encryption.Context cryptoContext = Encryption.Context.NONE;
  String cipherName = family.getEncryptionType();
  if (cipherName != null) {
    Cipher cipher;
    Key key;
    byte[] keyBytes = family.getEncryptionKey();
    if (keyBytes != null) {
      // Family provides specific key material
      key = unwrapKey(conf, keyBytes);
      // Use the algorithm the key wants
      cipher = Encryption.getCipher(conf, key.getAlgorithm());
      if (cipher == null) {
        throw new RuntimeException("Cipher '" + key.getAlgorithm() + "' is not available");
      }
      // Fail if misconfigured
      // We use the encryption type specified in the column schema as a sanity check on
      // what the wrapped key is telling us
      if (!cipher.getName().equalsIgnoreCase(cipherName)) {
        throw new RuntimeException("Encryption for family '" + family.getNameAsString()
          + "' configured with type '" + cipherName + "' but key specifies algorithm '"
          + cipher.getName() + "'");
      }
    } else {
      // Family does not provide key material, create a random key
      cipher = Encryption.getCipher(conf, cipherName);
      if (cipher == null) {
        throw new RuntimeException("Cipher '" + cipherName + "' is not available");
      }
      key = cipher.getRandomKey();
    }
    cryptoContext = Encryption.newContext(conf);
    cryptoContext.setCipher(cipher);
    cryptoContext.setKey(key);
  }
  return cryptoContext;
}
 
Example 4
Source File: HBaseAtlasHook.java    From atlas with Apache License 2.0 4 votes vote down vote up
private AtlasEntity buildColumnFamily(HBaseOperationContext hbaseOperationContext, ColumnFamilyDescriptor columnFamilyDescriptor, AtlasEntity nameSpace, AtlasEntity table) {
    AtlasEntity columnFamily      = new AtlasEntity(HBaseDataTypes.HBASE_COLUMN_FAMILY.getName());
    String      columnFamilyName  = columnFamilyDescriptor.getNameAsString();
    String      tableName         = (String) table.getAttribute(ATTR_NAME);
    String      nameSpaceName     = (String) nameSpace.getAttribute(ATTR_NAME);
    String      columnFamilyQName = getColumnFamilyQualifiedName(getMetadataNamespace(), nameSpaceName, tableName, columnFamilyName);
    Date        now               = new Date(System.currentTimeMillis());

    columnFamily.setAttribute(ATTR_NAME, columnFamilyName);
    columnFamily.setAttribute(ATTR_DESCRIPTION, columnFamilyName);
    columnFamily.setAttribute(REFERENCEABLE_ATTRIBUTE_NAME, columnFamilyQName);
    columnFamily.setAttribute(ATTR_OWNER, hbaseOperationContext.getOwner());
    columnFamily.setRelationshipAttribute(ATTR_TABLE, AtlasTypeUtil.getAtlasRelatedObjectId(table, RELATIONSHIP_HBASE_TABLE_COLUMN_FAMILIES));

    if (columnFamilyDescriptor!= null) {
        columnFamily.setAttribute(ATTR_CF_BLOCK_CACHE_ENABLED, columnFamilyDescriptor.isBlockCacheEnabled());
        columnFamily.setAttribute(ATTR_CF_BLOOMFILTER_TYPE, (columnFamilyDescriptor.getBloomFilterType() != null ? columnFamilyDescriptor.getBloomFilterType().name():null));
        columnFamily.setAttribute(ATTR_CF_CACHED_BLOOM_ON_WRITE, columnFamilyDescriptor.isCacheBloomsOnWrite());
        columnFamily.setAttribute(ATTR_CF_CACHED_DATA_ON_WRITE, columnFamilyDescriptor.isCacheDataOnWrite());
        columnFamily.setAttribute(ATTR_CF_CACHED_INDEXES_ON_WRITE, columnFamilyDescriptor.isCacheIndexesOnWrite());
        columnFamily.setAttribute(ATTR_CF_COMPACTION_COMPRESSION_TYPE, (columnFamilyDescriptor.getCompactionCompressionType() != null ? columnFamilyDescriptor.getCompactionCompressionType().name():null));
        columnFamily.setAttribute(ATTR_CF_COMPRESSION_TYPE, (columnFamilyDescriptor.getCompressionType() != null ? columnFamilyDescriptor.getCompressionType().name():null));
        columnFamily.setAttribute(ATTR_CF_DATA_BLOCK_ENCODING, (columnFamilyDescriptor.getDataBlockEncoding() != null ? columnFamilyDescriptor.getDataBlockEncoding().name():null));
        columnFamily.setAttribute(ATTR_CF_ENCRYPTION_TYPE, columnFamilyDescriptor.getEncryptionType());
        columnFamily.setAttribute(ATTR_CF_EVICT_BLOCK_ONCLOSE, columnFamilyDescriptor.isEvictBlocksOnClose());
        columnFamily.setAttribute(ATTR_CF_INMEMORY_COMPACTION_POLICY, (columnFamilyDescriptor.getInMemoryCompaction() != null ? columnFamilyDescriptor.getInMemoryCompaction().name():null));
        columnFamily.setAttribute(ATTR_CF_KEEP_DELETE_CELLS, ( columnFamilyDescriptor.getKeepDeletedCells() != null ? columnFamilyDescriptor.getKeepDeletedCells().name():null));
        columnFamily.setAttribute(ATTR_CF_MAX_VERSIONS, columnFamilyDescriptor.getMaxVersions());
        columnFamily.setAttribute(ATTR_CF_MIN_VERSIONS, columnFamilyDescriptor.getMinVersions());
        columnFamily.setAttribute(ATTR_CF_NEW_VERSION_BEHAVIOR, columnFamilyDescriptor.isNewVersionBehavior());
        columnFamily.setAttribute(ATTR_CF_MOB_ENABLED, columnFamilyDescriptor.isMobEnabled());
        columnFamily.setAttribute(ATTR_CF_MOB_COMPATCTPARTITION_POLICY, ( columnFamilyDescriptor.getMobCompactPartitionPolicy() != null ? columnFamilyDescriptor.getMobCompactPartitionPolicy().name():null));
        columnFamily.setAttribute(ATTR_CF_PREFETCH_BLOCK_ONOPEN, columnFamilyDescriptor.isPrefetchBlocksOnOpen());
        columnFamily.setAttribute(ATTR_CF_STORAGE_POLICY, columnFamilyDescriptor.getStoragePolicy());
        columnFamily.setAttribute(ATTR_CF_TTL, columnFamilyDescriptor.getTimeToLive());
    }

    switch (hbaseOperationContext.getOperation()) {
        case CREATE_COLUMN_FAMILY:
        case CREATE_TABLE:
            columnFamily.setAttribute(ATTR_CREATE_TIME, now);
            columnFamily.setAttribute(ATTR_MODIFIED_TIME, now);
            break;

        case ALTER_COLUMN_FAMILY:
            columnFamily.setAttribute(ATTR_MODIFIED_TIME, now);
            break;

        default:
            break;
    }

    return columnFamily;
}
 
Example 5
Source File: TableDescriptorChecker.java    From hbase with Apache License 2.0 4 votes vote down vote up
private static void checkCompactionPolicy(Configuration conf, TableDescriptor td)
    throws IOException {
  // FIFO compaction has some requirements
  // Actually FCP ignores periodic major compactions
  String className = td.getValue(DefaultStoreEngine.DEFAULT_COMPACTION_POLICY_CLASS_KEY);
  if (className == null) {
    className = conf.get(DefaultStoreEngine.DEFAULT_COMPACTION_POLICY_CLASS_KEY,
        ExploringCompactionPolicy.class.getName());
  }

  int blockingFileCount = HStore.DEFAULT_BLOCKING_STOREFILE_COUNT;
  String sv = td.getValue(HStore.BLOCKING_STOREFILES_KEY);
  if (sv != null) {
    blockingFileCount = Integer.parseInt(sv);
  } else {
    blockingFileCount = conf.getInt(HStore.BLOCKING_STOREFILES_KEY, blockingFileCount);
  }

  for (ColumnFamilyDescriptor hcd : td.getColumnFamilies()) {
    String compactionPolicy =
        hcd.getConfigurationValue(DefaultStoreEngine.DEFAULT_COMPACTION_POLICY_CLASS_KEY);
    if (compactionPolicy == null) {
      compactionPolicy = className;
    }
    if (!compactionPolicy.equals(FIFOCompactionPolicy.class.getName())) {
      continue;
    }
    // FIFOCompaction
    String message = null;

    // 1. Check TTL
    if (hcd.getTimeToLive() == ColumnFamilyDescriptorBuilder.DEFAULT_TTL) {
      message = "Default TTL is not supported for FIFO compaction";
      throw new IOException(message);
    }

    // 2. Check min versions
    if (hcd.getMinVersions() > 0) {
      message = "MIN_VERSION > 0 is not supported for FIFO compaction";
      throw new IOException(message);
    }

    // 3. blocking file count
    sv = hcd.getConfigurationValue(HStore.BLOCKING_STOREFILES_KEY);
    if (sv != null) {
      blockingFileCount = Integer.parseInt(sv);
    }
    if (blockingFileCount < 1000) {
      message =
          "Blocking file count '" + HStore.BLOCKING_STOREFILES_KEY + "' " + blockingFileCount +
              " is below recommended minimum of 1000 for column family " + hcd.getNameAsString();
      throw new IOException(message);
    }
  }
}