Permalink
Browse files

Encode integer values on a variable number of bytes.

The design always supported this, and the read-path already supports
reading those, but the write path never really bothered and always
wrote all integer values on 8 bytes no matter what.
  • Loading branch information...
1 parent a553c1c commit bbb6992c5319d58cd4617c6f0e3eee1ee95922fd @tsuna tsuna committed Jun 17, 2013
Showing with 14 additions and 5 deletions.
  1. +2 −2 src/core/RowSeq.java
  2. +12 −3 src/core/TSDB.java
View
@@ -425,12 +425,12 @@ public void seek(final long timestamp) {
// ------------------- //
public long timestamp() {
- assert qualifier != 0: "not initialized: " + this;
+ assert qual_index > 0: "not initialized: " + this;
return base_time + ((qualifier & 0xFFFF) >>> Const.FLAG_BITS);
}
public boolean isInteger() {
- assert qualifier != 0: "not initialized: " + this;
+ assert qual_index > 0: "not initialized: " + this;
return (qualifier & Const.FLAG_FLOAT) == 0x0;
}
View
@@ -237,9 +237,18 @@ public WritableDataPoints newDataPoints() {
final long timestamp,
final long value,
final Map<String, String> tags) {
- final short flags = 0x7; // An int stored on 8 bytes.
- return addPointInternal(metric, timestamp, Bytes.fromLong(value),
- tags, flags);
+ final byte[] v;
+ if (Byte.MIN_VALUE <= value && value <= Byte.MAX_VALUE) {
+ v = new byte[] { (byte) value };
+ } else if (Short.MIN_VALUE <= value && value <= Short.MAX_VALUE) {
+ v = Bytes.fromShort((short) value);
+ } else if (Integer.MIN_VALUE <= value && value <= Integer.MAX_VALUE) {
+ v = Bytes.fromInt((int) value);
+ } else {
+ v = Bytes.fromLong(value);
+ }
+ final short flags = (short) (v.length - 1); // Just the length.
+ return addPointInternal(metric, timestamp, v, tags, flags);
}
/**

0 comments on commit bbb6992

Please sign in to comment.