if (debug) { System.out.println("Got scan result for key: " + Bytes.pretty(column.key()));
public DeleteCompactedCB(final ArrayList<KeyValue> cells) { final KeyValue first = cells.get(0); key = first.key(); family = first.family(); qualifiers = new byte[cells.size()][]; for (int i = 0; i < qualifiers.length; i++) { qualifiers[i] = cells.get(i).qualifier(); } }
public Object call(final Object response) { ArrayList<ArrayList<KeyValue>> rows = null; Response resp = null; if (response instanceof Response) { // HBase 0.95 and up resp = (Response) response; rows = resp.rows; scannerClosedOnServer = resp.scannerClosedOnServer; moreRows = resp.more; } else if (response instanceof ArrayList) { // HBase 0.94 and before. @SuppressWarnings("unchecked") // I 3>> generics. final ArrayList<ArrayList<KeyValue>> r = (ArrayList<ArrayList<KeyValue>>) response; rows = r; } else if (response != null) { throw new InvalidResponseException(ArrayList.class, response); } if (rows == null) { // We're done scanning this region. return scanFinished(resp != null && !resp.more); } final ArrayList<KeyValue> lastrow = rows.get(rows.size() - 1); start_key = lastrow.get(0).key(); return rows; } public String toString() {
/** * Sets the row this instance holds in RAM using a row from a scanner. * * @param row The compacted HBase row to set. * @throws IllegalStateException if this method was already called. */ void setRow(final KeyValue row) { if (this.key != null) { throw new IllegalStateException("setRow was already called on " + this); } this.key = row.key(); this.qualifiers = row.qualifier(); this.values = row.value(); }
/** * Constructor to delete a specific cell. * @param table The table to edit. * @param kv The specific {@link KeyValue} to delete. Note that if this * {@link KeyValue} specifies a timestamp, then this specific timestamp only * will be deleted. * @since 1.2 */ public DeleteRequest(final byte[] table, final KeyValue kv) { this(table, kv.key(), kv.family(), new byte[][] { kv.qualifier() }, kv.timestamp(), RowLock.NO_LOCK); }
/** * Package private helper to access the last timestamp in an HBase row. * * @param metric_width The number of bytes on which metric IDs are stored. * @param row A compacted HBase row. * @return A strictly positive 32-bit timestamp. * @throws IllegalArgumentException if {@code row} doesn't contain any cell. */ static long lastTimestampInRow(final short metric_width, final KeyValue row) { final long base_time = Bytes.getUnsignedInt(row.key(), metric_width); final byte[] qual = row.qualifier(); final short last_delta = (short) (Bytes.getUnsignedShort(qual, qual.length - 2) >>> Const.FLAG_BITS); return base_time + last_delta; }
for (final ArrayList<KeyValue> row : rows) { buf.setLength(0); final byte[] key = row.get(0).key(); final long base_time = Internal.baseTime(tsdb, key); final String metric = Internal.metricName(tsdb, key);
/** Private constructor. */ private AppendRequest(final byte[] table, final byte[] key, final byte[] family, final byte[] qualifier, final byte[] value, final long timestamp, final long lockid) { this(table, key, family, new byte[][] { qualifier }, new byte[][] { value }, timestamp, lockid, false); }
/** Private constructor. */ private PutRequest(final byte[] table, final byte[] key, final byte[] family, final byte[] qualifier, final byte[] value, final long timestamp, final long lockid) { this(table, key, family, new byte[][] { qualifier }, new byte[][] { value }, timestamp, lockid); }
final byte[] key = row.get(0).key(); final String name = fromBytes(key); final byte[] id = row.get(0).value();
hbase_time += (System.nanoTime() - starttime) / 1000000; for (final ArrayList<KeyValue> row : rows) { final byte[] key = row.get(0).key(); if (Bytes.memcmp(metric, key, 0, metric_width) != 0) { throw new IllegalDataException("HBase returned a row that doesn't match"
/** * Helper to print the cells in a given family for a given row, if any. * * @param row The row to print. * @param family Only cells in this family (if any) will be printed. * @param formard If true, this row contains a forward mapping (name to ID). * Otherwise the row is assumed to contain a reverse mapping (ID to name). * @return {@code true} if at least one cell was printed. */ private static boolean printResult(final ArrayList<KeyValue> row, final byte[] family, final boolean formard) { final byte[] key = row.get(0).key(); String name = formard ? fromBytes(key) : null; String id = formard ? null : Arrays.toString(key); boolean printed = false; for (final KeyValue kv : row) { if (!Bytes.equals(kv.family(), family)) { continue; } printed = true; if (formard) { id = Arrays.toString(kv.value()); } else { name = fromBytes(kv.value()); } System.out.println(fromBytes(kv.qualifier()) + ' ' + name + ": " + id); } return printed; }
if (rows.size() != 0) { final byte[] key = row.key(); final RowSeq last = rows.get(rows.size() - 1); final short metric_width = tsdb.metrics.width();
return new KeyValue(first.key(), first.family(), qualifier, value);
static List<Deferred<Boolean>> doList(HBaseClient client) throws Throwable { final Scanner scanner = client.newScanner(TABLE_NAME); scanner.setFamily(INFO_FAM); scanner.setQualifier(PASSWORD_COL); ArrayList<ArrayList<KeyValue>> rows = null; ArrayList<Deferred<Boolean>> workers = new ArrayList<Deferred<Boolean>>(); while ((rows = scanner.nextRows(1).joinUninterruptibly()) != null) { LOG.info("received a page of users."); for (ArrayList<KeyValue> row : rows) { KeyValue kv = row.get(0); byte[] expected = kv.value(); String userId = new String(kv.key()); PutRequest put = new PutRequest( TABLE_NAME, kv.key(), kv.family(), kv.qualifier(), mkNewPassword(expected)); Deferred<Boolean> d = client.compareAndSet(put, expected) .addCallback(new InterpretResponse(userId)) .addCallbacks(new ResultToMessage(), new FailureToMessage()) .addCallback(new SendMessage()); workers.add(d); } } return workers; }
final byte[] key = row.get(0).key(); final Map<String, Object> dataTree = readDataTree(row); request.setSource(dataTree);
/** * De-serializes an {@code hbase.client.Result} object. * @param buf The buffer that contains a serialized {@code Result}. * @return The result parsed into a list of {@link KeyValue} objects. */ private static ArrayList<KeyValue> parseResult(final ChannelBuffer buf) { final int length = buf.readInt(); HBaseRpc.checkArrayLength(buf, length); //LOG.debug("total Result response length={}", length); final int num_kv = numberOfKeyValuesAhead(buf, length); final ArrayList<KeyValue> results = new ArrayList<KeyValue>(num_kv); KeyValue kv = null; for (int i = 0; i < num_kv; i++) { final int kv_length = buf.readInt(); // Previous loop checked it's >0. // Now read a KeyValue that spans over kv_length bytes. kv = KeyValue.fromBuffer(buf, kv); final int key_length = (2 + kv.key().length + 1 + kv.family().length + kv.qualifier().length + 8 + 1); // XXX DEBUG if (key_length + kv.value().length + 4 + 4 != kv_length) { badResponse("kv_length=" + kv_length + " doesn't match key_length + value_length (" + key_length + " + " + kv.value().length + ") in " + buf + '=' + Bytes.pretty(buf)); } results.add(kv); } return results; }
/** Private constructor. */ private DeleteRequest(final byte[] table, final byte[] key, final byte[] family, final byte[][] qualifiers, final long timestamp, final long lockid) { super(table, key, family == null ? WHOLE_ROW : family, timestamp, lockid); if (family != null) { KeyValue.checkFamily(family); } if (qualifiers != null) { if (family == null) { throw new IllegalArgumentException("You can't delete specific qualifiers" + " without specifying which family they belong to." + " table=" + Bytes.pretty(table) + ", key=" + Bytes.pretty(key)); } if (qualifiers.length == 0) { throw new IllegalArgumentException("Don't pass an empty list of" + " qualifiers, this would delete the entire row of table=" + Bytes.pretty(table) + " at key " + Bytes.pretty(key)); } for (final byte[] qualifier : qualifiers) { KeyValue.checkQualifier(qualifier); } this.qualifiers = qualifiers; } else { // No specific qualifier to delete: delete the entire family. Not that
ArrayList<ArrayList<KeyValue>> rows = _getSingleRow(start, end, filterList, metadata.tableName); while(rows != null && !rows.isEmpty()) { String rowKey = Bytes.toString(rows.get(0).get(0).key()); String splits[] = rowKey.split(String.valueOf(ROWKEY_SEPARATOR)); String record = (RecordType.METRIC.equals(type) && metadata.tableName.equals(METRIC_SCHEMA_TABLENAME)) ||
final byte[] start_key = Bytes.get(pb.getStartKey()); final byte[] stop_key = Bytes.get(pb.getEndKey()); final byte[] region_name = kv.key();