Deletes global or TSUID associated annotiations for the given time range. @param tsdb The TSDB object to use for storage access @param tsuid An optional TSUID. If set to null, then global annotations for the given range will be deleted @param start_time A start timestamp in milliseconds @param end_t
(final TSDB tsdb,
final byte[] tsuid, final long start_time, final long end_time)
| 393 | * @since 2.1 |
| 394 | */ |
| 395 | public static Deferred<Integer> deleteRange(final TSDB tsdb, |
| 396 | final byte[] tsuid, final long start_time, final long end_time) { |
| 397 | if (end_time < 1) { |
| 398 | throw new IllegalArgumentException("The end timestamp has not been set"); |
| 399 | } |
| 400 | if (end_time < start_time) { |
| 401 | throw new IllegalArgumentException( |
| 402 | "The end timestamp cannot be less than the start timestamp"); |
| 403 | } |
| 404 | |
| 405 | final List<Deferred<Object>> delete_requests = new ArrayList<Deferred<Object>>(); |
| 406 | int width = tsuid != null ? |
| 407 | Const.SALT_WIDTH() + tsuid.length + Const.TIMESTAMP_BYTES : |
| 408 | Const.SALT_WIDTH() + TSDB.metrics_width() + Const.TIMESTAMP_BYTES; |
| 409 | final byte[] start_row = new byte[width]; |
| 410 | final byte[] end_row = new byte[width]; |
| 411 | |
| 412 | // downsample to seconds for the row keys |
| 413 | final long start = start_time / 1000; |
| 414 | final long end = end_time / 1000; |
| 415 | final long normalized_start = (start - (start % Const.MAX_TIMESPAN)); |
| 416 | final long normalized_end = (end - (end % Const.MAX_TIMESPAN) + Const.MAX_TIMESPAN); |
| 417 | Bytes.setInt(start_row, (int) normalized_start, |
| 418 | Const.SALT_WIDTH() + TSDB.metrics_width()); |
| 419 | Bytes.setInt(end_row, (int) normalized_end, |
| 420 | Const.SALT_WIDTH() + TSDB.metrics_width()); |
| 421 | |
| 422 | if (tsuid != null) { |
| 423 | // first copy the metric UID then the tags |
| 424 | System.arraycopy(tsuid, 0, start_row, Const.SALT_WIDTH(), TSDB.metrics_width()); |
| 425 | System.arraycopy(tsuid, 0, end_row, Const.SALT_WIDTH(), TSDB.metrics_width()); |
| 426 | width = Const.SALT_WIDTH() + TSDB.metrics_width() + Const.TIMESTAMP_BYTES; |
| 427 | final int remainder = tsuid.length - TSDB.metrics_width(); |
| 428 | System.arraycopy(tsuid, TSDB.metrics_width(), start_row, width, remainder); |
| 429 | System.arraycopy(tsuid, TSDB.metrics_width(), end_row, width, remainder); |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Iterates through the scanner results in an asynchronous manner, returning |
| 434 | * once the scanner returns a null result set. |
| 435 | */ |
| 436 | final class ScannerCB implements Callback<Deferred<List<Deferred<Object>>>, |
| 437 | ArrayList<ArrayList<KeyValue>>> { |
| 438 | final Scanner scanner; |
| 439 | |
| 440 | public ScannerCB() { |
| 441 | scanner = tsdb.getClient().newScanner(tsdb.dataTable()); |
| 442 | scanner.setStartKey(start_row); |
| 443 | scanner.setStopKey(end_row); |
| 444 | scanner.setFamily(FAMILY); |
| 445 | if (tsuid != null) { |
| 446 | final List<String> tsuids = new ArrayList<String>(1); |
| 447 | tsuids.add(UniqueId.uidToString(tsuid)); |
| 448 | Internal.createAndSetTSUIDFilter(scanner, tsuids); |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | public Deferred<List<Deferred<Object>>> scan() { |