Implements #addPoint by storing a value with a specific flag. @param timestamp The timestamp to associate with the value. @param value The value to store. @param flags Flags to store in the qualifier (size and type of the data point).
(final long timestamp,
final byte[] value, final short flags)
| 191 | * @param flags Flags to store in the qualifier (size and type of the data point). |
| 192 | */ |
| 193 | private Deferred<Object> addPointInternal(final long timestamp, |
| 194 | final byte[] value, final short flags) throws IllegalDataException { |
| 195 | final boolean ms_timestamp = (timestamp & Const.SECOND_MASK) != 0; |
| 196 | |
| 197 | // we only accept unix epoch timestamps in seconds or milliseconds |
| 198 | if (timestamp < 0 || (ms_timestamp && timestamp > 9999999999999L)) { |
| 199 | throw new IllegalArgumentException((timestamp < 0 ? "negative " : "bad") |
| 200 | + " timestamp=" + timestamp |
| 201 | + " when trying to add value=" + Arrays.toString(value) + " to " + this); |
| 202 | } |
| 203 | |
| 204 | // always maintain lastTimestamp in milliseconds |
| 205 | if ((ms_timestamp ? timestamp : timestamp * 1000) <= last_timestamp) { |
| 206 | throw new IllegalArgumentException("New timestamp=" + timestamp |
| 207 | + " is less than or equal to previous=" + last_timestamp |
| 208 | + " when trying to add value=" + Arrays.toString(value) |
| 209 | + " to " + this); |
| 210 | } |
| 211 | last_timestamp = (ms_timestamp ? timestamp : timestamp * 1000); |
| 212 | |
| 213 | long incomingBaseTime; |
| 214 | if (ms_timestamp) { |
| 215 | // drop the ms timestamp to seconds to calculate the base timestamp |
| 216 | incomingBaseTime = |
| 217 | ((timestamp / 1000) - ((timestamp / 1000) % Const.MAX_TIMESPAN)); |
| 218 | } |
| 219 | else { |
| 220 | incomingBaseTime = (timestamp - (timestamp % Const.MAX_TIMESPAN)); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * First time we add a point initialize the rows timestamp. |
| 225 | */ |
| 226 | if (base_time == Long.MIN_VALUE) { |
| 227 | base_time = incomingBaseTime; |
| 228 | Bytes.setInt(row_key, (int) base_time, |
| 229 | tsdb.metrics.width() + Const.SALT_WIDTH()); |
| 230 | } |
| 231 | |
| 232 | if (incomingBaseTime - base_time >= Const.MAX_TIMESPAN) { |
| 233 | throw new IllegalDataException( |
| 234 | "The timestamp is beyond the boundary of this batch of data points"); |
| 235 | } |
| 236 | if (incomingBaseTime < base_time) { |
| 237 | throw new IllegalDataException( |
| 238 | "The timestamp is prior to the boundary of this batch of data points"); |
| 239 | } |
| 240 | |
| 241 | // Java is so stupid with its auto-promotion of int to float. |
| 242 | final byte[] new_qualifier = Internal.buildQualifier(timestamp, flags); |
| 243 | |
| 244 | // compact this data point with the previously compacted data points. |
| 245 | append(new_qualifier, value); |
| 246 | size++; |
| 247 | |
| 248 | /** |
| 249 | * Satisfies the interface. |
| 250 | */ |
no test coverage detected