Returns the UNIX timestamp at which we must stop scanning.
()
| 1615 | |
| 1616 | /** Returns the UNIX timestamp at which we must stop scanning. */ |
| 1617 | long getScanEndTimeSeconds() { |
| 1618 | // Begin with the raw query end time. |
| 1619 | long end = getEndTime(); |
| 1620 | |
| 1621 | // Convert to seconds if we have a query in ms. |
| 1622 | if ((end & Const.SECOND_MASK) != 0L) { |
| 1623 | end /= 1000L; |
| 1624 | if (end - (end * 1000) < 1) { |
| 1625 | // handle an edge case where a user may request a ms time between |
| 1626 | // 0 and 1 seconds. Just bump it a second. |
| 1627 | end++; |
| 1628 | } |
| 1629 | } |
| 1630 | |
| 1631 | if (rollup_query != null) { |
| 1632 | return RollupUtils.getRollupBasetime(end + |
| 1633 | (rollup_query.getRollupInterval().getIntervalSeconds() * |
| 1634 | rollup_query.getRollupInterval().getIntervals()), |
| 1635 | rollup_query.getRollupInterval()); |
| 1636 | } |
| 1637 | |
| 1638 | // The calculation depends on whether we're downsampling. |
| 1639 | if (downsampler != null && downsampler.getInterval() > 0) { |
| 1640 | // Downsampling enabled. |
| 1641 | // |
| 1642 | // First, we align the end timestamp to its representative value for the |
| 1643 | // interval FOLLOWING the one in which it appears. |
| 1644 | // |
| 1645 | // OpenTSDB's query bounds are inclusive, but HBase scan bounds are half- |
| 1646 | // open. The user may have provided an end bound that is already |
| 1647 | // interval-aligned (i.e., its interval offset is zero). If so, the user |
| 1648 | // wishes for that interval to appear in the output. In that case, we |
| 1649 | // skip forward an entire extra interval. |
| 1650 | // |
| 1651 | // This can be accomplished by simply not testing for zero offset. |
| 1652 | final long interval_offset = (1000L * end) % downsampler.getInterval(); |
| 1653 | final long interval_aligned_ts = end + |
| 1654 | (downsampler.getInterval() - interval_offset) / 1000L; |
| 1655 | |
| 1656 | // Then, if we're now aligned on a timespan boundary, then we need no |
| 1657 | // further adjustment: we are guaranteed to have always moved the end time |
| 1658 | // forward, so the scan will find the data we need. |
| 1659 | // |
| 1660 | // Otherwise, we need to align to the NEXT timespan to ensure that we scan |
| 1661 | // the needed data. |
| 1662 | final long timespan_offset = interval_aligned_ts % Const.MAX_TIMESPAN; |
| 1663 | return (0L == timespan_offset) ? |
| 1664 | interval_aligned_ts : |
| 1665 | interval_aligned_ts + (Const.MAX_TIMESPAN - timespan_offset); |
| 1666 | } else { |
| 1667 | // Not downsampling. |
| 1668 | // |
| 1669 | // Regardless of the end timestamp's position within the current timespan, |
| 1670 | // we must always align to the beginning of the next timespan. This is |
| 1671 | // true even if it's already aligned on a timespan boundary. Again, the |
| 1672 | // reason for this is OpenTSDB's closed interval vs. HBase's half-open. |
| 1673 | final long timespan_offset = end % Const.MAX_TIMESPAN; |
| 1674 | return end + (Const.MAX_TIMESPAN - timespan_offset); |