Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Extract an AbstractQuery
Extracts an AbstractQuery from the TsdbQuery implementation since we'd
like to reuse some parts of it in other Query classes (in this case
SplitRollupQuery)
  • Loading branch information
muffix committed Nov 13, 2019
commit 03e05e9b19dd9382cdff6f1154a81e21657d9289
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dist_noinst_DATA = pom.xml.in build-aux/rpm/opentsdb.conf \
build-aux/rpm/logback.xml build-aux/rpm/init.d/opentsdb \
build-aux/rpm/systemd/[email protected]
tsdb_SRC := \
src/core/AbstractQuery.java \
src/core/AggregationIterator.java \
src/core/Aggregator.java \
src/core/Aggregators.java \
Expand Down
66 changes: 66 additions & 0 deletions src/core/AbstractQuery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// This file is part of OpenTSDB.
// Copyright (C) 2010-2012 The OpenTSDB Authors.
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 2.1 of the License, or (at your
// option) any later version. This program is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
// General Public License for more details. You should have received a copy
// of the GNU Lesser General Public License along with this program. If not,
// see <http://www.gnu.org/licenses/>.
package net.opentsdb.core;

import org.hbase.async.HBaseException;

public abstract class AbstractQuery implements Query {
/**
* Runs this query.
*
* @return The data points matched by this query.
* <p>
* Each element in the non-{@code null} but possibly empty array returned
* corresponds to one time series for which some data points have been
* matched by the query.
* @throws HBaseException if there was a problem communicating with HBase to
* perform the search.
*/
@Override
public DataPoints[] run() throws HBaseException {
try {
return runAsync().joinUninterruptibly();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Should never be here", e);
}
}

/**
* Runs this query.
*
* @return The data points matched by this query and applied with percentile calculation
* <p>
* Each element in the non-{@code null} but possibly empty array returned
* corresponds to one time series for which some data points have been
* matched by the query.
* @throws HBaseException if there was a problem communicating with HBase to
* perform the search.
* @throws IllegalStateException if the query is not a histogram query
*/
@Override
public DataPoints[] runHistogram() throws HBaseException {
if (!isHistogramQuery()) {
throw new RuntimeException("Should never be here");
}

try {
return runHistogramAsync().joinUninterruptibly();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Should never be here", e);
}
}
}
53 changes: 1 addition & 52 deletions src/core/SplitRollupQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.Map;
import java.util.TreeSet;

public class SplitRollupQuery implements Query {
public class SplitRollupQuery extends AbstractQuery {

private TSDB tsdb;

Expand Down Expand Up @@ -319,57 +319,6 @@ public void downsample(long interval, Aggregator downsampler, FillPolicy fill_po
rawQuery.downsample(interval, downsampler, fill_policy);
}

/**
* Runs this query.
*
* @return The data points matched by this query.
* <p>
* Each element in the non-{@code null} but possibly empty array returned
* corresponds to one time series for which some data points have been
* matched by the query.
* @throws HBaseException if there was a problem communicating with HBase to
* perform the search.
*/
@Override
public DataPoints[] run() throws HBaseException {
// TODO: Avoid duplication
try {
return runAsync().joinUninterruptibly();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Should never be here", e);
}
}

/**
* Runs this query.
*
* @return The data points matched by this query and applied with percentile calculation
* <p>
* Each element in the non-{@code null} but possibly empty array returned
* corresponds to one time series for which some data points have been
* matched by the query.
* @throws HBaseException if there was a problem communicating with HBase to
* perform the search.
* @throws IllegalStateException if the query is not a histogram query
*/
@Override
public DataPoints[] runHistogram() throws HBaseException {
// TODO: Avoid duplication
if (!isHistogramQuery()) {
throw new RuntimeException("Should never be here");
}

try {
return runHistogramAsync().joinUninterruptibly();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Should never be here", e);
}
}

/**
* Executes the query asynchronously
*
Expand Down
37 changes: 2 additions & 35 deletions src/core/TsdbQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
/**
* Non-synchronized implementation of {@link Query}.
*/
final class TsdbQuery implements Query {
final class TsdbQuery extends AbstractQuery {

private static final Logger LOG = LoggerFactory.getLogger(TsdbQuery.class);

Expand Down Expand Up @@ -739,40 +739,7 @@ private void findGroupBys() {
}
}
}
/**
* Executes the query.
* NOTE: Do not run the same query multiple times. Construct a new query with
* the same parameters again if needed
* TODO(cl) There are some strange occurrences when unit testing where the end
* time, if not set, can change between calls to run()
* @return An array of data points with one time series per array value
*/
@Override
public DataPoints[] run() throws HBaseException {
try {
return runAsync().joinUninterruptibly();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Should never be here", e);
}
}

@Override
public DataPoints[] runHistogram() throws HBaseException {
if (!isHistogramQuery()) {
throw new RuntimeException("Should never be here");
}

try {
return runHistogramAsync().joinUninterruptibly();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Should never be here", e);
}
}


@Override
public Deferred<DataPoints[]> runAsync() throws HBaseException {
Deferred<DataPoints[]> result = null;
Expand Down