Search in sources :

Example 16 with HBaseDDLExecutor

use of io.cdap.cdap.spi.hbase.HBaseDDLExecutor in project cdap by caskdata.

the class HBaseTableFactory method createMetadataTable.

@Override
public MetadataTable createMetadataTable() throws IOException {
    TableId tableId = tableUtil.createHTableId(NamespaceId.SYSTEM, metadataTableName);
    Table table = null;
    // If the table descriptor is in the cache, we assume the table exists.
    if (!tableDescriptors.containsKey(tableId)) {
        synchronized (this) {
            if (!tableDescriptors.containsKey(tableId)) {
                try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get()) {
                    ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(Bytes.toString(COLUMN_FAMILY), hConf);
                    TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(tableId, cConf).addColumnFamily(cfdBuilder.build());
                    ddlExecutor.createTableIfNotExists(tdBuilder.build(), null);
                    table = tableUtil.createTable(hConf, tableId);
                    tableDescriptors.put(tableId, table.getTableDescriptor());
                }
            }
        }
    }
    if (table == null) {
        table = tableUtil.createTable(hConf, tableId);
    }
    return new HBaseMetadataTable(tableUtil, table, COLUMN_FAMILY, cConf.getInt(Constants.MessagingSystem.HBASE_SCAN_CACHE_ROWS), createExceptionHandler(tableId));
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) HBaseDDLExecutor(io.cdap.cdap.spi.hbase.HBaseDDLExecutor) MetadataTable(io.cdap.cdap.messaging.store.MetadataTable) MessageTable(io.cdap.cdap.messaging.store.MessageTable) PayloadTable(io.cdap.cdap.messaging.store.PayloadTable) Table(org.apache.hadoop.hbase.client.Table) ColumnFamilyDescriptorBuilder(io.cdap.cdap.data2.util.hbase.ColumnFamilyDescriptorBuilder) HTableDescriptorBuilder(io.cdap.cdap.data2.util.hbase.HTableDescriptorBuilder) TableDescriptorBuilder(io.cdap.cdap.data2.util.hbase.TableDescriptorBuilder)

Example 17 with HBaseDDLExecutor

use of io.cdap.cdap.spi.hbase.HBaseDDLExecutor in project cdap by caskdata.

the class HBaseDDLExecutorFactory method get.

@Override
public HBaseDDLExecutor get() {
    // Check if HBaseDDLExecutor extension is provided
    Map<String, HBaseDDLExecutor> extensions = hBaseDDLExecutorLoader.getAll();
    HBaseDDLExecutor executor;
    if (!extensions.isEmpty()) {
        // HBase DDL executor extension is provided.
        executor = extensions.values().iterator().next();
    } else {
        if (extensionDir != null) {
            // Extension directory is provided but the extension is not loaded
            throw new RuntimeException(String.format("HBaseDDLExecutor extension cannot be loaded from directory '%s'." + " Please make sure jar is available at that location with " + "appropriate permissions.", extensionDir));
        }
        // Return the version specific executor instance.
        executor = super.get();
    }
    executor.initialize(context);
    return executor;
}
Also used : HBaseDDLExecutor(io.cdap.cdap.spi.hbase.HBaseDDLExecutor)

Example 18 with HBaseDDLExecutor

use of io.cdap.cdap.spi.hbase.HBaseDDLExecutor in project cdap by cdapio.

the class DistributedStorageProviderNamespaceAdmin method delete.

