use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.
the class EntityTableTest method testGetId.
@Test
public void testGetId() throws Exception {
InMemoryTableService.create("testGetId");
MetricsTable table = new InMemoryMetricsTable("testGetId");
EntityTable entityTable = new EntityTable(table);
// Make sure it is created sequentially
for (int i = 1; i <= 10; i++) {
Assert.assertEquals((long) i, entityTable.getId("app", "app" + i));
}
// It should get the same value (from cache)
for (int i = 1; i <= 10; i++) {
Assert.assertEquals((long) i, entityTable.getId("app", "app" + i));
}
// Construct another entityTable, it should load from storage.
entityTable = new EntityTable(table);
for (int i = 1; i <= 10; i++) {
Assert.assertEquals((long) i, entityTable.getId("app", "app" + i));
}
// ID for different type should have ID starts from 1 again.
for (int i = 1; i <= 10; i++) {
Assert.assertEquals((long) i, entityTable.getId("flow", "flow" + i));
}
}
use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.
the class DefaultMetricDatasetFactory method getOrCreateFactTable.
// todo: figure out roll time based on resolution from config? See DefaultMetricsTableFactory for example
@Override
public FactTable getOrCreateFactTable(int resolution) {
String v3TableName = cConf.get(Constants.Metrics.METRICS_TABLE_PREFIX, Constants.Metrics.DEFAULT_METRIC_V3_TABLE_PREFIX) + ".ts." + resolution;
int ttl = cConf.getInt(Constants.Metrics.RETENTION_SECONDS + "." + resolution + ".seconds", -1);
TableProperties.Builder props = TableProperties.builder();
// don't add TTL for MAX_RESOLUTION table. CDAP-1626
if (ttl > 0 && resolution != Integer.MAX_VALUE) {
props.setTTL(ttl);
}
// for efficient counters
props.setReadlessIncrementSupport(true);
// configuring pre-splits
props.add(HBaseTableAdmin.PROPERTY_SPLITS, GSON.toJson(FactTable.getSplits(DefaultMetricStore.AGGREGATIONS.size())));
// Disable auto split
props.add(HBaseTableAdmin.SPLIT_POLICY, cConf.get(Constants.Metrics.METRICS_TABLE_HBASE_SPLIT_POLICY));
MetricsTable table = getOrCreateResolutionMetricsTable(v3TableName, props, resolution);
return new FactTable(table, entityTable.get(), resolution, getRollTime(resolution));
}
use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.
the class DefaultMetricDatasetFactory method getOrCreateMetricsTable.
protected MetricsTable getOrCreateMetricsTable(String tableName, DatasetProperties props) {
// metrics tables are in the system namespace
DatasetId metricsDatasetInstanceId = NamespaceId.SYSTEM.dataset(tableName);
MetricsTable table = null;
try {
table = DatasetsUtil.getOrCreateDataset(dsFramework, metricsDatasetInstanceId, MetricsTable.class.getName(), props, null);
} catch (Exception e) {
Throwables.propagate(e);
}
return table;
}
use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.
the class CubeModule method register.
@Override
public void register(DatasetDefinitionRegistry registry) {
DatasetDefinition<Table, ? extends DatasetAdmin> tableDef = registry.get("table");
DatasetDefinition<MetricsTable, ? extends DatasetAdmin> metricsTableDef = registry.get(MetricsTable.class.getName());
registry.add(new CubeDatasetDefinition(FULL_NAME, tableDef, metricsTableDef));
registry.add(new CubeDatasetDefinition(SHORT_NAME, tableDef, metricsTableDef));
}
use of io.cdap.cdap.data2.dataset2.lib.table.MetricsTable in project cdap by caskdata.
the class HBaseMetricsTableTest method testDataMigration.
@Test
public void testDataMigration() throws Exception {
MetricsTable v2Table = getTable("V2Table");
MetricsTable v3Table = getTable("V3Table");
v2Table.put(ImmutableSortedMap.<byte[], SortedMap<byte[], Long>>orderedBy(Bytes.BYTES_COMPARATOR).put(A, mapOf(A, Bytes.toLong(A), B, Bytes.toLong(B))).put(B, mapOf(A, Bytes.toLong(A), B, Bytes.toLong(B))).put(X, mapOf(A, Bytes.toLong(A), B, Bytes.toLong(B))).build());
// add just column A value for key X in table v3, so this is an increment, while column B is a gauge.
v3Table.put(ImmutableSortedMap.<byte[], SortedMap<byte[], Long>>orderedBy(Bytes.BYTES_COMPARATOR).put(X, mapOf(A, Bytes.toLong(A))).build());
MetricsTableMigration metricsTableMigration = new MetricsTableMigration("V2Table", v2Table, "V3Table", v3Table);
Assert.assertTrue(isMetricsDataAvailable(v2Table));
metricsTableMigration.transferData(1);
Assert.assertEquals(Bytes.toLong(A), Bytes.toLong(v3Table.get(A, A)));
Assert.assertEquals(Bytes.toLong(B), Bytes.toLong(v3Table.get(A, B)));
Assert.assertEquals(Bytes.toLong(A), Bytes.toLong(v3Table.get(B, A)));
Assert.assertEquals(Bytes.toLong(B), Bytes.toLong(v3Table.get(B, B)));
// this is an increment
Assert.assertEquals(Bytes.toLong(A) * 2, Bytes.toLong(v3Table.get(X, A)));
Assert.assertEquals(Bytes.toLong(B), Bytes.toLong(v3Table.get(X, B)));
Assert.assertFalse(isMetricsDataAvailable(v2Table));
}
Aggregations