Scans through the global annotation storage rows and returns a list of parsed annotation objects. If no annotations were found for the given timespan, the resulting list will be empty. @param tsdb The TSDB to use for storage access @param start_time Start time to scan from. May be 0 @param end_time
(final TSDB tsdb,
final long start_time, final long end_time)
| 302 | * the end time is less than the start time |
| 303 | */ |
| 304 | public static Deferred<List<Annotation>> getGlobalAnnotations(final TSDB tsdb, |
| 305 | final long start_time, final long end_time) { |
| 306 | if (end_time < 1) { |
| 307 | throw new IllegalArgumentException("The end timestamp has not been set"); |
| 308 | } |
| 309 | if (end_time < start_time) { |
| 310 | throw new IllegalArgumentException( |
| 311 | "The end timestamp cannot be less than the start timestamp"); |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * Scanner that loops through the [0, 0, 0, timestamp] rows looking for |
| 316 | * global annotations. Returns a list of parsed annotation objects. |
| 317 | * The list may be empty. |
| 318 | */ |
| 319 | final class ScannerCB implements Callback<Deferred<List<Annotation>>, |
| 320 | ArrayList<ArrayList<KeyValue>>> { |
| 321 | final Scanner scanner; |
| 322 | final ArrayList<Annotation> annotations = new ArrayList<Annotation>(); |
| 323 | |
| 324 | /** |
| 325 | * Initializes the scanner |
| 326 | */ |
| 327 | public ScannerCB() { |
| 328 | final byte[] start = new byte[Const.SALT_WIDTH() + |
| 329 | TSDB.metrics_width() + |
| 330 | Const.TIMESTAMP_BYTES]; |
| 331 | final byte[] end = new byte[Const.SALT_WIDTH() + |
| 332 | TSDB.metrics_width() + |
| 333 | Const.TIMESTAMP_BYTES]; |
| 334 | |
| 335 | final long normalized_start = (start_time - |
| 336 | (start_time % Const.MAX_TIMESPAN)); |
| 337 | final long normalized_end = (end_time - |
| 338 | (end_time % Const.MAX_TIMESPAN) + Const.MAX_TIMESPAN); |
| 339 | |
| 340 | Bytes.setInt(start, (int) normalized_start, |
| 341 | Const.SALT_WIDTH() + TSDB.metrics_width()); |
| 342 | Bytes.setInt(end, (int) normalized_end, |
| 343 | Const.SALT_WIDTH() + TSDB.metrics_width()); |
| 344 | |
| 345 | scanner = tsdb.getClient().newScanner(tsdb.dataTable()); |
| 346 | scanner.setStartKey(start); |
| 347 | scanner.setStopKey(end); |
| 348 | scanner.setFamily(FAMILY); |
| 349 | } |
| 350 | |
| 351 | public Deferred<List<Annotation>> scan() { |
| 352 | return scanner.nextRows().addCallbackDeferring(this); |
| 353 | } |
| 354 | |
| 355 | @Override |
| 356 | public Deferred<List<Annotation>> call ( |
| 357 | final ArrayList<ArrayList<KeyValue>> rows) throws Exception { |
| 358 | if (rows == null || rows.isEmpty()) { |
| 359 | return Deferred.fromResult((List<Annotation>)annotations); |
| 360 | } |
| 361 |