Attempts to fetch the last data point for the given metric or TSUID. If back_scan == 0 and meta is enabled via "tsd.core.meta.enable_tsuid_tracking" or "tsd.core.meta.enable_tsuid_incrementing" then we will look up the metric or TSUID in the meta table first and use the counter there to get the last
(final boolean resolve_names,
final int back_scan)
| 159 | * went pear shaped. |
| 160 | */ |
| 161 | public Deferred<IncomingDataPoint> getLastPoint(final boolean resolve_names, |
| 162 | final int back_scan) { |
| 163 | if (back_scan < 0) { |
| 164 | throw new IllegalArgumentException( |
| 165 | "Backscan must be zero or a positive number"); |
| 166 | } |
| 167 | |
| 168 | this.resolve_names = resolve_names; |
| 169 | this.back_scan = back_scan; |
| 170 | |
| 171 | final boolean meta_enabled = tsdb.getConfig().enable_tsuid_tracking() || |
| 172 | tsdb.getConfig().enable_tsuid_incrementing(); |
| 173 | |
| 174 | class TSUIDCB implements Callback<Deferred<IncomingDataPoint>, byte[]> { |
| 175 | @Override |
| 176 | public Deferred<IncomingDataPoint> call(final byte[] incoming_tsuid) |
| 177 | throws Exception { |
| 178 | if (tsuid == null && incoming_tsuid == null) { |
| 179 | return Deferred.fromError(new RuntimeException("Both incoming and " |
| 180 | + "supplied TSUIDs were null for " + TSUIDQuery.this)); |
| 181 | } else if (incoming_tsuid != null) { |
| 182 | setTSUID(incoming_tsuid); |
| 183 | } |
| 184 | if (back_scan < 1 && meta_enabled) { |
| 185 | final GetRequest get = new GetRequest(tsdb.metaTable(), tsuid); |
| 186 | get.family(TSMeta.FAMILY()); |
| 187 | get.qualifier(TSMeta.COUNTER_QUALIFIER()); |
| 188 | return tsdb.getClient().get(get).addCallbackDeferring(new MetaCB()); |
| 189 | } |
| 190 | |
| 191 | if (last_timestamp > 0) { |
| 192 | last_timestamp = Internal.baseTime(last_timestamp); |
| 193 | } else { |
| 194 | last_timestamp = Internal.baseTime(DateTime.currentTimeMillis()); |
| 195 | } |
| 196 | final byte[] key = RowKey.rowKeyFromTSUID(tsdb, tsuid, last_timestamp); |
| 197 | final GetRequest get = new GetRequest(tsdb.dataTable(), key); |
| 198 | get.family(TSDB.FAMILY()); |
| 199 | return tsdb.getClient().get(get).addCallbackDeferring(new LastPointCB()); |
| 200 | } |
| 201 | @Override |
| 202 | public String toString() { |
| 203 | return "TSUID callback"; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | if (tsuid == null) { |
| 208 | return tsuidFromMetric(tsdb, metric, tags) |
| 209 | .addCallbackDeferring(new TSUIDCB()); |
| 210 | } |
| 211 | try { |
| 212 | // damn typed exceptions.... |
| 213 | return new TSUIDCB().call(null); |
| 214 | } catch (Exception e) { |
| 215 | return Deferred.fromError(e); |
| 216 | } |
| 217 | } |
| 218 |