Search in sources :

Example 16 with Version

use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version in project cdap by caskdata.

the class MetricsDataMigrator method migrateMetricsTables.

public void migrateMetricsTables(HBaseTableUtil hBaseTableUtil, boolean keepOldData) throws DataMigrationException {
    Version cdapVersion = findMetricsTableVersion(new MetricHBaseTableUtil(hBaseTableUtil));
    if (cdapVersion == Version.VERSION_2_6_OR_LOWER) {
        migrateMetricsTableFromVersion26(cdapVersion);
    } else if (cdapVersion == Version.VERSION_2_7) {
        migrateMetricsTableFromVersion27(cdapVersion);
    } else {
        System.out.println("Unsupported version" + cdapVersion);
        return;
    }
    if (!keepOldData) {
        System.out.println("Performing cleanup of old metrics tables");
        cleanUpOldTables(cdapVersion);
    }
}
Also used : Version(co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version) MetricHBaseTableUtil(co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil)

Example 17 with Version

use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version in project cdap by caskdata.

the class HBaseTable method undo.

@Override
protected void undo(NavigableMap<byte[], NavigableMap<byte[], Update>> persisted) throws Exception {
    if (persisted.isEmpty()) {
        return;
    }
    // NOTE: we use Delete with the write pointer as the specific version to delete.
    List<Delete> deletes = Lists.newArrayList();
    for (Map.Entry<byte[], NavigableMap<byte[], Update>> row : persisted.entrySet()) {
        DeleteBuilder delete = tableUtil.buildDelete(row.getKey());
        delete.setAttribute(TX_MAX_LIFETIME_MILLIS_KEY, txMaxLifetimeMillis);
        for (Map.Entry<byte[], Update> column : row.getValue().entrySet()) {
            // we want support tx and non-tx modes
            if (tx != null) {
                delete.setAttribute(TxConstants.TX_ROLLBACK_ATTRIBUTE_KEY, new byte[0]);
                // TODO: hijacking timestamp... bad
                delete.deleteColumn(columnFamily, column.getKey(), tx.getWritePointer());
            } else {
                delete.deleteColumns(columnFamily, column.getKey());
            }
        }
        deletes.add(delete.build());
    }
    if (!deletes.isEmpty()) {
        hbaseDelete(deletes);
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) NavigableMap(java.util.NavigableMap) Update(co.cask.cdap.data2.dataset2.lib.table.Update) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) NavigableMap(java.util.NavigableMap) DeleteBuilder(co.cask.cdap.data2.util.hbase.DeleteBuilder)

Example 18 with Version

use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version in project cdap by caskdata.

the class InMemoryTableService method merge.

private static void merge(ConcurrentNavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, Update>>> table, byte[] row, Map<byte[], Update> changes, long version) {
    // get the correct row from the table, create it if it doesn't exist
    NavigableMap<byte[], NavigableMap<Long, Update>> rowMap = table.get(row);
    if (rowMap == null) {
        rowMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
        table.put(row, rowMap);
    }
    // now merge the changes into the row, one by one
    for (Map.Entry<byte[], Update> keyVal : changes.entrySet()) {
        // create the column in the row if it does not exist
        NavigableMap<Long, Update> colMap = rowMap.get(keyVal.getKey());
        if (colMap == null) {
            colMap = Maps.newTreeMap();
            rowMap.put(keyVal.getKey(), colMap);
        }
        // put into the column with given version
        Update merged = Updates.mergeUpdates(colMap.get(version), keyVal.getValue());
        colMap.put(version, merged);
    }
}
Also used : ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) NavigableMap(java.util.NavigableMap) Update(co.cask.cdap.data2.dataset2.lib.table.Update) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) NavigableMap(java.util.NavigableMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 19 with Version

use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version in project cdap by caskdata.

the class MdsKey method getMetadataKey.

static String getMetadataKey(String type, byte[] rowKey) {
    MDSKey.Splitter keySplitter = new MDSKey(rowKey).split();
    // The rowkey is
    // [rowPrefix][targetType][targetId][key] for value rows and
    // [rowPrefix][targetType][targetId][key][index] for value index rows
    // so skip the first few strings.
    // Skip rowType
    keySplitter.skipBytes();
    // Skip targetType
    keySplitter.skipString();
    // Skip targetId
    if (type.equals(EntityIdKeyHelper.TYPE_MAP.get(ProgramId.class))) {
        keySplitter.skipString();
        keySplitter.skipString();
        keySplitter.skipString();
        keySplitter.skipString();
    } else if (type.equals(EntityIdKeyHelper.TYPE_MAP.get(ApplicationId.class))) {
        keySplitter.skipString();
        keySplitter.skipString();
    } else if (type.equals(EntityIdKeyHelper.TYPE_MAP.get(DatasetId.class))) {
        keySplitter.skipString();
        keySplitter.skipString();
    } else if (type.equals(EntityIdKeyHelper.TYPE_MAP.get(StreamId.class))) {
        keySplitter.skipString();
        keySplitter.skipString();
    } else if (type.equals(EntityIdKeyHelper.TYPE_MAP.get(StreamViewId.class))) {
        // skip namespace, stream, view
        keySplitter.skipString();
        keySplitter.skipString();
        keySplitter.skipString();
    } else if (type.equals(EntityIdKeyHelper.TYPE_MAP.get(ArtifactId.class))) {
        // skip namespace, name, version
        keySplitter.skipString();
        keySplitter.skipString();
        keySplitter.skipString();
    } else {
        throw new IllegalArgumentException("Illegal Type " + type + " of metadata source.");
    }
    return keySplitter.getString();
}
Also used : MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) ProgramId(co.cask.cdap.proto.id.ProgramId) DatasetId(co.cask.cdap.proto.id.DatasetId) StreamViewId(co.cask.cdap.proto.id.StreamViewId)

Aggregations

MDSKey (co.cask.cdap.data2.dataset2.lib.table.MDSKey)8 Map (java.util.Map)4 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)4 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)4 Update (co.cask.cdap.data2.dataset2.lib.table.Update)3 GsonBuilder (com.google.gson.GsonBuilder)3 NavigableMap (java.util.NavigableMap)3 ProjectInfo (co.cask.cdap.common.utils.ProjectInfo)2 MetricsTable (co.cask.cdap.data2.dataset2.lib.table.MetricsTable)2 Version (co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version)2 EntityTable (co.cask.cdap.data2.dataset2.lib.timeseries.EntityTable)2 HBaseTableUtil (co.cask.cdap.data2.util.hbase.HBaseTableUtil)2 HTableDescriptorBuilder (co.cask.cdap.data2.util.hbase.HTableDescriptorBuilder)2 HBaseDDLExecutor (co.cask.cdap.spi.hbase.HBaseDDLExecutor)2 IOException (java.io.IOException)2 SortedMap (java.util.SortedMap)2 ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)2 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)2 TableName (org.apache.hadoop.hbase.TableName)2 DatasetAdmin (co.cask.cdap.api.dataset.DatasetAdmin)1