use of org.hbase.async.Bytes.ByteMap in project opentsdb by OpenTSDB.
the class MockBase method tsdbCompactAllRows.
/**
* Runs through all rows in the "tsdb" table and compacts them by making a
* call to the {@link TSDB.compact} method. It will delete any columns
* that were compacted and leave others untouched, just as the normal
* method does.
* And only iterates over the 't' family.
* @throws Exception if Whitebox couldn't access the compact method
*/
public void tsdbCompactAllRows() throws Exception {
final ByteMap<ByteMap<ByteMap<TreeMap<Long, byte[]>>>> map = storage.get("tsdb".getBytes(ASCII));
if (map == null) {
return;
}
final ByteMap<ByteMap<TreeMap<Long, byte[]>>> cf = map.get("t".getBytes(ASCII));
if (cf == null) {
return;
}
for (Entry<byte[], ByteMap<TreeMap<Long, byte[]>>> entry : cf.entrySet()) {
final byte[] key = entry.getKey();
final ByteMap<TreeMap<Long, byte[]>> row = entry.getValue();
ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(row.size());
final Set<byte[]> deletes = new HashSet<byte[]>();
for (Map.Entry<byte[], TreeMap<Long, byte[]>> column : row.entrySet()) {
if (column.getKey().length % 2 == 0) {
kvs.add(new KeyValue(key, default_family, column.getKey(), column.getValue().firstKey(), column.getValue().firstEntry().getValue()));
deletes.add(column.getKey());
}
}
if (kvs.size() > 0) {
for (final byte[] k : deletes) {
row.remove(k);
}
final KeyValue compacted = Whitebox.invokeMethod(tsdb, "compact", kvs, Collections.EMPTY_LIST);
final TreeMap<Long, byte[]> compacted_value = new TreeMap<Long, byte[]>();
compacted_value.put(current_timestamp++, compacted.value());
row.put(compacted.qualifier(), compacted_value);
}
}
}
Aggregations