use of co.cask.cdap.data2.dataset2.lib.table.hbase.CombinedHBaseMetricsTable in project cdap by caskdata.
the class DefaultMetricDatasetFactory method getOrCreateResolutionMetricsTable.
protected MetricsTable getOrCreateResolutionMetricsTable(String v3TableName, TableProperties.Builder props, int resolution) {
try {
String v2TableName = cConf.get(Constants.Metrics.METRICS_TABLE_PREFIX, Constants.Metrics.DEFAULT_METRIC_TABLE_PREFIX + ".ts." + resolution);
// metrics tables are in the system namespace
DatasetId v2TableId = NamespaceId.SYSTEM.dataset(v2TableName);
MetricsTable v2Table = dsFramework.getDataset(v2TableId, ImmutableMap.<String, String>of(), null);
props.add(HBaseTableAdmin.PROPERTY_SPLITS, GSON.toJson(getV3MetricsTableSplits(cConf.getInt(Constants.Metrics.METRICS_HBASE_TABLE_SPLITS))));
props.add(Constants.Metrics.METRICS_HBASE_TABLE_SPLITS, cConf.getInt(Constants.Metrics.METRICS_HBASE_TABLE_SPLITS));
DatasetId v3TableId = NamespaceId.SYSTEM.dataset(v3TableName);
MetricsTable v3Table = DatasetsUtil.getOrCreateDataset(dsFramework, v3TableId, MetricsTable.class.getName(), props.build(), null);
if (v2Table != null) {
// the cluster is upgraded, so use Combined Metrics Table
return new CombinedHBaseMetricsTable(v2Table, v3Table, resolution, cConf, dsFramework);
}
return v3Table;
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of co.cask.cdap.data2.dataset2.lib.table.hbase.CombinedHBaseMetricsTable in project cdap by caskdata.
the class HBaseMetricsTableTest method testCombinedTablePut.
@Test
public void testCombinedTablePut() throws Exception {
MetricsTable v2Table = getTable("v2Table");
MetricsTable v3Table = getTable("v3Table");
MetricsTable combinedMetricsTable = new CombinedHBaseMetricsTable(v2Table, v3Table, 1, cConf, dsFramework);
// Already existing data on v2
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))).build());
Assert.assertEquals(Bytes.toLong(A), Bytes.toLong(v2Table.get(A, A)));
Assert.assertEquals(Bytes.toLong(B), Bytes.toLong(v2Table.get(A, B)));
Assert.assertEquals(Bytes.toLong(A), Bytes.toLong(v2Table.get(B, A)));
Assert.assertEquals(Bytes.toLong(B), Bytes.toLong(v2Table.get(B, B)));
// Add some gauge metrics to v3 tables
combinedMetricsTable.put(ImmutableSortedMap.<byte[], SortedMap<byte[], Long>>orderedBy(Bytes.BYTES_COMPARATOR).put(B, mapOf(B, Bytes.toLong(B), C, Bytes.toLong(C))).put(C, mapOf(P, Bytes.toLong(P), X, Bytes.toLong(X))).build());
Assert.assertEquals(Bytes.toLong(B), Bytes.toLong(combinedMetricsTable.get(B, B)));
Assert.assertEquals(Bytes.toLong(C), Bytes.toLong(combinedMetricsTable.get(B, C)));
Assert.assertEquals(Bytes.toLong(X), Bytes.toLong(combinedMetricsTable.get(C, X)));
Assert.assertEquals(Bytes.toLong(P), Bytes.toLong(combinedMetricsTable.get(C, P)));
Scanner combinedScanner = combinedMetricsTable.scan(null, null, null);
Row firstRow = combinedScanner.next();
Assert.assertEquals(1L, Bytes.toLong(firstRow.getRow()));
Iterator<Map.Entry<byte[], byte[]>> colIterator = firstRow.getColumns().entrySet().iterator();
Map.Entry<byte[], byte[]> column = colIterator.next();
Assert.assertEquals(1L, Bytes.toLong(column.getKey()));
Assert.assertEquals(1L, Bytes.toLong(column.getValue()));
column = colIterator.next();
Assert.assertEquals(2L, Bytes.toLong(column.getKey()));
Assert.assertEquals(2L, Bytes.toLong(column.getValue()));
Row secondRow = combinedScanner.next();
Assert.assertEquals(2L, Bytes.toLong(secondRow.getRow()));
colIterator = secondRow.getColumns().entrySet().iterator();
column = colIterator.next();
Assert.assertEquals(1L, Bytes.toLong(column.getKey()));
Assert.assertEquals(1L, Bytes.toLong(column.getValue()));
column = colIterator.next();
Assert.assertEquals(2L, Bytes.toLong(column.getKey()));
// this should be latest value whichh is 2
Assert.assertEquals(2L, Bytes.toLong(column.getValue()));
column = colIterator.next();
Assert.assertEquals(3L, Bytes.toLong(column.getKey()));
Assert.assertEquals(3L, Bytes.toLong(column.getValue()));
Row thirdRow = combinedScanner.next();
Assert.assertEquals(3L, Bytes.toLong(thirdRow.getRow()));
colIterator = thirdRow.getColumns().entrySet().iterator();
column = colIterator.next();
Assert.assertEquals(4L, Bytes.toLong(column.getKey()));
Assert.assertEquals(4L, Bytes.toLong(column.getValue()));
column = colIterator.next();
Assert.assertEquals(7L, Bytes.toLong(column.getKey()));
Assert.assertEquals(7L, Bytes.toLong(column.getValue()));
}
Aggregations