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 AbstractSpanGroup
  • Loading branch information
muffix committed Nov 13, 2019
commit 0ec8bf9e29a01ac56d385f44141ad4d7a40d030e
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/AbstractSpanGroup.java \
src/core/AbstractQuery.java \
src/core/AggregationIterator.java \
src/core/Aggregator.java \
Expand Down
70 changes: 70 additions & 0 deletions src/core/AbstractSpanGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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 java.util.*;

import org.hbase.async.Bytes;
import org.hbase.async.Bytes.ByteMap;

import com.stumbleupon.async.Callback;
import com.stumbleupon.async.Deferred;

import net.opentsdb.meta.Annotation;
import net.opentsdb.rollup.RollupQuery;

/**
* Groups multiple spans together and offers a dynamic "view" on them.
* <p>
* This is used for queries to the TSDB, where we might group multiple
* {@link Span}s that are for the same time series but different tags
* together. We need to "hide" data points that are outside of the
* time period of the query and do on-the-fly aggregation of the data
* points coming from the different Spans, using an {@link Aggregator}.
* Since not all the Spans will have their data points at exactly the
* same time, we also do on-the-fly linear interpolation. If needed,
* this view can also return the rate of change instead of the actual
* data points.
* <p>
* This is one of the rare (if not the only) implementations of
* {@link DataPoints} for which {@link #getTags} can potentially return
* an empty map.
* <p>
* The implementation can also dynamically downsample the data when a
* sampling interval a downsampling function (in the form of an
* {@link Aggregator}) are given. This is done by using a special
* iterator when using the {@link Span.DownsamplingIterator}.
*/
abstract class AbstractSpanGroup implements DataPoints {
/**
* Finds the {@code i}th data point of this group in {@code O(n)}.
* Where {@code n} is the number of data points in this group.
*/
protected DataPoint getDataPoint(int i) {
if (i < 0) {
throw new IndexOutOfBoundsException("negative index: " + i);
}
final int saved_i = i;
final SeekableView it = iterator();
DataPoint dp = null;
while (it.hasNext() && i >= 0) {
dp = it.next();
i--;
}
if (i != -1 || dp == null) {
throw new IndexOutOfBoundsException("index " + saved_i
+ " too large (it's >= " + size() + ") for " + this);
}
return dp;
}
}
24 changes: 1 addition & 23 deletions src/core/SpanGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* {@link Aggregator}) are given. This is done by using a special
* iterator when using the {@link Span.DownsamplingIterator}.
*/
final class SpanGroup implements DataPoints {
final class SpanGroup extends AbstractSpanGroup {
/** Annotations */
private final ArrayList<Annotation> annotations;

Expand Down Expand Up @@ -529,28 +529,6 @@ public SeekableView iterator() {
rate, rate_options, rollup_query);
}

/**
* Finds the {@code i}th data point of this group in {@code O(n)}.
* Where {@code n} is the number of data points in this group.
*/
private DataPoint getDataPoint(int i) {
if (i < 0) {
throw new IndexOutOfBoundsException("negative index: " + i);
}
final int saved_i = i;
final SeekableView it = iterator();
DataPoint dp = null;
while (it.hasNext() && i >= 0) {
dp = it.next();
i--;
}
if (i != -1 || dp == null) {
throw new IndexOutOfBoundsException("index " + saved_i
+ " too large (it's >= " + size() + ") for " + this);
}
return dp;
}

public long timestamp(final int i) {
return getDataPoint(i).timestamp();
}
Expand Down
24 changes: 1 addition & 23 deletions src/core/SplitRollupSpanGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.List;
import java.util.Map;

public class SplitRollupSpanGroup implements DataPoints {
public class SplitRollupSpanGroup extends AbstractSpanGroup {
private final List<SpanGroup> spanGroups = new ArrayList<>();

public SplitRollupSpanGroup(SpanGroup... groups) {
Expand Down Expand Up @@ -414,26 +414,4 @@ public float getPercentile() {
public byte[] group() {
return spanGroups.get(0).group();
}

/**
* Finds the {@code i}th data point of this group in {@code O(n)}.
* Where {@code n} is the number of data points in this group.
*/
private DataPoint getDataPoint(int i) {
if (i < 0) {
throw new IndexOutOfBoundsException("negative index: " + i);
}
final int saved_i = i;
final SeekableView it = iterator();
DataPoint dp = null;
while (it.hasNext() && i >= 0) {
dp = it.next();
i--;
}
if (i != -1 || dp == null) {
throw new IndexOutOfBoundsException("index " + saved_i
+ " too large (it's >= " + size() + ") for " + this);
}
return dp;
}
}