assert value.length == 8 || value.length == 4 : Bytes.pretty(value); if (row == null) { throw new IllegalStateException("setSeries() never called!"); Bytes.setInt(row, (int) base_time, tsdb.metrics.width()); qualifiers[size] = qualifier; values[size] = (value.length == 8 ? Bytes.getLong(value) : Bytes.getInt(value) & 0x00000000FFFFFFFFL); size++; Bytes.fromShort(qualifier), value);
final long base_time = Bytes.getUnsignedInt(key, tsdb.metrics.width()); final int time_adj = (int) (base_time - baseTime()); if (time_adj <= 0) { if (time_adj != 0 || !Bytes.equals(this.key, key)) { throw new IllegalDataException("Attempt to save a row with a base_time=" + base_time + " <= baseTime()=" + baseTime() + "; Row added=" + row int last_delta = Bytes.getUnsignedShort(qualifiers, qualifiers.length - 2); last_delta >>= Const.FLAG_BITS; short qualifier = Bytes.getShort(qual, i); final int time_delta = time_adj + ((qualifier & 0xFFFF) >>> Const.FLAG_BITS); if (!canTimeDeltaFit(time_delta)) { Bytes.setShort(newquals, qualifier, old_qual_len + i);
/** * Extracts the value of a cell containing a data point. * * @param value The contents of a cell in HBase. * @param value_idx The offset inside {@code values} at which the value * starts. * @param flags The flags for this value. * @return The value of the cell. */ static long extractIntegerValue(final byte[] values, final int value_idx, final byte flags) { switch (flags & Const.LENGTH_MASK) { case 7: return Bytes.getLong(values, value_idx); case 3: return Bytes.getInt(values, value_idx); case 1: return Bytes.getShort(values, value_idx); case 0: return values[value_idx]; } throw new IllegalDataException("Integer value @ " + value_idx + " not on 8/4/2/1 bytes in " + Arrays.toString(values)); }
private static boolean byteArrayEquals(byte[][] self, byte[][] other) { if (self.length != other.length) { return false; } for (int i = 0; i < self.length; i++) { if (Bytes.memcmp(self[i], other[i]) != 0) { return false; } } return true; }
final long base_time = Bytes.getUnsignedInt(key, metric_width); for (int i = metric_width; i < metric_width + Const.TIMESTAMP_BYTES; i++) { key[i] = 0; boolean ooo = false; // Did we find out of order data? for (int i = 0; i < qual.length; i += 2) { final short qualifier = Bytes.getShort(qual, i); final short delta = (short) ((qualifier & 0xFFFF) >>> Internal.FLAG_BITS); final short qualifier = Bytes.getShort(qual); final short delta = (short) ((qualifier & 0xFFFF) >>> Internal.FLAG_BITS); final long timestamp = base_time + delta; Bytes.setInt(newkey, (int) new_base_time, metric_width); final short newqual = (short) ((timestamp - new_base_time) << Internal.FLAG_BITS | (qualifier & Internal.FLAGS_MASK)); if (timestamp < prev.timestamp()) { client.put(new PutRequest(table, newkey, kv.family(), Bytes.fromShort(newqual), value)) .append(") @ ").append(prev.kv).append("\n\t"); DumpSeries.formatKeyValue(buf, tsdb, prev.kv, Bytes.getUnsignedInt(prev.kv.key(), metric_width)); LOG.error(buf.toString());
public boolean equals(final Object other) { if (other == null || !(other instanceof BufferedIncrement)) { return false; } final BufferedIncrement incr = (BufferedIncrement) other; // Compare fields most likely to be different first. return Bytes.equals(qualifier, incr.qualifier) && Bytes.equals(key, incr.key) && Bytes.equals(family, incr.family) && Bytes.equals(table, incr.table); }
deserializeProtobufRegionInfo(final KeyValue kv, final byte[][] out_start_key) { final byte[] value = kv.value(); final int magic = Bytes.getInt(value); if (magic != HBaseClient.PBUF_MAGIC) { throw BrokenMetaException.badKV(null, "the magic number is invalid", kv); pb = HBasePB.RegionInfo.PARSER.parseFrom(value, 4, value.length - 4); } catch (InvalidProtocolBufferException e) { throw new BrokenMetaException("Failed to decode " + Bytes.pretty(value), e); final byte[] table = Bytes.get(pb.getTableName().getQualifier()); final byte[] start_key = Bytes.get(pb.getStartKey()); final byte[] stop_key = Bytes.get(pb.getEndKey()); final byte[] region_name = kv.key();
if (data[0] == MAGIC) { newstyle = true; final int metadata_length = Bytes.getInt(data, 1); if (metadata_length < 1 || metadata_length > 65000) { LOG.error("Malformed meta-data in " + Bytes.pretty(data) + ", invalid metadata length=" + metadata_length); return null; // TODO(tsuna): Add a watch to wait until the file changes. + " (':' or ','): " + Bytes.pretty(data)); return null; // TODO(tsuna): Add a watch to wait until the file changes. if (ip == null) { LOG.error("Couldn't resolve the IP of the -ROOT- region from " + host + " in \"" + Bytes.pretty(data) + '"'); return null; // TODO(tsuna): Add a watch to wait until the file changes.
final short delta = (short) ((Bytes.getShort(qual) & 0xFFFF) >>> Const.FLAG_BITS); KeyValue dup = null; int dup_idx = -1; if (Bytes.equals(longest_qual, qual)) { dup = longest; dup_idx = longest_idx; if (Bytes.equals(kv.qualifier(), qual)) { dup = kv; dup_idx = i; if (Bytes.equals(dup.value(), compact.value())) { final long base_time = Bytes.getUnsignedInt(compact.key(), metric_width); final long cut_off = System.currentTimeMillis() / 1000 - Const.MAX_TIMESPAN - 1;
/** * 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; }
/** * Extracts the value of a cell containing a data point. * * @param value The contents of a cell in HBase. * @param value_idx The offset inside {@code values} at which the value * starts. * @param flags The flags for this value. * @return The value of the cell. */ static double extractFloatingPointValue(final byte[] values, final int value_idx, final byte flags) { switch (flags & Const.LENGTH_MASK) { case 7: return Double.longBitsToDouble(Bytes.getLong(values, value_idx)); case 3: return Float.intBitsToFloat(Bytes.getInt(values, value_idx)); } throw new IllegalDataException("Floating point value @ " + value_idx + " not on 8 or 4 bytes in " + Arrays.toString(values)); }
if (Bytes.equals(table, HBASE98_ROOT)) { // HBase 0.98 and up. return new RegionInfo(HBASE98_ROOT, HBASE98_ROOT_REGION, EMPTY_ARRAY); if (Bytes.equals(table, ROOT)) { // HBase 0.94 and before. return new RegionInfo(ROOT, ROOT_REGION, EMPTY_ARRAY); } else if (Bytes.equals(table, HBASE96_META)) { // HBase 0.95 and up. return META_REGION; && Bytes.memcmp(key, stop_key) >= 0) {
for (int i = 0; i < ncells; i++) { final Cell cell = cells.get(i); final short delta = (short) ((Bytes.getShort(cell.qualifier) & 0xFFFF) >>> Const.FLAG_BITS); || !Bytes.equals(cell.value, prev.value)) { throw new IllegalDataException("Found out of order or duplicate" + " data: cell=" + cell + ", delta=" + delta + ", prev cell="
final byte[] family = kv.family(); final byte[] value = kv.value(); if (Bytes.equals(key, MAXID_ROW)) { if (value.length != 8) { uids.error(kv, "Invalid maximum ID for " + kind + ": should be on 8 bytes: "); } else { uids.maxid = Bytes.getLong(value); LOG.info("Maximum ID for " + kind + ": " + uids.maxid); if (Bytes.equals(family, ID_FAMILY)) { idwidth = (short) value.length; final String skey = fromBytes(key); + " and " + skey + " -> " + svalue); } else if (Bytes.equals(family, NAME_FAMILY)) { final String skey = Arrays.toString(key); final String svalue = fromBytes(value);
/** * Reads a big-endian 2-byte unsigned short from an offset in the * given array. * @param b The array to read from. * @param offset The offset in the array to start reading from. * @return A positive short integer. * @throws IndexOutOfBoundsException if the byte array is too small. */ public static int getUnsignedShort(final byte[] b, final int offset) { return getShort(b, offset) & 0x0000FFFF; }
/** * Reads a big-endian 4-byte unsigned integer from the begining of the * given array. * @param b The array to read from. * @return A positive integer. * @throws IndexOutOfBoundsException if the byte array is too small. */ public static long getUnsignedInt(final byte[] b) { return getUnsignedInt(b, 0); }
/** Serializes this request. */ ChannelBuffer serialize(final byte server_version) { if (server_version < RegionClient.SERVER_VERSION_095_OR_ABOVE) { throw new UnsupportedOperationException(server_version + " is not supported by " + this.getClass().getName()); } MutationProto.Builder incr = MutationProto.newBuilder() .setRow(Bytes.wrap(key)) .setMutateType(MutationProto.MutationType.INCREMENT); for (int i = 0; i < qualifiers.length; i++) { final MutationProto.ColumnValue.QualifierValue qualifier = MutationProto.ColumnValue.QualifierValue.newBuilder() .setQualifier(Bytes.wrap(this.qualifiers[i])) .setValue(Bytes.wrap(Bytes.fromLong(this.amounts[i]))) .build(); final MutationProto.ColumnValue column = MutationProto.ColumnValue.newBuilder() .setFamily(Bytes.wrap(family)) .addQualifierValue(qualifier) .build(); incr.addColumnValue(column); } if (!durable) { incr.setDurability(MutationProto.Durability.SKIP_WAL); } final MutateRequest req = MutateRequest.newBuilder() .setRegion(region.toProtobuf()) .setMutation(incr.build()) .build(); return toChannelBuffer(MUTATE, req); }