@SuppressWarnings("ConstantConditions")
@Override
public void delete(NamespaceId namespaceId) throws IOException, ExploreException, SQLException {
    // delete namespace directory from filesystem
    super.delete(namespaceId);
    if (NamespaceId.DEFAULT.equals(namespaceId)) {
        return;
    }
    // delete HBase namespace
    NamespaceConfig namespaceConfig;
    try {
        namespaceConfig = namespaceQueryAdmin.get(namespaceId).getConfig();
    } catch (Exception ex) {
        throw new IOException("Could not fetch custom HBase mapping.", ex);
    }
    if (!Strings.isNullOrEmpty(namespaceConfig.getHbaseNamespace())) {
        // custom namespace mapping is set for HBase, hence don't do anything during delete since the lifecycle of the
        // namespace will be managed by the user
        LOG.debug("Custom HBase mapping {} was found while deleting {}. Hence skipping deletion of HBase namespace", namespaceConfig.getHbaseNamespace(), namespaceId);
        return;
    }
    // delete HBase namespace
    String namespace = tableUtil.getHBaseNamespace(namespaceId);
    try (HBaseDDLExecutor executor = hBaseDDLExecutorFactory.get()) {
        executor.deleteNamespaceIfExists(namespace);
    }
}
Also used : NamespaceConfig(io.cdap.cdap.proto.NamespaceConfig) HBaseDDLExecutor(io.cdap.cdap.spi.hbase.HBaseDDLExecutor) IOException(java.io.IOException) IOException(java.io.IOException) ExploreException(io.cdap.cdap.explore.service.ExploreException) SQLException(java.sql.SQLException)

Example 19 with HBaseDDLExecutor

use of io.cdap.cdap.spi.hbase.HBaseDDLExecutor in project cdap by cdapio.

the class HBaseTableAdmin method create.

@Override
public void create() throws IOException {
    String columnFamily = Bytes.toString(TableProperties.getColumnFamilyBytes(spec.getProperties()));
    ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(columnFamily, hConf);
    if (TableProperties.getReadlessIncrementSupport(spec.getProperties())) {
        cfdBuilder.setMaxVersions(Integer.MAX_VALUE);
    } else if (DatasetsUtil.isTransactional(spec.getProperties())) {
        // NOTE: we cannot limit number of versions as there's no hard limit on # of excluded from read txs
        cfdBuilder.setMaxVersions(Integer.MAX_VALUE);
    } else {
        cfdBuilder.setMaxVersions(1);
    }
    cfdBuilder.setBloomType(ColumnFamilyDescriptor.BloomType.ROW);
    Long ttl = TableProperties.getTTL(spec.getProperties());
    if (ttl != null) {
        // convert ttl from seconds to milli-seconds
        ttl = TimeUnit.SECONDS.toMillis(ttl);
        cfdBuilder.addProperty(TxConstants.PROPERTY_TTL, String.valueOf(ttl));
    }
    final TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(tableId, cConf);
    // if the dataset is configured for read-less increments, then set the table property to support upgrades
    boolean supportsReadlessIncrements = TableProperties.getReadlessIncrementSupport(spec.getProperties());
    if (supportsReadlessIncrements) {
        tdBuilder.addProperty(Table.PROPERTY_READLESS_INCREMENT, "true");
    }
    // if the dataset is configured to be non-transactional, then set the table property to support upgrades
    if (!DatasetsUtil.isTransactional(spec.getProperties())) {
        tdBuilder.addProperty(Constants.Dataset.TABLE_TX_DISABLED, "true");
        if (supportsReadlessIncrements) {
            // read-less increments CPs by default assume that table is transactional
            cfdBuilder.addProperty("dataset.table.readless.increment.transactional", "false");
        }
    }
    tdBuilder.addColumnFamily(cfdBuilder.build());
    CoprocessorJar coprocessorJar = createCoprocessorJar();
    for (Class<? extends Coprocessor> coprocessor : coprocessorJar.getCoprocessors()) {
        tdBuilder.addCoprocessor(coprocessorManager.getCoprocessorDescriptor(coprocessor, coprocessorJar.getPriority(coprocessor)));
    }
    byte[][] splits = null;
    String splitsProperty = spec.getProperty(PROPERTY_SPLITS);
    if (splitsProperty != null) {
        splits = GSON.fromJson(splitsProperty, byte[][].class);
    }
    // Disable split policy
    String splitsPolicy = spec.getProperty(SPLIT_POLICY);
    if (!Strings.isNullOrEmpty(splitsPolicy)) {
        tdBuilder.addProperty(HTableDescriptor.SPLIT_POLICY, splitsPolicy);
    }
    try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get()) {
        ddlExecutor.createTableIfNotExists(tdBuilder.build(), splits);
        try {
            Map<String, String> permissions = TableProperties.getTablePermissions(spec.getProperties());
            if (permissions != null && !permissions.isEmpty()) {
                tableUtil.grantPermissions(ddlExecutor, tableId, permissions);
            }
        } catch (IOException | RuntimeException e) {
            try {
                drop();
            } catch (Throwable t) {
                e.addSuppressed(t);
            }
            throw e;
        }
    }
}
Also used : HBaseDDLExecutor(io.cdap.cdap.spi.hbase.HBaseDDLExecutor) ColumnFamilyDescriptorBuilder(io.cdap.cdap.data2.util.hbase.ColumnFamilyDescriptorBuilder) HTableDescriptorBuilder(io.cdap.cdap.data2.util.hbase.HTableDescriptorBuilder) TableDescriptorBuilder(io.cdap.cdap.data2.util.hbase.TableDescriptorBuilder) IOException(java.io.IOException)

