Search in sources :

Example 6 with ByteMap

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);
        }
    }
}
Also used : KeyValue(org.hbase.async.KeyValue) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) ByteMap(org.hbase.async.Bytes.ByteMap) Map(java.util.Map) ByteMap(org.hbase.async.Bytes.ByteMap) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet)

Aggregations

ByteMap (org.hbase.async.Bytes.ByteMap)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Callback (com.stumbleupon.async.Callback)2 Deferred (com.stumbleupon.async.Deferred)2 IOException (java.io.IOException)2 KeyValue (org.hbase.async.KeyValue)2 DeferredGroupException (com.stumbleupon.async.DeferredGroupException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IncomingDataPoint (net.opentsdb.core.IncomingDataPoint)1 QueryException (net.opentsdb.core.QueryException)1 TSUIDQuery (net.opentsdb.meta.TSUIDQuery)1 TagVFilter (net.opentsdb.query.filter.TagVFilter)1 ByteSet (net.opentsdb.utils.ByteSet)1 HBaseException (org.hbase.async.HBaseException)1 RpcTimedOutException (org.hbase.async.RpcTimedOutException)1