Example 20 with HBaseDDLExecutor

use of io.cdap.cdap.spi.hbase.HBaseDDLExecutor in project cdap by cdapio.

the class MetricHBaseTableUtilTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    cConf = CConfiguration.create();
    hBaseTableUtil = new HBaseTableUtilFactory(cConf, new SimpleNamespaceQueryAdmin()).get();
    HBaseDDLExecutor executor = new HBaseDDLExecutorFactory(cConf, TEST_HBASE.getHBaseAdmin().getConfiguration()).get();
    executor.createNamespaceIfNotExists(hBaseTableUtil.getHBaseNamespace(NamespaceId.SYSTEM));
}
Also used : HBaseDDLExecutor(io.cdap.cdap.spi.hbase.HBaseDDLExecutor) SimpleNamespaceQueryAdmin(io.cdap.cdap.common.namespace.SimpleNamespaceQueryAdmin) HBaseDDLExecutorFactory(io.cdap.cdap.data2.util.hbase.HBaseDDLExecutorFactory) HBaseTableUtilFactory(io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory) BeforeClass(org.junit.BeforeClass)

Aggregations

HBaseDDLExecutor (io.cdap.cdap.spi.hbase.HBaseDDLExecutor)22 HTableDescriptorBuilder (io.cdap.cdap.data2.util.hbase.HTableDescriptorBuilder)10 IOException (java.io.IOException)8 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)8 TableId (io.cdap.cdap.data2.util.TableId)6 ColumnFamilyDescriptorBuilder (io.cdap.cdap.data2.util.hbase.ColumnFamilyDescriptorBuilder)6 TableDescriptorBuilder (io.cdap.cdap.data2.util.hbase.TableDescriptorBuilder)6 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)6 ProjectInfo (io.cdap.cdap.common.utils.ProjectInfo)4 ExploreException (io.cdap.cdap.explore.service.ExploreException)4 MessageTable (io.cdap.cdap.messaging.store.MessageTable)4 MetadataTable (io.cdap.cdap.messaging.store.MetadataTable)4 PayloadTable (io.cdap.cdap.messaging.store.PayloadTable)4 SQLException (java.sql.SQLException)4 Map (java.util.Map)4 Table (org.apache.hadoop.hbase.client.Table)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 SimpleNamespaceQueryAdmin (io.cdap.cdap.common.namespace.SimpleNamespaceQueryAdmin)2 HBaseDDLExecutorFactory (io.cdap.cdap.data2.util.hbase.HBaseDDLExecutorFactory)2 HBaseTableUtil (io.cdap.cdap.data2.util.hbase.HBaseTableUtil)2