id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
list | docstring
stringlengths 3
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 105
339
|
|---|---|---|---|---|---|---|---|---|---|---|---|
13,600
|
OpenTSDB/opentsdb
|
src/core/TSDB.java
|
TSDB.preFetchHBaseMeta
|
public void preFetchHBaseMeta() {
LOG.info("Pre-fetching meta data for all tables");
final long start = System.currentTimeMillis();
final ArrayList<Deferred<Object>> deferreds = new ArrayList<Deferred<Object>>();
deferreds.add(client.prefetchMeta(table));
deferreds.add(client.prefetchMeta(uidtable));
// TODO(cl) - meta, tree, etc
try {
Deferred.group(deferreds).join();
LOG.info("Fetched meta data for tables in " +
(System.currentTimeMillis() - start) + "ms");
} catch (InterruptedException e) {
LOG.error("Interrupted", e);
Thread.currentThread().interrupt();
return;
} catch (Exception e) {
LOG.error("Failed to prefetch meta for our tables", e);
}
}
|
java
|
public void preFetchHBaseMeta() {
LOG.info("Pre-fetching meta data for all tables");
final long start = System.currentTimeMillis();
final ArrayList<Deferred<Object>> deferreds = new ArrayList<Deferred<Object>>();
deferreds.add(client.prefetchMeta(table));
deferreds.add(client.prefetchMeta(uidtable));
// TODO(cl) - meta, tree, etc
try {
Deferred.group(deferreds).join();
LOG.info("Fetched meta data for tables in " +
(System.currentTimeMillis() - start) + "ms");
} catch (InterruptedException e) {
LOG.error("Interrupted", e);
Thread.currentThread().interrupt();
return;
} catch (Exception e) {
LOG.error("Failed to prefetch meta for our tables", e);
}
}
|
[
"public",
"void",
"preFetchHBaseMeta",
"(",
")",
"{",
"LOG",
".",
"info",
"(",
"\"Pre-fetching meta data for all tables\"",
")",
";",
"final",
"long",
"start",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"final",
"ArrayList",
"<",
"Deferred",
"<",
"Object",
">",
">",
"deferreds",
"=",
"new",
"ArrayList",
"<",
"Deferred",
"<",
"Object",
">",
">",
"(",
")",
";",
"deferreds",
".",
"add",
"(",
"client",
".",
"prefetchMeta",
"(",
"table",
")",
")",
";",
"deferreds",
".",
"add",
"(",
"client",
".",
"prefetchMeta",
"(",
"uidtable",
")",
")",
";",
"// TODO(cl) - meta, tree, etc",
"try",
"{",
"Deferred",
".",
"group",
"(",
"deferreds",
")",
".",
"join",
"(",
")",
";",
"LOG",
".",
"info",
"(",
"\"Fetched meta data for tables in \"",
"+",
"(",
"System",
".",
"currentTimeMillis",
"(",
")",
"-",
"start",
")",
"+",
"\"ms\"",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"LOG",
".",
"error",
"(",
"\"Interrupted\"",
",",
"e",
")",
";",
"Thread",
".",
"currentThread",
"(",
")",
".",
"interrupt",
"(",
")",
";",
"return",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"LOG",
".",
"error",
"(",
"\"Failed to prefetch meta for our tables\"",
",",
"e",
")",
";",
"}",
"}"
] |
Blocks while pre-fetching meta data from the data and uid tables
so that performance improves, particularly with a large number of
regions and region servers.
@since 2.2
|
[
"Blocks",
"while",
"pre",
"-",
"fetching",
"meta",
"data",
"from",
"the",
"data",
"and",
"uid",
"tables",
"so",
"that",
"performance",
"improves",
"particularly",
"with",
"a",
"large",
"number",
"of",
"regions",
"and",
"region",
"servers",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/TSDB.java#L2080-L2100
|
13,601
|
OpenTSDB/opentsdb
|
src/core/TSDB.java
|
TSDB.get
|
final Deferred<ArrayList<KeyValue>> get(final byte[] key) {
return client.get(new GetRequest(table, key, FAMILY));
}
|
java
|
final Deferred<ArrayList<KeyValue>> get(final byte[] key) {
return client.get(new GetRequest(table, key, FAMILY));
}
|
[
"final",
"Deferred",
"<",
"ArrayList",
"<",
"KeyValue",
">",
">",
"get",
"(",
"final",
"byte",
"[",
"]",
"key",
")",
"{",
"return",
"client",
".",
"get",
"(",
"new",
"GetRequest",
"(",
"table",
",",
"key",
",",
"FAMILY",
")",
")",
";",
"}"
] |
Gets the entire given row from the data table.
|
[
"Gets",
"the",
"entire",
"given",
"row",
"from",
"the",
"data",
"table",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/TSDB.java#L2175-L2177
|
13,602
|
OpenTSDB/opentsdb
|
src/core/TSDB.java
|
TSDB.put
|
final Deferred<Object> put(final byte[] key,
final byte[] qualifier,
final byte[] value,
long timestamp) {
return client.put(RequestBuilder.buildPutRequest(config, table, key, FAMILY, qualifier, value, timestamp));
}
|
java
|
final Deferred<Object> put(final byte[] key,
final byte[] qualifier,
final byte[] value,
long timestamp) {
return client.put(RequestBuilder.buildPutRequest(config, table, key, FAMILY, qualifier, value, timestamp));
}
|
[
"final",
"Deferred",
"<",
"Object",
">",
"put",
"(",
"final",
"byte",
"[",
"]",
"key",
",",
"final",
"byte",
"[",
"]",
"qualifier",
",",
"final",
"byte",
"[",
"]",
"value",
",",
"long",
"timestamp",
")",
"{",
"return",
"client",
".",
"put",
"(",
"RequestBuilder",
".",
"buildPutRequest",
"(",
"config",
",",
"table",
",",
"key",
",",
"FAMILY",
",",
"qualifier",
",",
"value",
",",
"timestamp",
")",
")",
";",
"}"
] |
Puts the given value into the data table.
|
[
"Puts",
"the",
"given",
"value",
"into",
"the",
"data",
"table",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/TSDB.java#L2180-L2185
|
13,603
|
OpenTSDB/opentsdb
|
src/core/TSDB.java
|
TSDB.delete
|
final Deferred<Object> delete(final byte[] key, final byte[][] qualifiers) {
return client.delete(new DeleteRequest(table, key, FAMILY, qualifiers));
}
|
java
|
final Deferred<Object> delete(final byte[] key, final byte[][] qualifiers) {
return client.delete(new DeleteRequest(table, key, FAMILY, qualifiers));
}
|
[
"final",
"Deferred",
"<",
"Object",
">",
"delete",
"(",
"final",
"byte",
"[",
"]",
"key",
",",
"final",
"byte",
"[",
"]",
"[",
"]",
"qualifiers",
")",
"{",
"return",
"client",
".",
"delete",
"(",
"new",
"DeleteRequest",
"(",
"table",
",",
"key",
",",
"FAMILY",
",",
"qualifiers",
")",
")",
";",
"}"
] |
Deletes the given cells from the data table.
|
[
"Deletes",
"the",
"given",
"cells",
"from",
"the",
"data",
"table",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/TSDB.java#L2188-L2190
|
13,604
|
OpenTSDB/opentsdb
|
src/tools/DumpSeries.java
|
DumpSeries.date
|
static String date(final long timestamp) {
if ((timestamp & Const.SECOND_MASK) != 0) {
return new Date(timestamp).toString();
} else {
return new Date(timestamp * 1000).toString();
}
}
|
java
|
static String date(final long timestamp) {
if ((timestamp & Const.SECOND_MASK) != 0) {
return new Date(timestamp).toString();
} else {
return new Date(timestamp * 1000).toString();
}
}
|
[
"static",
"String",
"date",
"(",
"final",
"long",
"timestamp",
")",
"{",
"if",
"(",
"(",
"timestamp",
"&",
"Const",
".",
"SECOND_MASK",
")",
"!=",
"0",
")",
"{",
"return",
"new",
"Date",
"(",
"timestamp",
")",
".",
"toString",
"(",
")",
";",
"}",
"else",
"{",
"return",
"new",
"Date",
"(",
"timestamp",
"*",
"1000",
")",
".",
"toString",
"(",
")",
";",
"}",
"}"
] |
Transforms a UNIX timestamp into a human readable date.
|
[
"Transforms",
"a",
"UNIX",
"timestamp",
"into",
"a",
"human",
"readable",
"date",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/DumpSeries.java#L294-L300
|
13,605
|
OpenTSDB/opentsdb
|
src/core/Internal.java
|
Internal.getScanners
|
public static List<Scanner> getScanners(final Query query) {
final List<Scanner> scanners = new ArrayList<Scanner>(
Const.SALT_WIDTH() > 0 ? Const.SALT_BUCKETS() : 1);
if (Const.SALT_WIDTH() > 0) {
for (int i = 0; i < Const.SALT_BUCKETS(); i++) {
scanners.add(((TsdbQuery) query).getScanner(i));
}
} else {
scanners.add(((TsdbQuery) query).getScanner());
}
return scanners;
}
|
java
|
public static List<Scanner> getScanners(final Query query) {
final List<Scanner> scanners = new ArrayList<Scanner>(
Const.SALT_WIDTH() > 0 ? Const.SALT_BUCKETS() : 1);
if (Const.SALT_WIDTH() > 0) {
for (int i = 0; i < Const.SALT_BUCKETS(); i++) {
scanners.add(((TsdbQuery) query).getScanner(i));
}
} else {
scanners.add(((TsdbQuery) query).getScanner());
}
return scanners;
}
|
[
"public",
"static",
"List",
"<",
"Scanner",
">",
"getScanners",
"(",
"final",
"Query",
"query",
")",
"{",
"final",
"List",
"<",
"Scanner",
">",
"scanners",
"=",
"new",
"ArrayList",
"<",
"Scanner",
">",
"(",
"Const",
".",
"SALT_WIDTH",
"(",
")",
">",
"0",
"?",
"Const",
".",
"SALT_BUCKETS",
"(",
")",
":",
"1",
")",
";",
"if",
"(",
"Const",
".",
"SALT_WIDTH",
"(",
")",
">",
"0",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"Const",
".",
"SALT_BUCKETS",
"(",
")",
";",
"i",
"++",
")",
"{",
"scanners",
".",
"add",
"(",
"(",
"(",
"TsdbQuery",
")",
"query",
")",
".",
"getScanner",
"(",
"i",
")",
")",
";",
"}",
"}",
"else",
"{",
"scanners",
".",
"add",
"(",
"(",
"(",
"TsdbQuery",
")",
"query",
")",
".",
"getScanner",
"(",
")",
")",
";",
"}",
"return",
"scanners",
";",
"}"
] |
Returns a set of scanners, one for each bucket if salted, or one scanner
if salting is disabled.
@see TsdbQuery#getScanner()
|
[
"Returns",
"a",
"set",
"of",
"scanners",
"one",
"for",
"each",
"bucket",
"if",
"salted",
"or",
"one",
"scanner",
"if",
"salting",
"is",
"disabled",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Internal.java#L96-L107
|
13,606
|
OpenTSDB/opentsdb
|
src/core/Internal.java
|
Internal.baseTime
|
public static long baseTime(final TSDB tsdb, final byte[] row) {
return Bytes.getUnsignedInt(row, Const.SALT_WIDTH() + TSDB.metrics_width());
}
|
java
|
public static long baseTime(final TSDB tsdb, final byte[] row) {
return Bytes.getUnsignedInt(row, Const.SALT_WIDTH() + TSDB.metrics_width());
}
|
[
"public",
"static",
"long",
"baseTime",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"byte",
"[",
"]",
"row",
")",
"{",
"return",
"Bytes",
".",
"getUnsignedInt",
"(",
"row",
",",
"Const",
".",
"SALT_WIDTH",
"(",
")",
"+",
"TSDB",
".",
"metrics_width",
"(",
")",
")",
";",
"}"
] |
Extracts the timestamp from a row key.
|
[
"Extracts",
"the",
"timestamp",
"from",
"a",
"row",
"key",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Internal.java#L115-L117
|
13,607
|
OpenTSDB/opentsdb
|
src/core/Internal.java
|
Internal.setBaseTime
|
public static void setBaseTime(final byte[] row, int base_time) {
Bytes.setInt(row, base_time, Const.SALT_WIDTH() +
TSDB.metrics_width());
}
|
java
|
public static void setBaseTime(final byte[] row, int base_time) {
Bytes.setInt(row, base_time, Const.SALT_WIDTH() +
TSDB.metrics_width());
}
|
[
"public",
"static",
"void",
"setBaseTime",
"(",
"final",
"byte",
"[",
"]",
"row",
",",
"int",
"base_time",
")",
"{",
"Bytes",
".",
"setInt",
"(",
"row",
",",
"base_time",
",",
"Const",
".",
"SALT_WIDTH",
"(",
")",
"+",
"TSDB",
".",
"metrics_width",
"(",
")",
")",
";",
"}"
] |
Sets the time in a raw data table row key
@param row The row to modify
@param base_time The base time to store
@since 2.3
|
[
"Sets",
"the",
"time",
"in",
"a",
"raw",
"data",
"table",
"row",
"key"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Internal.java#L146-L149
|
13,608
|
OpenTSDB/opentsdb
|
src/core/Internal.java
|
Internal.parseSingleValue
|
public static Cell parseSingleValue(final KeyValue column) {
if (column.qualifier().length == 2 || (column.qualifier().length == 4 &&
inMilliseconds(column.qualifier()))) {
final ArrayList<KeyValue> row = new ArrayList<KeyValue>(1);
row.add(column);
final ArrayList<Cell> cells = extractDataPoints(row, 1);
if (cells.isEmpty()) {
return null;
}
return cells.get(0);
}
throw new IllegalDataException (
"Qualifier does not appear to be a single data point: " + column);
}
|
java
|
public static Cell parseSingleValue(final KeyValue column) {
if (column.qualifier().length == 2 || (column.qualifier().length == 4 &&
inMilliseconds(column.qualifier()))) {
final ArrayList<KeyValue> row = new ArrayList<KeyValue>(1);
row.add(column);
final ArrayList<Cell> cells = extractDataPoints(row, 1);
if (cells.isEmpty()) {
return null;
}
return cells.get(0);
}
throw new IllegalDataException (
"Qualifier does not appear to be a single data point: " + column);
}
|
[
"public",
"static",
"Cell",
"parseSingleValue",
"(",
"final",
"KeyValue",
"column",
")",
"{",
"if",
"(",
"column",
".",
"qualifier",
"(",
")",
".",
"length",
"==",
"2",
"||",
"(",
"column",
".",
"qualifier",
"(",
")",
".",
"length",
"==",
"4",
"&&",
"inMilliseconds",
"(",
"column",
".",
"qualifier",
"(",
")",
")",
")",
")",
"{",
"final",
"ArrayList",
"<",
"KeyValue",
">",
"row",
"=",
"new",
"ArrayList",
"<",
"KeyValue",
">",
"(",
"1",
")",
";",
"row",
".",
"add",
"(",
"column",
")",
";",
"final",
"ArrayList",
"<",
"Cell",
">",
"cells",
"=",
"extractDataPoints",
"(",
"row",
",",
"1",
")",
";",
"if",
"(",
"cells",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"cells",
".",
"get",
"(",
"0",
")",
";",
"}",
"throw",
"new",
"IllegalDataException",
"(",
"\"Qualifier does not appear to be a single data point: \"",
"+",
"column",
")",
";",
"}"
] |
Extracts a Cell from a single data point, fixing potential errors with
the qualifier flags
@param column The column to parse
@return A Cell if successful, null if the column did not contain a data
point (i.e. it was meta data) or failed to parse
@throws IllegalDataException if the qualifier was not 2 bytes long or
it wasn't a millisecond qualifier
@since 2.0
|
[
"Extracts",
"a",
"Cell",
"from",
"a",
"single",
"data",
"point",
"fixing",
"potential",
"errors",
"with",
"the",
"qualifier",
"flags"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Internal.java#L185-L198
|
13,609
|
OpenTSDB/opentsdb
|
src/core/Internal.java
|
Internal.getValueLengthFromQualifier
|
public static byte getValueLengthFromQualifier(final byte[] qualifier,
final int offset) {
validateQualifier(qualifier, offset);
short length;
if ((qualifier[offset] & Const.MS_BYTE_FLAG) == Const.MS_BYTE_FLAG) {
length = (short) (qualifier[offset + 3] & Internal.LENGTH_MASK);
} else {
length = (short) (qualifier[offset + 1] & Internal.LENGTH_MASK);
}
return (byte) (length + 1);
}
|
java
|
public static byte getValueLengthFromQualifier(final byte[] qualifier,
final int offset) {
validateQualifier(qualifier, offset);
short length;
if ((qualifier[offset] & Const.MS_BYTE_FLAG) == Const.MS_BYTE_FLAG) {
length = (short) (qualifier[offset + 3] & Internal.LENGTH_MASK);
} else {
length = (short) (qualifier[offset + 1] & Internal.LENGTH_MASK);
}
return (byte) (length + 1);
}
|
[
"public",
"static",
"byte",
"getValueLengthFromQualifier",
"(",
"final",
"byte",
"[",
"]",
"qualifier",
",",
"final",
"int",
"offset",
")",
"{",
"validateQualifier",
"(",
"qualifier",
",",
"offset",
")",
";",
"short",
"length",
";",
"if",
"(",
"(",
"qualifier",
"[",
"offset",
"]",
"&",
"Const",
".",
"MS_BYTE_FLAG",
")",
"==",
"Const",
".",
"MS_BYTE_FLAG",
")",
"{",
"length",
"=",
"(",
"short",
")",
"(",
"qualifier",
"[",
"offset",
"+",
"3",
"]",
"&",
"Internal",
".",
"LENGTH_MASK",
")",
";",
"}",
"else",
"{",
"length",
"=",
"(",
"short",
")",
"(",
"qualifier",
"[",
"offset",
"+",
"1",
"]",
"&",
"Internal",
".",
"LENGTH_MASK",
")",
";",
"}",
"return",
"(",
"byte",
")",
"(",
"length",
"+",
"1",
")",
";",
"}"
] |
Returns the length of the value, in bytes, parsed from the qualifier
@param qualifier The qualifier to parse
@param offset An offset within the byte array
@return The length of the value in bytes, from 1 to 8.
@throws IllegalArgumentException if the qualifier is null or the offset falls
outside of the qualifier array
@since 2.0
|
[
"Returns",
"the",
"length",
"of",
"the",
"value",
"in",
"bytes",
"parsed",
"from",
"the",
"qualifier"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Internal.java#L659-L669
|
13,610
|
OpenTSDB/opentsdb
|
src/core/Internal.java
|
Internal.getFlagsFromQualifier
|
public static short getFlagsFromQualifier(final byte[] qualifier,
final int offset) {
validateQualifier(qualifier, offset);
if ((qualifier[offset] & Const.MS_BYTE_FLAG) == Const.MS_BYTE_FLAG) {
return (short) (qualifier[offset + 3] & Internal.FLAGS_MASK);
} else {
return (short) (qualifier[offset + 1] & Internal.FLAGS_MASK);
}
}
|
java
|
public static short getFlagsFromQualifier(final byte[] qualifier,
final int offset) {
validateQualifier(qualifier, offset);
if ((qualifier[offset] & Const.MS_BYTE_FLAG) == Const.MS_BYTE_FLAG) {
return (short) (qualifier[offset + 3] & Internal.FLAGS_MASK);
} else {
return (short) (qualifier[offset + 1] & Internal.FLAGS_MASK);
}
}
|
[
"public",
"static",
"short",
"getFlagsFromQualifier",
"(",
"final",
"byte",
"[",
"]",
"qualifier",
",",
"final",
"int",
"offset",
")",
"{",
"validateQualifier",
"(",
"qualifier",
",",
"offset",
")",
";",
"if",
"(",
"(",
"qualifier",
"[",
"offset",
"]",
"&",
"Const",
".",
"MS_BYTE_FLAG",
")",
"==",
"Const",
".",
"MS_BYTE_FLAG",
")",
"{",
"return",
"(",
"short",
")",
"(",
"qualifier",
"[",
"offset",
"+",
"3",
"]",
"&",
"Internal",
".",
"FLAGS_MASK",
")",
";",
"}",
"else",
"{",
"return",
"(",
"short",
")",
"(",
"qualifier",
"[",
"offset",
"+",
"1",
"]",
"&",
"Internal",
".",
"FLAGS_MASK",
")",
";",
"}",
"}"
] |
Parses the flag bits from the qualifier
@param qualifier The qualifier to parse
@param offset An offset within the byte array
@return A short representing the last 4 bits of the qualifier
@throws IllegalArgumentException if the qualifier is null or the offset falls
outside of the qualifier array
@since 2.0
|
[
"Parses",
"the",
"flag",
"bits",
"from",
"the",
"qualifier"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Internal.java#L756-L764
|
13,611
|
OpenTSDB/opentsdb
|
src/core/Internal.java
|
Internal.isFloat
|
public static boolean isFloat(final byte[] qualifier, final int offset) {
validateQualifier(qualifier, offset);
if ((qualifier[offset] & Const.MS_BYTE_FLAG) == Const.MS_BYTE_FLAG) {
return (qualifier[offset + 3] & Const.FLAG_FLOAT) == Const.FLAG_FLOAT;
} else {
return (qualifier[offset + 1] & Const.FLAG_FLOAT) == Const.FLAG_FLOAT;
}
}
|
java
|
public static boolean isFloat(final byte[] qualifier, final int offset) {
validateQualifier(qualifier, offset);
if ((qualifier[offset] & Const.MS_BYTE_FLAG) == Const.MS_BYTE_FLAG) {
return (qualifier[offset + 3] & Const.FLAG_FLOAT) == Const.FLAG_FLOAT;
} else {
return (qualifier[offset + 1] & Const.FLAG_FLOAT) == Const.FLAG_FLOAT;
}
}
|
[
"public",
"static",
"boolean",
"isFloat",
"(",
"final",
"byte",
"[",
"]",
"qualifier",
",",
"final",
"int",
"offset",
")",
"{",
"validateQualifier",
"(",
"qualifier",
",",
"offset",
")",
";",
"if",
"(",
"(",
"qualifier",
"[",
"offset",
"]",
"&",
"Const",
".",
"MS_BYTE_FLAG",
")",
"==",
"Const",
".",
"MS_BYTE_FLAG",
")",
"{",
"return",
"(",
"qualifier",
"[",
"offset",
"+",
"3",
"]",
"&",
"Const",
".",
"FLAG_FLOAT",
")",
"==",
"Const",
".",
"FLAG_FLOAT",
";",
"}",
"else",
"{",
"return",
"(",
"qualifier",
"[",
"offset",
"+",
"1",
"]",
"&",
"Const",
".",
"FLAG_FLOAT",
")",
"==",
"Const",
".",
"FLAG_FLOAT",
";",
"}",
"}"
] |
Parses the qualifier to determine if the data is a floating point value.
4 bytes == Float, 8 bytes == Double
@param qualifier The qualifier to parse
@param offset An offset within the byte array
@return True if the encoded data is a floating point value
@throws IllegalArgumentException if the qualifier is null or the offset falls
outside of the qualifier array
@since 2.1
|
[
"Parses",
"the",
"qualifier",
"to",
"determine",
"if",
"the",
"data",
"is",
"a",
"floating",
"point",
"value",
".",
"4",
"bytes",
"==",
"Float",
"8",
"bytes",
"==",
"Double"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Internal.java#L789-L796
|
13,612
|
OpenTSDB/opentsdb
|
src/core/Internal.java
|
Internal.extractQualifier
|
public static byte[] extractQualifier(final byte[] qualifier,
final int offset) {
validateQualifier(qualifier, offset);
if ((qualifier[offset] & Const.MS_BYTE_FLAG) == Const.MS_BYTE_FLAG) {
return new byte[] { qualifier[offset], qualifier[offset + 1],
qualifier[offset + 2], qualifier[offset + 3] };
} else {
return new byte[] { qualifier[offset], qualifier[offset + 1] };
}
}
|
java
|
public static byte[] extractQualifier(final byte[] qualifier,
final int offset) {
validateQualifier(qualifier, offset);
if ((qualifier[offset] & Const.MS_BYTE_FLAG) == Const.MS_BYTE_FLAG) {
return new byte[] { qualifier[offset], qualifier[offset + 1],
qualifier[offset + 2], qualifier[offset + 3] };
} else {
return new byte[] { qualifier[offset], qualifier[offset + 1] };
}
}
|
[
"public",
"static",
"byte",
"[",
"]",
"extractQualifier",
"(",
"final",
"byte",
"[",
"]",
"qualifier",
",",
"final",
"int",
"offset",
")",
"{",
"validateQualifier",
"(",
"qualifier",
",",
"offset",
")",
";",
"if",
"(",
"(",
"qualifier",
"[",
"offset",
"]",
"&",
"Const",
".",
"MS_BYTE_FLAG",
")",
"==",
"Const",
".",
"MS_BYTE_FLAG",
")",
"{",
"return",
"new",
"byte",
"[",
"]",
"{",
"qualifier",
"[",
"offset",
"]",
",",
"qualifier",
"[",
"offset",
"+",
"1",
"]",
",",
"qualifier",
"[",
"offset",
"+",
"2",
"]",
",",
"qualifier",
"[",
"offset",
"+",
"3",
"]",
"}",
";",
"}",
"else",
"{",
"return",
"new",
"byte",
"[",
"]",
"{",
"qualifier",
"[",
"offset",
"]",
",",
"qualifier",
"[",
"offset",
"+",
"1",
"]",
"}",
";",
"}",
"}"
] |
Extracts the 2 or 4 byte qualifier from a compacted byte array
@param qualifier The qualifier to parse
@param offset An offset within the byte array
@return A byte array with only the requested qualifier
@throws IllegalArgumentException if the qualifier is null or the offset falls
outside of the qualifier array
@since 2.0
|
[
"Extracts",
"the",
"2",
"or",
"4",
"byte",
"qualifier",
"from",
"a",
"compacted",
"byte",
"array"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Internal.java#L807-L816
|
13,613
|
OpenTSDB/opentsdb
|
src/core/Internal.java
|
Internal.buildQualifier
|
public static byte[] buildQualifier(final long timestamp, final short flags) {
final long base_time;
if ((timestamp & Const.SECOND_MASK) != 0) {
// drop the ms timestamp to seconds to calculate the base timestamp
base_time = ((timestamp / 1000) - ((timestamp / 1000)
% Const.MAX_TIMESPAN));
final int qual = (int) (((timestamp - (base_time * 1000)
<< (Const.MS_FLAG_BITS)) | flags) | Const.MS_FLAG);
return Bytes.fromInt(qual);
} else {
base_time = (timestamp - (timestamp % Const.MAX_TIMESPAN));
final short qual = (short) ((timestamp - base_time) << Const.FLAG_BITS
| flags);
return Bytes.fromShort(qual);
}
}
|
java
|
public static byte[] buildQualifier(final long timestamp, final short flags) {
final long base_time;
if ((timestamp & Const.SECOND_MASK) != 0) {
// drop the ms timestamp to seconds to calculate the base timestamp
base_time = ((timestamp / 1000) - ((timestamp / 1000)
% Const.MAX_TIMESPAN));
final int qual = (int) (((timestamp - (base_time * 1000)
<< (Const.MS_FLAG_BITS)) | flags) | Const.MS_FLAG);
return Bytes.fromInt(qual);
} else {
base_time = (timestamp - (timestamp % Const.MAX_TIMESPAN));
final short qual = (short) ((timestamp - base_time) << Const.FLAG_BITS
| flags);
return Bytes.fromShort(qual);
}
}
|
[
"public",
"static",
"byte",
"[",
"]",
"buildQualifier",
"(",
"final",
"long",
"timestamp",
",",
"final",
"short",
"flags",
")",
"{",
"final",
"long",
"base_time",
";",
"if",
"(",
"(",
"timestamp",
"&",
"Const",
".",
"SECOND_MASK",
")",
"!=",
"0",
")",
"{",
"// drop the ms timestamp to seconds to calculate the base timestamp",
"base_time",
"=",
"(",
"(",
"timestamp",
"/",
"1000",
")",
"-",
"(",
"(",
"timestamp",
"/",
"1000",
")",
"%",
"Const",
".",
"MAX_TIMESPAN",
")",
")",
";",
"final",
"int",
"qual",
"=",
"(",
"int",
")",
"(",
"(",
"(",
"timestamp",
"-",
"(",
"base_time",
"*",
"1000",
")",
"<<",
"(",
"Const",
".",
"MS_FLAG_BITS",
")",
")",
"|",
"flags",
")",
"|",
"Const",
".",
"MS_FLAG",
")",
";",
"return",
"Bytes",
".",
"fromInt",
"(",
"qual",
")",
";",
"}",
"else",
"{",
"base_time",
"=",
"(",
"timestamp",
"-",
"(",
"timestamp",
"%",
"Const",
".",
"MAX_TIMESPAN",
")",
")",
";",
"final",
"short",
"qual",
"=",
"(",
"short",
")",
"(",
"(",
"timestamp",
"-",
"base_time",
")",
"<<",
"Const",
".",
"FLAG_BITS",
"|",
"flags",
")",
";",
"return",
"Bytes",
".",
"fromShort",
"(",
"qual",
")",
";",
"}",
"}"
] |
Returns a 2 or 4 byte qualifier based on the timestamp and the flags. If
the timestamp is in seconds, this returns a 2 byte qualifier. If it's in
milliseconds, returns a 4 byte qualifier
@param timestamp A Unix epoch timestamp in seconds or milliseconds
@param flags Flags to set on the qualifier (length &| float)
@return A 2 or 4 byte qualifier for storage in column or compacted column
@since 2.0
|
[
"Returns",
"a",
"2",
"or",
"4",
"byte",
"qualifier",
"based",
"on",
"the",
"timestamp",
"and",
"the",
"flags",
".",
"If",
"the",
"timestamp",
"is",
"in",
"seconds",
"this",
"returns",
"a",
"2",
"byte",
"qualifier",
".",
"If",
"it",
"s",
"in",
"milliseconds",
"returns",
"a",
"4",
"byte",
"qualifier"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Internal.java#L827-L842
|
13,614
|
OpenTSDB/opentsdb
|
src/core/Internal.java
|
Internal.validateQualifier
|
private static void validateQualifier(final byte[] qualifier,
final int offset) {
if (offset < 0 || offset >= qualifier.length - 1) {
throw new IllegalDataException("Offset of [" + offset +
"] is out of bounds for the qualifier length of [" +
qualifier.length + "]");
}
}
|
java
|
private static void validateQualifier(final byte[] qualifier,
final int offset) {
if (offset < 0 || offset >= qualifier.length - 1) {
throw new IllegalDataException("Offset of [" + offset +
"] is out of bounds for the qualifier length of [" +
qualifier.length + "]");
}
}
|
[
"private",
"static",
"void",
"validateQualifier",
"(",
"final",
"byte",
"[",
"]",
"qualifier",
",",
"final",
"int",
"offset",
")",
"{",
"if",
"(",
"offset",
"<",
"0",
"||",
"offset",
">=",
"qualifier",
".",
"length",
"-",
"1",
")",
"{",
"throw",
"new",
"IllegalDataException",
"(",
"\"Offset of [\"",
"+",
"offset",
"+",
"\"] is out of bounds for the qualifier length of [\"",
"+",
"qualifier",
".",
"length",
"+",
"\"]\"",
")",
";",
"}",
"}"
] |
Checks the qualifier to verify that it has data and that the offset is
within bounds
@param qualifier The qualifier to validate
@param offset An optional offset
@throws IllegalDataException if the qualifier is null or the offset falls
outside of the qualifier array
@since 2.0
|
[
"Checks",
"the",
"qualifier",
"to",
"verify",
"that",
"it",
"has",
"data",
"and",
"that",
"the",
"offset",
"is",
"within",
"bounds"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Internal.java#L853-L860
|
13,615
|
OpenTSDB/opentsdb
|
src/core/Internal.java
|
Internal.getMaxUnsignedValueOnBytes
|
public static long getMaxUnsignedValueOnBytes(final int width) {
if (width < 0 || width > 8) {
throw new IllegalArgumentException("Width must be from 1 to 8 bytes: "
+ width);
}
if (width < 8) {
return ((long) 1 << width * Byte.SIZE) - 1;
} else {
return Long.MAX_VALUE;
}
}
|
java
|
public static long getMaxUnsignedValueOnBytes(final int width) {
if (width < 0 || width > 8) {
throw new IllegalArgumentException("Width must be from 1 to 8 bytes: "
+ width);
}
if (width < 8) {
return ((long) 1 << width * Byte.SIZE) - 1;
} else {
return Long.MAX_VALUE;
}
}
|
[
"public",
"static",
"long",
"getMaxUnsignedValueOnBytes",
"(",
"final",
"int",
"width",
")",
"{",
"if",
"(",
"width",
"<",
"0",
"||",
"width",
">",
"8",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Width must be from 1 to 8 bytes: \"",
"+",
"width",
")",
";",
"}",
"if",
"(",
"width",
"<",
"8",
")",
"{",
"return",
"(",
"(",
"long",
")",
"1",
"<<",
"width",
"*",
"Byte",
".",
"SIZE",
")",
"-",
"1",
";",
"}",
"else",
"{",
"return",
"Long",
".",
"MAX_VALUE",
";",
"}",
"}"
] |
Simple helper to calculate the max value for any width of long from 0 to 8
bytes.
@param width The width of the byte array we're comparing
@return The maximum unsigned integer value on {@code width} bytes. Note:
If you ask for 8 bytes, it will return the max signed value. This is due
to Java lacking unsigned integers... *sigh*.
@since 2.2
|
[
"Simple",
"helper",
"to",
"calculate",
"the",
"max",
"value",
"for",
"any",
"width",
"of",
"long",
"from",
"0",
"to",
"8",
"bytes",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Internal.java#L924-L934
|
13,616
|
OpenTSDB/opentsdb
|
src/core/Internal.java
|
Internal.vleEncodeLong
|
public static byte[] vleEncodeLong(final long value) {
if (Byte.MIN_VALUE <= value && value <= Byte.MAX_VALUE) {
return new byte[] { (byte) value };
} else if (Short.MIN_VALUE <= value && value <= Short.MAX_VALUE) {
return Bytes.fromShort((short) value);
} else if (Integer.MIN_VALUE <= value && value <= Integer.MAX_VALUE) {
return Bytes.fromInt((int) value);
} else {
return Bytes.fromLong(value);
}
}
|
java
|
public static byte[] vleEncodeLong(final long value) {
if (Byte.MIN_VALUE <= value && value <= Byte.MAX_VALUE) {
return new byte[] { (byte) value };
} else if (Short.MIN_VALUE <= value && value <= Short.MAX_VALUE) {
return Bytes.fromShort((short) value);
} else if (Integer.MIN_VALUE <= value && value <= Integer.MAX_VALUE) {
return Bytes.fromInt((int) value);
} else {
return Bytes.fromLong(value);
}
}
|
[
"public",
"static",
"byte",
"[",
"]",
"vleEncodeLong",
"(",
"final",
"long",
"value",
")",
"{",
"if",
"(",
"Byte",
".",
"MIN_VALUE",
"<=",
"value",
"&&",
"value",
"<=",
"Byte",
".",
"MAX_VALUE",
")",
"{",
"return",
"new",
"byte",
"[",
"]",
"{",
"(",
"byte",
")",
"value",
"}",
";",
"}",
"else",
"if",
"(",
"Short",
".",
"MIN_VALUE",
"<=",
"value",
"&&",
"value",
"<=",
"Short",
".",
"MAX_VALUE",
")",
"{",
"return",
"Bytes",
".",
"fromShort",
"(",
"(",
"short",
")",
"value",
")",
";",
"}",
"else",
"if",
"(",
"Integer",
".",
"MIN_VALUE",
"<=",
"value",
"&&",
"value",
"<=",
"Integer",
".",
"MAX_VALUE",
")",
"{",
"return",
"Bytes",
".",
"fromInt",
"(",
"(",
"int",
")",
"value",
")",
";",
"}",
"else",
"{",
"return",
"Bytes",
".",
"fromLong",
"(",
"value",
")",
";",
"}",
"}"
] |
Encodes a long on 1, 2, 4 or 8 bytes
@param value The value to encode
@return A byte array containing the encoded value
@since 2.4
|
[
"Encodes",
"a",
"long",
"on",
"1",
"2",
"4",
"or",
"8",
"bytes"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Internal.java#L942-L952
|
13,617
|
OpenTSDB/opentsdb
|
src/core/Internal.java
|
Internal.getTimeStampFromNonDP
|
public static long getTimeStampFromNonDP(final long base_time, byte[] quantifier) {
long ret = base_time;
if (quantifier.length == 3) {
ret += quantifier[1] << 8 | (quantifier[2] & 0xFF);
ret *= 1000;
} else if (quantifier.length == 5) {
ret *= 1000;
ret += (quantifier[1] & 0xFF) << 24 | (quantifier[2] & 0xFF) << 16
| (quantifier[3] & 0xFF) << 8 | quantifier[4] & 0xFF;
} else {
throw new IllegalArgumentException("Quantifier is not valid: " + Bytes.pretty(quantifier));
}
return ret;
}
|
java
|
public static long getTimeStampFromNonDP(final long base_time, byte[] quantifier) {
long ret = base_time;
if (quantifier.length == 3) {
ret += quantifier[1] << 8 | (quantifier[2] & 0xFF);
ret *= 1000;
} else if (quantifier.length == 5) {
ret *= 1000;
ret += (quantifier[1] & 0xFF) << 24 | (quantifier[2] & 0xFF) << 16
| (quantifier[3] & 0xFF) << 8 | quantifier[4] & 0xFF;
} else {
throw new IllegalArgumentException("Quantifier is not valid: " + Bytes.pretty(quantifier));
}
return ret;
}
|
[
"public",
"static",
"long",
"getTimeStampFromNonDP",
"(",
"final",
"long",
"base_time",
",",
"byte",
"[",
"]",
"quantifier",
")",
"{",
"long",
"ret",
"=",
"base_time",
";",
"if",
"(",
"quantifier",
".",
"length",
"==",
"3",
")",
"{",
"ret",
"+=",
"quantifier",
"[",
"1",
"]",
"<<",
"8",
"|",
"(",
"quantifier",
"[",
"2",
"]",
"&",
"0xFF",
")",
";",
"ret",
"*=",
"1000",
";",
"}",
"else",
"if",
"(",
"quantifier",
".",
"length",
"==",
"5",
")",
"{",
"ret",
"*=",
"1000",
";",
"ret",
"+=",
"(",
"quantifier",
"[",
"1",
"]",
"&",
"0xFF",
")",
"<<",
"24",
"|",
"(",
"quantifier",
"[",
"2",
"]",
"&",
"0xFF",
")",
"<<",
"16",
"|",
"(",
"quantifier",
"[",
"3",
"]",
"&",
"0xFF",
")",
"<<",
"8",
"|",
"quantifier",
"[",
"4",
"]",
"&",
"0xFF",
";",
"}",
"else",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Quantifier is not valid: \"",
"+",
"Bytes",
".",
"pretty",
"(",
"quantifier",
")",
")",
";",
"}",
"return",
"ret",
";",
"}"
] |
Get timestamp from base time and quantifier for non datapoints. The returned time
will always be in ms.
@param base_time the base time of the point
@param quantifier the quantifier of the point, it is expected to be either length of
3 or length of 5 (the first byte represents the type of the point)
@return The timestamp in ms
|
[
"Get",
"timestamp",
"from",
"base",
"time",
"and",
"quantifier",
"for",
"non",
"datapoints",
".",
"The",
"returned",
"time",
"will",
"always",
"be",
"in",
"ms",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Internal.java#L1038-L1053
|
13,618
|
OpenTSDB/opentsdb
|
src/core/Internal.java
|
Internal.decodeHistogramDataPoint
|
public static HistogramDataPoint decodeHistogramDataPoint(final TSDB tsdb,
final KeyValue kv) {
long timestamp = Internal.baseTime(kv.key());
return decodeHistogramDataPoint(tsdb, timestamp, kv.qualifier(), kv.value());
}
|
java
|
public static HistogramDataPoint decodeHistogramDataPoint(final TSDB tsdb,
final KeyValue kv) {
long timestamp = Internal.baseTime(kv.key());
return decodeHistogramDataPoint(tsdb, timestamp, kv.qualifier(), kv.value());
}
|
[
"public",
"static",
"HistogramDataPoint",
"decodeHistogramDataPoint",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"KeyValue",
"kv",
")",
"{",
"long",
"timestamp",
"=",
"Internal",
".",
"baseTime",
"(",
"kv",
".",
"key",
"(",
")",
")",
";",
"return",
"decodeHistogramDataPoint",
"(",
"tsdb",
",",
"timestamp",
",",
"kv",
".",
"qualifier",
"(",
")",
",",
"kv",
".",
"value",
"(",
")",
")",
";",
"}"
] |
Decode the histogram point from the given key value
@param kv the key value that contains a histogram
@return the decoded {@code HistogramDataPoint}
|
[
"Decode",
"the",
"histogram",
"point",
"from",
"the",
"given",
"key",
"value"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Internal.java#L1060-L1064
|
13,619
|
OpenTSDB/opentsdb
|
src/core/Internal.java
|
Internal.decodeHistogramDataPoint
|
public static HistogramDataPoint decodeHistogramDataPoint(final TSDB tsdb,
final long base_time,
final byte[] qualifier,
final byte[] value) {
final HistogramDataPointCodec decoder =
tsdb.histogramManager().getCodec((int) value[0]);
long timestamp = getTimeStampFromNonDP(base_time, qualifier);
final Histogram histogram = decoder.decode(value, true);
return new SimpleHistogramDataPointAdapter(histogram, timestamp);
}
|
java
|
public static HistogramDataPoint decodeHistogramDataPoint(final TSDB tsdb,
final long base_time,
final byte[] qualifier,
final byte[] value) {
final HistogramDataPointCodec decoder =
tsdb.histogramManager().getCodec((int) value[0]);
long timestamp = getTimeStampFromNonDP(base_time, qualifier);
final Histogram histogram = decoder.decode(value, true);
return new SimpleHistogramDataPointAdapter(histogram, timestamp);
}
|
[
"public",
"static",
"HistogramDataPoint",
"decodeHistogramDataPoint",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"long",
"base_time",
",",
"final",
"byte",
"[",
"]",
"qualifier",
",",
"final",
"byte",
"[",
"]",
"value",
")",
"{",
"final",
"HistogramDataPointCodec",
"decoder",
"=",
"tsdb",
".",
"histogramManager",
"(",
")",
".",
"getCodec",
"(",
"(",
"int",
")",
"value",
"[",
"0",
"]",
")",
";",
"long",
"timestamp",
"=",
"getTimeStampFromNonDP",
"(",
"base_time",
",",
"qualifier",
")",
";",
"final",
"Histogram",
"histogram",
"=",
"decoder",
".",
"decode",
"(",
"value",
",",
"true",
")",
";",
"return",
"new",
"SimpleHistogramDataPointAdapter",
"(",
"histogram",
",",
"timestamp",
")",
";",
"}"
] |
Decode the histogram point from the given key and values
@param tsdb The TSDB to use when fetching the decoder manager.
@param base_time the base time of the histogram
@param qualifier the qualifier used to store the histogram
@param value the encoded value of the histogram
@return the decoded {@code HistogramDataPoint}
|
[
"Decode",
"the",
"histogram",
"point",
"from",
"the",
"given",
"key",
"and",
"values"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/Internal.java#L1074-L1083
|
13,620
|
OpenTSDB/opentsdb
|
src/rollup/RollupQuery.java
|
RollupQuery.isValidQuery
|
public static boolean isValidQuery(final RollupQuery rollup_query) {
return (rollup_query != null && rollup_query.rollup_interval != null &&
!rollup_query.rollup_interval.isDefaultInterval());
}
|
java
|
public static boolean isValidQuery(final RollupQuery rollup_query) {
return (rollup_query != null && rollup_query.rollup_interval != null &&
!rollup_query.rollup_interval.isDefaultInterval());
}
|
[
"public",
"static",
"boolean",
"isValidQuery",
"(",
"final",
"RollupQuery",
"rollup_query",
")",
"{",
"return",
"(",
"rollup_query",
"!=",
"null",
"&&",
"rollup_query",
".",
"rollup_interval",
"!=",
"null",
"&&",
"!",
"rollup_query",
".",
"rollup_interval",
".",
"isDefaultInterval",
"(",
")",
")",
";",
"}"
] |
Does it contain a valid rollup interval, mainly says it is not the default
rollup. Default rollup is of same resolution as raw data. So if true,
which means the raw cell column qualifier is encoded with the aggregate
function and the cell is not appended or compacted
@param rollup_query related RollupQuery object, null if rollup is disabled
@return true if it is rollup query
|
[
"Does",
"it",
"contain",
"a",
"valid",
"rollup",
"interval",
"mainly",
"says",
"it",
"is",
"not",
"the",
"default",
"rollup",
".",
"Default",
"rollup",
"is",
"of",
"same",
"resolution",
"as",
"raw",
"data",
".",
"So",
"if",
"true",
"which",
"means",
"the",
"raw",
"cell",
"column",
"qualifier",
"is",
"encoded",
"with",
"the",
"aggregate",
"function",
"and",
"the",
"cell",
"is",
"not",
"appended",
"or",
"compacted"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/rollup/RollupQuery.java#L161-L164
|
13,621
|
OpenTSDB/opentsdb
|
src/meta/TSUIDQuery.java
|
TSUIDQuery.setQuery
|
public void setQuery(final String metric, final Map<String, String> tags) {
this.metric = metric;
this.tags = tags;
metric_uid = tsdb.getUID(UniqueIdType.METRIC, metric);
tag_uids = Tags.resolveAll(tsdb, tags);
}
|
java
|
public void setQuery(final String metric, final Map<String, String> tags) {
this.metric = metric;
this.tags = tags;
metric_uid = tsdb.getUID(UniqueIdType.METRIC, metric);
tag_uids = Tags.resolveAll(tsdb, tags);
}
|
[
"public",
"void",
"setQuery",
"(",
"final",
"String",
"metric",
",",
"final",
"Map",
"<",
"String",
",",
"String",
">",
"tags",
")",
"{",
"this",
".",
"metric",
"=",
"metric",
";",
"this",
".",
"tags",
"=",
"tags",
";",
"metric_uid",
"=",
"tsdb",
".",
"getUID",
"(",
"UniqueIdType",
".",
"METRIC",
",",
"metric",
")",
";",
"tag_uids",
"=",
"Tags",
".",
"resolveAll",
"(",
"tsdb",
",",
"tags",
")",
";",
"}"
] |
Sets the query to perform
@param metric Name of the metric to search for
@param tags A map of tag value pairs or simply an empty map
@throws NoSuchUniqueName if the metric or any of the tag names/values did
not exist
@deprecated Please use one of the constructors instead. Will be removed in 2.3
|
[
"Sets",
"the",
"query",
"to",
"perform"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/meta/TSUIDQuery.java#L227-L232
|
13,622
|
OpenTSDB/opentsdb
|
src/meta/TSUIDQuery.java
|
TSUIDQuery.tsuidFromMetric
|
public static Deferred<byte[]> tsuidFromMetric(final TSDB tsdb,
final String metric, final Map<String, String> tags) {
if (metric == null || metric.isEmpty()) {
throw new IllegalArgumentException("The metric cannot be empty");
}
if (tags == null || tags.isEmpty()) {
throw new IllegalArgumentException("Tags cannot be null or empty "
+ "when getting a TSUID");
}
final byte[] metric_uid = new byte[TSDB.metrics_width()];
class TagsCB implements Callback<byte[], ArrayList<byte[]>> {
@Override
public byte[] call(final ArrayList<byte[]> tag_list) throws Exception {
final byte[] tsuid = new byte[metric_uid.length +
((TSDB.tagk_width() + TSDB.tagv_width())
* tag_list.size())];
int idx = 0;
System.arraycopy(metric_uid, 0, tsuid, 0, metric_uid.length);
idx += metric_uid.length;
for (final byte[] t : tag_list) {
System.arraycopy(t, 0, tsuid, idx, t.length);
idx += t.length;
}
return tsuid;
}
@Override
public String toString() {
return "Tag resolution callback";
}
}
class MetricCB implements Callback<Deferred<byte[]>, byte[]> {
@Override
public Deferred<byte[]> call(final byte[] uid)
throws Exception {
System.arraycopy(uid, 0, metric_uid, 0, uid.length);
return Tags.resolveAllAsync(tsdb, tags).addCallback(new TagsCB());
}
@Override
public String toString() {
return "Metric resolution callback";
}
}
return tsdb.getUIDAsync(UniqueIdType.METRIC, metric)
.addCallbackDeferring(new MetricCB());
}
|
java
|
public static Deferred<byte[]> tsuidFromMetric(final TSDB tsdb,
final String metric, final Map<String, String> tags) {
if (metric == null || metric.isEmpty()) {
throw new IllegalArgumentException("The metric cannot be empty");
}
if (tags == null || tags.isEmpty()) {
throw new IllegalArgumentException("Tags cannot be null or empty "
+ "when getting a TSUID");
}
final byte[] metric_uid = new byte[TSDB.metrics_width()];
class TagsCB implements Callback<byte[], ArrayList<byte[]>> {
@Override
public byte[] call(final ArrayList<byte[]> tag_list) throws Exception {
final byte[] tsuid = new byte[metric_uid.length +
((TSDB.tagk_width() + TSDB.tagv_width())
* tag_list.size())];
int idx = 0;
System.arraycopy(metric_uid, 0, tsuid, 0, metric_uid.length);
idx += metric_uid.length;
for (final byte[] t : tag_list) {
System.arraycopy(t, 0, tsuid, idx, t.length);
idx += t.length;
}
return tsuid;
}
@Override
public String toString() {
return "Tag resolution callback";
}
}
class MetricCB implements Callback<Deferred<byte[]>, byte[]> {
@Override
public Deferred<byte[]> call(final byte[] uid)
throws Exception {
System.arraycopy(uid, 0, metric_uid, 0, uid.length);
return Tags.resolveAllAsync(tsdb, tags).addCallback(new TagsCB());
}
@Override
public String toString() {
return "Metric resolution callback";
}
}
return tsdb.getUIDAsync(UniqueIdType.METRIC, metric)
.addCallbackDeferring(new MetricCB());
}
|
[
"public",
"static",
"Deferred",
"<",
"byte",
"[",
"]",
">",
"tsuidFromMetric",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"String",
"metric",
",",
"final",
"Map",
"<",
"String",
",",
"String",
">",
"tags",
")",
"{",
"if",
"(",
"metric",
"==",
"null",
"||",
"metric",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"The metric cannot be empty\"",
")",
";",
"}",
"if",
"(",
"tags",
"==",
"null",
"||",
"tags",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Tags cannot be null or empty \"",
"+",
"\"when getting a TSUID\"",
")",
";",
"}",
"final",
"byte",
"[",
"]",
"metric_uid",
"=",
"new",
"byte",
"[",
"TSDB",
".",
"metrics_width",
"(",
")",
"]",
";",
"class",
"TagsCB",
"implements",
"Callback",
"<",
"byte",
"[",
"]",
",",
"ArrayList",
"<",
"byte",
"[",
"]",
">",
">",
"{",
"@",
"Override",
"public",
"byte",
"[",
"]",
"call",
"(",
"final",
"ArrayList",
"<",
"byte",
"[",
"]",
">",
"tag_list",
")",
"throws",
"Exception",
"{",
"final",
"byte",
"[",
"]",
"tsuid",
"=",
"new",
"byte",
"[",
"metric_uid",
".",
"length",
"+",
"(",
"(",
"TSDB",
".",
"tagk_width",
"(",
")",
"+",
"TSDB",
".",
"tagv_width",
"(",
")",
")",
"*",
"tag_list",
".",
"size",
"(",
")",
")",
"]",
";",
"int",
"idx",
"=",
"0",
";",
"System",
".",
"arraycopy",
"(",
"metric_uid",
",",
"0",
",",
"tsuid",
",",
"0",
",",
"metric_uid",
".",
"length",
")",
";",
"idx",
"+=",
"metric_uid",
".",
"length",
";",
"for",
"(",
"final",
"byte",
"[",
"]",
"t",
":",
"tag_list",
")",
"{",
"System",
".",
"arraycopy",
"(",
"t",
",",
"0",
",",
"tsuid",
",",
"idx",
",",
"t",
".",
"length",
")",
";",
"idx",
"+=",
"t",
".",
"length",
";",
"}",
"return",
"tsuid",
";",
"}",
"@",
"Override",
"public",
"String",
"toString",
"(",
")",
"{",
"return",
"\"Tag resolution callback\"",
";",
"}",
"}",
"class",
"MetricCB",
"implements",
"Callback",
"<",
"Deferred",
"<",
"byte",
"[",
"]",
">",
",",
"byte",
"[",
"]",
">",
"{",
"@",
"Override",
"public",
"Deferred",
"<",
"byte",
"[",
"]",
">",
"call",
"(",
"final",
"byte",
"[",
"]",
"uid",
")",
"throws",
"Exception",
"{",
"System",
".",
"arraycopy",
"(",
"uid",
",",
"0",
",",
"metric_uid",
",",
"0",
",",
"uid",
".",
"length",
")",
";",
"return",
"Tags",
".",
"resolveAllAsync",
"(",
"tsdb",
",",
"tags",
")",
".",
"addCallback",
"(",
"new",
"TagsCB",
"(",
")",
")",
";",
"}",
"@",
"Override",
"public",
"String",
"toString",
"(",
")",
"{",
"return",
"\"Metric resolution callback\"",
";",
"}",
"}",
"return",
"tsdb",
".",
"getUIDAsync",
"(",
"UniqueIdType",
".",
"METRIC",
",",
"metric",
")",
".",
"addCallbackDeferring",
"(",
"new",
"MetricCB",
"(",
")",
")",
";",
"}"
] |
Converts the given metric and tags to a TSUID by resolving the strings to
their UIDs. Note that the resulting TSUID may not exist if the combination
was not written to TSDB
@param tsdb The TSDB to use for storage access
@param metric The metric name to resolve
@param tags The tags to resolve. May not be empty.
@return A deferred containing the TSUID when ready or an error such as
a NoSuchUniqueName exception if the metric didn't exist or a
DeferredGroupException if one of the tag keys or values did not exist.
@throws IllegalArgumentException if the metric or tags were null or
empty.
|
[
"Converts",
"the",
"given",
"metric",
"and",
"tags",
"to",
"a",
"TSUID",
"by",
"resolving",
"the",
"strings",
"to",
"their",
"UIDs",
".",
"Note",
"that",
"the",
"resulting",
"TSUID",
"may",
"not",
"exist",
"if",
"the",
"combination",
"was",
"not",
"written",
"to",
"TSDB"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/meta/TSUIDQuery.java#L475-L523
|
13,623
|
OpenTSDB/opentsdb
|
src/meta/TSUIDQuery.java
|
TSUIDQuery.resolveNames
|
private Deferred<IncomingDataPoint> resolveNames(final IncomingDataPoint dp) {
// If the caller gave us a metric and tags, save some time by NOT hitting
// our UID tables or storage.
if (metric != null) {
dp.setMetric(metric);
dp.setTags((HashMap<String, String>)tags);
return Deferred.fromResult(dp);
}
class TagsCB implements Callback<IncomingDataPoint, HashMap<String, String>> {
public IncomingDataPoint call(final HashMap<String, String> tags)
throws Exception {
dp.setTags(tags);
return dp;
}
@Override
public String toString() {
return "Tags resolution CB";
}
}
class MetricCB implements Callback<Deferred<IncomingDataPoint>, String> {
public Deferred<IncomingDataPoint> call(final String name)
throws Exception {
dp.setMetric(name);
final List<byte[]> tags = UniqueId.getTagPairsFromTSUID(tsuid);
return Tags.resolveIdsAsync(tsdb, tags).addCallback(new TagsCB());
}
@Override
public String toString() {
return "Metric resolution CB";
}
}
final byte[] metric_uid = Arrays.copyOfRange(tsuid, 0, TSDB.metrics_width());
return tsdb.getUidName(UniqueIdType.METRIC, metric_uid)
.addCallbackDeferring(new MetricCB());
}
|
java
|
private Deferred<IncomingDataPoint> resolveNames(final IncomingDataPoint dp) {
// If the caller gave us a metric and tags, save some time by NOT hitting
// our UID tables or storage.
if (metric != null) {
dp.setMetric(metric);
dp.setTags((HashMap<String, String>)tags);
return Deferred.fromResult(dp);
}
class TagsCB implements Callback<IncomingDataPoint, HashMap<String, String>> {
public IncomingDataPoint call(final HashMap<String, String> tags)
throws Exception {
dp.setTags(tags);
return dp;
}
@Override
public String toString() {
return "Tags resolution CB";
}
}
class MetricCB implements Callback<Deferred<IncomingDataPoint>, String> {
public Deferred<IncomingDataPoint> call(final String name)
throws Exception {
dp.setMetric(name);
final List<byte[]> tags = UniqueId.getTagPairsFromTSUID(tsuid);
return Tags.resolveIdsAsync(tsdb, tags).addCallback(new TagsCB());
}
@Override
public String toString() {
return "Metric resolution CB";
}
}
final byte[] metric_uid = Arrays.copyOfRange(tsuid, 0, TSDB.metrics_width());
return tsdb.getUidName(UniqueIdType.METRIC, metric_uid)
.addCallbackDeferring(new MetricCB());
}
|
[
"private",
"Deferred",
"<",
"IncomingDataPoint",
">",
"resolveNames",
"(",
"final",
"IncomingDataPoint",
"dp",
")",
"{",
"// If the caller gave us a metric and tags, save some time by NOT hitting",
"// our UID tables or storage.",
"if",
"(",
"metric",
"!=",
"null",
")",
"{",
"dp",
".",
"setMetric",
"(",
"metric",
")",
";",
"dp",
".",
"setTags",
"(",
"(",
"HashMap",
"<",
"String",
",",
"String",
">",
")",
"tags",
")",
";",
"return",
"Deferred",
".",
"fromResult",
"(",
"dp",
")",
";",
"}",
"class",
"TagsCB",
"implements",
"Callback",
"<",
"IncomingDataPoint",
",",
"HashMap",
"<",
"String",
",",
"String",
">",
">",
"{",
"public",
"IncomingDataPoint",
"call",
"(",
"final",
"HashMap",
"<",
"String",
",",
"String",
">",
"tags",
")",
"throws",
"Exception",
"{",
"dp",
".",
"setTags",
"(",
"tags",
")",
";",
"return",
"dp",
";",
"}",
"@",
"Override",
"public",
"String",
"toString",
"(",
")",
"{",
"return",
"\"Tags resolution CB\"",
";",
"}",
"}",
"class",
"MetricCB",
"implements",
"Callback",
"<",
"Deferred",
"<",
"IncomingDataPoint",
">",
",",
"String",
">",
"{",
"public",
"Deferred",
"<",
"IncomingDataPoint",
">",
"call",
"(",
"final",
"String",
"name",
")",
"throws",
"Exception",
"{",
"dp",
".",
"setMetric",
"(",
"name",
")",
";",
"final",
"List",
"<",
"byte",
"[",
"]",
">",
"tags",
"=",
"UniqueId",
".",
"getTagPairsFromTSUID",
"(",
"tsuid",
")",
";",
"return",
"Tags",
".",
"resolveIdsAsync",
"(",
"tsdb",
",",
"tags",
")",
".",
"addCallback",
"(",
"new",
"TagsCB",
"(",
")",
")",
";",
"}",
"@",
"Override",
"public",
"String",
"toString",
"(",
")",
"{",
"return",
"\"Metric resolution CB\"",
";",
"}",
"}",
"final",
"byte",
"[",
"]",
"metric_uid",
"=",
"Arrays",
".",
"copyOfRange",
"(",
"tsuid",
",",
"0",
",",
"TSDB",
".",
"metrics_width",
"(",
")",
")",
";",
"return",
"tsdb",
".",
"getUidName",
"(",
"UniqueIdType",
".",
"METRIC",
",",
"metric_uid",
")",
".",
"addCallbackDeferring",
"(",
"new",
"MetricCB",
"(",
")",
")",
";",
"}"
] |
Resolve the UIDs to names. If the query was for a metric and tags then we
can just use those.
@param dp The data point to fill in values for
@return A deferred with the data point or an exception if something went
wrong.
|
[
"Resolve",
"the",
"UIDs",
"to",
"names",
".",
"If",
"the",
"query",
"was",
"for",
"a",
"metric",
"and",
"tags",
"then",
"we",
"can",
"just",
"use",
"those",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/meta/TSUIDQuery.java#L566-L603
|
13,624
|
OpenTSDB/opentsdb
|
src/meta/TSUIDQuery.java
|
TSUIDQuery.getScanner
|
private Scanner getScanner() {
final Scanner scanner = tsdb.getClient().newScanner(tsdb.metaTable());
scanner.setStartKey(metric_uid);
// increment the metric UID by one so we can scan all of the rows for the
// given metric
final long stop = UniqueId.uidToLong(metric_uid, TSDB.metrics_width()) + 1;
scanner.setStopKey(UniqueId.longToUID(stop, TSDB.metrics_width()));
scanner.setFamily(TSMeta.FAMILY());
// set the filter if we have tags
if (!tags.isEmpty()) {
final short name_width = TSDB.tagk_width();
final short value_width = TSDB.tagv_width();
final short tagsize = (short) (name_width + value_width);
// Generate a regexp for our tags. Say we have 2 tags: { 0 0 1 0 0 2 }
// and { 4 5 6 9 8 7 }, the regexp will be:
// "^.{7}(?:.{6})*\\Q\000\000\001\000\000\002\\E(?:.{6})*\\Q\004\005\006\011\010\007\\E(?:.{6})*$"
final StringBuilder buf = new StringBuilder(
15 // "^.{N}" + "(?:.{M})*" + "$"
+ ((13 + tagsize) // "(?:.{M})*\\Q" + tagsize bytes + "\\E"
* (tags.size())));
// Alright, let's build this regexp. From the beginning...
buf.append("(?s)" // Ensure we use the DOTALL flag.
+ "^.{")
// ... start by skipping the metric ID.
.append(TSDB.metrics_width())
.append("}");
final Iterator<byte[]> tags = this.tag_uids.iterator();
byte[] tag = tags.hasNext() ? tags.next() : null;
// Tags and group_bys are already sorted. We need to put them in the
// regexp in order by ID, which means we just merge two sorted lists.
do {
// Skip any number of tags.
buf.append("(?:.{").append(tagsize).append("})*\\Q");
UniqueId.addIdToRegexp(buf, tag);
tag = tags.hasNext() ? tags.next() : null;
} while (tag != null); // Stop when they both become null.
// Skip any number of tags before the end.
buf.append("(?:.{").append(tagsize).append("})*$");
scanner.setKeyRegexp(buf.toString(), CHARSET);
}
return scanner;
}
|
java
|
private Scanner getScanner() {
final Scanner scanner = tsdb.getClient().newScanner(tsdb.metaTable());
scanner.setStartKey(metric_uid);
// increment the metric UID by one so we can scan all of the rows for the
// given metric
final long stop = UniqueId.uidToLong(metric_uid, TSDB.metrics_width()) + 1;
scanner.setStopKey(UniqueId.longToUID(stop, TSDB.metrics_width()));
scanner.setFamily(TSMeta.FAMILY());
// set the filter if we have tags
if (!tags.isEmpty()) {
final short name_width = TSDB.tagk_width();
final short value_width = TSDB.tagv_width();
final short tagsize = (short) (name_width + value_width);
// Generate a regexp for our tags. Say we have 2 tags: { 0 0 1 0 0 2 }
// and { 4 5 6 9 8 7 }, the regexp will be:
// "^.{7}(?:.{6})*\\Q\000\000\001\000\000\002\\E(?:.{6})*\\Q\004\005\006\011\010\007\\E(?:.{6})*$"
final StringBuilder buf = new StringBuilder(
15 // "^.{N}" + "(?:.{M})*" + "$"
+ ((13 + tagsize) // "(?:.{M})*\\Q" + tagsize bytes + "\\E"
* (tags.size())));
// Alright, let's build this regexp. From the beginning...
buf.append("(?s)" // Ensure we use the DOTALL flag.
+ "^.{")
// ... start by skipping the metric ID.
.append(TSDB.metrics_width())
.append("}");
final Iterator<byte[]> tags = this.tag_uids.iterator();
byte[] tag = tags.hasNext() ? tags.next() : null;
// Tags and group_bys are already sorted. We need to put them in the
// regexp in order by ID, which means we just merge two sorted lists.
do {
// Skip any number of tags.
buf.append("(?:.{").append(tagsize).append("})*\\Q");
UniqueId.addIdToRegexp(buf, tag);
tag = tags.hasNext() ? tags.next() : null;
} while (tag != null); // Stop when they both become null.
// Skip any number of tags before the end.
buf.append("(?:.{").append(tagsize).append("})*$");
scanner.setKeyRegexp(buf.toString(), CHARSET);
}
return scanner;
}
|
[
"private",
"Scanner",
"getScanner",
"(",
")",
"{",
"final",
"Scanner",
"scanner",
"=",
"tsdb",
".",
"getClient",
"(",
")",
".",
"newScanner",
"(",
"tsdb",
".",
"metaTable",
"(",
")",
")",
";",
"scanner",
".",
"setStartKey",
"(",
"metric_uid",
")",
";",
"// increment the metric UID by one so we can scan all of the rows for the",
"// given metric",
"final",
"long",
"stop",
"=",
"UniqueId",
".",
"uidToLong",
"(",
"metric_uid",
",",
"TSDB",
".",
"metrics_width",
"(",
")",
")",
"+",
"1",
";",
"scanner",
".",
"setStopKey",
"(",
"UniqueId",
".",
"longToUID",
"(",
"stop",
",",
"TSDB",
".",
"metrics_width",
"(",
")",
")",
")",
";",
"scanner",
".",
"setFamily",
"(",
"TSMeta",
".",
"FAMILY",
"(",
")",
")",
";",
"// set the filter if we have tags",
"if",
"(",
"!",
"tags",
".",
"isEmpty",
"(",
")",
")",
"{",
"final",
"short",
"name_width",
"=",
"TSDB",
".",
"tagk_width",
"(",
")",
";",
"final",
"short",
"value_width",
"=",
"TSDB",
".",
"tagv_width",
"(",
")",
";",
"final",
"short",
"tagsize",
"=",
"(",
"short",
")",
"(",
"name_width",
"+",
"value_width",
")",
";",
"// Generate a regexp for our tags. Say we have 2 tags: { 0 0 1 0 0 2 }",
"// and { 4 5 6 9 8 7 }, the regexp will be:",
"// \"^.{7}(?:.{6})*\\\\Q\\000\\000\\001\\000\\000\\002\\\\E(?:.{6})*\\\\Q\\004\\005\\006\\011\\010\\007\\\\E(?:.{6})*$\"",
"final",
"StringBuilder",
"buf",
"=",
"new",
"StringBuilder",
"(",
"15",
"// \"^.{N}\" + \"(?:.{M})*\" + \"$\"",
"+",
"(",
"(",
"13",
"+",
"tagsize",
")",
"// \"(?:.{M})*\\\\Q\" + tagsize bytes + \"\\\\E\"",
"*",
"(",
"tags",
".",
"size",
"(",
")",
")",
")",
")",
";",
"// Alright, let's build this regexp. From the beginning...",
"buf",
".",
"append",
"(",
"\"(?s)\"",
"// Ensure we use the DOTALL flag.",
"+",
"\"^.{\"",
")",
"// ... start by skipping the metric ID.",
".",
"append",
"(",
"TSDB",
".",
"metrics_width",
"(",
")",
")",
".",
"append",
"(",
"\"}\"",
")",
";",
"final",
"Iterator",
"<",
"byte",
"[",
"]",
">",
"tags",
"=",
"this",
".",
"tag_uids",
".",
"iterator",
"(",
")",
";",
"byte",
"[",
"]",
"tag",
"=",
"tags",
".",
"hasNext",
"(",
")",
"?",
"tags",
".",
"next",
"(",
")",
":",
"null",
";",
"// Tags and group_bys are already sorted. We need to put them in the",
"// regexp in order by ID, which means we just merge two sorted lists.",
"do",
"{",
"// Skip any number of tags.",
"buf",
".",
"append",
"(",
"\"(?:.{\"",
")",
".",
"append",
"(",
"tagsize",
")",
".",
"append",
"(",
"\"})*\\\\Q\"",
")",
";",
"UniqueId",
".",
"addIdToRegexp",
"(",
"buf",
",",
"tag",
")",
";",
"tag",
"=",
"tags",
".",
"hasNext",
"(",
")",
"?",
"tags",
".",
"next",
"(",
")",
":",
"null",
";",
"}",
"while",
"(",
"tag",
"!=",
"null",
")",
";",
"// Stop when they both become null.",
"// Skip any number of tags before the end.",
"buf",
".",
"append",
"(",
"\"(?:.{\"",
")",
".",
"append",
"(",
"tagsize",
")",
".",
"append",
"(",
"\"})*$\"",
")",
";",
"scanner",
".",
"setKeyRegexp",
"(",
"buf",
".",
"toString",
"(",
")",
",",
"CHARSET",
")",
";",
"}",
"return",
"scanner",
";",
"}"
] |
Configures the scanner for a specific metric and optional tags
@return A configured scanner
|
[
"Configures",
"the",
"scanner",
"for",
"a",
"specific",
"metric",
"and",
"optional",
"tags"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/meta/TSUIDQuery.java#L741-L786
|
13,625
|
OpenTSDB/opentsdb
|
src/rollup/RollupUtils.java
|
RollupUtils.getRollupBasetime
|
public static int getRollupBasetime(final long timestamp,
final RollupInterval interval) {
if (timestamp < 0) {
throw new IllegalArgumentException("Not supporting negative "
+ "timestamps at this time: " + timestamp);
}
// avoid instantiating a calendar at all costs! If we are based on an hourly
// span then use the old method of snapping to the hour
if (interval.getUnits() == 'h') {
int modulo = Const.MAX_TIMESPAN;
if (interval.getUnitMultiplier() > 1) {
modulo = interval.getUnitMultiplier() * 60 * 60;
}
if ((timestamp & Const.SECOND_MASK) != 0) {
// drop the ms timestamp to seconds to calculate the base timestamp
return (int) ((timestamp / 1000) -
((timestamp / 1000) % modulo));
} else {
return (int) (timestamp - (timestamp % modulo));
}
} else {
final long time_milliseconds = (timestamp & Const.SECOND_MASK) != 0 ?
timestamp : timestamp * 1000;
// gotta go the long way with the calendar to snap to an appropriate
// daily, monthly or weekly boundary
final Calendar calendar = Calendar.getInstance(Const.UTC_TZ);
calendar.setTimeInMillis(time_milliseconds);
// zero out the hour, minutes, seconds
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
switch (interval.getUnits()) {
case 'd':
// all set via the zeros above
break;
case 'n':
calendar.set(Calendar.DAY_OF_MONTH, 1);
break;
case 'y':
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.MONTH, 0); // 0 for January
break;
default:
throw new IllegalArgumentException("Unrecogznied span: " + interval);
}
return (int) (calendar.getTimeInMillis() / 1000);
}
}
|
java
|
public static int getRollupBasetime(final long timestamp,
final RollupInterval interval) {
if (timestamp < 0) {
throw new IllegalArgumentException("Not supporting negative "
+ "timestamps at this time: " + timestamp);
}
// avoid instantiating a calendar at all costs! If we are based on an hourly
// span then use the old method of snapping to the hour
if (interval.getUnits() == 'h') {
int modulo = Const.MAX_TIMESPAN;
if (interval.getUnitMultiplier() > 1) {
modulo = interval.getUnitMultiplier() * 60 * 60;
}
if ((timestamp & Const.SECOND_MASK) != 0) {
// drop the ms timestamp to seconds to calculate the base timestamp
return (int) ((timestamp / 1000) -
((timestamp / 1000) % modulo));
} else {
return (int) (timestamp - (timestamp % modulo));
}
} else {
final long time_milliseconds = (timestamp & Const.SECOND_MASK) != 0 ?
timestamp : timestamp * 1000;
// gotta go the long way with the calendar to snap to an appropriate
// daily, monthly or weekly boundary
final Calendar calendar = Calendar.getInstance(Const.UTC_TZ);
calendar.setTimeInMillis(time_milliseconds);
// zero out the hour, minutes, seconds
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
switch (interval.getUnits()) {
case 'd':
// all set via the zeros above
break;
case 'n':
calendar.set(Calendar.DAY_OF_MONTH, 1);
break;
case 'y':
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.MONTH, 0); // 0 for January
break;
default:
throw new IllegalArgumentException("Unrecogznied span: " + interval);
}
return (int) (calendar.getTimeInMillis() / 1000);
}
}
|
[
"public",
"static",
"int",
"getRollupBasetime",
"(",
"final",
"long",
"timestamp",
",",
"final",
"RollupInterval",
"interval",
")",
"{",
"if",
"(",
"timestamp",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Not supporting negative \"",
"+",
"\"timestamps at this time: \"",
"+",
"timestamp",
")",
";",
"}",
"// avoid instantiating a calendar at all costs! If we are based on an hourly",
"// span then use the old method of snapping to the hour",
"if",
"(",
"interval",
".",
"getUnits",
"(",
")",
"==",
"'",
"'",
")",
"{",
"int",
"modulo",
"=",
"Const",
".",
"MAX_TIMESPAN",
";",
"if",
"(",
"interval",
".",
"getUnitMultiplier",
"(",
")",
">",
"1",
")",
"{",
"modulo",
"=",
"interval",
".",
"getUnitMultiplier",
"(",
")",
"*",
"60",
"*",
"60",
";",
"}",
"if",
"(",
"(",
"timestamp",
"&",
"Const",
".",
"SECOND_MASK",
")",
"!=",
"0",
")",
"{",
"// drop the ms timestamp to seconds to calculate the base timestamp",
"return",
"(",
"int",
")",
"(",
"(",
"timestamp",
"/",
"1000",
")",
"-",
"(",
"(",
"timestamp",
"/",
"1000",
")",
"%",
"modulo",
")",
")",
";",
"}",
"else",
"{",
"return",
"(",
"int",
")",
"(",
"timestamp",
"-",
"(",
"timestamp",
"%",
"modulo",
")",
")",
";",
"}",
"}",
"else",
"{",
"final",
"long",
"time_milliseconds",
"=",
"(",
"timestamp",
"&",
"Const",
".",
"SECOND_MASK",
")",
"!=",
"0",
"?",
"timestamp",
":",
"timestamp",
"*",
"1000",
";",
"// gotta go the long way with the calendar to snap to an appropriate",
"// daily, monthly or weekly boundary",
"final",
"Calendar",
"calendar",
"=",
"Calendar",
".",
"getInstance",
"(",
"Const",
".",
"UTC_TZ",
")",
";",
"calendar",
".",
"setTimeInMillis",
"(",
"time_milliseconds",
")",
";",
"// zero out the hour, minutes, seconds",
"calendar",
".",
"set",
"(",
"Calendar",
".",
"HOUR_OF_DAY",
",",
"0",
")",
";",
"calendar",
".",
"set",
"(",
"Calendar",
".",
"MINUTE",
",",
"0",
")",
";",
"calendar",
".",
"set",
"(",
"Calendar",
".",
"SECOND",
",",
"0",
")",
";",
"switch",
"(",
"interval",
".",
"getUnits",
"(",
")",
")",
"{",
"case",
"'",
"'",
":",
"// all set via the zeros above",
"break",
";",
"case",
"'",
"'",
":",
"calendar",
".",
"set",
"(",
"Calendar",
".",
"DAY_OF_MONTH",
",",
"1",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"calendar",
".",
"set",
"(",
"Calendar",
".",
"DAY_OF_MONTH",
",",
"1",
")",
";",
"calendar",
".",
"set",
"(",
"Calendar",
".",
"MONTH",
",",
"0",
")",
";",
"// 0 for January",
"break",
";",
"default",
":",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unrecogznied span: \"",
"+",
"interval",
")",
";",
"}",
"return",
"(",
"int",
")",
"(",
"calendar",
".",
"getTimeInMillis",
"(",
")",
"/",
"1000",
")",
";",
"}",
"}"
] |
Calculates the base time for a rollup interval, the time that can be
stored in the row key.
@param timestamp The data point timestamp to calculate from in seconds
or milliseconds
@param interval The configured interval object to use for calcaulting
the base time with a valid span of 'h', 'd', 'm' or 'y'
@return A base time as a unix epoch timestamp in seconds
@throws IllegalArgumentException if the timestamp is negative or the interval
has an unsupported span
|
[
"Calculates",
"the",
"base",
"time",
"for",
"a",
"rollup",
"interval",
"the",
"time",
"that",
"can",
"be",
"stored",
"in",
"the",
"row",
"key",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/rollup/RollupUtils.java#L52-L104
|
13,626
|
OpenTSDB/opentsdb
|
src/rollup/RollupUtils.java
|
RollupUtils.getTimestampFromRollupQualifier
|
public static long getTimestampFromRollupQualifier(final byte[] qualifier,
final long base_time,
final RollupInterval interval,
final int offset) {
return (base_time * 1000) +
getOffsetFromRollupQualifier(qualifier, offset, interval);
}
|
java
|
public static long getTimestampFromRollupQualifier(final byte[] qualifier,
final long base_time,
final RollupInterval interval,
final int offset) {
return (base_time * 1000) +
getOffsetFromRollupQualifier(qualifier, offset, interval);
}
|
[
"public",
"static",
"long",
"getTimestampFromRollupQualifier",
"(",
"final",
"byte",
"[",
"]",
"qualifier",
",",
"final",
"long",
"base_time",
",",
"final",
"RollupInterval",
"interval",
",",
"final",
"int",
"offset",
")",
"{",
"return",
"(",
"base_time",
"*",
"1000",
")",
"+",
"getOffsetFromRollupQualifier",
"(",
"qualifier",
",",
"offset",
",",
"interval",
")",
";",
"}"
] |
Returns the absolute timestamp of a data point qualifier in milliseconds
@param qualifier The qualifier to parse
@param base_time The base time, in seconds, from the row key
@param interval The RollupInterval object with data about the interval
@param offset An offset within the byte array
@return The absolute timestamp in milliseconds
|
[
"Returns",
"the",
"absolute",
"timestamp",
"of",
"a",
"data",
"point",
"qualifier",
"in",
"milliseconds"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/rollup/RollupUtils.java#L178-L184
|
13,627
|
OpenTSDB/opentsdb
|
src/query/QueryLimitOverride.java
|
QueryLimitOverride.loadFromFile
|
private void loadFromFile() {
// load from disk if the caller gave us a file
if (file_location != null && !file_location.isEmpty()) {
final File file = new File(file_location);
if (!file.exists()) {
LOG.warn("Query override file " + file_location + " does not exist");
return;
}
try {
final String raw_json = Files.toString(file, Const.UTF8_CHARSET);
if (raw_json != null && !raw_json.isEmpty()) {
final Set<QueryLimitOverrideItem> cached_items =
JSON.parseToObject(raw_json, TR_OVERRIDES);
// iterate so we only change bits that are different.
for (final QueryLimitOverrideItem override : cached_items) {
QueryLimitOverrideItem existing = overrides.get(override.getRegex());
if (existing == null || !existing.equals(override)) {
overrides.put(override.getRegex(), override);
}
}
// reverse quadratic, woot! Ugly but if the limit file is so big that
// this takes over 60 seconds or starts blocking queries on modifications
// to the map then something is really wrong.
final Iterator<Entry<String, QueryLimitOverrideItem>> iterator =
overrides.entrySet().iterator();
while (iterator.hasNext()) {
final Entry<String, QueryLimitOverrideItem> entry = iterator.next();
boolean matched = false;
for (final QueryLimitOverrideItem override : cached_items) {
if (override.getRegex().equals(entry.getKey())) {
matched = true;
break;
}
}
if (!matched) {
iterator.remove();
}
}
}
LOG.info("Successfully loaded query overrides: " + this);
} catch (Exception e) {
LOG.error("Failed to read cache file for query limit override: " +
this, e);
}
}
}
|
java
|
private void loadFromFile() {
// load from disk if the caller gave us a file
if (file_location != null && !file_location.isEmpty()) {
final File file = new File(file_location);
if (!file.exists()) {
LOG.warn("Query override file " + file_location + " does not exist");
return;
}
try {
final String raw_json = Files.toString(file, Const.UTF8_CHARSET);
if (raw_json != null && !raw_json.isEmpty()) {
final Set<QueryLimitOverrideItem> cached_items =
JSON.parseToObject(raw_json, TR_OVERRIDES);
// iterate so we only change bits that are different.
for (final QueryLimitOverrideItem override : cached_items) {
QueryLimitOverrideItem existing = overrides.get(override.getRegex());
if (existing == null || !existing.equals(override)) {
overrides.put(override.getRegex(), override);
}
}
// reverse quadratic, woot! Ugly but if the limit file is so big that
// this takes over 60 seconds or starts blocking queries on modifications
// to the map then something is really wrong.
final Iterator<Entry<String, QueryLimitOverrideItem>> iterator =
overrides.entrySet().iterator();
while (iterator.hasNext()) {
final Entry<String, QueryLimitOverrideItem> entry = iterator.next();
boolean matched = false;
for (final QueryLimitOverrideItem override : cached_items) {
if (override.getRegex().equals(entry.getKey())) {
matched = true;
break;
}
}
if (!matched) {
iterator.remove();
}
}
}
LOG.info("Successfully loaded query overrides: " + this);
} catch (Exception e) {
LOG.error("Failed to read cache file for query limit override: " +
this, e);
}
}
}
|
[
"private",
"void",
"loadFromFile",
"(",
")",
"{",
"// load from disk if the caller gave us a file",
"if",
"(",
"file_location",
"!=",
"null",
"&&",
"!",
"file_location",
".",
"isEmpty",
"(",
")",
")",
"{",
"final",
"File",
"file",
"=",
"new",
"File",
"(",
"file_location",
")",
";",
"if",
"(",
"!",
"file",
".",
"exists",
"(",
")",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Query override file \"",
"+",
"file_location",
"+",
"\" does not exist\"",
")",
";",
"return",
";",
"}",
"try",
"{",
"final",
"String",
"raw_json",
"=",
"Files",
".",
"toString",
"(",
"file",
",",
"Const",
".",
"UTF8_CHARSET",
")",
";",
"if",
"(",
"raw_json",
"!=",
"null",
"&&",
"!",
"raw_json",
".",
"isEmpty",
"(",
")",
")",
"{",
"final",
"Set",
"<",
"QueryLimitOverrideItem",
">",
"cached_items",
"=",
"JSON",
".",
"parseToObject",
"(",
"raw_json",
",",
"TR_OVERRIDES",
")",
";",
"// iterate so we only change bits that are different.",
"for",
"(",
"final",
"QueryLimitOverrideItem",
"override",
":",
"cached_items",
")",
"{",
"QueryLimitOverrideItem",
"existing",
"=",
"overrides",
".",
"get",
"(",
"override",
".",
"getRegex",
"(",
")",
")",
";",
"if",
"(",
"existing",
"==",
"null",
"||",
"!",
"existing",
".",
"equals",
"(",
"override",
")",
")",
"{",
"overrides",
".",
"put",
"(",
"override",
".",
"getRegex",
"(",
")",
",",
"override",
")",
";",
"}",
"}",
"// reverse quadratic, woot! Ugly but if the limit file is so big that",
"// this takes over 60 seconds or starts blocking queries on modifications",
"// to the map then something is really wrong.",
"final",
"Iterator",
"<",
"Entry",
"<",
"String",
",",
"QueryLimitOverrideItem",
">",
">",
"iterator",
"=",
"overrides",
".",
"entrySet",
"(",
")",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"iterator",
".",
"hasNext",
"(",
")",
")",
"{",
"final",
"Entry",
"<",
"String",
",",
"QueryLimitOverrideItem",
">",
"entry",
"=",
"iterator",
".",
"next",
"(",
")",
";",
"boolean",
"matched",
"=",
"false",
";",
"for",
"(",
"final",
"QueryLimitOverrideItem",
"override",
":",
"cached_items",
")",
"{",
"if",
"(",
"override",
".",
"getRegex",
"(",
")",
".",
"equals",
"(",
"entry",
".",
"getKey",
"(",
")",
")",
")",
"{",
"matched",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"matched",
")",
"{",
"iterator",
".",
"remove",
"(",
")",
";",
"}",
"}",
"}",
"LOG",
".",
"info",
"(",
"\"Successfully loaded query overrides: \"",
"+",
"this",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"LOG",
".",
"error",
"(",
"\"Failed to read cache file for query limit override: \"",
"+",
"this",
",",
"e",
")",
";",
"}",
"}",
"}"
] |
Attempts to load the file from disk
|
[
"Attempts",
"to",
"load",
"the",
"file",
"from",
"disk"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/QueryLimitOverride.java#L196-L243
|
13,628
|
OpenTSDB/opentsdb
|
src/query/expression/ExpressionReader.java
|
ExpressionReader.skipWhitespaces
|
public void skipWhitespaces() {
for (int i = mark; i < chars.length; i++) {
if (Character.isWhitespace(chars[i])) {
mark++;
} else {
break;
}
}
}
|
java
|
public void skipWhitespaces() {
for (int i = mark; i < chars.length; i++) {
if (Character.isWhitespace(chars[i])) {
mark++;
} else {
break;
}
}
}
|
[
"public",
"void",
"skipWhitespaces",
"(",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"mark",
";",
"i",
"<",
"chars",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"Character",
".",
"isWhitespace",
"(",
"chars",
"[",
"i",
"]",
")",
")",
"{",
"mark",
"++",
";",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"}"
] |
Increments the mark over white spaces
|
[
"Increments",
"the",
"mark",
"over",
"white",
"spaces"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/expression/ExpressionReader.java#L116-L124
|
13,629
|
OpenTSDB/opentsdb
|
src/stats/StatsCollector.java
|
StatsCollector.setGlobalTags
|
public static final void setGlobalTags(final Config config) {
if (config == null) {
throw new IllegalArgumentException("Configuration cannot be null.");
}
if (config.getBoolean("tsd.core.stats_with_port")) {
global_tags = new HashMap<String, String>(1);
global_tags.put("port", config.getString("tsd.network.port"));
}
}
|
java
|
public static final void setGlobalTags(final Config config) {
if (config == null) {
throw new IllegalArgumentException("Configuration cannot be null.");
}
if (config.getBoolean("tsd.core.stats_with_port")) {
global_tags = new HashMap<String, String>(1);
global_tags.put("port", config.getString("tsd.network.port"));
}
}
|
[
"public",
"static",
"final",
"void",
"setGlobalTags",
"(",
"final",
"Config",
"config",
")",
"{",
"if",
"(",
"config",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Configuration cannot be null.\"",
")",
";",
"}",
"if",
"(",
"config",
".",
"getBoolean",
"(",
"\"tsd.core.stats_with_port\"",
")",
")",
"{",
"global_tags",
"=",
"new",
"HashMap",
"<",
"String",
",",
"String",
">",
"(",
"1",
")",
";",
"global_tags",
".",
"put",
"(",
"\"port\"",
",",
"config",
".",
"getString",
"(",
"\"tsd.network.port\"",
")",
")",
";",
"}",
"}"
] |
Parses the configuration to determine if any extra tags should be included
with every stat emitted.
@param config The config object to parse
@throws IllegalArgumentException if the config is null. Other exceptions
may be thrown if the config values are unparseable.
|
[
"Parses",
"the",
"configuration",
"to",
"determine",
"if",
"any",
"extra",
"tags",
"should",
"be",
"included",
"with",
"every",
"stat",
"emitted",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/stats/StatsCollector.java#L261-L270
|
13,630
|
OpenTSDB/opentsdb
|
src/core/TsdbQuery.java
|
TsdbQuery.setStartTime
|
@Override
public void setStartTime(final long timestamp) {
if (timestamp < 0 || ((timestamp & Const.SECOND_MASK) != 0 &&
timestamp > 9999999999999L)) {
throw new IllegalArgumentException("Invalid timestamp: " + timestamp);
} else if (end_time != UNSET && timestamp >= getEndTime()) {
throw new IllegalArgumentException("new start time (" + timestamp
+ ") is greater than or equal to end time: " + getEndTime());
}
start_time = timestamp;
}
|
java
|
@Override
public void setStartTime(final long timestamp) {
if (timestamp < 0 || ((timestamp & Const.SECOND_MASK) != 0 &&
timestamp > 9999999999999L)) {
throw new IllegalArgumentException("Invalid timestamp: " + timestamp);
} else if (end_time != UNSET && timestamp >= getEndTime()) {
throw new IllegalArgumentException("new start time (" + timestamp
+ ") is greater than or equal to end time: " + getEndTime());
}
start_time = timestamp;
}
|
[
"@",
"Override",
"public",
"void",
"setStartTime",
"(",
"final",
"long",
"timestamp",
")",
"{",
"if",
"(",
"timestamp",
"<",
"0",
"||",
"(",
"(",
"timestamp",
"&",
"Const",
".",
"SECOND_MASK",
")",
"!=",
"0",
"&&",
"timestamp",
">",
"9999999999999L",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid timestamp: \"",
"+",
"timestamp",
")",
";",
"}",
"else",
"if",
"(",
"end_time",
"!=",
"UNSET",
"&&",
"timestamp",
">=",
"getEndTime",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"new start time (\"",
"+",
"timestamp",
"+",
"\") is greater than or equal to end time: \"",
"+",
"getEndTime",
"(",
")",
")",
";",
"}",
"start_time",
"=",
"timestamp",
";",
"}"
] |
Sets the start time for the query
@param timestamp Unix epoch timestamp in seconds or milliseconds
@throws IllegalArgumentException if the timestamp is invalid or greater
than the end time (if set)
|
[
"Sets",
"the",
"start",
"time",
"for",
"the",
"query"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/TsdbQuery.java#L266-L276
|
13,631
|
OpenTSDB/opentsdb
|
src/core/TsdbQuery.java
|
TsdbQuery.downsample
|
@Override
public void downsample(final long interval, final Aggregator downsampler) {
if (downsampler == Aggregators.NONE) {
throw new IllegalArgumentException("cannot use the NONE "
+ "aggregator for downsampling");
}
downsample(interval, downsampler, FillPolicy.NONE);
}
|
java
|
@Override
public void downsample(final long interval, final Aggregator downsampler) {
if (downsampler == Aggregators.NONE) {
throw new IllegalArgumentException("cannot use the NONE "
+ "aggregator for downsampling");
}
downsample(interval, downsampler, FillPolicy.NONE);
}
|
[
"@",
"Override",
"public",
"void",
"downsample",
"(",
"final",
"long",
"interval",
",",
"final",
"Aggregator",
"downsampler",
")",
"{",
"if",
"(",
"downsampler",
"==",
"Aggregators",
".",
"NONE",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"cannot use the NONE \"",
"+",
"\"aggregator for downsampling\"",
")",
";",
"}",
"downsample",
"(",
"interval",
",",
"downsampler",
",",
"FillPolicy",
".",
"NONE",
")",
";",
"}"
] |
Sets an optional downsampling function with interpolation on this query.
@param interval The interval, in milliseconds to rollup data points
@param downsampler An aggregation function to use when rolling up data points
@throws NullPointerException if the aggregation function is null
@throws IllegalArgumentException if the interval is not greater than 0
|
[
"Sets",
"an",
"optional",
"downsampling",
"function",
"with",
"interpolation",
"on",
"this",
"query",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/TsdbQuery.java#L599-L606
|
13,632
|
OpenTSDB/opentsdb
|
src/core/TsdbQuery.java
|
TsdbQuery.tableToBeScanned
|
private byte[] tableToBeScanned() {
final byte[] tableName;
if (RollupQuery.isValidQuery(rollup_query)) {
if (pre_aggregate) {
tableName= rollup_query.getRollupInterval().getGroupbyTable();
}
else {
tableName= rollup_query.getRollupInterval().getTemporalTable();
}
}
else if (pre_aggregate) {
tableName = tsdb.getDefaultInterval().getGroupbyTable();
}
else {
tableName = tsdb.dataTable();
}
return tableName;
}
|
java
|
private byte[] tableToBeScanned() {
final byte[] tableName;
if (RollupQuery.isValidQuery(rollup_query)) {
if (pre_aggregate) {
tableName= rollup_query.getRollupInterval().getGroupbyTable();
}
else {
tableName= rollup_query.getRollupInterval().getTemporalTable();
}
}
else if (pre_aggregate) {
tableName = tsdb.getDefaultInterval().getGroupbyTable();
}
else {
tableName = tsdb.dataTable();
}
return tableName;
}
|
[
"private",
"byte",
"[",
"]",
"tableToBeScanned",
"(",
")",
"{",
"final",
"byte",
"[",
"]",
"tableName",
";",
"if",
"(",
"RollupQuery",
".",
"isValidQuery",
"(",
"rollup_query",
")",
")",
"{",
"if",
"(",
"pre_aggregate",
")",
"{",
"tableName",
"=",
"rollup_query",
".",
"getRollupInterval",
"(",
")",
".",
"getGroupbyTable",
"(",
")",
";",
"}",
"else",
"{",
"tableName",
"=",
"rollup_query",
".",
"getRollupInterval",
"(",
")",
".",
"getTemporalTable",
"(",
")",
";",
"}",
"}",
"else",
"if",
"(",
"pre_aggregate",
")",
"{",
"tableName",
"=",
"tsdb",
".",
"getDefaultInterval",
"(",
")",
".",
"getGroupbyTable",
"(",
")",
";",
"}",
"else",
"{",
"tableName",
"=",
"tsdb",
".",
"dataTable",
"(",
")",
";",
"}",
"return",
"tableName",
";",
"}"
] |
Identify the table to be scanned based on the roll up and pre-aggregate
query parameters
@return table name as byte array
@since 2.4
|
[
"Identify",
"the",
"table",
"to",
"be",
"scanned",
"based",
"on",
"the",
"roll",
"up",
"and",
"pre",
"-",
"aggregate",
"query",
"parameters"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/TsdbQuery.java#L1483-L1502
|
13,633
|
OpenTSDB/opentsdb
|
src/core/TsdbQuery.java
|
TsdbQuery.getScanStartTimeSeconds
|
private long getScanStartTimeSeconds() {
// Begin with the raw query start time.
long start = getStartTime();
// Convert to seconds if we have a query in ms.
if ((start & Const.SECOND_MASK) != 0L) {
start /= 1000L;
}
// if we have a rollup query, we have different row key start times so find
// the base time from which we need to search
if (rollup_query != null) {
long base_time = RollupUtils.getRollupBasetime(start,
rollup_query.getRollupInterval());
if (rate) {
// scan one row back so we can get the first rate value.
base_time = RollupUtils.getRollupBasetime(base_time - 1,
rollup_query.getRollupInterval());
}
return base_time;
}
// First, we align the start timestamp to its representative value for the
// interval in which it appears, if downsampling.
long interval_aligned_ts = start;
if (downsampler != null && downsampler.getInterval() > 0) {
// Downsampling enabled.
// TODO - calendar interval
final long interval_offset = (1000L * start) % downsampler.getInterval();
interval_aligned_ts -= interval_offset / 1000L;
}
// Then snap that timestamp back to its representative value for the
// timespan in which it appears.
final long timespan_offset = interval_aligned_ts % Const.MAX_TIMESPAN;
final long timespan_aligned_ts = interval_aligned_ts - timespan_offset;
// Don't return negative numbers.
return timespan_aligned_ts > 0L ? timespan_aligned_ts : 0L;
}
|
java
|
private long getScanStartTimeSeconds() {
// Begin with the raw query start time.
long start = getStartTime();
// Convert to seconds if we have a query in ms.
if ((start & Const.SECOND_MASK) != 0L) {
start /= 1000L;
}
// if we have a rollup query, we have different row key start times so find
// the base time from which we need to search
if (rollup_query != null) {
long base_time = RollupUtils.getRollupBasetime(start,
rollup_query.getRollupInterval());
if (rate) {
// scan one row back so we can get the first rate value.
base_time = RollupUtils.getRollupBasetime(base_time - 1,
rollup_query.getRollupInterval());
}
return base_time;
}
// First, we align the start timestamp to its representative value for the
// interval in which it appears, if downsampling.
long interval_aligned_ts = start;
if (downsampler != null && downsampler.getInterval() > 0) {
// Downsampling enabled.
// TODO - calendar interval
final long interval_offset = (1000L * start) % downsampler.getInterval();
interval_aligned_ts -= interval_offset / 1000L;
}
// Then snap that timestamp back to its representative value for the
// timespan in which it appears.
final long timespan_offset = interval_aligned_ts % Const.MAX_TIMESPAN;
final long timespan_aligned_ts = interval_aligned_ts - timespan_offset;
// Don't return negative numbers.
return timespan_aligned_ts > 0L ? timespan_aligned_ts : 0L;
}
|
[
"private",
"long",
"getScanStartTimeSeconds",
"(",
")",
"{",
"// Begin with the raw query start time.",
"long",
"start",
"=",
"getStartTime",
"(",
")",
";",
"// Convert to seconds if we have a query in ms.",
"if",
"(",
"(",
"start",
"&",
"Const",
".",
"SECOND_MASK",
")",
"!=",
"0L",
")",
"{",
"start",
"/=",
"1000L",
";",
"}",
"// if we have a rollup query, we have different row key start times so find",
"// the base time from which we need to search",
"if",
"(",
"rollup_query",
"!=",
"null",
")",
"{",
"long",
"base_time",
"=",
"RollupUtils",
".",
"getRollupBasetime",
"(",
"start",
",",
"rollup_query",
".",
"getRollupInterval",
"(",
")",
")",
";",
"if",
"(",
"rate",
")",
"{",
"// scan one row back so we can get the first rate value.",
"base_time",
"=",
"RollupUtils",
".",
"getRollupBasetime",
"(",
"base_time",
"-",
"1",
",",
"rollup_query",
".",
"getRollupInterval",
"(",
")",
")",
";",
"}",
"return",
"base_time",
";",
"}",
"// First, we align the start timestamp to its representative value for the",
"// interval in which it appears, if downsampling.",
"long",
"interval_aligned_ts",
"=",
"start",
";",
"if",
"(",
"downsampler",
"!=",
"null",
"&&",
"downsampler",
".",
"getInterval",
"(",
")",
">",
"0",
")",
"{",
"// Downsampling enabled.",
"// TODO - calendar interval",
"final",
"long",
"interval_offset",
"=",
"(",
"1000L",
"*",
"start",
")",
"%",
"downsampler",
".",
"getInterval",
"(",
")",
";",
"interval_aligned_ts",
"-=",
"interval_offset",
"/",
"1000L",
";",
"}",
"// Then snap that timestamp back to its representative value for the",
"// timespan in which it appears.",
"final",
"long",
"timespan_offset",
"=",
"interval_aligned_ts",
"%",
"Const",
".",
"MAX_TIMESPAN",
";",
"final",
"long",
"timespan_aligned_ts",
"=",
"interval_aligned_ts",
"-",
"timespan_offset",
";",
"// Don't return negative numbers.",
"return",
"timespan_aligned_ts",
">",
"0L",
"?",
"timespan_aligned_ts",
":",
"0L",
";",
"}"
] |
Returns the UNIX timestamp from which we must start scanning.
|
[
"Returns",
"the",
"UNIX",
"timestamp",
"from",
"which",
"we",
"must",
"start",
"scanning",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/TsdbQuery.java#L1505-L1544
|
13,634
|
OpenTSDB/opentsdb
|
src/core/TsdbQuery.java
|
TsdbQuery.getScanEndTimeSeconds
|
private long getScanEndTimeSeconds() {
// Begin with the raw query end time.
long end = getEndTime();
// Convert to seconds if we have a query in ms.
if ((end & Const.SECOND_MASK) != 0L) {
end /= 1000L;
if (end - (end * 1000) < 1) {
// handle an edge case where a user may request a ms time between
// 0 and 1 seconds. Just bump it a second.
end++;
}
}
if (rollup_query != null) {
return RollupUtils.getRollupBasetime(end +
(rollup_query.getRollupInterval().getIntervalSeconds() *
rollup_query.getRollupInterval().getIntervals()),
rollup_query.getRollupInterval());
}
// The calculation depends on whether we're downsampling.
if (downsampler != null && downsampler.getInterval() > 0) {
// Downsampling enabled.
//
// First, we align the end timestamp to its representative value for the
// interval FOLLOWING the one in which it appears.
//
// OpenTSDB's query bounds are inclusive, but HBase scan bounds are half-
// open. The user may have provided an end bound that is already
// interval-aligned (i.e., its interval offset is zero). If so, the user
// wishes for that interval to appear in the output. In that case, we
// skip forward an entire extra interval.
//
// This can be accomplished by simply not testing for zero offset.
final long interval_offset = (1000L * end) % downsampler.getInterval();
final long interval_aligned_ts = end +
(downsampler.getInterval() - interval_offset) / 1000L;
// Then, if we're now aligned on a timespan boundary, then we need no
// further adjustment: we are guaranteed to have always moved the end time
// forward, so the scan will find the data we need.
//
// Otherwise, we need to align to the NEXT timespan to ensure that we scan
// the needed data.
final long timespan_offset = interval_aligned_ts % Const.MAX_TIMESPAN;
return (0L == timespan_offset) ?
interval_aligned_ts :
interval_aligned_ts + (Const.MAX_TIMESPAN - timespan_offset);
} else {
// Not downsampling.
//
// Regardless of the end timestamp's position within the current timespan,
// we must always align to the beginning of the next timespan. This is
// true even if it's already aligned on a timespan boundary. Again, the
// reason for this is OpenTSDB's closed interval vs. HBase's half-open.
final long timespan_offset = end % Const.MAX_TIMESPAN;
return end + (Const.MAX_TIMESPAN - timespan_offset);
}
}
|
java
|
private long getScanEndTimeSeconds() {
// Begin with the raw query end time.
long end = getEndTime();
// Convert to seconds if we have a query in ms.
if ((end & Const.SECOND_MASK) != 0L) {
end /= 1000L;
if (end - (end * 1000) < 1) {
// handle an edge case where a user may request a ms time between
// 0 and 1 seconds. Just bump it a second.
end++;
}
}
if (rollup_query != null) {
return RollupUtils.getRollupBasetime(end +
(rollup_query.getRollupInterval().getIntervalSeconds() *
rollup_query.getRollupInterval().getIntervals()),
rollup_query.getRollupInterval());
}
// The calculation depends on whether we're downsampling.
if (downsampler != null && downsampler.getInterval() > 0) {
// Downsampling enabled.
//
// First, we align the end timestamp to its representative value for the
// interval FOLLOWING the one in which it appears.
//
// OpenTSDB's query bounds are inclusive, but HBase scan bounds are half-
// open. The user may have provided an end bound that is already
// interval-aligned (i.e., its interval offset is zero). If so, the user
// wishes for that interval to appear in the output. In that case, we
// skip forward an entire extra interval.
//
// This can be accomplished by simply not testing for zero offset.
final long interval_offset = (1000L * end) % downsampler.getInterval();
final long interval_aligned_ts = end +
(downsampler.getInterval() - interval_offset) / 1000L;
// Then, if we're now aligned on a timespan boundary, then we need no
// further adjustment: we are guaranteed to have always moved the end time
// forward, so the scan will find the data we need.
//
// Otherwise, we need to align to the NEXT timespan to ensure that we scan
// the needed data.
final long timespan_offset = interval_aligned_ts % Const.MAX_TIMESPAN;
return (0L == timespan_offset) ?
interval_aligned_ts :
interval_aligned_ts + (Const.MAX_TIMESPAN - timespan_offset);
} else {
// Not downsampling.
//
// Regardless of the end timestamp's position within the current timespan,
// we must always align to the beginning of the next timespan. This is
// true even if it's already aligned on a timespan boundary. Again, the
// reason for this is OpenTSDB's closed interval vs. HBase's half-open.
final long timespan_offset = end % Const.MAX_TIMESPAN;
return end + (Const.MAX_TIMESPAN - timespan_offset);
}
}
|
[
"private",
"long",
"getScanEndTimeSeconds",
"(",
")",
"{",
"// Begin with the raw query end time.",
"long",
"end",
"=",
"getEndTime",
"(",
")",
";",
"// Convert to seconds if we have a query in ms.",
"if",
"(",
"(",
"end",
"&",
"Const",
".",
"SECOND_MASK",
")",
"!=",
"0L",
")",
"{",
"end",
"/=",
"1000L",
";",
"if",
"(",
"end",
"-",
"(",
"end",
"*",
"1000",
")",
"<",
"1",
")",
"{",
"// handle an edge case where a user may request a ms time between",
"// 0 and 1 seconds. Just bump it a second.",
"end",
"++",
";",
"}",
"}",
"if",
"(",
"rollup_query",
"!=",
"null",
")",
"{",
"return",
"RollupUtils",
".",
"getRollupBasetime",
"(",
"end",
"+",
"(",
"rollup_query",
".",
"getRollupInterval",
"(",
")",
".",
"getIntervalSeconds",
"(",
")",
"*",
"rollup_query",
".",
"getRollupInterval",
"(",
")",
".",
"getIntervals",
"(",
")",
")",
",",
"rollup_query",
".",
"getRollupInterval",
"(",
")",
")",
";",
"}",
"// The calculation depends on whether we're downsampling.",
"if",
"(",
"downsampler",
"!=",
"null",
"&&",
"downsampler",
".",
"getInterval",
"(",
")",
">",
"0",
")",
"{",
"// Downsampling enabled.",
"//",
"// First, we align the end timestamp to its representative value for the",
"// interval FOLLOWING the one in which it appears.",
"//",
"// OpenTSDB's query bounds are inclusive, but HBase scan bounds are half-",
"// open. The user may have provided an end bound that is already",
"// interval-aligned (i.e., its interval offset is zero). If so, the user",
"// wishes for that interval to appear in the output. In that case, we",
"// skip forward an entire extra interval.",
"//",
"// This can be accomplished by simply not testing for zero offset.",
"final",
"long",
"interval_offset",
"=",
"(",
"1000L",
"*",
"end",
")",
"%",
"downsampler",
".",
"getInterval",
"(",
")",
";",
"final",
"long",
"interval_aligned_ts",
"=",
"end",
"+",
"(",
"downsampler",
".",
"getInterval",
"(",
")",
"-",
"interval_offset",
")",
"/",
"1000L",
";",
"// Then, if we're now aligned on a timespan boundary, then we need no",
"// further adjustment: we are guaranteed to have always moved the end time",
"// forward, so the scan will find the data we need.",
"//",
"// Otherwise, we need to align to the NEXT timespan to ensure that we scan",
"// the needed data.",
"final",
"long",
"timespan_offset",
"=",
"interval_aligned_ts",
"%",
"Const",
".",
"MAX_TIMESPAN",
";",
"return",
"(",
"0L",
"==",
"timespan_offset",
")",
"?",
"interval_aligned_ts",
":",
"interval_aligned_ts",
"+",
"(",
"Const",
".",
"MAX_TIMESPAN",
"-",
"timespan_offset",
")",
";",
"}",
"else",
"{",
"// Not downsampling.",
"//",
"// Regardless of the end timestamp's position within the current timespan,",
"// we must always align to the beginning of the next timespan. This is",
"// true even if it's already aligned on a timespan boundary. Again, the",
"// reason for this is OpenTSDB's closed interval vs. HBase's half-open.",
"final",
"long",
"timespan_offset",
"=",
"end",
"%",
"Const",
".",
"MAX_TIMESPAN",
";",
"return",
"end",
"+",
"(",
"Const",
".",
"MAX_TIMESPAN",
"-",
"timespan_offset",
")",
";",
"}",
"}"
] |
Returns the UNIX timestamp at which we must stop scanning.
|
[
"Returns",
"the",
"UNIX",
"timestamp",
"at",
"which",
"we",
"must",
"stop",
"scanning",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/TsdbQuery.java#L1547-L1606
|
13,635
|
OpenTSDB/opentsdb
|
src/core/TsdbQuery.java
|
TsdbQuery.createAndSetFilter
|
private void createAndSetFilter(final Scanner scanner) {
QueryUtil.setDataTableScanFilter(scanner, group_bys, row_key_literals,
explicit_tags, enable_fuzzy_filter,
(end_time == UNSET
? -1 // Will scan until the end (0xFFF...).
: (int) getScanEndTimeSeconds()));
}
|
java
|
private void createAndSetFilter(final Scanner scanner) {
QueryUtil.setDataTableScanFilter(scanner, group_bys, row_key_literals,
explicit_tags, enable_fuzzy_filter,
(end_time == UNSET
? -1 // Will scan until the end (0xFFF...).
: (int) getScanEndTimeSeconds()));
}
|
[
"private",
"void",
"createAndSetFilter",
"(",
"final",
"Scanner",
"scanner",
")",
"{",
"QueryUtil",
".",
"setDataTableScanFilter",
"(",
"scanner",
",",
"group_bys",
",",
"row_key_literals",
",",
"explicit_tags",
",",
"enable_fuzzy_filter",
",",
"(",
"end_time",
"==",
"UNSET",
"?",
"-",
"1",
"// Will scan until the end (0xFFF...).",
":",
"(",
"int",
")",
"getScanEndTimeSeconds",
"(",
")",
")",
")",
";",
"}"
] |
Sets the server-side regexp filter on the scanner.
In order to find the rows with the relevant tags, we use a
server-side filter that matches a regular expression on the row key.
@param scanner The scanner on which to add the filter.
|
[
"Sets",
"the",
"server",
"-",
"side",
"regexp",
"filter",
"on",
"the",
"scanner",
".",
"In",
"order",
"to",
"find",
"the",
"rows",
"with",
"the",
"relevant",
"tags",
"we",
"use",
"a",
"server",
"-",
"side",
"filter",
"that",
"matches",
"a",
"regular",
"expression",
"on",
"the",
"row",
"key",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/TsdbQuery.java#L1614-L1620
|
13,636
|
OpenTSDB/opentsdb
|
src/core/TsdbQuery.java
|
TsdbQuery.transformDownSamplerToRollupQuery
|
public void transformDownSamplerToRollupQuery(final Aggregator group_by,
final String str_interval) {
if (downsampler != null && downsampler.getInterval() > 0) {
if (tsdb.getRollupConfig() != null) {
try {
best_match_rollups = tsdb.getRollupConfig().
getRollupInterval(downsampler.getInterval() / 1000, str_interval);
//It is thread safe as each thread will be working on unique
// TsdbQuery object
//RollupConfig.getRollupInterval guarantees that,
// it always return a non-empty list
// TODO
rollup_query = new RollupQuery(best_match_rollups.remove(0),
downsampler.getFunction(), downsampler.getInterval(),
group_by);
if (group_by == Aggregators.COUNT) {
aggregator = Aggregators.SUM;
}
}
catch (NoSuchRollupForIntervalException nre) {
LOG.error("There is no such rollup for the downsample interval "
+ str_interval + ". So fall back to the default tsdb down"
+ " sampling approach and it requires raw data scan." );
//nullify the rollup_query if this api is called explicitly
rollup_query = null;
return;
}
if (rollup_query.getRollupInterval().isDefaultInterval()) {
//Anyways it is a scan on raw data
rollup_query = null;
}
}
}
}
|
java
|
public void transformDownSamplerToRollupQuery(final Aggregator group_by,
final String str_interval) {
if (downsampler != null && downsampler.getInterval() > 0) {
if (tsdb.getRollupConfig() != null) {
try {
best_match_rollups = tsdb.getRollupConfig().
getRollupInterval(downsampler.getInterval() / 1000, str_interval);
//It is thread safe as each thread will be working on unique
// TsdbQuery object
//RollupConfig.getRollupInterval guarantees that,
// it always return a non-empty list
// TODO
rollup_query = new RollupQuery(best_match_rollups.remove(0),
downsampler.getFunction(), downsampler.getInterval(),
group_by);
if (group_by == Aggregators.COUNT) {
aggregator = Aggregators.SUM;
}
}
catch (NoSuchRollupForIntervalException nre) {
LOG.error("There is no such rollup for the downsample interval "
+ str_interval + ". So fall back to the default tsdb down"
+ " sampling approach and it requires raw data scan." );
//nullify the rollup_query if this api is called explicitly
rollup_query = null;
return;
}
if (rollup_query.getRollupInterval().isDefaultInterval()) {
//Anyways it is a scan on raw data
rollup_query = null;
}
}
}
}
|
[
"public",
"void",
"transformDownSamplerToRollupQuery",
"(",
"final",
"Aggregator",
"group_by",
",",
"final",
"String",
"str_interval",
")",
"{",
"if",
"(",
"downsampler",
"!=",
"null",
"&&",
"downsampler",
".",
"getInterval",
"(",
")",
">",
"0",
")",
"{",
"if",
"(",
"tsdb",
".",
"getRollupConfig",
"(",
")",
"!=",
"null",
")",
"{",
"try",
"{",
"best_match_rollups",
"=",
"tsdb",
".",
"getRollupConfig",
"(",
")",
".",
"getRollupInterval",
"(",
"downsampler",
".",
"getInterval",
"(",
")",
"/",
"1000",
",",
"str_interval",
")",
";",
"//It is thread safe as each thread will be working on unique ",
"// TsdbQuery object",
"//RollupConfig.getRollupInterval guarantees that, ",
"// it always return a non-empty list",
"// TODO",
"rollup_query",
"=",
"new",
"RollupQuery",
"(",
"best_match_rollups",
".",
"remove",
"(",
"0",
")",
",",
"downsampler",
".",
"getFunction",
"(",
")",
",",
"downsampler",
".",
"getInterval",
"(",
")",
",",
"group_by",
")",
";",
"if",
"(",
"group_by",
"==",
"Aggregators",
".",
"COUNT",
")",
"{",
"aggregator",
"=",
"Aggregators",
".",
"SUM",
";",
"}",
"}",
"catch",
"(",
"NoSuchRollupForIntervalException",
"nre",
")",
"{",
"LOG",
".",
"error",
"(",
"\"There is no such rollup for the downsample interval \"",
"+",
"str_interval",
"+",
"\". So fall back to the default tsdb down\"",
"+",
"\" sampling approach and it requires raw data scan.\"",
")",
";",
"//nullify the rollup_query if this api is called explicitly",
"rollup_query",
"=",
"null",
";",
"return",
";",
"}",
"if",
"(",
"rollup_query",
".",
"getRollupInterval",
"(",
")",
".",
"isDefaultInterval",
"(",
")",
")",
"{",
"//Anyways it is a scan on raw data",
"rollup_query",
"=",
"null",
";",
"}",
"}",
"}",
"}"
] |
Transform downsampler properties to rollup properties, if the rollup
is enabled at configuration level and down sampler is set.
It falls back to raw data and down sampling if there is no
RollupInterval is configured against this down sample interval
@param group_by The group by aggregator.
@param str_interval String representation of the interval, for logging
@since 2.4
|
[
"Transform",
"downsampler",
"properties",
"to",
"rollup",
"properties",
"if",
"the",
"rollup",
"is",
"enabled",
"at",
"configuration",
"level",
"and",
"down",
"sampler",
"is",
"set",
".",
"It",
"falls",
"back",
"to",
"raw",
"data",
"and",
"down",
"sampling",
"if",
"there",
"is",
"no",
"RollupInterval",
"is",
"configured",
"against",
"this",
"down",
"sample",
"interval"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/TsdbQuery.java#L1664-L1699
|
13,637
|
OpenTSDB/opentsdb
|
src/core/TsdbQuery.java
|
TsdbQuery.transformRollupQueryToDownSampler
|
private void transformRollupQueryToDownSampler() {
if (rollup_query != null) {
// TODO - clean up and handle fill
downsampler = new DownsamplingSpecification(
rollup_query.getRollupInterval().getIntervalSeconds() * 1000,
rollup_query.getRollupAgg(),
(downsampler != null ? downsampler.getFillPolicy() :
FillPolicy.ZERO));
rollup_query = null;
}
}
|
java
|
private void transformRollupQueryToDownSampler() {
if (rollup_query != null) {
// TODO - clean up and handle fill
downsampler = new DownsamplingSpecification(
rollup_query.getRollupInterval().getIntervalSeconds() * 1000,
rollup_query.getRollupAgg(),
(downsampler != null ? downsampler.getFillPolicy() :
FillPolicy.ZERO));
rollup_query = null;
}
}
|
[
"private",
"void",
"transformRollupQueryToDownSampler",
"(",
")",
"{",
"if",
"(",
"rollup_query",
"!=",
"null",
")",
"{",
"// TODO - clean up and handle fill",
"downsampler",
"=",
"new",
"DownsamplingSpecification",
"(",
"rollup_query",
".",
"getRollupInterval",
"(",
")",
".",
"getIntervalSeconds",
"(",
")",
"*",
"1000",
",",
"rollup_query",
".",
"getRollupAgg",
"(",
")",
",",
"(",
"downsampler",
"!=",
"null",
"?",
"downsampler",
".",
"getFillPolicy",
"(",
")",
":",
"FillPolicy",
".",
"ZERO",
")",
")",
";",
"rollup_query",
"=",
"null",
";",
"}",
"}"
] |
Transform rollup query to downsampler
It is mainly useful when it scan on raw data on fallback.
@since 2.4
|
[
"Transform",
"rollup",
"query",
"to",
"downsampler",
"It",
"is",
"mainly",
"useful",
"when",
"it",
"scan",
"on",
"raw",
"data",
"on",
"fallback",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/TsdbQuery.java#L1706-L1717
|
13,638
|
OpenTSDB/opentsdb
|
src/tree/Tree.java
|
Tree.copyChanges
|
public boolean copyChanges(final Tree tree, final boolean overwrite) {
if (tree == null) {
throw new IllegalArgumentException("Cannot copy a null tree");
}
if (tree_id != tree.tree_id) {
throw new IllegalArgumentException("Tree IDs do not match");
}
if (overwrite || tree.changed.get("name")) {
name = tree.name;
changed.put("name", true);
}
if (overwrite || tree.changed.get("description")) {
description = tree.description;
changed.put("description", true);
}
if (overwrite || tree.changed.get("notes")) {
notes = tree.notes;
changed.put("notes", true);
}
if (overwrite || tree.changed.get("strict_match")) {
strict_match = tree.strict_match;
changed.put("strict_match", true);
}
if (overwrite || tree.changed.get("enabled")) {
enabled = tree.enabled;
changed.put("enabled", true);
}
if (overwrite || tree.changed.get("store_failures")) {
store_failures = tree.store_failures;
changed.put("store_failures", true);
}
for (boolean has_changes : changed.values()) {
if (has_changes) {
return true;
}
}
return false;
}
|
java
|
public boolean copyChanges(final Tree tree, final boolean overwrite) {
if (tree == null) {
throw new IllegalArgumentException("Cannot copy a null tree");
}
if (tree_id != tree.tree_id) {
throw new IllegalArgumentException("Tree IDs do not match");
}
if (overwrite || tree.changed.get("name")) {
name = tree.name;
changed.put("name", true);
}
if (overwrite || tree.changed.get("description")) {
description = tree.description;
changed.put("description", true);
}
if (overwrite || tree.changed.get("notes")) {
notes = tree.notes;
changed.put("notes", true);
}
if (overwrite || tree.changed.get("strict_match")) {
strict_match = tree.strict_match;
changed.put("strict_match", true);
}
if (overwrite || tree.changed.get("enabled")) {
enabled = tree.enabled;
changed.put("enabled", true);
}
if (overwrite || tree.changed.get("store_failures")) {
store_failures = tree.store_failures;
changed.put("store_failures", true);
}
for (boolean has_changes : changed.values()) {
if (has_changes) {
return true;
}
}
return false;
}
|
[
"public",
"boolean",
"copyChanges",
"(",
"final",
"Tree",
"tree",
",",
"final",
"boolean",
"overwrite",
")",
"{",
"if",
"(",
"tree",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Cannot copy a null tree\"",
")",
";",
"}",
"if",
"(",
"tree_id",
"!=",
"tree",
".",
"tree_id",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Tree IDs do not match\"",
")",
";",
"}",
"if",
"(",
"overwrite",
"||",
"tree",
".",
"changed",
".",
"get",
"(",
"\"name\"",
")",
")",
"{",
"name",
"=",
"tree",
".",
"name",
";",
"changed",
".",
"put",
"(",
"\"name\"",
",",
"true",
")",
";",
"}",
"if",
"(",
"overwrite",
"||",
"tree",
".",
"changed",
".",
"get",
"(",
"\"description\"",
")",
")",
"{",
"description",
"=",
"tree",
".",
"description",
";",
"changed",
".",
"put",
"(",
"\"description\"",
",",
"true",
")",
";",
"}",
"if",
"(",
"overwrite",
"||",
"tree",
".",
"changed",
".",
"get",
"(",
"\"notes\"",
")",
")",
"{",
"notes",
"=",
"tree",
".",
"notes",
";",
"changed",
".",
"put",
"(",
"\"notes\"",
",",
"true",
")",
";",
"}",
"if",
"(",
"overwrite",
"||",
"tree",
".",
"changed",
".",
"get",
"(",
"\"strict_match\"",
")",
")",
"{",
"strict_match",
"=",
"tree",
".",
"strict_match",
";",
"changed",
".",
"put",
"(",
"\"strict_match\"",
",",
"true",
")",
";",
"}",
"if",
"(",
"overwrite",
"||",
"tree",
".",
"changed",
".",
"get",
"(",
"\"enabled\"",
")",
")",
"{",
"enabled",
"=",
"tree",
".",
"enabled",
";",
"changed",
".",
"put",
"(",
"\"enabled\"",
",",
"true",
")",
";",
"}",
"if",
"(",
"overwrite",
"||",
"tree",
".",
"changed",
".",
"get",
"(",
"\"store_failures\"",
")",
")",
"{",
"store_failures",
"=",
"tree",
".",
"store_failures",
";",
"changed",
".",
"put",
"(",
"\"store_failures\"",
",",
"true",
")",
";",
"}",
"for",
"(",
"boolean",
"has_changes",
":",
"changed",
".",
"values",
"(",
")",
")",
"{",
"if",
"(",
"has_changes",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Copies changes from the incoming tree into the local tree, overriding if
called to. Only parses user mutable fields, excluding rules.
@param tree The tree to copy from
@param overwrite Whether or not to copy all values from the incoming tree
@return True if there were changes, false if not
@throws IllegalArgumentException if the incoming tree was invalid
|
[
"Copies",
"changes",
"from",
"the",
"incoming",
"tree",
"into",
"the",
"local",
"tree",
"overriding",
"if",
"called",
"to",
".",
"Only",
"parses",
"user",
"mutable",
"fields",
"excluding",
"rules",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tree/Tree.java#L202-L240
|
13,639
|
OpenTSDB/opentsdb
|
src/tree/Tree.java
|
Tree.addRule
|
public void addRule(final TreeRule rule) {
if (rule == null) {
throw new IllegalArgumentException("Null rules are not accepted");
}
if (rules == null) {
rules = new TreeMap<Integer, TreeMap<Integer, TreeRule>>();
}
TreeMap<Integer, TreeRule> level = rules.get(rule.getLevel());
if (level == null) {
level = new TreeMap<Integer, TreeRule>();
level.put(rule.getOrder(), rule);
rules.put(rule.getLevel(), level);
} else {
level.put(rule.getOrder(), rule);
}
changed.put("rules", true);
}
|
java
|
public void addRule(final TreeRule rule) {
if (rule == null) {
throw new IllegalArgumentException("Null rules are not accepted");
}
if (rules == null) {
rules = new TreeMap<Integer, TreeMap<Integer, TreeRule>>();
}
TreeMap<Integer, TreeRule> level = rules.get(rule.getLevel());
if (level == null) {
level = new TreeMap<Integer, TreeRule>();
level.put(rule.getOrder(), rule);
rules.put(rule.getLevel(), level);
} else {
level.put(rule.getOrder(), rule);
}
changed.put("rules", true);
}
|
[
"public",
"void",
"addRule",
"(",
"final",
"TreeRule",
"rule",
")",
"{",
"if",
"(",
"rule",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Null rules are not accepted\"",
")",
";",
"}",
"if",
"(",
"rules",
"==",
"null",
")",
"{",
"rules",
"=",
"new",
"TreeMap",
"<",
"Integer",
",",
"TreeMap",
"<",
"Integer",
",",
"TreeRule",
">",
">",
"(",
")",
";",
"}",
"TreeMap",
"<",
"Integer",
",",
"TreeRule",
">",
"level",
"=",
"rules",
".",
"get",
"(",
"rule",
".",
"getLevel",
"(",
")",
")",
";",
"if",
"(",
"level",
"==",
"null",
")",
"{",
"level",
"=",
"new",
"TreeMap",
"<",
"Integer",
",",
"TreeRule",
">",
"(",
")",
";",
"level",
".",
"put",
"(",
"rule",
".",
"getOrder",
"(",
")",
",",
"rule",
")",
";",
"rules",
".",
"put",
"(",
"rule",
".",
"getLevel",
"(",
")",
",",
"level",
")",
";",
"}",
"else",
"{",
"level",
".",
"put",
"(",
"rule",
".",
"getOrder",
"(",
")",
",",
"rule",
")",
";",
"}",
"changed",
".",
"put",
"(",
"\"rules\"",
",",
"true",
")",
";",
"}"
] |
Adds the given rule to the tree, replacing anything in the designated spot
@param rule The rule to add
@throws IllegalArgumentException if the incoming rule was invalid
|
[
"Adds",
"the",
"given",
"rule",
"to",
"the",
"tree",
"replacing",
"anything",
"in",
"the",
"designated",
"spot"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tree/Tree.java#L247-L265
|
13,640
|
OpenTSDB/opentsdb
|
src/tree/Tree.java
|
Tree.addCollision
|
public void addCollision(final String tsuid, final String existing_tsuid) {
if (tsuid == null || tsuid.isEmpty()) {
throw new IllegalArgumentException("Empty or null collisions not allowed");
}
if (collisions == null) {
collisions = new HashMap<String, String>();
}
if (!collisions.containsKey(tsuid)) {
collisions.put(tsuid, existing_tsuid);
changed.put("collisions", true);
}
}
|
java
|
public void addCollision(final String tsuid, final String existing_tsuid) {
if (tsuid == null || tsuid.isEmpty()) {
throw new IllegalArgumentException("Empty or null collisions not allowed");
}
if (collisions == null) {
collisions = new HashMap<String, String>();
}
if (!collisions.containsKey(tsuid)) {
collisions.put(tsuid, existing_tsuid);
changed.put("collisions", true);
}
}
|
[
"public",
"void",
"addCollision",
"(",
"final",
"String",
"tsuid",
",",
"final",
"String",
"existing_tsuid",
")",
"{",
"if",
"(",
"tsuid",
"==",
"null",
"||",
"tsuid",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Empty or null collisions not allowed\"",
")",
";",
"}",
"if",
"(",
"collisions",
"==",
"null",
")",
"{",
"collisions",
"=",
"new",
"HashMap",
"<",
"String",
",",
"String",
">",
"(",
")",
";",
"}",
"if",
"(",
"!",
"collisions",
".",
"containsKey",
"(",
"tsuid",
")",
")",
"{",
"collisions",
".",
"put",
"(",
"tsuid",
",",
"existing_tsuid",
")",
";",
"changed",
".",
"put",
"(",
"\"collisions\"",
",",
"true",
")",
";",
"}",
"}"
] |
Adds a TSUID to the collision local list, must then be synced with storage
@param tsuid TSUID to add to the set
@throws IllegalArgumentException if the tsuid was invalid
|
[
"Adds",
"a",
"TSUID",
"to",
"the",
"collision",
"local",
"list",
"must",
"then",
"be",
"synced",
"with",
"storage"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tree/Tree.java#L272-L283
|
13,641
|
OpenTSDB/opentsdb
|
src/tree/Tree.java
|
Tree.addNotMatched
|
public void addNotMatched(final String tsuid, final String message) {
if (tsuid == null || tsuid.isEmpty()) {
throw new IllegalArgumentException("Empty or null non matches not allowed");
}
if (not_matched == null) {
not_matched = new HashMap<String, String>();
}
if (!not_matched.containsKey(tsuid)) {
not_matched.put(tsuid, message);
changed.put("not_matched", true);
}
}
|
java
|
public void addNotMatched(final String tsuid, final String message) {
if (tsuid == null || tsuid.isEmpty()) {
throw new IllegalArgumentException("Empty or null non matches not allowed");
}
if (not_matched == null) {
not_matched = new HashMap<String, String>();
}
if (!not_matched.containsKey(tsuid)) {
not_matched.put(tsuid, message);
changed.put("not_matched", true);
}
}
|
[
"public",
"void",
"addNotMatched",
"(",
"final",
"String",
"tsuid",
",",
"final",
"String",
"message",
")",
"{",
"if",
"(",
"tsuid",
"==",
"null",
"||",
"tsuid",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Empty or null non matches not allowed\"",
")",
";",
"}",
"if",
"(",
"not_matched",
"==",
"null",
")",
"{",
"not_matched",
"=",
"new",
"HashMap",
"<",
"String",
",",
"String",
">",
"(",
")",
";",
"}",
"if",
"(",
"!",
"not_matched",
".",
"containsKey",
"(",
"tsuid",
")",
")",
"{",
"not_matched",
".",
"put",
"(",
"tsuid",
",",
"message",
")",
";",
"changed",
".",
"put",
"(",
"\"not_matched\"",
",",
"true",
")",
";",
"}",
"}"
] |
Adds a TSUID to the not-matched local list when strict_matching is enabled.
Must be synced with storage.
@param tsuid TSUID to add to the set
@throws IllegalArgumentException if the tsuid was invalid
|
[
"Adds",
"a",
"TSUID",
"to",
"the",
"not",
"-",
"matched",
"local",
"list",
"when",
"strict_matching",
"is",
"enabled",
".",
"Must",
"be",
"synced",
"with",
"storage",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tree/Tree.java#L291-L302
|
13,642
|
OpenTSDB/opentsdb
|
src/tree/Tree.java
|
Tree.storeTree
|
public Deferred<Boolean> storeTree(final TSDB tsdb, final boolean overwrite) {
if (tree_id < 1 || tree_id > 65535) {
throw new IllegalArgumentException("Invalid Tree ID");
}
// if there aren't any changes, save time and bandwidth by not writing to
// storage
boolean has_changes = false;
for (Map.Entry<String, Boolean> entry : changed.entrySet()) {
if (entry.getValue()) {
has_changes = true;
break;
}
}
if (!has_changes) {
LOG.debug(this + " does not have changes, skipping sync to storage");
throw new IllegalStateException("No changes detected in the tree");
}
/**
* Callback executed after loading a tree from storage so that we can
* synchronize changes to the meta data and write them back to storage.
*/
final class StoreTreeCB implements Callback<Deferred<Boolean>, Tree> {
final private Tree local_tree;
public StoreTreeCB(final Tree local_tree) {
this.local_tree = local_tree;
}
/**
* Synchronizes the stored tree object (if found) with the local tree
* and issues a CAS call to write the update to storage.
* @return True if the CAS was successful, false if something changed
* in flight
*/
@Override
public Deferred<Boolean> call(final Tree fetched_tree) throws Exception {
Tree stored_tree = fetched_tree;
final byte[] original_tree = stored_tree == null ? new byte[0] :
stored_tree.toStorageJson();
// now copy changes
if (stored_tree == null) {
stored_tree = local_tree;
} else {
stored_tree.copyChanges(local_tree, overwrite);
}
// reset the change map so we don't keep writing
initializeChangedMap();
final PutRequest put = new PutRequest(tsdb.treeTable(),
Tree.idToBytes(tree_id), TREE_FAMILY, TREE_QUALIFIER,
stored_tree.toStorageJson());
return tsdb.getClient().compareAndSet(put, original_tree);
}
}
// initiate the sync by attempting to fetch an existing tree from storage
return fetchTree(tsdb, tree_id).addCallbackDeferring(new StoreTreeCB(this));
}
|
java
|
public Deferred<Boolean> storeTree(final TSDB tsdb, final boolean overwrite) {
if (tree_id < 1 || tree_id > 65535) {
throw new IllegalArgumentException("Invalid Tree ID");
}
// if there aren't any changes, save time and bandwidth by not writing to
// storage
boolean has_changes = false;
for (Map.Entry<String, Boolean> entry : changed.entrySet()) {
if (entry.getValue()) {
has_changes = true;
break;
}
}
if (!has_changes) {
LOG.debug(this + " does not have changes, skipping sync to storage");
throw new IllegalStateException("No changes detected in the tree");
}
/**
* Callback executed after loading a tree from storage so that we can
* synchronize changes to the meta data and write them back to storage.
*/
final class StoreTreeCB implements Callback<Deferred<Boolean>, Tree> {
final private Tree local_tree;
public StoreTreeCB(final Tree local_tree) {
this.local_tree = local_tree;
}
/**
* Synchronizes the stored tree object (if found) with the local tree
* and issues a CAS call to write the update to storage.
* @return True if the CAS was successful, false if something changed
* in flight
*/
@Override
public Deferred<Boolean> call(final Tree fetched_tree) throws Exception {
Tree stored_tree = fetched_tree;
final byte[] original_tree = stored_tree == null ? new byte[0] :
stored_tree.toStorageJson();
// now copy changes
if (stored_tree == null) {
stored_tree = local_tree;
} else {
stored_tree.copyChanges(local_tree, overwrite);
}
// reset the change map so we don't keep writing
initializeChangedMap();
final PutRequest put = new PutRequest(tsdb.treeTable(),
Tree.idToBytes(tree_id), TREE_FAMILY, TREE_QUALIFIER,
stored_tree.toStorageJson());
return tsdb.getClient().compareAndSet(put, original_tree);
}
}
// initiate the sync by attempting to fetch an existing tree from storage
return fetchTree(tsdb, tree_id).addCallbackDeferring(new StoreTreeCB(this));
}
|
[
"public",
"Deferred",
"<",
"Boolean",
">",
"storeTree",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"boolean",
"overwrite",
")",
"{",
"if",
"(",
"tree_id",
"<",
"1",
"||",
"tree_id",
">",
"65535",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid Tree ID\"",
")",
";",
"}",
"// if there aren't any changes, save time and bandwidth by not writing to",
"// storage",
"boolean",
"has_changes",
"=",
"false",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"Boolean",
">",
"entry",
":",
"changed",
".",
"entrySet",
"(",
")",
")",
"{",
"if",
"(",
"entry",
".",
"getValue",
"(",
")",
")",
"{",
"has_changes",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"has_changes",
")",
"{",
"LOG",
".",
"debug",
"(",
"this",
"+",
"\" does not have changes, skipping sync to storage\"",
")",
";",
"throw",
"new",
"IllegalStateException",
"(",
"\"No changes detected in the tree\"",
")",
";",
"}",
"/**\n * Callback executed after loading a tree from storage so that we can\n * synchronize changes to the meta data and write them back to storage.\n */",
"final",
"class",
"StoreTreeCB",
"implements",
"Callback",
"<",
"Deferred",
"<",
"Boolean",
">",
",",
"Tree",
">",
"{",
"final",
"private",
"Tree",
"local_tree",
";",
"public",
"StoreTreeCB",
"(",
"final",
"Tree",
"local_tree",
")",
"{",
"this",
".",
"local_tree",
"=",
"local_tree",
";",
"}",
"/**\n * Synchronizes the stored tree object (if found) with the local tree \n * and issues a CAS call to write the update to storage.\n * @return True if the CAS was successful, false if something changed \n * in flight\n */",
"@",
"Override",
"public",
"Deferred",
"<",
"Boolean",
">",
"call",
"(",
"final",
"Tree",
"fetched_tree",
")",
"throws",
"Exception",
"{",
"Tree",
"stored_tree",
"=",
"fetched_tree",
";",
"final",
"byte",
"[",
"]",
"original_tree",
"=",
"stored_tree",
"==",
"null",
"?",
"new",
"byte",
"[",
"0",
"]",
":",
"stored_tree",
".",
"toStorageJson",
"(",
")",
";",
"// now copy changes",
"if",
"(",
"stored_tree",
"==",
"null",
")",
"{",
"stored_tree",
"=",
"local_tree",
";",
"}",
"else",
"{",
"stored_tree",
".",
"copyChanges",
"(",
"local_tree",
",",
"overwrite",
")",
";",
"}",
"// reset the change map so we don't keep writing",
"initializeChangedMap",
"(",
")",
";",
"final",
"PutRequest",
"put",
"=",
"new",
"PutRequest",
"(",
"tsdb",
".",
"treeTable",
"(",
")",
",",
"Tree",
".",
"idToBytes",
"(",
"tree_id",
")",
",",
"TREE_FAMILY",
",",
"TREE_QUALIFIER",
",",
"stored_tree",
".",
"toStorageJson",
"(",
")",
")",
";",
"return",
"tsdb",
".",
"getClient",
"(",
")",
".",
"compareAndSet",
"(",
"put",
",",
"original_tree",
")",
";",
"}",
"}",
"// initiate the sync by attempting to fetch an existing tree from storage",
"return",
"fetchTree",
"(",
"tsdb",
",",
"tree_id",
")",
".",
"addCallbackDeferring",
"(",
"new",
"StoreTreeCB",
"(",
"this",
")",
")",
";",
"}"
] |
Attempts to store the tree definition via a CompareAndSet call.
@param tsdb The TSDB to use for access
@param overwrite Whether or not tree data should be overwritten
@return True if the write was successful, false if an error occurred
@throws IllegalArgumentException if the tree ID is missing or invalid
@throws HBaseException if a storage exception occurred
|
[
"Attempts",
"to",
"store",
"the",
"tree",
"definition",
"via",
"a",
"CompareAndSet",
"call",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tree/Tree.java#L312-L375
|
13,643
|
OpenTSDB/opentsdb
|
src/tree/Tree.java
|
Tree.getRule
|
public TreeRule getRule(final int level, final int order) {
if (rules == null || rules.isEmpty()) {
return null;
}
TreeMap<Integer, TreeRule> rule_level = rules.get(level);
if (rule_level == null || rule_level.isEmpty()) {
return null;
}
return rule_level.get(order);
}
|
java
|
public TreeRule getRule(final int level, final int order) {
if (rules == null || rules.isEmpty()) {
return null;
}
TreeMap<Integer, TreeRule> rule_level = rules.get(level);
if (rule_level == null || rule_level.isEmpty()) {
return null;
}
return rule_level.get(order);
}
|
[
"public",
"TreeRule",
"getRule",
"(",
"final",
"int",
"level",
",",
"final",
"int",
"order",
")",
"{",
"if",
"(",
"rules",
"==",
"null",
"||",
"rules",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"TreeMap",
"<",
"Integer",
",",
"TreeRule",
">",
"rule_level",
"=",
"rules",
".",
"get",
"(",
"level",
")",
";",
"if",
"(",
"rule_level",
"==",
"null",
"||",
"rule_level",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"rule_level",
".",
"get",
"(",
"order",
")",
";",
"}"
] |
Retrieves a single rule from the rule set given a level and order
@param level The level where the rule resides
@param order The order in the level where the rule resides
@return The rule if found, null if not found
|
[
"Retrieves",
"a",
"single",
"rule",
"from",
"the",
"rule",
"set",
"given",
"a",
"level",
"and",
"order"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tree/Tree.java#L383-L394
|
13,644
|
OpenTSDB/opentsdb
|
src/tree/Tree.java
|
Tree.fetchTree
|
public static Deferred<Tree> fetchTree(final TSDB tsdb, final int tree_id) {
if (tree_id < 1 || tree_id > 65535) {
throw new IllegalArgumentException("Invalid Tree ID");
}
// fetch the whole row
final GetRequest get = new GetRequest(tsdb.treeTable(), idToBytes(tree_id));
get.family(TREE_FAMILY);
/**
* Called from the GetRequest with results from storage. Loops through the
* columns and loads the tree definition and rules
*/
final class FetchTreeCB implements Callback<Deferred<Tree>,
ArrayList<KeyValue>> {
@Override
public Deferred<Tree> call(ArrayList<KeyValue> row) throws Exception {
if (row == null || row.isEmpty()) {
return Deferred.fromResult(null);
}
final Tree tree = new Tree();
// WARNING: Since the JSON in storage doesn't store the tree ID, we need
// to loadi t from the row key.
tree.setTreeId(bytesToId(row.get(0).key()));
for (KeyValue column : row) {
if (Bytes.memcmp(TREE_QUALIFIER, column.qualifier()) == 0) {
// it's *this* tree. We deserialize to a new object and copy
// since the columns could be in any order and we may get a rule
// before the tree object
final Tree local_tree = JSON.parseToObject(column.value(), Tree.class);
tree.created = local_tree.created;
tree.description = local_tree.description;
tree.name = local_tree.name;
tree.notes = local_tree.notes;
tree.strict_match = local_tree.strict_match;
tree.enabled = local_tree.enabled;
tree.store_failures = local_tree.store_failures;
// Tree rule
} else if (Bytes.memcmp(TreeRule.RULE_PREFIX(), column.qualifier(), 0,
TreeRule.RULE_PREFIX().length) == 0) {
final TreeRule rule = TreeRule.parseFromStorage(column);
tree.addRule(rule);
}
}
return Deferred.fromResult(tree);
}
}
// issue the get request
return tsdb.getClient().get(get).addCallbackDeferring(new FetchTreeCB());
}
|
java
|
public static Deferred<Tree> fetchTree(final TSDB tsdb, final int tree_id) {
if (tree_id < 1 || tree_id > 65535) {
throw new IllegalArgumentException("Invalid Tree ID");
}
// fetch the whole row
final GetRequest get = new GetRequest(tsdb.treeTable(), idToBytes(tree_id));
get.family(TREE_FAMILY);
/**
* Called from the GetRequest with results from storage. Loops through the
* columns and loads the tree definition and rules
*/
final class FetchTreeCB implements Callback<Deferred<Tree>,
ArrayList<KeyValue>> {
@Override
public Deferred<Tree> call(ArrayList<KeyValue> row) throws Exception {
if (row == null || row.isEmpty()) {
return Deferred.fromResult(null);
}
final Tree tree = new Tree();
// WARNING: Since the JSON in storage doesn't store the tree ID, we need
// to loadi t from the row key.
tree.setTreeId(bytesToId(row.get(0).key()));
for (KeyValue column : row) {
if (Bytes.memcmp(TREE_QUALIFIER, column.qualifier()) == 0) {
// it's *this* tree. We deserialize to a new object and copy
// since the columns could be in any order and we may get a rule
// before the tree object
final Tree local_tree = JSON.parseToObject(column.value(), Tree.class);
tree.created = local_tree.created;
tree.description = local_tree.description;
tree.name = local_tree.name;
tree.notes = local_tree.notes;
tree.strict_match = local_tree.strict_match;
tree.enabled = local_tree.enabled;
tree.store_failures = local_tree.store_failures;
// Tree rule
} else if (Bytes.memcmp(TreeRule.RULE_PREFIX(), column.qualifier(), 0,
TreeRule.RULE_PREFIX().length) == 0) {
final TreeRule rule = TreeRule.parseFromStorage(column);
tree.addRule(rule);
}
}
return Deferred.fromResult(tree);
}
}
// issue the get request
return tsdb.getClient().get(get).addCallbackDeferring(new FetchTreeCB());
}
|
[
"public",
"static",
"Deferred",
"<",
"Tree",
">",
"fetchTree",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"int",
"tree_id",
")",
"{",
"if",
"(",
"tree_id",
"<",
"1",
"||",
"tree_id",
">",
"65535",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid Tree ID\"",
")",
";",
"}",
"// fetch the whole row",
"final",
"GetRequest",
"get",
"=",
"new",
"GetRequest",
"(",
"tsdb",
".",
"treeTable",
"(",
")",
",",
"idToBytes",
"(",
"tree_id",
")",
")",
";",
"get",
".",
"family",
"(",
"TREE_FAMILY",
")",
";",
"/**\n * Called from the GetRequest with results from storage. Loops through the\n * columns and loads the tree definition and rules\n */",
"final",
"class",
"FetchTreeCB",
"implements",
"Callback",
"<",
"Deferred",
"<",
"Tree",
">",
",",
"ArrayList",
"<",
"KeyValue",
">",
">",
"{",
"@",
"Override",
"public",
"Deferred",
"<",
"Tree",
">",
"call",
"(",
"ArrayList",
"<",
"KeyValue",
">",
"row",
")",
"throws",
"Exception",
"{",
"if",
"(",
"row",
"==",
"null",
"||",
"row",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"Deferred",
".",
"fromResult",
"(",
"null",
")",
";",
"}",
"final",
"Tree",
"tree",
"=",
"new",
"Tree",
"(",
")",
";",
"// WARNING: Since the JSON in storage doesn't store the tree ID, we need",
"// to loadi t from the row key.",
"tree",
".",
"setTreeId",
"(",
"bytesToId",
"(",
"row",
".",
"get",
"(",
"0",
")",
".",
"key",
"(",
")",
")",
")",
";",
"for",
"(",
"KeyValue",
"column",
":",
"row",
")",
"{",
"if",
"(",
"Bytes",
".",
"memcmp",
"(",
"TREE_QUALIFIER",
",",
"column",
".",
"qualifier",
"(",
")",
")",
"==",
"0",
")",
"{",
"// it's *this* tree. We deserialize to a new object and copy",
"// since the columns could be in any order and we may get a rule ",
"// before the tree object",
"final",
"Tree",
"local_tree",
"=",
"JSON",
".",
"parseToObject",
"(",
"column",
".",
"value",
"(",
")",
",",
"Tree",
".",
"class",
")",
";",
"tree",
".",
"created",
"=",
"local_tree",
".",
"created",
";",
"tree",
".",
"description",
"=",
"local_tree",
".",
"description",
";",
"tree",
".",
"name",
"=",
"local_tree",
".",
"name",
";",
"tree",
".",
"notes",
"=",
"local_tree",
".",
"notes",
";",
"tree",
".",
"strict_match",
"=",
"local_tree",
".",
"strict_match",
";",
"tree",
".",
"enabled",
"=",
"local_tree",
".",
"enabled",
";",
"tree",
".",
"store_failures",
"=",
"local_tree",
".",
"store_failures",
";",
"// Tree rule",
"}",
"else",
"if",
"(",
"Bytes",
".",
"memcmp",
"(",
"TreeRule",
".",
"RULE_PREFIX",
"(",
")",
",",
"column",
".",
"qualifier",
"(",
")",
",",
"0",
",",
"TreeRule",
".",
"RULE_PREFIX",
"(",
")",
".",
"length",
")",
"==",
"0",
")",
"{",
"final",
"TreeRule",
"rule",
"=",
"TreeRule",
".",
"parseFromStorage",
"(",
"column",
")",
";",
"tree",
".",
"addRule",
"(",
"rule",
")",
";",
"}",
"}",
"return",
"Deferred",
".",
"fromResult",
"(",
"tree",
")",
";",
"}",
"}",
"// issue the get request",
"return",
"tsdb",
".",
"getClient",
"(",
")",
".",
"get",
"(",
"get",
")",
".",
"addCallbackDeferring",
"(",
"new",
"FetchTreeCB",
"(",
")",
")",
";",
"}"
] |
Attempts to fetch the given tree from storage, loading the rule set at
the same time.
@param tsdb The TSDB to use for access
@param tree_id The Tree to fetch
@return A tree object if found, null if the tree did not exist
@throws IllegalArgumentException if the tree ID was invalid
@throws HBaseException if a storage exception occurred
@throws JSONException if the object could not be deserialized
|
[
"Attempts",
"to",
"fetch",
"the",
"given",
"tree",
"from",
"storage",
"loading",
"the",
"rule",
"set",
"at",
"the",
"same",
"time",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tree/Tree.java#L470-L527
|
13,645
|
OpenTSDB/opentsdb
|
src/tree/Tree.java
|
Tree.fetchAllTrees
|
public static Deferred<List<Tree>> fetchAllTrees(final TSDB tsdb) {
final Deferred<List<Tree>> result = new Deferred<List<Tree>>();
/**
* Scanner callback that recursively calls itself to load the next set of
* rows from storage. When the scanner returns a null, the callback will
* return with the list of trees discovered.
*/
final class AllTreeScanner implements Callback<Object,
ArrayList<ArrayList<KeyValue>>> {
private final List<Tree> trees = new ArrayList<Tree>();
private final Scanner scanner;
public AllTreeScanner() {
scanner = setupAllTreeScanner(tsdb);
}
/**
* Fetches the next set of results from the scanner and adds this class
* as a callback.
* @return A list of trees if the scanner has reached the end
*/
public Object fetchTrees() {
return scanner.nextRows().addCallback(this);
}
@Override
public Object call(ArrayList<ArrayList<KeyValue>> rows)
throws Exception {
if (rows == null) {
result.callback(trees);
return null;
}
for (ArrayList<KeyValue> row : rows) {
final Tree tree = new Tree();
for (KeyValue column : row) {
if (column.qualifier().length >= TREE_QUALIFIER.length &&
Bytes.memcmp(TREE_QUALIFIER, column.qualifier()) == 0) {
// it's *this* tree. We deserialize to a new object and copy
// since the columns could be in any order and we may get a rule
// before the tree object
final Tree local_tree = JSON.parseToObject(column.value(),
Tree.class);
tree.created = local_tree.created;
tree.description = local_tree.description;
tree.name = local_tree.name;
tree.notes = local_tree.notes;
tree.strict_match = local_tree.strict_match;
tree.enabled = local_tree.enabled;
tree.store_failures = local_tree.store_failures;
// WARNING: Since the JSON data in storage doesn't contain the tree
// ID, we need to parse it from the row key
tree.setTreeId(bytesToId(row.get(0).key()));
// tree rule
} else if (column.qualifier().length > TreeRule.RULE_PREFIX().length &&
Bytes.memcmp(TreeRule.RULE_PREFIX(), column.qualifier(),
0, TreeRule.RULE_PREFIX().length) == 0) {
final TreeRule rule = TreeRule.parseFromStorage(column);
tree.addRule(rule);
}
}
// only add the tree if we parsed a valid ID
if (tree.tree_id > 0) {
trees.add(tree);
}
}
// recurse to get the next set of rows from the scanner
return fetchTrees();
}
}
// start the scanning process
new AllTreeScanner().fetchTrees();
return result;
}
|
java
|
public static Deferred<List<Tree>> fetchAllTrees(final TSDB tsdb) {
final Deferred<List<Tree>> result = new Deferred<List<Tree>>();
/**
* Scanner callback that recursively calls itself to load the next set of
* rows from storage. When the scanner returns a null, the callback will
* return with the list of trees discovered.
*/
final class AllTreeScanner implements Callback<Object,
ArrayList<ArrayList<KeyValue>>> {
private final List<Tree> trees = new ArrayList<Tree>();
private final Scanner scanner;
public AllTreeScanner() {
scanner = setupAllTreeScanner(tsdb);
}
/**
* Fetches the next set of results from the scanner and adds this class
* as a callback.
* @return A list of trees if the scanner has reached the end
*/
public Object fetchTrees() {
return scanner.nextRows().addCallback(this);
}
@Override
public Object call(ArrayList<ArrayList<KeyValue>> rows)
throws Exception {
if (rows == null) {
result.callback(trees);
return null;
}
for (ArrayList<KeyValue> row : rows) {
final Tree tree = new Tree();
for (KeyValue column : row) {
if (column.qualifier().length >= TREE_QUALIFIER.length &&
Bytes.memcmp(TREE_QUALIFIER, column.qualifier()) == 0) {
// it's *this* tree. We deserialize to a new object and copy
// since the columns could be in any order and we may get a rule
// before the tree object
final Tree local_tree = JSON.parseToObject(column.value(),
Tree.class);
tree.created = local_tree.created;
tree.description = local_tree.description;
tree.name = local_tree.name;
tree.notes = local_tree.notes;
tree.strict_match = local_tree.strict_match;
tree.enabled = local_tree.enabled;
tree.store_failures = local_tree.store_failures;
// WARNING: Since the JSON data in storage doesn't contain the tree
// ID, we need to parse it from the row key
tree.setTreeId(bytesToId(row.get(0).key()));
// tree rule
} else if (column.qualifier().length > TreeRule.RULE_PREFIX().length &&
Bytes.memcmp(TreeRule.RULE_PREFIX(), column.qualifier(),
0, TreeRule.RULE_PREFIX().length) == 0) {
final TreeRule rule = TreeRule.parseFromStorage(column);
tree.addRule(rule);
}
}
// only add the tree if we parsed a valid ID
if (tree.tree_id > 0) {
trees.add(tree);
}
}
// recurse to get the next set of rows from the scanner
return fetchTrees();
}
}
// start the scanning process
new AllTreeScanner().fetchTrees();
return result;
}
|
[
"public",
"static",
"Deferred",
"<",
"List",
"<",
"Tree",
">",
">",
"fetchAllTrees",
"(",
"final",
"TSDB",
"tsdb",
")",
"{",
"final",
"Deferred",
"<",
"List",
"<",
"Tree",
">",
">",
"result",
"=",
"new",
"Deferred",
"<",
"List",
"<",
"Tree",
">",
">",
"(",
")",
";",
"/**\n * Scanner callback that recursively calls itself to load the next set of\n * rows from storage. When the scanner returns a null, the callback will\n * return with the list of trees discovered.\n */",
"final",
"class",
"AllTreeScanner",
"implements",
"Callback",
"<",
"Object",
",",
"ArrayList",
"<",
"ArrayList",
"<",
"KeyValue",
">",
">",
">",
"{",
"private",
"final",
"List",
"<",
"Tree",
">",
"trees",
"=",
"new",
"ArrayList",
"<",
"Tree",
">",
"(",
")",
";",
"private",
"final",
"Scanner",
"scanner",
";",
"public",
"AllTreeScanner",
"(",
")",
"{",
"scanner",
"=",
"setupAllTreeScanner",
"(",
"tsdb",
")",
";",
"}",
"/**\n * Fetches the next set of results from the scanner and adds this class\n * as a callback.\n * @return A list of trees if the scanner has reached the end\n */",
"public",
"Object",
"fetchTrees",
"(",
")",
"{",
"return",
"scanner",
".",
"nextRows",
"(",
")",
".",
"addCallback",
"(",
"this",
")",
";",
"}",
"@",
"Override",
"public",
"Object",
"call",
"(",
"ArrayList",
"<",
"ArrayList",
"<",
"KeyValue",
">",
">",
"rows",
")",
"throws",
"Exception",
"{",
"if",
"(",
"rows",
"==",
"null",
")",
"{",
"result",
".",
"callback",
"(",
"trees",
")",
";",
"return",
"null",
";",
"}",
"for",
"(",
"ArrayList",
"<",
"KeyValue",
">",
"row",
":",
"rows",
")",
"{",
"final",
"Tree",
"tree",
"=",
"new",
"Tree",
"(",
")",
";",
"for",
"(",
"KeyValue",
"column",
":",
"row",
")",
"{",
"if",
"(",
"column",
".",
"qualifier",
"(",
")",
".",
"length",
">=",
"TREE_QUALIFIER",
".",
"length",
"&&",
"Bytes",
".",
"memcmp",
"(",
"TREE_QUALIFIER",
",",
"column",
".",
"qualifier",
"(",
")",
")",
"==",
"0",
")",
"{",
"// it's *this* tree. We deserialize to a new object and copy",
"// since the columns could be in any order and we may get a rule ",
"// before the tree object",
"final",
"Tree",
"local_tree",
"=",
"JSON",
".",
"parseToObject",
"(",
"column",
".",
"value",
"(",
")",
",",
"Tree",
".",
"class",
")",
";",
"tree",
".",
"created",
"=",
"local_tree",
".",
"created",
";",
"tree",
".",
"description",
"=",
"local_tree",
".",
"description",
";",
"tree",
".",
"name",
"=",
"local_tree",
".",
"name",
";",
"tree",
".",
"notes",
"=",
"local_tree",
".",
"notes",
";",
"tree",
".",
"strict_match",
"=",
"local_tree",
".",
"strict_match",
";",
"tree",
".",
"enabled",
"=",
"local_tree",
".",
"enabled",
";",
"tree",
".",
"store_failures",
"=",
"local_tree",
".",
"store_failures",
";",
"// WARNING: Since the JSON data in storage doesn't contain the tree",
"// ID, we need to parse it from the row key",
"tree",
".",
"setTreeId",
"(",
"bytesToId",
"(",
"row",
".",
"get",
"(",
"0",
")",
".",
"key",
"(",
")",
")",
")",
";",
"// tree rule",
"}",
"else",
"if",
"(",
"column",
".",
"qualifier",
"(",
")",
".",
"length",
">",
"TreeRule",
".",
"RULE_PREFIX",
"(",
")",
".",
"length",
"&&",
"Bytes",
".",
"memcmp",
"(",
"TreeRule",
".",
"RULE_PREFIX",
"(",
")",
",",
"column",
".",
"qualifier",
"(",
")",
",",
"0",
",",
"TreeRule",
".",
"RULE_PREFIX",
"(",
")",
".",
"length",
")",
"==",
"0",
")",
"{",
"final",
"TreeRule",
"rule",
"=",
"TreeRule",
".",
"parseFromStorage",
"(",
"column",
")",
";",
"tree",
".",
"addRule",
"(",
"rule",
")",
";",
"}",
"}",
"// only add the tree if we parsed a valid ID",
"if",
"(",
"tree",
".",
"tree_id",
">",
"0",
")",
"{",
"trees",
".",
"add",
"(",
"tree",
")",
";",
"}",
"}",
"// recurse to get the next set of rows from the scanner",
"return",
"fetchTrees",
"(",
")",
";",
"}",
"}",
"// start the scanning process",
"new",
"AllTreeScanner",
"(",
")",
".",
"fetchTrees",
"(",
")",
";",
"return",
"result",
";",
"}"
] |
Attempts to retrieve all trees from the UID table, including their rules.
If no trees were found, the result will be an empty list
@param tsdb The TSDB to use for storage
@return A list of tree objects. May be empty if none were found
|
[
"Attempts",
"to",
"retrieve",
"all",
"trees",
"from",
"the",
"UID",
"table",
"including",
"their",
"rules",
".",
"If",
"no",
"trees",
"were",
"found",
"the",
"result",
"will",
"be",
"an",
"empty",
"list"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tree/Tree.java#L535-L617
|
13,646
|
OpenTSDB/opentsdb
|
src/tree/Tree.java
|
Tree.toStorageJson
|
private byte[] toStorageJson() {
// TODO - precalc how much memory to grab
final ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
final JsonGenerator json = JSON.getFactory().createGenerator(output);
json.writeStartObject();
// we only need to write a small amount of information
//json.writeNumberField("treeId", tree_id);
json.writeStringField("name", name);
json.writeStringField("description", description);
json.writeStringField("notes", notes);
json.writeBooleanField("strictMatch", strict_match);
json.writeNumberField("created", created);
json.writeBooleanField("enabled", enabled);
json.writeBooleanField("storeFailures", store_failures);
json.writeEndObject();
json.close();
// TODO zero copy?
return output.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
|
java
|
private byte[] toStorageJson() {
// TODO - precalc how much memory to grab
final ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
final JsonGenerator json = JSON.getFactory().createGenerator(output);
json.writeStartObject();
// we only need to write a small amount of information
//json.writeNumberField("treeId", tree_id);
json.writeStringField("name", name);
json.writeStringField("description", description);
json.writeStringField("notes", notes);
json.writeBooleanField("strictMatch", strict_match);
json.writeNumberField("created", created);
json.writeBooleanField("enabled", enabled);
json.writeBooleanField("storeFailures", store_failures);
json.writeEndObject();
json.close();
// TODO zero copy?
return output.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
|
[
"private",
"byte",
"[",
"]",
"toStorageJson",
"(",
")",
"{",
"// TODO - precalc how much memory to grab",
"final",
"ByteArrayOutputStream",
"output",
"=",
"new",
"ByteArrayOutputStream",
"(",
")",
";",
"try",
"{",
"final",
"JsonGenerator",
"json",
"=",
"JSON",
".",
"getFactory",
"(",
")",
".",
"createGenerator",
"(",
"output",
")",
";",
"json",
".",
"writeStartObject",
"(",
")",
";",
"// we only need to write a small amount of information",
"//json.writeNumberField(\"treeId\", tree_id);",
"json",
".",
"writeStringField",
"(",
"\"name\"",
",",
"name",
")",
";",
"json",
".",
"writeStringField",
"(",
"\"description\"",
",",
"description",
")",
";",
"json",
".",
"writeStringField",
"(",
"\"notes\"",
",",
"notes",
")",
";",
"json",
".",
"writeBooleanField",
"(",
"\"strictMatch\"",
",",
"strict_match",
")",
";",
"json",
".",
"writeNumberField",
"(",
"\"created\"",
",",
"created",
")",
";",
"json",
".",
"writeBooleanField",
"(",
"\"enabled\"",
",",
"enabled",
")",
";",
"json",
".",
"writeBooleanField",
"(",
"\"storeFailures\"",
",",
"store_failures",
")",
";",
"json",
".",
"writeEndObject",
"(",
")",
";",
"json",
".",
"close",
"(",
")",
";",
"// TODO zero copy?",
"return",
"output",
".",
"toByteArray",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Converts the object to a JSON byte array, necessary for CAS calls and to
keep redundant data down
@return A byte array with the serialized tree
|
[
"Converts",
"the",
"object",
"to",
"a",
"JSON",
"byte",
"array",
"necessary",
"for",
"CAS",
"calls",
"and",
"to",
"keep",
"redundant",
"data",
"down"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tree/Tree.java#L1013-L1038
|
13,647
|
OpenTSDB/opentsdb
|
src/tools/UidManager.java
|
UidManager.printResult
|
private static boolean printResult(final ArrayList<KeyValue> row,
final byte[] family,
final boolean formard) {
if (null == row || row.isEmpty()) {
return false;
}
final byte[] key = row.get(0).key();
String name = formard ? CliUtils.fromBytes(key) : null;
String id = formard ? null : Arrays.toString(key);
boolean printed = false;
for (final KeyValue kv : row) {
if (!Bytes.equals(kv.family(), family)) {
continue;
}
printed = true;
if (formard) {
id = Arrays.toString(kv.value());
} else {
name = CliUtils.fromBytes(kv.value());
}
System.out.println(CliUtils.fromBytes(kv.qualifier()) + ' ' + name + ": " + id);
}
return printed;
}
|
java
|
private static boolean printResult(final ArrayList<KeyValue> row,
final byte[] family,
final boolean formard) {
if (null == row || row.isEmpty()) {
return false;
}
final byte[] key = row.get(0).key();
String name = formard ? CliUtils.fromBytes(key) : null;
String id = formard ? null : Arrays.toString(key);
boolean printed = false;
for (final KeyValue kv : row) {
if (!Bytes.equals(kv.family(), family)) {
continue;
}
printed = true;
if (formard) {
id = Arrays.toString(kv.value());
} else {
name = CliUtils.fromBytes(kv.value());
}
System.out.println(CliUtils.fromBytes(kv.qualifier()) + ' ' + name + ": " + id);
}
return printed;
}
|
[
"private",
"static",
"boolean",
"printResult",
"(",
"final",
"ArrayList",
"<",
"KeyValue",
">",
"row",
",",
"final",
"byte",
"[",
"]",
"family",
",",
"final",
"boolean",
"formard",
")",
"{",
"if",
"(",
"null",
"==",
"row",
"||",
"row",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"final",
"byte",
"[",
"]",
"key",
"=",
"row",
".",
"get",
"(",
"0",
")",
".",
"key",
"(",
")",
";",
"String",
"name",
"=",
"formard",
"?",
"CliUtils",
".",
"fromBytes",
"(",
"key",
")",
":",
"null",
";",
"String",
"id",
"=",
"formard",
"?",
"null",
":",
"Arrays",
".",
"toString",
"(",
"key",
")",
";",
"boolean",
"printed",
"=",
"false",
";",
"for",
"(",
"final",
"KeyValue",
"kv",
":",
"row",
")",
"{",
"if",
"(",
"!",
"Bytes",
".",
"equals",
"(",
"kv",
".",
"family",
"(",
")",
",",
"family",
")",
")",
"{",
"continue",
";",
"}",
"printed",
"=",
"true",
";",
"if",
"(",
"formard",
")",
"{",
"id",
"=",
"Arrays",
".",
"toString",
"(",
"kv",
".",
"value",
"(",
")",
")",
";",
"}",
"else",
"{",
"name",
"=",
"CliUtils",
".",
"fromBytes",
"(",
"kv",
".",
"value",
"(",
")",
")",
";",
"}",
"System",
".",
"out",
".",
"println",
"(",
"CliUtils",
".",
"fromBytes",
"(",
"kv",
".",
"qualifier",
"(",
")",
")",
"+",
"'",
"'",
"+",
"name",
"+",
"\": \"",
"+",
"id",
")",
";",
"}",
"return",
"printed",
";",
"}"
] |
Helper to print the cells in a given family for a given row, if any.
@param row The row to print.
@param family Only cells in this family (if any) will be printed.
@param formard If true, this row contains a forward mapping (name to ID).
Otherwise the row is assumed to contain a reverse mapping (ID to name).
@return {@code true} if at least one cell was printed.
|
[
"Helper",
"to",
"print",
"the",
"cells",
"in",
"a",
"given",
"family",
"for",
"a",
"given",
"row",
"if",
"any",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/UidManager.java#L330-L353
|
13,648
|
OpenTSDB/opentsdb
|
src/tools/UidManager.java
|
UidManager.findAndPrintRow
|
private static int findAndPrintRow(final HBaseClient client,
final byte[] table,
final byte[] key,
final byte[] family,
boolean formard) {
final GetRequest get = new GetRequest(table, key);
get.family(family);
ArrayList<KeyValue> row;
try {
row = client.get(get).joinUninterruptibly();
} catch (HBaseException e) {
LOG.error("Get failed: " + get, e);
return 1;
} catch (Exception e) {
LOG.error("WTF? Unexpected exception type, get=" + get, e);
return 42;
}
return printResult(row, family, formard) ? 0 : 1;
}
|
java
|
private static int findAndPrintRow(final HBaseClient client,
final byte[] table,
final byte[] key,
final byte[] family,
boolean formard) {
final GetRequest get = new GetRequest(table, key);
get.family(family);
ArrayList<KeyValue> row;
try {
row = client.get(get).joinUninterruptibly();
} catch (HBaseException e) {
LOG.error("Get failed: " + get, e);
return 1;
} catch (Exception e) {
LOG.error("WTF? Unexpected exception type, get=" + get, e);
return 42;
}
return printResult(row, family, formard) ? 0 : 1;
}
|
[
"private",
"static",
"int",
"findAndPrintRow",
"(",
"final",
"HBaseClient",
"client",
",",
"final",
"byte",
"[",
"]",
"table",
",",
"final",
"byte",
"[",
"]",
"key",
",",
"final",
"byte",
"[",
"]",
"family",
",",
"boolean",
"formard",
")",
"{",
"final",
"GetRequest",
"get",
"=",
"new",
"GetRequest",
"(",
"table",
",",
"key",
")",
";",
"get",
".",
"family",
"(",
"family",
")",
";",
"ArrayList",
"<",
"KeyValue",
">",
"row",
";",
"try",
"{",
"row",
"=",
"client",
".",
"get",
"(",
"get",
")",
".",
"joinUninterruptibly",
"(",
")",
";",
"}",
"catch",
"(",
"HBaseException",
"e",
")",
"{",
"LOG",
".",
"error",
"(",
"\"Get failed: \"",
"+",
"get",
",",
"e",
")",
";",
"return",
"1",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"LOG",
".",
"error",
"(",
"\"WTF? Unexpected exception type, get=\"",
"+",
"get",
",",
"e",
")",
";",
"return",
"42",
";",
"}",
"return",
"printResult",
"(",
"row",
",",
"family",
",",
"formard",
")",
"?",
"0",
":",
"1",
";",
"}"
] |
Gets a given row in HBase and prints it on standard output.
@param client The HBase client to use.
@param table The name of the HBase table to use.
@param key The row key to attempt to get from HBase.
@param family The family in which we're interested.
@return 0 if at least one cell was found and printed, 1 otherwise.
|
[
"Gets",
"a",
"given",
"row",
"in",
"HBase",
"and",
"prints",
"it",
"on",
"standard",
"output",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/UidManager.java#L862-L880
|
13,649
|
OpenTSDB/opentsdb
|
src/tools/UidManager.java
|
UidManager.extactLookupId
|
private static int extactLookupId(final HBaseClient client,
final byte[] table,
final short idwidth,
final String kind,
final byte[] id) {
final UniqueId uid = new UniqueId(client, table, kind, (int) idwidth);
try {
final String name = uid.getName(id);
System.out.println(kind + ' ' + name + ": " + Arrays.toString(id));
return 0;
} catch (NoSuchUniqueId e) {
LOG.error(e.getMessage());
return 1;
}
}
|
java
|
private static int extactLookupId(final HBaseClient client,
final byte[] table,
final short idwidth,
final String kind,
final byte[] id) {
final UniqueId uid = new UniqueId(client, table, kind, (int) idwidth);
try {
final String name = uid.getName(id);
System.out.println(kind + ' ' + name + ": " + Arrays.toString(id));
return 0;
} catch (NoSuchUniqueId e) {
LOG.error(e.getMessage());
return 1;
}
}
|
[
"private",
"static",
"int",
"extactLookupId",
"(",
"final",
"HBaseClient",
"client",
",",
"final",
"byte",
"[",
"]",
"table",
",",
"final",
"short",
"idwidth",
",",
"final",
"String",
"kind",
",",
"final",
"byte",
"[",
"]",
"id",
")",
"{",
"final",
"UniqueId",
"uid",
"=",
"new",
"UniqueId",
"(",
"client",
",",
"table",
",",
"kind",
",",
"(",
"int",
")",
"idwidth",
")",
";",
"try",
"{",
"final",
"String",
"name",
"=",
"uid",
".",
"getName",
"(",
"id",
")",
";",
"System",
".",
"out",
".",
"println",
"(",
"kind",
"+",
"'",
"'",
"+",
"name",
"+",
"\": \"",
"+",
"Arrays",
".",
"toString",
"(",
"id",
")",
")",
";",
"return",
"0",
";",
"}",
"catch",
"(",
"NoSuchUniqueId",
"e",
")",
"{",
"LOG",
".",
"error",
"(",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"return",
"1",
";",
"}",
"}"
] |
Looks up an ID for a given kind, and prints it if found.
@param client The HBase client to use.
@param table The name of the HBase table to use.
@param idwidth Number of bytes on which the UIDs should be.
@param kind The 'kind' of the ID (must not be {@code null}).
@param id The ID to look for.
@return 0 if the ID for this kind was found, 1 otherwise.
|
[
"Looks",
"up",
"an",
"ID",
"for",
"a",
"given",
"kind",
"and",
"prints",
"it",
"if",
"found",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/UidManager.java#L891-L905
|
13,650
|
OpenTSDB/opentsdb
|
src/tools/UidManager.java
|
UidManager.idInBytes
|
private static byte[] idInBytes(final short idwidth, final long lid) {
if (idwidth <= 0) {
throw new AssertionError("negative idwidth: " + idwidth);
}
final byte[] id = Bytes.fromLong(lid);
for (int i = 0; i < id.length - idwidth; i++) {
if (id[i] != 0) {
System.err.println(lid + " is too large to fit on " + idwidth
+ " bytes. Maybe you forgot to adjust --idwidth?");
return null;
}
}
return Arrays.copyOfRange(id, id.length - idwidth, id.length);
}
|
java
|
private static byte[] idInBytes(final short idwidth, final long lid) {
if (idwidth <= 0) {
throw new AssertionError("negative idwidth: " + idwidth);
}
final byte[] id = Bytes.fromLong(lid);
for (int i = 0; i < id.length - idwidth; i++) {
if (id[i] != 0) {
System.err.println(lid + " is too large to fit on " + idwidth
+ " bytes. Maybe you forgot to adjust --idwidth?");
return null;
}
}
return Arrays.copyOfRange(id, id.length - idwidth, id.length);
}
|
[
"private",
"static",
"byte",
"[",
"]",
"idInBytes",
"(",
"final",
"short",
"idwidth",
",",
"final",
"long",
"lid",
")",
"{",
"if",
"(",
"idwidth",
"<=",
"0",
")",
"{",
"throw",
"new",
"AssertionError",
"(",
"\"negative idwidth: \"",
"+",
"idwidth",
")",
";",
"}",
"final",
"byte",
"[",
"]",
"id",
"=",
"Bytes",
".",
"fromLong",
"(",
"lid",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"id",
".",
"length",
"-",
"idwidth",
";",
"i",
"++",
")",
"{",
"if",
"(",
"id",
"[",
"i",
"]",
"!=",
"0",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"lid",
"+",
"\" is too large to fit on \"",
"+",
"idwidth",
"+",
"\" bytes. Maybe you forgot to adjust --idwidth?\"",
")",
";",
"return",
"null",
";",
"}",
"}",
"return",
"Arrays",
".",
"copyOfRange",
"(",
"id",
",",
"id",
".",
"length",
"-",
"idwidth",
",",
"id",
".",
"length",
")",
";",
"}"
] |
Transforms an ID into the corresponding byte array.
@param idwidth Number of bytes on which the UIDs should be.
@param lid The ID to transform.
@return The ID represented in {@code idwidth} bytes, or
{@code null} if {@code lid} couldn't fit in {@code idwidth} bytes.
|
[
"Transforms",
"an",
"ID",
"into",
"the",
"corresponding",
"byte",
"array",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/UidManager.java#L914-L927
|
13,651
|
OpenTSDB/opentsdb
|
src/tools/UidManager.java
|
UidManager.extactLookupName
|
private static int extactLookupName(final HBaseClient client,
final byte[] table,
final short idwidth,
final String kind,
final String name) {
final UniqueId uid = new UniqueId(client, table, kind, (int) idwidth);
try {
final byte[] id = uid.getId(name);
System.out.println(kind + ' ' + name + ": " + Arrays.toString(id));
return 0;
} catch (NoSuchUniqueName e) {
LOG.error(e.getMessage());
return 1;
}
}
|
java
|
private static int extactLookupName(final HBaseClient client,
final byte[] table,
final short idwidth,
final String kind,
final String name) {
final UniqueId uid = new UniqueId(client, table, kind, (int) idwidth);
try {
final byte[] id = uid.getId(name);
System.out.println(kind + ' ' + name + ": " + Arrays.toString(id));
return 0;
} catch (NoSuchUniqueName e) {
LOG.error(e.getMessage());
return 1;
}
}
|
[
"private",
"static",
"int",
"extactLookupName",
"(",
"final",
"HBaseClient",
"client",
",",
"final",
"byte",
"[",
"]",
"table",
",",
"final",
"short",
"idwidth",
",",
"final",
"String",
"kind",
",",
"final",
"String",
"name",
")",
"{",
"final",
"UniqueId",
"uid",
"=",
"new",
"UniqueId",
"(",
"client",
",",
"table",
",",
"kind",
",",
"(",
"int",
")",
"idwidth",
")",
";",
"try",
"{",
"final",
"byte",
"[",
"]",
"id",
"=",
"uid",
".",
"getId",
"(",
"name",
")",
";",
"System",
".",
"out",
".",
"println",
"(",
"kind",
"+",
"'",
"'",
"+",
"name",
"+",
"\": \"",
"+",
"Arrays",
".",
"toString",
"(",
"id",
")",
")",
";",
"return",
"0",
";",
"}",
"catch",
"(",
"NoSuchUniqueName",
"e",
")",
"{",
"LOG",
".",
"error",
"(",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"return",
"1",
";",
"}",
"}"
] |
Looks up a name for a given kind, and prints it if found.
@param client The HBase client to use.
@param idwidth Number of bytes on which the UIDs should be.
@param kind The 'kind' of the ID (must not be {@code null}).
@param name The name to look for.
@return 0 if the name for this kind was found, 1 otherwise.
|
[
"Looks",
"up",
"a",
"name",
"for",
"a",
"given",
"kind",
"and",
"prints",
"it",
"if",
"found",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/UidManager.java#L958-L972
|
13,652
|
OpenTSDB/opentsdb
|
src/tools/UidManager.java
|
UidManager.purgeTree
|
private static int purgeTree(final TSDB tsdb, final int tree_id,
final boolean delete_definition) throws Exception {
final TreeSync sync = new TreeSync(tsdb, 0, 1, 0);
return sync.purgeTree(tree_id, delete_definition);
}
|
java
|
private static int purgeTree(final TSDB tsdb, final int tree_id,
final boolean delete_definition) throws Exception {
final TreeSync sync = new TreeSync(tsdb, 0, 1, 0);
return sync.purgeTree(tree_id, delete_definition);
}
|
[
"private",
"static",
"int",
"purgeTree",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"int",
"tree_id",
",",
"final",
"boolean",
"delete_definition",
")",
"throws",
"Exception",
"{",
"final",
"TreeSync",
"sync",
"=",
"new",
"TreeSync",
"(",
"tsdb",
",",
"0",
",",
"1",
",",
"0",
")",
";",
"return",
"sync",
".",
"purgeTree",
"(",
"tree_id",
",",
"delete_definition",
")",
";",
"}"
] |
Attempts to delete the branches, leaves, collisions and not-matched entries
for a given tree. Optionally removes the tree definition itself
@param tsdb The TSDB to use for access
@param tree_id ID of the tree to delete
@param delete_definition Whether or not to delete the tree definition as
well
@return 0 if completed successfully, something else if an error occurred
|
[
"Attempts",
"to",
"delete",
"the",
"branches",
"leaves",
"collisions",
"and",
"not",
"-",
"matched",
"entries",
"for",
"a",
"given",
"tree",
".",
"Optionally",
"removes",
"the",
"tree",
"definition",
"itself"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tools/UidManager.java#L1149-L1153
|
13,653
|
OpenTSDB/opentsdb
|
src/core/MultiGetQuery.java
|
MultiGetQuery.fetch
|
public Deferred<TreeMap<byte[], Span>> fetch() {
if(tags.isEmpty()) {
return Deferred.fromResult(null);
}
startFetch();
return results;
}
|
java
|
public Deferred<TreeMap<byte[], Span>> fetch() {
if(tags.isEmpty()) {
return Deferred.fromResult(null);
}
startFetch();
return results;
}
|
[
"public",
"Deferred",
"<",
"TreeMap",
"<",
"byte",
"[",
"]",
",",
"Span",
">",
">",
"fetch",
"(",
")",
"{",
"if",
"(",
"tags",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"Deferred",
".",
"fromResult",
"(",
"null",
")",
";",
"}",
"startFetch",
"(",
")",
";",
"return",
"results",
";",
"}"
] |
Initiate the get requests and return the tree map of results.
@return A non-null tree map of results (may be empty)
|
[
"Initiate",
"the",
"get",
"requests",
"and",
"return",
"the",
"tree",
"map",
"of",
"results",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/MultiGetQuery.java#L611-L617
|
13,654
|
OpenTSDB/opentsdb
|
src/core/MultiGetQuery.java
|
MultiGetQuery.startFetch
|
private void startFetch() {
prepareConcurrentMultiGetTasks();
// set the time of starting
fetch_start_time = System.currentTimeMillis();
if (LOG.isDebugEnabled()) {
LOG.debug("Start to fetch data using multiget, there will be " + multi_get_wait_cnt
+ " multigets to call");
}
for (int con_idx = 0; con_idx < concurrency_multi_get; ++con_idx) {
final List<MultiGetTask> con_mul_get_tasks = multi_get_tasks.get(con_idx);
final int task_index = multi_get_indexs.get(con_idx).incrementAndGet();
if (task_index < con_mul_get_tasks.size()) {
final MultiGetTask task = con_mul_get_tasks.get(task_index);
final MulGetCB mgcb = new MulGetCB(con_idx, task.getTSUIDs(), task.getGets());
mgcb.fetch();
}
} // end for
}
|
java
|
private void startFetch() {
prepareConcurrentMultiGetTasks();
// set the time of starting
fetch_start_time = System.currentTimeMillis();
if (LOG.isDebugEnabled()) {
LOG.debug("Start to fetch data using multiget, there will be " + multi_get_wait_cnt
+ " multigets to call");
}
for (int con_idx = 0; con_idx < concurrency_multi_get; ++con_idx) {
final List<MultiGetTask> con_mul_get_tasks = multi_get_tasks.get(con_idx);
final int task_index = multi_get_indexs.get(con_idx).incrementAndGet();
if (task_index < con_mul_get_tasks.size()) {
final MultiGetTask task = con_mul_get_tasks.get(task_index);
final MulGetCB mgcb = new MulGetCB(con_idx, task.getTSUIDs(), task.getGets());
mgcb.fetch();
}
} // end for
}
|
[
"private",
"void",
"startFetch",
"(",
")",
"{",
"prepareConcurrentMultiGetTasks",
"(",
")",
";",
"// set the time of starting",
"fetch_start_time",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"if",
"(",
"LOG",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"LOG",
".",
"debug",
"(",
"\"Start to fetch data using multiget, there will be \"",
"+",
"multi_get_wait_cnt",
"+",
"\" multigets to call\"",
")",
";",
"}",
"for",
"(",
"int",
"con_idx",
"=",
"0",
";",
"con_idx",
"<",
"concurrency_multi_get",
";",
"++",
"con_idx",
")",
"{",
"final",
"List",
"<",
"MultiGetTask",
">",
"con_mul_get_tasks",
"=",
"multi_get_tasks",
".",
"get",
"(",
"con_idx",
")",
";",
"final",
"int",
"task_index",
"=",
"multi_get_indexs",
".",
"get",
"(",
"con_idx",
")",
".",
"incrementAndGet",
"(",
")",
";",
"if",
"(",
"task_index",
"<",
"con_mul_get_tasks",
".",
"size",
"(",
")",
")",
"{",
"final",
"MultiGetTask",
"task",
"=",
"con_mul_get_tasks",
".",
"get",
"(",
"task_index",
")",
";",
"final",
"MulGetCB",
"mgcb",
"=",
"new",
"MulGetCB",
"(",
"con_idx",
",",
"task",
".",
"getTSUIDs",
"(",
")",
",",
"task",
".",
"getGets",
"(",
")",
")",
";",
"mgcb",
".",
"fetch",
"(",
")",
";",
"}",
"}",
"// end for",
"}"
] |
Start the work of firing up X concurrent get requests.
|
[
"Start",
"the",
"work",
"of",
"firing",
"up",
"X",
"concurrent",
"get",
"requests",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/MultiGetQuery.java#L631-L651
|
13,655
|
OpenTSDB/opentsdb
|
src/query/QueryUtil.java
|
QueryUtil.setDataTableScanFilter
|
public static void setDataTableScanFilter(
final Scanner scanner,
final List<byte[]> group_bys,
final ByteMap<byte[][]> row_key_literals,
final boolean explicit_tags,
final boolean enable_fuzzy_filter,
final int end_time) {
// no-op
if ((group_bys == null || group_bys.isEmpty())
&& (row_key_literals == null || row_key_literals.isEmpty())) {
return;
}
final int prefix_width = Const.SALT_WIDTH() + TSDB.metrics_width() +
Const.TIMESTAMP_BYTES;
final short name_width = TSDB.tagk_width();
final short value_width = TSDB.tagv_width();
final byte[] fuzzy_key;
final byte[] fuzzy_mask;
if (explicit_tags && enable_fuzzy_filter) {
fuzzy_key = new byte[prefix_width + (row_key_literals.size() *
(name_width + value_width))];
fuzzy_mask = new byte[prefix_width + (row_key_literals.size() *
(name_width + value_width))];
System.arraycopy(scanner.getCurrentKey(), 0, fuzzy_key, 0,
scanner.getCurrentKey().length);
} else {
fuzzy_key = fuzzy_mask = null;
}
final String regex = getRowKeyUIDRegex(group_bys, row_key_literals,
explicit_tags, fuzzy_key, fuzzy_mask);
final KeyRegexpFilter regex_filter = new KeyRegexpFilter(
regex.toString(), Const.ASCII_CHARSET);
if (LOG.isDebugEnabled()) {
LOG.debug("Regex for scanner: " + scanner + ": " +
byteRegexToString(regex));
}
if (!(explicit_tags && enable_fuzzy_filter)) {
scanner.setFilter(regex_filter);
return;
}
scanner.setStartKey(fuzzy_key);
final byte[] stop_key = Arrays.copyOf(fuzzy_key, fuzzy_key.length);
Internal.setBaseTime(stop_key, end_time);
int idx = Const.SALT_WIDTH() + TSDB.metrics_width() +
Const.TIMESTAMP_BYTES + TSDB.tagk_width();
// max out the tag values
while (idx < stop_key.length) {
for (int i = 0; i < TSDB.tagv_width(); i++) {
stop_key[idx++] = (byte) 0xFF;
}
idx += TSDB.tagk_width();
}
scanner.setStopKey(stop_key);
final List<ScanFilter> filters = new ArrayList<ScanFilter>(2);
filters.add(
new FuzzyRowFilter(
new FuzzyRowFilter.FuzzyFilterPair(fuzzy_key, fuzzy_mask)));
filters.add(regex_filter);
scanner.setFilter(new FilterList(filters));
}
|
java
|
public static void setDataTableScanFilter(
final Scanner scanner,
final List<byte[]> group_bys,
final ByteMap<byte[][]> row_key_literals,
final boolean explicit_tags,
final boolean enable_fuzzy_filter,
final int end_time) {
// no-op
if ((group_bys == null || group_bys.isEmpty())
&& (row_key_literals == null || row_key_literals.isEmpty())) {
return;
}
final int prefix_width = Const.SALT_WIDTH() + TSDB.metrics_width() +
Const.TIMESTAMP_BYTES;
final short name_width = TSDB.tagk_width();
final short value_width = TSDB.tagv_width();
final byte[] fuzzy_key;
final byte[] fuzzy_mask;
if (explicit_tags && enable_fuzzy_filter) {
fuzzy_key = new byte[prefix_width + (row_key_literals.size() *
(name_width + value_width))];
fuzzy_mask = new byte[prefix_width + (row_key_literals.size() *
(name_width + value_width))];
System.arraycopy(scanner.getCurrentKey(), 0, fuzzy_key, 0,
scanner.getCurrentKey().length);
} else {
fuzzy_key = fuzzy_mask = null;
}
final String regex = getRowKeyUIDRegex(group_bys, row_key_literals,
explicit_tags, fuzzy_key, fuzzy_mask);
final KeyRegexpFilter regex_filter = new KeyRegexpFilter(
regex.toString(), Const.ASCII_CHARSET);
if (LOG.isDebugEnabled()) {
LOG.debug("Regex for scanner: " + scanner + ": " +
byteRegexToString(regex));
}
if (!(explicit_tags && enable_fuzzy_filter)) {
scanner.setFilter(regex_filter);
return;
}
scanner.setStartKey(fuzzy_key);
final byte[] stop_key = Arrays.copyOf(fuzzy_key, fuzzy_key.length);
Internal.setBaseTime(stop_key, end_time);
int idx = Const.SALT_WIDTH() + TSDB.metrics_width() +
Const.TIMESTAMP_BYTES + TSDB.tagk_width();
// max out the tag values
while (idx < stop_key.length) {
for (int i = 0; i < TSDB.tagv_width(); i++) {
stop_key[idx++] = (byte) 0xFF;
}
idx += TSDB.tagk_width();
}
scanner.setStopKey(stop_key);
final List<ScanFilter> filters = new ArrayList<ScanFilter>(2);
filters.add(
new FuzzyRowFilter(
new FuzzyRowFilter.FuzzyFilterPair(fuzzy_key, fuzzy_mask)));
filters.add(regex_filter);
scanner.setFilter(new FilterList(filters));
}
|
[
"public",
"static",
"void",
"setDataTableScanFilter",
"(",
"final",
"Scanner",
"scanner",
",",
"final",
"List",
"<",
"byte",
"[",
"]",
">",
"group_bys",
",",
"final",
"ByteMap",
"<",
"byte",
"[",
"]",
"[",
"]",
">",
"row_key_literals",
",",
"final",
"boolean",
"explicit_tags",
",",
"final",
"boolean",
"enable_fuzzy_filter",
",",
"final",
"int",
"end_time",
")",
"{",
"// no-op",
"if",
"(",
"(",
"group_bys",
"==",
"null",
"||",
"group_bys",
".",
"isEmpty",
"(",
")",
")",
"&&",
"(",
"row_key_literals",
"==",
"null",
"||",
"row_key_literals",
".",
"isEmpty",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"final",
"int",
"prefix_width",
"=",
"Const",
".",
"SALT_WIDTH",
"(",
")",
"+",
"TSDB",
".",
"metrics_width",
"(",
")",
"+",
"Const",
".",
"TIMESTAMP_BYTES",
";",
"final",
"short",
"name_width",
"=",
"TSDB",
".",
"tagk_width",
"(",
")",
";",
"final",
"short",
"value_width",
"=",
"TSDB",
".",
"tagv_width",
"(",
")",
";",
"final",
"byte",
"[",
"]",
"fuzzy_key",
";",
"final",
"byte",
"[",
"]",
"fuzzy_mask",
";",
"if",
"(",
"explicit_tags",
"&&",
"enable_fuzzy_filter",
")",
"{",
"fuzzy_key",
"=",
"new",
"byte",
"[",
"prefix_width",
"+",
"(",
"row_key_literals",
".",
"size",
"(",
")",
"*",
"(",
"name_width",
"+",
"value_width",
")",
")",
"]",
";",
"fuzzy_mask",
"=",
"new",
"byte",
"[",
"prefix_width",
"+",
"(",
"row_key_literals",
".",
"size",
"(",
")",
"*",
"(",
"name_width",
"+",
"value_width",
")",
")",
"]",
";",
"System",
".",
"arraycopy",
"(",
"scanner",
".",
"getCurrentKey",
"(",
")",
",",
"0",
",",
"fuzzy_key",
",",
"0",
",",
"scanner",
".",
"getCurrentKey",
"(",
")",
".",
"length",
")",
";",
"}",
"else",
"{",
"fuzzy_key",
"=",
"fuzzy_mask",
"=",
"null",
";",
"}",
"final",
"String",
"regex",
"=",
"getRowKeyUIDRegex",
"(",
"group_bys",
",",
"row_key_literals",
",",
"explicit_tags",
",",
"fuzzy_key",
",",
"fuzzy_mask",
")",
";",
"final",
"KeyRegexpFilter",
"regex_filter",
"=",
"new",
"KeyRegexpFilter",
"(",
"regex",
".",
"toString",
"(",
")",
",",
"Const",
".",
"ASCII_CHARSET",
")",
";",
"if",
"(",
"LOG",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"LOG",
".",
"debug",
"(",
"\"Regex for scanner: \"",
"+",
"scanner",
"+",
"\": \"",
"+",
"byteRegexToString",
"(",
"regex",
")",
")",
";",
"}",
"if",
"(",
"!",
"(",
"explicit_tags",
"&&",
"enable_fuzzy_filter",
")",
")",
"{",
"scanner",
".",
"setFilter",
"(",
"regex_filter",
")",
";",
"return",
";",
"}",
"scanner",
".",
"setStartKey",
"(",
"fuzzy_key",
")",
";",
"final",
"byte",
"[",
"]",
"stop_key",
"=",
"Arrays",
".",
"copyOf",
"(",
"fuzzy_key",
",",
"fuzzy_key",
".",
"length",
")",
";",
"Internal",
".",
"setBaseTime",
"(",
"stop_key",
",",
"end_time",
")",
";",
"int",
"idx",
"=",
"Const",
".",
"SALT_WIDTH",
"(",
")",
"+",
"TSDB",
".",
"metrics_width",
"(",
")",
"+",
"Const",
".",
"TIMESTAMP_BYTES",
"+",
"TSDB",
".",
"tagk_width",
"(",
")",
";",
"// max out the tag values",
"while",
"(",
"idx",
"<",
"stop_key",
".",
"length",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"TSDB",
".",
"tagv_width",
"(",
")",
";",
"i",
"++",
")",
"{",
"stop_key",
"[",
"idx",
"++",
"]",
"=",
"(",
"byte",
")",
"0xFF",
";",
"}",
"idx",
"+=",
"TSDB",
".",
"tagk_width",
"(",
")",
";",
"}",
"scanner",
".",
"setStopKey",
"(",
"stop_key",
")",
";",
"final",
"List",
"<",
"ScanFilter",
">",
"filters",
"=",
"new",
"ArrayList",
"<",
"ScanFilter",
">",
"(",
"2",
")",
";",
"filters",
".",
"add",
"(",
"new",
"FuzzyRowFilter",
"(",
"new",
"FuzzyRowFilter",
".",
"FuzzyFilterPair",
"(",
"fuzzy_key",
",",
"fuzzy_mask",
")",
")",
")",
";",
"filters",
".",
"add",
"(",
"regex_filter",
")",
";",
"scanner",
".",
"setFilter",
"(",
"new",
"FilterList",
"(",
"filters",
")",
")",
";",
"}"
] |
Sets a filter or filter list on the scanner based on whether or not the
query had tags it needed to match.
@param scanner The scanner to modify.
@param group_bys An optional list of tag keys that we want to group on. May
be null.
@param row_key_literals An optional list of key value pairs to filter on.
May be null.
@param explicit_tags Whether or not explicit tags are enabled so that the
regex only picks out series with the specified tags
@param enable_fuzzy_filter Whether or not a fuzzy filter should be used
in combination with the explicit tags param. If explicit tags is disabled
then this param is ignored.
@param end_time The end of the query time so the fuzzy filter knows when
to stop scanning.
|
[
"Sets",
"a",
"filter",
"or",
"filter",
"list",
"on",
"the",
"scanner",
"based",
"on",
"whether",
"or",
"not",
"the",
"query",
"had",
"tags",
"it",
"needed",
"to",
"match",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/QueryUtil.java#L194-L258
|
13,656
|
OpenTSDB/opentsdb
|
src/query/QueryUtil.java
|
QueryUtil.getRowKeyTSUIDRegex
|
public static String getRowKeyTSUIDRegex(final List<String> tsuids) {
Collections.sort(tsuids);
// first, convert the tags to byte arrays and count up the total length
// so we can allocate the string builder
final short metric_width = TSDB.metrics_width();
int tags_length = 0;
final ArrayList<byte[]> uids = new ArrayList<byte[]>(tsuids.size());
for (final String tsuid : tsuids) {
final String tags = tsuid.substring(metric_width * 2);
final byte[] tag_bytes = UniqueId.stringToUid(tags);
tags_length += tag_bytes.length;
uids.add(tag_bytes);
}
// Generate a regexp for our tags based on any metric and timestamp (since
// those are handled by the row start/stop) and the list of TSUID tagk/v
// pairs. The generated regex will look like: ^.{7}(tags|tags|tags)$
// where each "tags" is similar to \\Q\000\000\001\000\000\002\\E
final StringBuilder buf = new StringBuilder(
13 // "(?s)^.{N}(" + ")$"
+ (tsuids.size() * 11) // "\\Q" + "\\E|"
+ tags_length); // total # of bytes in tsuids tagk/v pairs
// Alright, let's build this regexp. From the beginning...
buf.append("(?s)" // Ensure we use the DOTALL flag.
+ "^.{")
// ... start by skipping the metric ID and timestamp.
.append(Const.SALT_WIDTH() + metric_width + Const.TIMESTAMP_BYTES)
.append("}(");
for (final byte[] tags : uids) {
// quote the bytes
buf.append("\\Q");
addId(buf, tags, true);
buf.append('|');
}
// Replace the pipe of the last iteration, close and set
buf.setCharAt(buf.length() - 1, ')');
buf.append("$");
return buf.toString();
}
|
java
|
public static String getRowKeyTSUIDRegex(final List<String> tsuids) {
Collections.sort(tsuids);
// first, convert the tags to byte arrays and count up the total length
// so we can allocate the string builder
final short metric_width = TSDB.metrics_width();
int tags_length = 0;
final ArrayList<byte[]> uids = new ArrayList<byte[]>(tsuids.size());
for (final String tsuid : tsuids) {
final String tags = tsuid.substring(metric_width * 2);
final byte[] tag_bytes = UniqueId.stringToUid(tags);
tags_length += tag_bytes.length;
uids.add(tag_bytes);
}
// Generate a regexp for our tags based on any metric and timestamp (since
// those are handled by the row start/stop) and the list of TSUID tagk/v
// pairs. The generated regex will look like: ^.{7}(tags|tags|tags)$
// where each "tags" is similar to \\Q\000\000\001\000\000\002\\E
final StringBuilder buf = new StringBuilder(
13 // "(?s)^.{N}(" + ")$"
+ (tsuids.size() * 11) // "\\Q" + "\\E|"
+ tags_length); // total # of bytes in tsuids tagk/v pairs
// Alright, let's build this regexp. From the beginning...
buf.append("(?s)" // Ensure we use the DOTALL flag.
+ "^.{")
// ... start by skipping the metric ID and timestamp.
.append(Const.SALT_WIDTH() + metric_width + Const.TIMESTAMP_BYTES)
.append("}(");
for (final byte[] tags : uids) {
// quote the bytes
buf.append("\\Q");
addId(buf, tags, true);
buf.append('|');
}
// Replace the pipe of the last iteration, close and set
buf.setCharAt(buf.length() - 1, ')');
buf.append("$");
return buf.toString();
}
|
[
"public",
"static",
"String",
"getRowKeyTSUIDRegex",
"(",
"final",
"List",
"<",
"String",
">",
"tsuids",
")",
"{",
"Collections",
".",
"sort",
"(",
"tsuids",
")",
";",
"// first, convert the tags to byte arrays and count up the total length",
"// so we can allocate the string builder",
"final",
"short",
"metric_width",
"=",
"TSDB",
".",
"metrics_width",
"(",
")",
";",
"int",
"tags_length",
"=",
"0",
";",
"final",
"ArrayList",
"<",
"byte",
"[",
"]",
">",
"uids",
"=",
"new",
"ArrayList",
"<",
"byte",
"[",
"]",
">",
"(",
"tsuids",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"final",
"String",
"tsuid",
":",
"tsuids",
")",
"{",
"final",
"String",
"tags",
"=",
"tsuid",
".",
"substring",
"(",
"metric_width",
"*",
"2",
")",
";",
"final",
"byte",
"[",
"]",
"tag_bytes",
"=",
"UniqueId",
".",
"stringToUid",
"(",
"tags",
")",
";",
"tags_length",
"+=",
"tag_bytes",
".",
"length",
";",
"uids",
".",
"add",
"(",
"tag_bytes",
")",
";",
"}",
"// Generate a regexp for our tags based on any metric and timestamp (since",
"// those are handled by the row start/stop) and the list of TSUID tagk/v",
"// pairs. The generated regex will look like: ^.{7}(tags|tags|tags)$",
"// where each \"tags\" is similar to \\\\Q\\000\\000\\001\\000\\000\\002\\\\E",
"final",
"StringBuilder",
"buf",
"=",
"new",
"StringBuilder",
"(",
"13",
"// \"(?s)^.{N}(\" + \")$\"",
"+",
"(",
"tsuids",
".",
"size",
"(",
")",
"*",
"11",
")",
"// \"\\\\Q\" + \"\\\\E|\"",
"+",
"tags_length",
")",
";",
"// total # of bytes in tsuids tagk/v pairs",
"// Alright, let's build this regexp. From the beginning...",
"buf",
".",
"append",
"(",
"\"(?s)\"",
"// Ensure we use the DOTALL flag.",
"+",
"\"^.{\"",
")",
"// ... start by skipping the metric ID and timestamp.",
".",
"append",
"(",
"Const",
".",
"SALT_WIDTH",
"(",
")",
"+",
"metric_width",
"+",
"Const",
".",
"TIMESTAMP_BYTES",
")",
".",
"append",
"(",
"\"}(\"",
")",
";",
"for",
"(",
"final",
"byte",
"[",
"]",
"tags",
":",
"uids",
")",
"{",
"// quote the bytes",
"buf",
".",
"append",
"(",
"\"\\\\Q\"",
")",
";",
"addId",
"(",
"buf",
",",
"tags",
",",
"true",
")",
";",
"buf",
".",
"append",
"(",
"'",
"'",
")",
";",
"}",
"// Replace the pipe of the last iteration, close and set",
"buf",
".",
"setCharAt",
"(",
"buf",
".",
"length",
"(",
")",
"-",
"1",
",",
"'",
"'",
")",
";",
"buf",
".",
"append",
"(",
"\"$\"",
")",
";",
"return",
"buf",
".",
"toString",
"(",
")",
";",
"}"
] |
Creates a regular expression with a list of or'd TUIDs to compare
against the rows in storage.
@param tsuids The list of TSUIDs to scan for
@return A regular expression string to pass to the storage layer.
|
[
"Creates",
"a",
"regular",
"expression",
"with",
"a",
"list",
"of",
"or",
"d",
"TUIDs",
"to",
"compare",
"against",
"the",
"rows",
"in",
"storage",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/QueryUtil.java#L266-L308
|
13,657
|
OpenTSDB/opentsdb
|
src/query/QueryUtil.java
|
QueryUtil.getMetricScanner
|
public static Scanner getMetricScanner(final TSDB tsdb, final int salt_bucket,
final byte[] metric, final int start, final int stop,
final byte[] table, final byte[] family) {
final short metric_width = TSDB.metrics_width();
final int metric_salt_width = metric_width + Const.SALT_WIDTH();
final byte[] start_row = new byte[metric_salt_width + Const.TIMESTAMP_BYTES];
final byte[] end_row = new byte[metric_salt_width + Const.TIMESTAMP_BYTES];
if (Const.SALT_WIDTH() > 0) {
final byte[] salt = RowKey.getSaltBytes(salt_bucket);
System.arraycopy(salt, 0, start_row, 0, Const.SALT_WIDTH());
System.arraycopy(salt, 0, end_row, 0, Const.SALT_WIDTH());
}
Bytes.setInt(start_row, start, metric_salt_width);
Bytes.setInt(end_row, stop, metric_salt_width);
System.arraycopy(metric, 0, start_row, Const.SALT_WIDTH(), metric_width);
System.arraycopy(metric, 0, end_row, Const.SALT_WIDTH(), metric_width);
final Scanner scanner = tsdb.getClient().newScanner(table);
scanner.setMaxNumRows(tsdb.getConfig().scanner_maxNumRows());
scanner.setStartKey(start_row);
scanner.setStopKey(end_row);
scanner.setFamily(family);
return scanner;
}
|
java
|
public static Scanner getMetricScanner(final TSDB tsdb, final int salt_bucket,
final byte[] metric, final int start, final int stop,
final byte[] table, final byte[] family) {
final short metric_width = TSDB.metrics_width();
final int metric_salt_width = metric_width + Const.SALT_WIDTH();
final byte[] start_row = new byte[metric_salt_width + Const.TIMESTAMP_BYTES];
final byte[] end_row = new byte[metric_salt_width + Const.TIMESTAMP_BYTES];
if (Const.SALT_WIDTH() > 0) {
final byte[] salt = RowKey.getSaltBytes(salt_bucket);
System.arraycopy(salt, 0, start_row, 0, Const.SALT_WIDTH());
System.arraycopy(salt, 0, end_row, 0, Const.SALT_WIDTH());
}
Bytes.setInt(start_row, start, metric_salt_width);
Bytes.setInt(end_row, stop, metric_salt_width);
System.arraycopy(metric, 0, start_row, Const.SALT_WIDTH(), metric_width);
System.arraycopy(metric, 0, end_row, Const.SALT_WIDTH(), metric_width);
final Scanner scanner = tsdb.getClient().newScanner(table);
scanner.setMaxNumRows(tsdb.getConfig().scanner_maxNumRows());
scanner.setStartKey(start_row);
scanner.setStopKey(end_row);
scanner.setFamily(family);
return scanner;
}
|
[
"public",
"static",
"Scanner",
"getMetricScanner",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"int",
"salt_bucket",
",",
"final",
"byte",
"[",
"]",
"metric",
",",
"final",
"int",
"start",
",",
"final",
"int",
"stop",
",",
"final",
"byte",
"[",
"]",
"table",
",",
"final",
"byte",
"[",
"]",
"family",
")",
"{",
"final",
"short",
"metric_width",
"=",
"TSDB",
".",
"metrics_width",
"(",
")",
";",
"final",
"int",
"metric_salt_width",
"=",
"metric_width",
"+",
"Const",
".",
"SALT_WIDTH",
"(",
")",
";",
"final",
"byte",
"[",
"]",
"start_row",
"=",
"new",
"byte",
"[",
"metric_salt_width",
"+",
"Const",
".",
"TIMESTAMP_BYTES",
"]",
";",
"final",
"byte",
"[",
"]",
"end_row",
"=",
"new",
"byte",
"[",
"metric_salt_width",
"+",
"Const",
".",
"TIMESTAMP_BYTES",
"]",
";",
"if",
"(",
"Const",
".",
"SALT_WIDTH",
"(",
")",
">",
"0",
")",
"{",
"final",
"byte",
"[",
"]",
"salt",
"=",
"RowKey",
".",
"getSaltBytes",
"(",
"salt_bucket",
")",
";",
"System",
".",
"arraycopy",
"(",
"salt",
",",
"0",
",",
"start_row",
",",
"0",
",",
"Const",
".",
"SALT_WIDTH",
"(",
")",
")",
";",
"System",
".",
"arraycopy",
"(",
"salt",
",",
"0",
",",
"end_row",
",",
"0",
",",
"Const",
".",
"SALT_WIDTH",
"(",
")",
")",
";",
"}",
"Bytes",
".",
"setInt",
"(",
"start_row",
",",
"start",
",",
"metric_salt_width",
")",
";",
"Bytes",
".",
"setInt",
"(",
"end_row",
",",
"stop",
",",
"metric_salt_width",
")",
";",
"System",
".",
"arraycopy",
"(",
"metric",
",",
"0",
",",
"start_row",
",",
"Const",
".",
"SALT_WIDTH",
"(",
")",
",",
"metric_width",
")",
";",
"System",
".",
"arraycopy",
"(",
"metric",
",",
"0",
",",
"end_row",
",",
"Const",
".",
"SALT_WIDTH",
"(",
")",
",",
"metric_width",
")",
";",
"final",
"Scanner",
"scanner",
"=",
"tsdb",
".",
"getClient",
"(",
")",
".",
"newScanner",
"(",
"table",
")",
";",
"scanner",
".",
"setMaxNumRows",
"(",
"tsdb",
".",
"getConfig",
"(",
")",
".",
"scanner_maxNumRows",
"(",
")",
")",
";",
"scanner",
".",
"setStartKey",
"(",
"start_row",
")",
";",
"scanner",
".",
"setStopKey",
"(",
"end_row",
")",
";",
"scanner",
".",
"setFamily",
"(",
"family",
")",
";",
"return",
"scanner",
";",
"}"
] |
Compiles an HBase scanner against the main data table
@param tsdb The TSDB with a configured HBaseClient
@param salt_bucket An optional salt bucket ID for salting the start/stop
keys.
@param metric The metric to scan for
@param start The start time stamp in seconds
@param stop The stop timestamp in seconds
@param table The table name to scan over
@param family The table family to scan over
@return A scanner ready for processing.
|
[
"Compiles",
"an",
"HBase",
"scanner",
"against",
"the",
"main",
"data",
"table"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/QueryUtil.java#L322-L348
|
13,658
|
OpenTSDB/opentsdb
|
src/query/QueryUtil.java
|
QueryUtil.addId
|
public static void addId(final StringBuilder buf, final byte[] id,
final boolean close) {
boolean backslash = false;
for (final byte b : id) {
buf.append((char) (b & 0xFF));
if (b == 'E' && backslash) { // If we saw a `\' and now we have a `E'.
// So we just terminated the quoted section because we just added \E
// to `buf'. So let's put a litteral \E now and start quoting again.
buf.append("\\\\E\\Q");
} else {
backslash = b == '\\';
}
}
if (close) {
buf.append("\\E");
}
}
|
java
|
public static void addId(final StringBuilder buf, final byte[] id,
final boolean close) {
boolean backslash = false;
for (final byte b : id) {
buf.append((char) (b & 0xFF));
if (b == 'E' && backslash) { // If we saw a `\' and now we have a `E'.
// So we just terminated the quoted section because we just added \E
// to `buf'. So let's put a litteral \E now and start quoting again.
buf.append("\\\\E\\Q");
} else {
backslash = b == '\\';
}
}
if (close) {
buf.append("\\E");
}
}
|
[
"public",
"static",
"void",
"addId",
"(",
"final",
"StringBuilder",
"buf",
",",
"final",
"byte",
"[",
"]",
"id",
",",
"final",
"boolean",
"close",
")",
"{",
"boolean",
"backslash",
"=",
"false",
";",
"for",
"(",
"final",
"byte",
"b",
":",
"id",
")",
"{",
"buf",
".",
"append",
"(",
"(",
"char",
")",
"(",
"b",
"&",
"0xFF",
")",
")",
";",
"if",
"(",
"b",
"==",
"'",
"'",
"&&",
"backslash",
")",
"{",
"// If we saw a `\\' and now we have a `E'.",
"// So we just terminated the quoted section because we just added \\E",
"// to `buf'. So let's put a litteral \\E now and start quoting again.",
"buf",
".",
"append",
"(",
"\"\\\\\\\\E\\\\Q\"",
")",
";",
"}",
"else",
"{",
"backslash",
"=",
"b",
"==",
"'",
"'",
";",
"}",
"}",
"if",
"(",
"close",
")",
"{",
"buf",
".",
"append",
"(",
"\"\\\\E\"",
")",
";",
"}",
"}"
] |
Appends the given UID to the given regular expression buffer
@param buf The String buffer to modify
@param id The UID to add
@param close Whether or not to append "\\E" to the end
|
[
"Appends",
"the",
"given",
"UID",
"to",
"the",
"given",
"regular",
"expression",
"buffer"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/QueryUtil.java#L356-L372
|
13,659
|
OpenTSDB/opentsdb
|
src/query/QueryUtil.java
|
QueryUtil.byteRegexToString
|
public static String byteRegexToString(final String regexp) {
final StringBuilder buf = new StringBuilder();
for (int i = 0; i < regexp.length(); i++) {
if (i > 0 && regexp.charAt(i - 1) == 'Q') {
if (regexp.charAt(i - 3) == '*') {
// tagk
byte[] tagk = new byte[TSDB.tagk_width()];
for (int x = 0; x < TSDB.tagk_width(); x++) {
tagk[x] = (byte)regexp.charAt(i + x);
}
i += TSDB.tagk_width();
buf.append(Arrays.toString(tagk));
} else {
// tagv
byte[] tagv = new byte[TSDB.tagv_width()];
for (int x = 0; x < TSDB.tagv_width(); x++) {
tagv[x] = (byte)regexp.charAt(i + x);
}
i += TSDB.tagv_width();
buf.append(Arrays.toString(tagv));
}
} else {
buf.append(regexp.charAt(i));
}
}
return buf.toString();
}
|
java
|
public static String byteRegexToString(final String regexp) {
final StringBuilder buf = new StringBuilder();
for (int i = 0; i < regexp.length(); i++) {
if (i > 0 && regexp.charAt(i - 1) == 'Q') {
if (regexp.charAt(i - 3) == '*') {
// tagk
byte[] tagk = new byte[TSDB.tagk_width()];
for (int x = 0; x < TSDB.tagk_width(); x++) {
tagk[x] = (byte)regexp.charAt(i + x);
}
i += TSDB.tagk_width();
buf.append(Arrays.toString(tagk));
} else {
// tagv
byte[] tagv = new byte[TSDB.tagv_width()];
for (int x = 0; x < TSDB.tagv_width(); x++) {
tagv[x] = (byte)regexp.charAt(i + x);
}
i += TSDB.tagv_width();
buf.append(Arrays.toString(tagv));
}
} else {
buf.append(regexp.charAt(i));
}
}
return buf.toString();
}
|
[
"public",
"static",
"String",
"byteRegexToString",
"(",
"final",
"String",
"regexp",
")",
"{",
"final",
"StringBuilder",
"buf",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"regexp",
".",
"length",
"(",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
">",
"0",
"&&",
"regexp",
".",
"charAt",
"(",
"i",
"-",
"1",
")",
"==",
"'",
"'",
")",
"{",
"if",
"(",
"regexp",
".",
"charAt",
"(",
"i",
"-",
"3",
")",
"==",
"'",
"'",
")",
"{",
"// tagk",
"byte",
"[",
"]",
"tagk",
"=",
"new",
"byte",
"[",
"TSDB",
".",
"tagk_width",
"(",
")",
"]",
";",
"for",
"(",
"int",
"x",
"=",
"0",
";",
"x",
"<",
"TSDB",
".",
"tagk_width",
"(",
")",
";",
"x",
"++",
")",
"{",
"tagk",
"[",
"x",
"]",
"=",
"(",
"byte",
")",
"regexp",
".",
"charAt",
"(",
"i",
"+",
"x",
")",
";",
"}",
"i",
"+=",
"TSDB",
".",
"tagk_width",
"(",
")",
";",
"buf",
".",
"append",
"(",
"Arrays",
".",
"toString",
"(",
"tagk",
")",
")",
";",
"}",
"else",
"{",
"// tagv",
"byte",
"[",
"]",
"tagv",
"=",
"new",
"byte",
"[",
"TSDB",
".",
"tagv_width",
"(",
")",
"]",
";",
"for",
"(",
"int",
"x",
"=",
"0",
";",
"x",
"<",
"TSDB",
".",
"tagv_width",
"(",
")",
";",
"x",
"++",
")",
"{",
"tagv",
"[",
"x",
"]",
"=",
"(",
"byte",
")",
"regexp",
".",
"charAt",
"(",
"i",
"+",
"x",
")",
";",
"}",
"i",
"+=",
"TSDB",
".",
"tagv_width",
"(",
")",
";",
"buf",
".",
"append",
"(",
"Arrays",
".",
"toString",
"(",
"tagv",
")",
")",
";",
"}",
"}",
"else",
"{",
"buf",
".",
"append",
"(",
"regexp",
".",
"charAt",
"(",
"i",
")",
")",
";",
"}",
"}",
"return",
"buf",
".",
"toString",
"(",
")",
";",
"}"
] |
Little helper to print out the regular expression by converting the UID
bytes to an array.
@param regexp The regex string to print to the debug log
|
[
"Little",
"helper",
"to",
"print",
"out",
"the",
"regular",
"expression",
"by",
"converting",
"the",
"UID",
"bytes",
"to",
"an",
"array",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/QueryUtil.java#L379-L405
|
13,660
|
OpenTSDB/opentsdb
|
src/query/expression/UnionIterator.java
|
UnionIterator.computeUnion
|
private void computeUnion() {
// key = flattened tags, array of queries.size()
final ByteMap<ExpressionDataPoint[]> ordered_union =
new ByteMap<ExpressionDataPoint[]>();
final Iterator<ITimeSyncedIterator> it = queries.values().iterator();
while (it.hasNext()) {
final ITimeSyncedIterator sub = it.next();
final ExpressionDataPoint[] dps = sub.values();
final ByteMap<Integer> local_tags = new ByteMap<Integer>();
for (int i = 0; i < sub.size(); i++) {
final byte[] key = flattenTags(union_on_query_tagks, include_agg_tags,
dps[i], sub);
local_tags.put(key, i);
ExpressionDataPoint[] udps = ordered_union.get(key);
if (udps == null) {
udps = new ExpressionDataPoint[queries.size()];
ordered_union.put(key, udps);
}
udps[sub.getIndex()] = dps[i];
}
}
if (ordered_union.size() < 1) {
// if no data, just stop here
return;
}
setCurrentAndMeta(ordered_union);
}
|
java
|
private void computeUnion() {
// key = flattened tags, array of queries.size()
final ByteMap<ExpressionDataPoint[]> ordered_union =
new ByteMap<ExpressionDataPoint[]>();
final Iterator<ITimeSyncedIterator> it = queries.values().iterator();
while (it.hasNext()) {
final ITimeSyncedIterator sub = it.next();
final ExpressionDataPoint[] dps = sub.values();
final ByteMap<Integer> local_tags = new ByteMap<Integer>();
for (int i = 0; i < sub.size(); i++) {
final byte[] key = flattenTags(union_on_query_tagks, include_agg_tags,
dps[i], sub);
local_tags.put(key, i);
ExpressionDataPoint[] udps = ordered_union.get(key);
if (udps == null) {
udps = new ExpressionDataPoint[queries.size()];
ordered_union.put(key, udps);
}
udps[sub.getIndex()] = dps[i];
}
}
if (ordered_union.size() < 1) {
// if no data, just stop here
return;
}
setCurrentAndMeta(ordered_union);
}
|
[
"private",
"void",
"computeUnion",
"(",
")",
"{",
"// key = flattened tags, array of queries.size()",
"final",
"ByteMap",
"<",
"ExpressionDataPoint",
"[",
"]",
">",
"ordered_union",
"=",
"new",
"ByteMap",
"<",
"ExpressionDataPoint",
"[",
"]",
">",
"(",
")",
";",
"final",
"Iterator",
"<",
"ITimeSyncedIterator",
">",
"it",
"=",
"queries",
".",
"values",
"(",
")",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"it",
".",
"hasNext",
"(",
")",
")",
"{",
"final",
"ITimeSyncedIterator",
"sub",
"=",
"it",
".",
"next",
"(",
")",
";",
"final",
"ExpressionDataPoint",
"[",
"]",
"dps",
"=",
"sub",
".",
"values",
"(",
")",
";",
"final",
"ByteMap",
"<",
"Integer",
">",
"local_tags",
"=",
"new",
"ByteMap",
"<",
"Integer",
">",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"sub",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"final",
"byte",
"[",
"]",
"key",
"=",
"flattenTags",
"(",
"union_on_query_tagks",
",",
"include_agg_tags",
",",
"dps",
"[",
"i",
"]",
",",
"sub",
")",
";",
"local_tags",
".",
"put",
"(",
"key",
",",
"i",
")",
";",
"ExpressionDataPoint",
"[",
"]",
"udps",
"=",
"ordered_union",
".",
"get",
"(",
"key",
")",
";",
"if",
"(",
"udps",
"==",
"null",
")",
"{",
"udps",
"=",
"new",
"ExpressionDataPoint",
"[",
"queries",
".",
"size",
"(",
")",
"]",
";",
"ordered_union",
".",
"put",
"(",
"key",
",",
"udps",
")",
";",
"}",
"udps",
"[",
"sub",
".",
"getIndex",
"(",
")",
"]",
"=",
"dps",
"[",
"i",
"]",
";",
"}",
"}",
"if",
"(",
"ordered_union",
".",
"size",
"(",
")",
"<",
"1",
")",
"{",
"// if no data, just stop here",
"return",
";",
"}",
"setCurrentAndMeta",
"(",
"ordered_union",
")",
";",
"}"
] |
Computes the union of all sets, matching on tags and optionally the
aggregated tags across each variable.
|
[
"Computes",
"the",
"union",
"of",
"all",
"sets",
"matching",
"on",
"tags",
"and",
"optionally",
"the",
"aggregated",
"tags",
"across",
"each",
"variable",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/expression/UnionIterator.java#L171-L201
|
13,661
|
OpenTSDB/opentsdb
|
src/query/expression/UnionIterator.java
|
UnionIterator.flattenTags
|
static byte[] flattenTags(final boolean use_query_tags,
final boolean include_agg_tags, final ExpressionDataPoint dp,
final ITimeSyncedIterator sub) {
if (dp.tags() == null || dp.tags().isEmpty()) {
return HBaseClient.EMPTY_ARRAY;
}
final int tagk_width = TSDB.tagk_width();
final int tagv_width = TSDB.tagv_width();
final ByteSet query_tagks;
// NOTE: We MAY need the agg tags but I'm not sure yet
final int tag_size;
if (use_query_tags) {
int i = 0;
if (sub.getQueryTagKs() != null && !sub.getQueryTagKs().isEmpty()) {
query_tagks = sub.getQueryTagKs();
for (final Map.Entry<byte[], byte[]> pair : dp.tags().entrySet()) {
if (query_tagks.contains(pair.getKey())) {
i++;
}
}
} else {
query_tagks = new ByteSet();
}
tag_size = i;
} else {
query_tagks = new ByteSet();
tag_size = dp.tags().size();
}
final int length = (tag_size * (tagk_width + tagv_width))
+ (include_agg_tags ? (dp.aggregatedTags().size() * tagk_width) : 0);
final byte[] key = new byte[length];
int idx = 0;
for (final Entry<byte[], byte[]> pair : dp.tags().entrySet()) {
if (use_query_tags && !query_tagks.contains(pair.getKey())) {
continue;
}
System.arraycopy(pair.getKey(), 0, key, idx, tagk_width);
idx += tagk_width;
System.arraycopy(pair.getValue(), 0, key, idx, tagv_width);
idx += tagv_width;
}
if (include_agg_tags) {
for (final byte[] tagk : dp.aggregatedTags()) {
System.arraycopy(tagk, 0, key, idx, tagk_width);
idx += tagk_width;
}
}
return key;
}
|
java
|
static byte[] flattenTags(final boolean use_query_tags,
final boolean include_agg_tags, final ExpressionDataPoint dp,
final ITimeSyncedIterator sub) {
if (dp.tags() == null || dp.tags().isEmpty()) {
return HBaseClient.EMPTY_ARRAY;
}
final int tagk_width = TSDB.tagk_width();
final int tagv_width = TSDB.tagv_width();
final ByteSet query_tagks;
// NOTE: We MAY need the agg tags but I'm not sure yet
final int tag_size;
if (use_query_tags) {
int i = 0;
if (sub.getQueryTagKs() != null && !sub.getQueryTagKs().isEmpty()) {
query_tagks = sub.getQueryTagKs();
for (final Map.Entry<byte[], byte[]> pair : dp.tags().entrySet()) {
if (query_tagks.contains(pair.getKey())) {
i++;
}
}
} else {
query_tagks = new ByteSet();
}
tag_size = i;
} else {
query_tagks = new ByteSet();
tag_size = dp.tags().size();
}
final int length = (tag_size * (tagk_width + tagv_width))
+ (include_agg_tags ? (dp.aggregatedTags().size() * tagk_width) : 0);
final byte[] key = new byte[length];
int idx = 0;
for (final Entry<byte[], byte[]> pair : dp.tags().entrySet()) {
if (use_query_tags && !query_tagks.contains(pair.getKey())) {
continue;
}
System.arraycopy(pair.getKey(), 0, key, idx, tagk_width);
idx += tagk_width;
System.arraycopy(pair.getValue(), 0, key, idx, tagv_width);
idx += tagv_width;
}
if (include_agg_tags) {
for (final byte[] tagk : dp.aggregatedTags()) {
System.arraycopy(tagk, 0, key, idx, tagk_width);
idx += tagk_width;
}
}
return key;
}
|
[
"static",
"byte",
"[",
"]",
"flattenTags",
"(",
"final",
"boolean",
"use_query_tags",
",",
"final",
"boolean",
"include_agg_tags",
",",
"final",
"ExpressionDataPoint",
"dp",
",",
"final",
"ITimeSyncedIterator",
"sub",
")",
"{",
"if",
"(",
"dp",
".",
"tags",
"(",
")",
"==",
"null",
"||",
"dp",
".",
"tags",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"HBaseClient",
".",
"EMPTY_ARRAY",
";",
"}",
"final",
"int",
"tagk_width",
"=",
"TSDB",
".",
"tagk_width",
"(",
")",
";",
"final",
"int",
"tagv_width",
"=",
"TSDB",
".",
"tagv_width",
"(",
")",
";",
"final",
"ByteSet",
"query_tagks",
";",
"// NOTE: We MAY need the agg tags but I'm not sure yet",
"final",
"int",
"tag_size",
";",
"if",
"(",
"use_query_tags",
")",
"{",
"int",
"i",
"=",
"0",
";",
"if",
"(",
"sub",
".",
"getQueryTagKs",
"(",
")",
"!=",
"null",
"&&",
"!",
"sub",
".",
"getQueryTagKs",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"query_tagks",
"=",
"sub",
".",
"getQueryTagKs",
"(",
")",
";",
"for",
"(",
"final",
"Map",
".",
"Entry",
"<",
"byte",
"[",
"]",
",",
"byte",
"[",
"]",
">",
"pair",
":",
"dp",
".",
"tags",
"(",
")",
".",
"entrySet",
"(",
")",
")",
"{",
"if",
"(",
"query_tagks",
".",
"contains",
"(",
"pair",
".",
"getKey",
"(",
")",
")",
")",
"{",
"i",
"++",
";",
"}",
"}",
"}",
"else",
"{",
"query_tagks",
"=",
"new",
"ByteSet",
"(",
")",
";",
"}",
"tag_size",
"=",
"i",
";",
"}",
"else",
"{",
"query_tagks",
"=",
"new",
"ByteSet",
"(",
")",
";",
"tag_size",
"=",
"dp",
".",
"tags",
"(",
")",
".",
"size",
"(",
")",
";",
"}",
"final",
"int",
"length",
"=",
"(",
"tag_size",
"*",
"(",
"tagk_width",
"+",
"tagv_width",
")",
")",
"+",
"(",
"include_agg_tags",
"?",
"(",
"dp",
".",
"aggregatedTags",
"(",
")",
".",
"size",
"(",
")",
"*",
"tagk_width",
")",
":",
"0",
")",
";",
"final",
"byte",
"[",
"]",
"key",
"=",
"new",
"byte",
"[",
"length",
"]",
";",
"int",
"idx",
"=",
"0",
";",
"for",
"(",
"final",
"Entry",
"<",
"byte",
"[",
"]",
",",
"byte",
"[",
"]",
">",
"pair",
":",
"dp",
".",
"tags",
"(",
")",
".",
"entrySet",
"(",
")",
")",
"{",
"if",
"(",
"use_query_tags",
"&&",
"!",
"query_tagks",
".",
"contains",
"(",
"pair",
".",
"getKey",
"(",
")",
")",
")",
"{",
"continue",
";",
"}",
"System",
".",
"arraycopy",
"(",
"pair",
".",
"getKey",
"(",
")",
",",
"0",
",",
"key",
",",
"idx",
",",
"tagk_width",
")",
";",
"idx",
"+=",
"tagk_width",
";",
"System",
".",
"arraycopy",
"(",
"pair",
".",
"getValue",
"(",
")",
",",
"0",
",",
"key",
",",
"idx",
",",
"tagv_width",
")",
";",
"idx",
"+=",
"tagv_width",
";",
"}",
"if",
"(",
"include_agg_tags",
")",
"{",
"for",
"(",
"final",
"byte",
"[",
"]",
"tagk",
":",
"dp",
".",
"aggregatedTags",
"(",
")",
")",
"{",
"System",
".",
"arraycopy",
"(",
"tagk",
",",
"0",
",",
"key",
",",
"idx",
",",
"tagk_width",
")",
";",
"idx",
"+=",
"tagk_width",
";",
"}",
"}",
"return",
"key",
";",
"}"
] |
Creates a key based on the concatenation of the tag pairs then the agg
tag keys.
@param use_query_tags Whether or not to include tags returned with the
results or just use those group by'd in the query
@param include_agg_tags Whether or not to include the aggregated tags in
the identifier
@param dp The current expression data point
@param sub The sub query iterator
@return A byte array with the flattened tag keys and values. Note that
if the tags set is empty, this may return an empty array (but not a null
array)
|
[
"Creates",
"a",
"key",
"based",
"on",
"the",
"concatenation",
"of",
"the",
"tag",
"pairs",
"then",
"the",
"agg",
"tag",
"keys",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/query/expression/UnionIterator.java#L259-L309
|
13,662
|
OpenTSDB/opentsdb
|
src/core/MutableDataPoint.java
|
MutableDataPoint.reset
|
public void reset(DataPoint dp) {
this.timestamp = dp.timestamp();
this.is_integer = dp.isInteger();
if (is_integer) {
this.value = dp.longValue();
} else {
this.value = Double.doubleToRawLongBits(dp.doubleValue());
}
}
|
java
|
public void reset(DataPoint dp) {
this.timestamp = dp.timestamp();
this.is_integer = dp.isInteger();
if (is_integer) {
this.value = dp.longValue();
} else {
this.value = Double.doubleToRawLongBits(dp.doubleValue());
}
}
|
[
"public",
"void",
"reset",
"(",
"DataPoint",
"dp",
")",
"{",
"this",
".",
"timestamp",
"=",
"dp",
".",
"timestamp",
"(",
")",
";",
"this",
".",
"is_integer",
"=",
"dp",
".",
"isInteger",
"(",
")",
";",
"if",
"(",
"is_integer",
")",
"{",
"this",
".",
"value",
"=",
"dp",
".",
"longValue",
"(",
")",
";",
"}",
"else",
"{",
"this",
".",
"value",
"=",
"Double",
".",
"doubleToRawLongBits",
"(",
"dp",
".",
"doubleValue",
"(",
")",
")",
";",
"}",
"}"
] |
Resets with a new data point.
@param dp A new data point to store.
|
[
"Resets",
"with",
"a",
"new",
"data",
"point",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/MutableDataPoint.java#L59-L67
|
13,663
|
OpenTSDB/opentsdb
|
src/core/MutableDataPoint.java
|
MutableDataPoint.ofLongValue
|
public static MutableDataPoint ofLongValue(final long timestamp,
final long value) {
final MutableDataPoint dp = new MutableDataPoint();
dp.reset(timestamp, value);
return dp;
}
|
java
|
public static MutableDataPoint ofLongValue(final long timestamp,
final long value) {
final MutableDataPoint dp = new MutableDataPoint();
dp.reset(timestamp, value);
return dp;
}
|
[
"public",
"static",
"MutableDataPoint",
"ofLongValue",
"(",
"final",
"long",
"timestamp",
",",
"final",
"long",
"value",
")",
"{",
"final",
"MutableDataPoint",
"dp",
"=",
"new",
"MutableDataPoint",
"(",
")",
";",
"dp",
".",
"reset",
"(",
"timestamp",
",",
"value",
")",
";",
"return",
"dp",
";",
"}"
] |
Resets with a new pair of a timestamp and a long value.
@param timestamp A timestamp.
@param value A double value.
|
[
"Resets",
"with",
"a",
"new",
"pair",
"of",
"a",
"timestamp",
"and",
"a",
"long",
"value",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/MutableDataPoint.java#L88-L93
|
13,664
|
OpenTSDB/opentsdb
|
src/core/BatchedDataPoints.java
|
BatchedDataPoints.setSeries
|
@Override
public void setSeries(final String metric, final Map<String, String> tags) {
IncomingDataPoints.checkMetricAndTags(metric, tags);
try {
row_key = IncomingDataPoints.rowKeyTemplate(tsdb, metric, tags);
RowKey.prefixKeyWithSalt(row_key);
reset();
}
catch (RuntimeException e) {
throw e;
}
catch (Exception e) {
throw new RuntimeException("Should never happen", e);
}
}
|
java
|
@Override
public void setSeries(final String metric, final Map<String, String> tags) {
IncomingDataPoints.checkMetricAndTags(metric, tags);
try {
row_key = IncomingDataPoints.rowKeyTemplate(tsdb, metric, tags);
RowKey.prefixKeyWithSalt(row_key);
reset();
}
catch (RuntimeException e) {
throw e;
}
catch (Exception e) {
throw new RuntimeException("Should never happen", e);
}
}
|
[
"@",
"Override",
"public",
"void",
"setSeries",
"(",
"final",
"String",
"metric",
",",
"final",
"Map",
"<",
"String",
",",
"String",
">",
"tags",
")",
"{",
"IncomingDataPoints",
".",
"checkMetricAndTags",
"(",
"metric",
",",
"tags",
")",
";",
"try",
"{",
"row_key",
"=",
"IncomingDataPoints",
".",
"rowKeyTemplate",
"(",
"tsdb",
",",
"metric",
",",
"tags",
")",
";",
"RowKey",
".",
"prefixKeyWithSalt",
"(",
"row_key",
")",
";",
"reset",
"(",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"e",
")",
"{",
"throw",
"e",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Should never happen\"",
",",
"e",
")",
";",
"}",
"}"
] |
Sets the metric name and tags of this batch. This method only need be
called if there is a desire to reuse the data structure after the data has
been flushed. This will reset all cached information in this data structure.
@throws IllegalArgumentException if the metric name is empty or contains
illegal characters or if the tags list is empty or one of the elements
contains illegal characters.
|
[
"Sets",
"the",
"metric",
"name",
"and",
"tags",
"of",
"this",
"batch",
".",
"This",
"method",
"only",
"need",
"be",
"called",
"if",
"there",
"is",
"a",
"desire",
"to",
"reuse",
"the",
"data",
"structure",
"after",
"the",
"data",
"has",
"been",
"flushed",
".",
"This",
"will",
"reset",
"all",
"cached",
"information",
"in",
"this",
"data",
"structure",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/BatchedDataPoints.java#L101-L115
|
13,665
|
OpenTSDB/opentsdb
|
src/core/BatchedDataPoints.java
|
BatchedDataPoints.reset
|
private void reset() {
size = 0;
qualifier_index = 0;
value_index = 0;
base_time = Long.MIN_VALUE;
last_timestamp = Long.MIN_VALUE;
}
|
java
|
private void reset() {
size = 0;
qualifier_index = 0;
value_index = 0;
base_time = Long.MIN_VALUE;
last_timestamp = Long.MIN_VALUE;
}
|
[
"private",
"void",
"reset",
"(",
")",
"{",
"size",
"=",
"0",
";",
"qualifier_index",
"=",
"0",
";",
"value_index",
"=",
"0",
";",
"base_time",
"=",
"Long",
".",
"MIN_VALUE",
";",
"last_timestamp",
"=",
"Long",
".",
"MIN_VALUE",
";",
"}"
] |
Resets the indices without overwriting the buffers. So the same amount of
space will remain allocated.
|
[
"Resets",
"the",
"indices",
"without",
"overwriting",
"the",
"buffers",
".",
"So",
"the",
"same",
"amount",
"of",
"space",
"will",
"remain",
"allocated",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/BatchedDataPoints.java#L121-L127
|
13,666
|
OpenTSDB/opentsdb
|
src/core/BatchedDataPoints.java
|
BatchedDataPoints.persist
|
@Override
public Deferred<Object> persist() {
final byte[] q = Arrays.copyOfRange(batched_qualifier, 0, qualifier_index);
final byte[] v = Arrays.copyOfRange(batched_value, 0, value_index);
final byte[] r = Arrays.copyOfRange(row_key, 0, row_key.length);
final long base_time = this.base_time; // shadow fixes issue #1436
System.out.println(Arrays.toString(q) + " " + Arrays.toString(v) + " " + Arrays.toString(r));
reset();
return tsdb.put(r, q, v, base_time);
}
|
java
|
@Override
public Deferred<Object> persist() {
final byte[] q = Arrays.copyOfRange(batched_qualifier, 0, qualifier_index);
final byte[] v = Arrays.copyOfRange(batched_value, 0, value_index);
final byte[] r = Arrays.copyOfRange(row_key, 0, row_key.length);
final long base_time = this.base_time; // shadow fixes issue #1436
System.out.println(Arrays.toString(q) + " " + Arrays.toString(v) + " " + Arrays.toString(r));
reset();
return tsdb.put(r, q, v, base_time);
}
|
[
"@",
"Override",
"public",
"Deferred",
"<",
"Object",
">",
"persist",
"(",
")",
"{",
"final",
"byte",
"[",
"]",
"q",
"=",
"Arrays",
".",
"copyOfRange",
"(",
"batched_qualifier",
",",
"0",
",",
"qualifier_index",
")",
";",
"final",
"byte",
"[",
"]",
"v",
"=",
"Arrays",
".",
"copyOfRange",
"(",
"batched_value",
",",
"0",
",",
"value_index",
")",
";",
"final",
"byte",
"[",
"]",
"r",
"=",
"Arrays",
".",
"copyOfRange",
"(",
"row_key",
",",
"0",
",",
"row_key",
".",
"length",
")",
";",
"final",
"long",
"base_time",
"=",
"this",
".",
"base_time",
";",
"// shadow fixes issue #1436",
"System",
".",
"out",
".",
"println",
"(",
"Arrays",
".",
"toString",
"(",
"q",
")",
"+",
"\" \"",
"+",
"Arrays",
".",
"toString",
"(",
"v",
")",
"+",
"\" \"",
"+",
"Arrays",
".",
"toString",
"(",
"r",
")",
")",
";",
"reset",
"(",
")",
";",
"return",
"tsdb",
".",
"put",
"(",
"r",
",",
"q",
",",
"v",
",",
"base_time",
")",
";",
"}"
] |
A copy of the values is created and sent with a put request. A reset is
initialized which makes this data structure ready to be reused for the same
metric and tags but for a different hour of data.
@return {@inheritDoc}
|
[
"A",
"copy",
"of",
"the",
"values",
"is",
"created",
"and",
"sent",
"with",
"a",
"put",
"request",
".",
"A",
"reset",
"is",
"initialized",
"which",
"makes",
"this",
"data",
"structure",
"ready",
"to",
"be",
"reused",
"for",
"the",
"same",
"metric",
"and",
"tags",
"but",
"for",
"a",
"different",
"hour",
"of",
"data",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/BatchedDataPoints.java#L135-L144
|
13,667
|
OpenTSDB/opentsdb
|
src/core/BatchedDataPoints.java
|
BatchedDataPoints.ensureCapacity
|
private void ensureCapacity(final byte[] next_qualifier,
final byte[] next_value) {
if (qualifier_index + next_qualifier.length >= batched_qualifier.length) {
batched_qualifier = Arrays.copyOf(batched_qualifier,
batched_qualifier.length * 2);
}
if (value_index + next_value.length >= batched_value.length) {
batched_value = Arrays.copyOf(batched_value, batched_value.length * 2);
}
}
|
java
|
private void ensureCapacity(final byte[] next_qualifier,
final byte[] next_value) {
if (qualifier_index + next_qualifier.length >= batched_qualifier.length) {
batched_qualifier = Arrays.copyOf(batched_qualifier,
batched_qualifier.length * 2);
}
if (value_index + next_value.length >= batched_value.length) {
batched_value = Arrays.copyOf(batched_value, batched_value.length * 2);
}
}
|
[
"private",
"void",
"ensureCapacity",
"(",
"final",
"byte",
"[",
"]",
"next_qualifier",
",",
"final",
"byte",
"[",
"]",
"next_value",
")",
"{",
"if",
"(",
"qualifier_index",
"+",
"next_qualifier",
".",
"length",
">=",
"batched_qualifier",
".",
"length",
")",
"{",
"batched_qualifier",
"=",
"Arrays",
".",
"copyOf",
"(",
"batched_qualifier",
",",
"batched_qualifier",
".",
"length",
"*",
"2",
")",
";",
"}",
"if",
"(",
"value_index",
"+",
"next_value",
".",
"length",
">=",
"batched_value",
".",
"length",
")",
"{",
"batched_value",
"=",
"Arrays",
".",
"copyOf",
"(",
"batched_value",
",",
"batched_value",
".",
"length",
"*",
"2",
")",
";",
"}",
"}"
] |
Checks the size of the qualifier and value arrays to make sure we have
space. If not then we double the size of the arrays. This way a row
allocates space for a full hour of second data but if the user requires
millisecond storage with more than 3600 points, it will expand.
@param next_qualifier The next qualifier to use for it's length
@param next_value The next value to use for it's length
|
[
"Checks",
"the",
"size",
"of",
"the",
"qualifier",
"and",
"value",
"arrays",
"to",
"make",
"sure",
"we",
"have",
"space",
".",
"If",
"not",
"then",
"we",
"double",
"the",
"size",
"of",
"the",
"arrays",
".",
"This",
"way",
"a",
"row",
"allocates",
"space",
"for",
"a",
"full",
"hour",
"of",
"second",
"data",
"but",
"if",
"the",
"user",
"requires",
"millisecond",
"storage",
"with",
"more",
"than",
"3600",
"points",
"it",
"will",
"expand",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/BatchedDataPoints.java#L262-L271
|
13,668
|
OpenTSDB/opentsdb
|
src/core/BatchedDataPoints.java
|
BatchedDataPoints.append
|
private void append(final byte[] next_qualifier, final byte[] next_value) {
ensureCapacity(next_qualifier, next_value);
// Now let's simply concatenate all the values together.
System.arraycopy(next_value, 0, batched_value, value_index, next_value.length);
value_index += next_value.length;
// Now let's concatenate all the qualifiers together.
System.arraycopy(next_qualifier, 0, batched_qualifier, qualifier_index,
next_qualifier.length);
qualifier_index += next_qualifier.length;
}
|
java
|
private void append(final byte[] next_qualifier, final byte[] next_value) {
ensureCapacity(next_qualifier, next_value);
// Now let's simply concatenate all the values together.
System.arraycopy(next_value, 0, batched_value, value_index, next_value.length);
value_index += next_value.length;
// Now let's concatenate all the qualifiers together.
System.arraycopy(next_qualifier, 0, batched_qualifier, qualifier_index,
next_qualifier.length);
qualifier_index += next_qualifier.length;
}
|
[
"private",
"void",
"append",
"(",
"final",
"byte",
"[",
"]",
"next_qualifier",
",",
"final",
"byte",
"[",
"]",
"next_value",
")",
"{",
"ensureCapacity",
"(",
"next_qualifier",
",",
"next_value",
")",
";",
"// Now let's simply concatenate all the values together.",
"System",
".",
"arraycopy",
"(",
"next_value",
",",
"0",
",",
"batched_value",
",",
"value_index",
",",
"next_value",
".",
"length",
")",
";",
"value_index",
"+=",
"next_value",
".",
"length",
";",
"// Now let's concatenate all the qualifiers together.",
"System",
".",
"arraycopy",
"(",
"next_qualifier",
",",
"0",
",",
"batched_qualifier",
",",
"qualifier_index",
",",
"next_qualifier",
".",
"length",
")",
";",
"qualifier_index",
"+=",
"next_qualifier",
".",
"length",
";",
"}"
] |
Appends the value and qualifier to the appropriate arrays
@param next_qualifier The next qualifier to append
@param next_value The next value to append
|
[
"Appends",
"the",
"value",
"and",
"qualifier",
"to",
"the",
"appropriate",
"arrays"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/BatchedDataPoints.java#L278-L289
|
13,669
|
OpenTSDB/opentsdb
|
src/core/BatchedDataPoints.java
|
BatchedDataPoints.qualifierOffset
|
private int qualifierOffset(final int i) {
int offset = 0;
for (int j = 0; j < i; j++) {
offset += Internal.getQualifierLength(batched_qualifier, offset);
}
return offset;
}
|
java
|
private int qualifierOffset(final int i) {
int offset = 0;
for (int j = 0; j < i; j++) {
offset += Internal.getQualifierLength(batched_qualifier, offset);
}
return offset;
}
|
[
"private",
"int",
"qualifierOffset",
"(",
"final",
"int",
"i",
")",
"{",
"int",
"offset",
"=",
"0",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"i",
";",
"j",
"++",
")",
"{",
"offset",
"+=",
"Internal",
".",
"getQualifierLength",
"(",
"batched_qualifier",
",",
"offset",
")",
";",
"}",
"return",
"offset",
";",
"}"
] |
Computes the proper offset to reach qualifier
@param i
@return
|
[
"Computes",
"the",
"proper",
"offset",
"to",
"reach",
"qualifier"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/BatchedDataPoints.java#L403-L409
|
13,670
|
OpenTSDB/opentsdb
|
src/core/BatchedDataPoints.java
|
BatchedDataPoints.isInteger
|
private boolean isInteger(final int i, final int q_offset) {
final short flags = Internal.getFlagsFromQualifier(batched_qualifier, q_offset);
return (flags & Const.FLAG_FLOAT) == 0x0;
}
|
java
|
private boolean isInteger(final int i, final int q_offset) {
final short flags = Internal.getFlagsFromQualifier(batched_qualifier, q_offset);
return (flags & Const.FLAG_FLOAT) == 0x0;
}
|
[
"private",
"boolean",
"isInteger",
"(",
"final",
"int",
"i",
",",
"final",
"int",
"q_offset",
")",
"{",
"final",
"short",
"flags",
"=",
"Internal",
".",
"getFlagsFromQualifier",
"(",
"batched_qualifier",
",",
"q_offset",
")",
";",
"return",
"(",
"flags",
"&",
"Const",
".",
"FLAG_FLOAT",
")",
"==",
"0x0",
";",
"}"
] |
Tells whether or not the ith value is integer. Uses pre-computed qualifier offset.
@param i
@param q_offset qualifier offset
@return
|
[
"Tells",
"whether",
"or",
"not",
"the",
"ith",
"value",
"is",
"integer",
".",
"Uses",
"pre",
"-",
"computed",
"qualifier",
"offset",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/BatchedDataPoints.java#L429-L432
|
13,671
|
OpenTSDB/opentsdb
|
src/tsd/QueryRpc.java
|
QueryRpc.handleExpressionQuery
|
private void handleExpressionQuery(final TSDB tsdb, final HttpQuery query) {
final net.opentsdb.query.pojo.Query v2_query =
JSON.parseToObject(query.getContent(), net.opentsdb.query.pojo.Query.class);
v2_query.validate();
checkAuthorization(tsdb, query.channel(), v2_query);
final QueryExecutor executor = new QueryExecutor(tsdb, v2_query);
executor.execute(query);
}
|
java
|
private void handleExpressionQuery(final TSDB tsdb, final HttpQuery query) {
final net.opentsdb.query.pojo.Query v2_query =
JSON.parseToObject(query.getContent(), net.opentsdb.query.pojo.Query.class);
v2_query.validate();
checkAuthorization(tsdb, query.channel(), v2_query);
final QueryExecutor executor = new QueryExecutor(tsdb, v2_query);
executor.execute(query);
}
|
[
"private",
"void",
"handleExpressionQuery",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"HttpQuery",
"query",
")",
"{",
"final",
"net",
".",
"opentsdb",
".",
"query",
".",
"pojo",
".",
"Query",
"v2_query",
"=",
"JSON",
".",
"parseToObject",
"(",
"query",
".",
"getContent",
"(",
")",
",",
"net",
".",
"opentsdb",
".",
"query",
".",
"pojo",
".",
"Query",
".",
"class",
")",
";",
"v2_query",
".",
"validate",
"(",
")",
";",
"checkAuthorization",
"(",
"tsdb",
",",
"query",
".",
"channel",
"(",
")",
",",
"v2_query",
")",
";",
"final",
"QueryExecutor",
"executor",
"=",
"new",
"QueryExecutor",
"(",
"tsdb",
",",
"v2_query",
")",
";",
"executor",
".",
"execute",
"(",
"query",
")",
";",
"}"
] |
Handles an expression query
@param tsdb The TSDB to which we belong
@param query The HTTP query to parse/respond
@since 2.3
|
[
"Handles",
"an",
"expression",
"query"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/QueryRpc.java#L330-L339
|
13,672
|
OpenTSDB/opentsdb
|
src/tsd/QueryRpc.java
|
QueryRpc.parseMTypeSubQuery
|
private static void parseMTypeSubQuery(final String query_string,
TSQuery data_query) {
if (query_string == null || query_string.isEmpty()) {
throw new BadRequestException("The query string was empty");
}
// m is of the following forms:
// agg:[interval-agg:][rate:]metric[{tag=value,...}]
// where the parts in square brackets `[' .. `]' are optional.
final String[] parts = Tags.splitString(query_string, ':');
int i = parts.length;
if (i < 2 || i > 5) {
throw new BadRequestException("Invalid parameter m=" + query_string + " ("
+ (i < 2 ? "not enough" : "too many") + " :-separated parts)");
}
final TSSubQuery sub_query = new TSSubQuery();
// the aggregator is first
sub_query.setAggregator(parts[0]);
i--; // Move to the last part (the metric name).
List<TagVFilter> filters = new ArrayList<TagVFilter>();
sub_query.setMetric(Tags.parseWithMetricAndFilters(parts[i], filters));
sub_query.setFilters(filters);
// parse out the rate and downsampler
for (int x = 1; x < parts.length - 1; x++) {
if (parts[x].toLowerCase().startsWith("rate")) {
sub_query.setRate(true);
if (parts[x].indexOf("{") >= 0) {
sub_query.setRateOptions(QueryRpc.parseRateOptions(true, parts[x]));
}
} else if (Character.isDigit(parts[x].charAt(0))) {
sub_query.setDownsample(parts[x]);
} else if (parts[x].equalsIgnoreCase("pre-agg")) {
sub_query.setPreAggregate(true);
} else if (parts[x].toLowerCase().startsWith("rollup_")) {
sub_query.setRollupUsage(parts[x]);
} else if (parts[x].toLowerCase().startsWith("percentiles")) {
sub_query.setPercentiles(QueryRpc.parsePercentiles(parts[x]));
} else if (parts[x].toLowerCase().startsWith("show-histogram-buckets")) {
sub_query.setShowHistogramBuckets(true);
} else if (parts[x].toLowerCase().startsWith("explicit_tags")) {
sub_query.setExplicitTags(true);
}
}
if (data_query.getQueries() == null) {
final ArrayList<TSSubQuery> subs = new ArrayList<TSSubQuery>(1);
data_query.setQueries(subs);
}
data_query.getQueries().add(sub_query);
}
|
java
|
private static void parseMTypeSubQuery(final String query_string,
TSQuery data_query) {
if (query_string == null || query_string.isEmpty()) {
throw new BadRequestException("The query string was empty");
}
// m is of the following forms:
// agg:[interval-agg:][rate:]metric[{tag=value,...}]
// where the parts in square brackets `[' .. `]' are optional.
final String[] parts = Tags.splitString(query_string, ':');
int i = parts.length;
if (i < 2 || i > 5) {
throw new BadRequestException("Invalid parameter m=" + query_string + " ("
+ (i < 2 ? "not enough" : "too many") + " :-separated parts)");
}
final TSSubQuery sub_query = new TSSubQuery();
// the aggregator is first
sub_query.setAggregator(parts[0]);
i--; // Move to the last part (the metric name).
List<TagVFilter> filters = new ArrayList<TagVFilter>();
sub_query.setMetric(Tags.parseWithMetricAndFilters(parts[i], filters));
sub_query.setFilters(filters);
// parse out the rate and downsampler
for (int x = 1; x < parts.length - 1; x++) {
if (parts[x].toLowerCase().startsWith("rate")) {
sub_query.setRate(true);
if (parts[x].indexOf("{") >= 0) {
sub_query.setRateOptions(QueryRpc.parseRateOptions(true, parts[x]));
}
} else if (Character.isDigit(parts[x].charAt(0))) {
sub_query.setDownsample(parts[x]);
} else if (parts[x].equalsIgnoreCase("pre-agg")) {
sub_query.setPreAggregate(true);
} else if (parts[x].toLowerCase().startsWith("rollup_")) {
sub_query.setRollupUsage(parts[x]);
} else if (parts[x].toLowerCase().startsWith("percentiles")) {
sub_query.setPercentiles(QueryRpc.parsePercentiles(parts[x]));
} else if (parts[x].toLowerCase().startsWith("show-histogram-buckets")) {
sub_query.setShowHistogramBuckets(true);
} else if (parts[x].toLowerCase().startsWith("explicit_tags")) {
sub_query.setExplicitTags(true);
}
}
if (data_query.getQueries() == null) {
final ArrayList<TSSubQuery> subs = new ArrayList<TSSubQuery>(1);
data_query.setQueries(subs);
}
data_query.getQueries().add(sub_query);
}
|
[
"private",
"static",
"void",
"parseMTypeSubQuery",
"(",
"final",
"String",
"query_string",
",",
"TSQuery",
"data_query",
")",
"{",
"if",
"(",
"query_string",
"==",
"null",
"||",
"query_string",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"The query string was empty\"",
")",
";",
"}",
"// m is of the following forms:",
"// agg:[interval-agg:][rate:]metric[{tag=value,...}]",
"// where the parts in square brackets `[' .. `]' are optional.",
"final",
"String",
"[",
"]",
"parts",
"=",
"Tags",
".",
"splitString",
"(",
"query_string",
",",
"'",
"'",
")",
";",
"int",
"i",
"=",
"parts",
".",
"length",
";",
"if",
"(",
"i",
"<",
"2",
"||",
"i",
">",
"5",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Invalid parameter m=\"",
"+",
"query_string",
"+",
"\" (\"",
"+",
"(",
"i",
"<",
"2",
"?",
"\"not enough\"",
":",
"\"too many\"",
")",
"+",
"\" :-separated parts)\"",
")",
";",
"}",
"final",
"TSSubQuery",
"sub_query",
"=",
"new",
"TSSubQuery",
"(",
")",
";",
"// the aggregator is first",
"sub_query",
".",
"setAggregator",
"(",
"parts",
"[",
"0",
"]",
")",
";",
"i",
"--",
";",
"// Move to the last part (the metric name).",
"List",
"<",
"TagVFilter",
">",
"filters",
"=",
"new",
"ArrayList",
"<",
"TagVFilter",
">",
"(",
")",
";",
"sub_query",
".",
"setMetric",
"(",
"Tags",
".",
"parseWithMetricAndFilters",
"(",
"parts",
"[",
"i",
"]",
",",
"filters",
")",
")",
";",
"sub_query",
".",
"setFilters",
"(",
"filters",
")",
";",
"// parse out the rate and downsampler ",
"for",
"(",
"int",
"x",
"=",
"1",
";",
"x",
"<",
"parts",
".",
"length",
"-",
"1",
";",
"x",
"++",
")",
"{",
"if",
"(",
"parts",
"[",
"x",
"]",
".",
"toLowerCase",
"(",
")",
".",
"startsWith",
"(",
"\"rate\"",
")",
")",
"{",
"sub_query",
".",
"setRate",
"(",
"true",
")",
";",
"if",
"(",
"parts",
"[",
"x",
"]",
".",
"indexOf",
"(",
"\"{\"",
")",
">=",
"0",
")",
"{",
"sub_query",
".",
"setRateOptions",
"(",
"QueryRpc",
".",
"parseRateOptions",
"(",
"true",
",",
"parts",
"[",
"x",
"]",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"Character",
".",
"isDigit",
"(",
"parts",
"[",
"x",
"]",
".",
"charAt",
"(",
"0",
")",
")",
")",
"{",
"sub_query",
".",
"setDownsample",
"(",
"parts",
"[",
"x",
"]",
")",
";",
"}",
"else",
"if",
"(",
"parts",
"[",
"x",
"]",
".",
"equalsIgnoreCase",
"(",
"\"pre-agg\"",
")",
")",
"{",
"sub_query",
".",
"setPreAggregate",
"(",
"true",
")",
";",
"}",
"else",
"if",
"(",
"parts",
"[",
"x",
"]",
".",
"toLowerCase",
"(",
")",
".",
"startsWith",
"(",
"\"rollup_\"",
")",
")",
"{",
"sub_query",
".",
"setRollupUsage",
"(",
"parts",
"[",
"x",
"]",
")",
";",
"}",
"else",
"if",
"(",
"parts",
"[",
"x",
"]",
".",
"toLowerCase",
"(",
")",
".",
"startsWith",
"(",
"\"percentiles\"",
")",
")",
"{",
"sub_query",
".",
"setPercentiles",
"(",
"QueryRpc",
".",
"parsePercentiles",
"(",
"parts",
"[",
"x",
"]",
")",
")",
";",
"}",
"else",
"if",
"(",
"parts",
"[",
"x",
"]",
".",
"toLowerCase",
"(",
")",
".",
"startsWith",
"(",
"\"show-histogram-buckets\"",
")",
")",
"{",
"sub_query",
".",
"setShowHistogramBuckets",
"(",
"true",
")",
";",
"}",
"else",
"if",
"(",
"parts",
"[",
"x",
"]",
".",
"toLowerCase",
"(",
")",
".",
"startsWith",
"(",
"\"explicit_tags\"",
")",
")",
"{",
"sub_query",
".",
"setExplicitTags",
"(",
"true",
")",
";",
"}",
"}",
"if",
"(",
"data_query",
".",
"getQueries",
"(",
")",
"==",
"null",
")",
"{",
"final",
"ArrayList",
"<",
"TSSubQuery",
">",
"subs",
"=",
"new",
"ArrayList",
"<",
"TSSubQuery",
">",
"(",
"1",
")",
";",
"data_query",
".",
"setQueries",
"(",
"subs",
")",
";",
"}",
"data_query",
".",
"getQueries",
"(",
")",
".",
"add",
"(",
"sub_query",
")",
";",
"}"
] |
Parses a query string "m=..." type query and adds it to the TSQuery.
This will generate a TSSubQuery and add it to the TSQuery if successful
@param query_string The value of the m query string parameter, i.e. what
comes after the equals sign
@param data_query The query we're building
@throws BadRequestException if we are unable to parse the query or it is
missing components
|
[
"Parses",
"a",
"query",
"string",
"m",
"=",
"...",
"type",
"query",
"and",
"adds",
"it",
"to",
"the",
"TSQuery",
".",
"This",
"will",
"generate",
"a",
"TSSubQuery",
"and",
"add",
"it",
"to",
"the",
"TSQuery",
"if",
"successful"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/QueryRpc.java#L634-L686
|
13,673
|
OpenTSDB/opentsdb
|
src/tsd/QueryRpc.java
|
QueryRpc.parseTsuidTypeSubQuery
|
private static void parseTsuidTypeSubQuery(final String query_string,
TSQuery data_query) {
if (query_string == null || query_string.isEmpty()) {
throw new BadRequestException("The tsuid query string was empty");
}
// tsuid queries are of the following forms:
// agg:[interval-agg:][rate:]tsuid[,s]
// where the parts in square brackets `[' .. `]' are optional.
final String[] parts = Tags.splitString(query_string, ':');
int i = parts.length;
if (i < 2 || i > 5) {
throw new BadRequestException("Invalid parameter m=" + query_string + " ("
+ (i < 2 ? "not enough" : "too many") + " :-separated parts)");
}
final TSSubQuery sub_query = new TSSubQuery();
// the aggregator is first
sub_query.setAggregator(parts[0]);
i--; // Move to the last part (the metric name).
final List<String> tsuid_array = Arrays.asList(parts[i].split(","));
sub_query.setTsuids(tsuid_array);
// parse out the rate and downsampler
for (int x = 1; x < parts.length - 1; x++) {
if (parts[x].toLowerCase().startsWith("rate")) {
sub_query.setRate(true);
if (parts[x].indexOf("{") >= 0) {
sub_query.setRateOptions(QueryRpc.parseRateOptions(true, parts[x]));
}
} else if (Character.isDigit(parts[x].charAt(0))) {
sub_query.setDownsample(parts[x]);
} else if (parts[x].toLowerCase().startsWith("percentiles")) {
sub_query.setPercentiles(QueryRpc.parsePercentiles(parts[x]));
} else if (parts[x].toLowerCase().startsWith("show-histogram-buckets")) {
sub_query.setShowHistogramBuckets(true);
}
}
if (data_query.getQueries() == null) {
final ArrayList<TSSubQuery> subs = new ArrayList<TSSubQuery>(1);
data_query.setQueries(subs);
}
data_query.getQueries().add(sub_query);
}
|
java
|
private static void parseTsuidTypeSubQuery(final String query_string,
TSQuery data_query) {
if (query_string == null || query_string.isEmpty()) {
throw new BadRequestException("The tsuid query string was empty");
}
// tsuid queries are of the following forms:
// agg:[interval-agg:][rate:]tsuid[,s]
// where the parts in square brackets `[' .. `]' are optional.
final String[] parts = Tags.splitString(query_string, ':');
int i = parts.length;
if (i < 2 || i > 5) {
throw new BadRequestException("Invalid parameter m=" + query_string + " ("
+ (i < 2 ? "not enough" : "too many") + " :-separated parts)");
}
final TSSubQuery sub_query = new TSSubQuery();
// the aggregator is first
sub_query.setAggregator(parts[0]);
i--; // Move to the last part (the metric name).
final List<String> tsuid_array = Arrays.asList(parts[i].split(","));
sub_query.setTsuids(tsuid_array);
// parse out the rate and downsampler
for (int x = 1; x < parts.length - 1; x++) {
if (parts[x].toLowerCase().startsWith("rate")) {
sub_query.setRate(true);
if (parts[x].indexOf("{") >= 0) {
sub_query.setRateOptions(QueryRpc.parseRateOptions(true, parts[x]));
}
} else if (Character.isDigit(parts[x].charAt(0))) {
sub_query.setDownsample(parts[x]);
} else if (parts[x].toLowerCase().startsWith("percentiles")) {
sub_query.setPercentiles(QueryRpc.parsePercentiles(parts[x]));
} else if (parts[x].toLowerCase().startsWith("show-histogram-buckets")) {
sub_query.setShowHistogramBuckets(true);
}
}
if (data_query.getQueries() == null) {
final ArrayList<TSSubQuery> subs = new ArrayList<TSSubQuery>(1);
data_query.setQueries(subs);
}
data_query.getQueries().add(sub_query);
}
|
[
"private",
"static",
"void",
"parseTsuidTypeSubQuery",
"(",
"final",
"String",
"query_string",
",",
"TSQuery",
"data_query",
")",
"{",
"if",
"(",
"query_string",
"==",
"null",
"||",
"query_string",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"The tsuid query string was empty\"",
")",
";",
"}",
"// tsuid queries are of the following forms:",
"// agg:[interval-agg:][rate:]tsuid[,s]",
"// where the parts in square brackets `[' .. `]' are optional.",
"final",
"String",
"[",
"]",
"parts",
"=",
"Tags",
".",
"splitString",
"(",
"query_string",
",",
"'",
"'",
")",
";",
"int",
"i",
"=",
"parts",
".",
"length",
";",
"if",
"(",
"i",
"<",
"2",
"||",
"i",
">",
"5",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Invalid parameter m=\"",
"+",
"query_string",
"+",
"\" (\"",
"+",
"(",
"i",
"<",
"2",
"?",
"\"not enough\"",
":",
"\"too many\"",
")",
"+",
"\" :-separated parts)\"",
")",
";",
"}",
"final",
"TSSubQuery",
"sub_query",
"=",
"new",
"TSSubQuery",
"(",
")",
";",
"// the aggregator is first",
"sub_query",
".",
"setAggregator",
"(",
"parts",
"[",
"0",
"]",
")",
";",
"i",
"--",
";",
"// Move to the last part (the metric name).",
"final",
"List",
"<",
"String",
">",
"tsuid_array",
"=",
"Arrays",
".",
"asList",
"(",
"parts",
"[",
"i",
"]",
".",
"split",
"(",
"\",\"",
")",
")",
";",
"sub_query",
".",
"setTsuids",
"(",
"tsuid_array",
")",
";",
"// parse out the rate and downsampler ",
"for",
"(",
"int",
"x",
"=",
"1",
";",
"x",
"<",
"parts",
".",
"length",
"-",
"1",
";",
"x",
"++",
")",
"{",
"if",
"(",
"parts",
"[",
"x",
"]",
".",
"toLowerCase",
"(",
")",
".",
"startsWith",
"(",
"\"rate\"",
")",
")",
"{",
"sub_query",
".",
"setRate",
"(",
"true",
")",
";",
"if",
"(",
"parts",
"[",
"x",
"]",
".",
"indexOf",
"(",
"\"{\"",
")",
">=",
"0",
")",
"{",
"sub_query",
".",
"setRateOptions",
"(",
"QueryRpc",
".",
"parseRateOptions",
"(",
"true",
",",
"parts",
"[",
"x",
"]",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"Character",
".",
"isDigit",
"(",
"parts",
"[",
"x",
"]",
".",
"charAt",
"(",
"0",
")",
")",
")",
"{",
"sub_query",
".",
"setDownsample",
"(",
"parts",
"[",
"x",
"]",
")",
";",
"}",
"else",
"if",
"(",
"parts",
"[",
"x",
"]",
".",
"toLowerCase",
"(",
")",
".",
"startsWith",
"(",
"\"percentiles\"",
")",
")",
"{",
"sub_query",
".",
"setPercentiles",
"(",
"QueryRpc",
".",
"parsePercentiles",
"(",
"parts",
"[",
"x",
"]",
")",
")",
";",
"}",
"else",
"if",
"(",
"parts",
"[",
"x",
"]",
".",
"toLowerCase",
"(",
")",
".",
"startsWith",
"(",
"\"show-histogram-buckets\"",
")",
")",
"{",
"sub_query",
".",
"setShowHistogramBuckets",
"(",
"true",
")",
";",
"}",
"}",
"if",
"(",
"data_query",
".",
"getQueries",
"(",
")",
"==",
"null",
")",
"{",
"final",
"ArrayList",
"<",
"TSSubQuery",
">",
"subs",
"=",
"new",
"ArrayList",
"<",
"TSSubQuery",
">",
"(",
"1",
")",
";",
"data_query",
".",
"setQueries",
"(",
"subs",
")",
";",
"}",
"data_query",
".",
"getQueries",
"(",
")",
".",
"add",
"(",
"sub_query",
")",
";",
"}"
] |
Parses a "tsuid=..." type query and adds it to the TSQuery.
This will generate a TSSubQuery and add it to the TSQuery if successful
@param query_string The value of the m query string parameter, i.e. what
comes after the equals sign
@param data_query The query we're building
@throws BadRequestException if we are unable to parse the query or it is
missing components
|
[
"Parses",
"a",
"tsuid",
"=",
"...",
"type",
"query",
"and",
"adds",
"it",
"to",
"the",
"TSQuery",
".",
"This",
"will",
"generate",
"a",
"TSSubQuery",
"and",
"add",
"it",
"to",
"the",
"TSQuery",
"if",
"successful"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/QueryRpc.java#L697-L743
|
13,674
|
OpenTSDB/opentsdb
|
src/tsd/QueryRpc.java
|
QueryRpc.parseLastPointQuery
|
private LastPointQuery parseLastPointQuery(final TSDB tsdb,
final HttpQuery http_query) {
final LastPointQuery query = new LastPointQuery();
if (http_query.hasQueryStringParam("resolve")) {
query.setResolveNames(true);
}
if (http_query.hasQueryStringParam("back_scan")) {
try {
query.setBackScan(Integer.parseInt(http_query.getQueryStringParam("back_scan")));
} catch (NumberFormatException e) {
throw new BadRequestException("Unable to parse back_scan parameter");
}
}
final List<String> ts_queries = http_query.getQueryStringParams("timeseries");
final List<String> tsuid_queries = http_query.getQueryStringParams("tsuids");
final int num_queries =
(ts_queries != null ? ts_queries.size() : 0) +
(tsuid_queries != null ? tsuid_queries.size() : 0);
final List<LastPointSubQuery> sub_queries =
new ArrayList<LastPointSubQuery>(num_queries);
if (ts_queries != null) {
for (String ts_query : ts_queries) {
sub_queries.add(LastPointSubQuery.parseTimeSeriesQuery(ts_query));
}
}
if (tsuid_queries != null) {
for (String tsuid_query : tsuid_queries) {
sub_queries.add(LastPointSubQuery.parseTSUIDQuery(tsuid_query));
}
}
query.setQueries(sub_queries);
return query;
}
|
java
|
private LastPointQuery parseLastPointQuery(final TSDB tsdb,
final HttpQuery http_query) {
final LastPointQuery query = new LastPointQuery();
if (http_query.hasQueryStringParam("resolve")) {
query.setResolveNames(true);
}
if (http_query.hasQueryStringParam("back_scan")) {
try {
query.setBackScan(Integer.parseInt(http_query.getQueryStringParam("back_scan")));
} catch (NumberFormatException e) {
throw new BadRequestException("Unable to parse back_scan parameter");
}
}
final List<String> ts_queries = http_query.getQueryStringParams("timeseries");
final List<String> tsuid_queries = http_query.getQueryStringParams("tsuids");
final int num_queries =
(ts_queries != null ? ts_queries.size() : 0) +
(tsuid_queries != null ? tsuid_queries.size() : 0);
final List<LastPointSubQuery> sub_queries =
new ArrayList<LastPointSubQuery>(num_queries);
if (ts_queries != null) {
for (String ts_query : ts_queries) {
sub_queries.add(LastPointSubQuery.parseTimeSeriesQuery(ts_query));
}
}
if (tsuid_queries != null) {
for (String tsuid_query : tsuid_queries) {
sub_queries.add(LastPointSubQuery.parseTSUIDQuery(tsuid_query));
}
}
query.setQueries(sub_queries);
return query;
}
|
[
"private",
"LastPointQuery",
"parseLastPointQuery",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"HttpQuery",
"http_query",
")",
"{",
"final",
"LastPointQuery",
"query",
"=",
"new",
"LastPointQuery",
"(",
")",
";",
"if",
"(",
"http_query",
".",
"hasQueryStringParam",
"(",
"\"resolve\"",
")",
")",
"{",
"query",
".",
"setResolveNames",
"(",
"true",
")",
";",
"}",
"if",
"(",
"http_query",
".",
"hasQueryStringParam",
"(",
"\"back_scan\"",
")",
")",
"{",
"try",
"{",
"query",
".",
"setBackScan",
"(",
"Integer",
".",
"parseInt",
"(",
"http_query",
".",
"getQueryStringParam",
"(",
"\"back_scan\"",
")",
")",
")",
";",
"}",
"catch",
"(",
"NumberFormatException",
"e",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Unable to parse back_scan parameter\"",
")",
";",
"}",
"}",
"final",
"List",
"<",
"String",
">",
"ts_queries",
"=",
"http_query",
".",
"getQueryStringParams",
"(",
"\"timeseries\"",
")",
";",
"final",
"List",
"<",
"String",
">",
"tsuid_queries",
"=",
"http_query",
".",
"getQueryStringParams",
"(",
"\"tsuids\"",
")",
";",
"final",
"int",
"num_queries",
"=",
"(",
"ts_queries",
"!=",
"null",
"?",
"ts_queries",
".",
"size",
"(",
")",
":",
"0",
")",
"+",
"(",
"tsuid_queries",
"!=",
"null",
"?",
"tsuid_queries",
".",
"size",
"(",
")",
":",
"0",
")",
";",
"final",
"List",
"<",
"LastPointSubQuery",
">",
"sub_queries",
"=",
"new",
"ArrayList",
"<",
"LastPointSubQuery",
">",
"(",
"num_queries",
")",
";",
"if",
"(",
"ts_queries",
"!=",
"null",
")",
"{",
"for",
"(",
"String",
"ts_query",
":",
"ts_queries",
")",
"{",
"sub_queries",
".",
"add",
"(",
"LastPointSubQuery",
".",
"parseTimeSeriesQuery",
"(",
"ts_query",
")",
")",
";",
"}",
"}",
"if",
"(",
"tsuid_queries",
"!=",
"null",
")",
"{",
"for",
"(",
"String",
"tsuid_query",
":",
"tsuid_queries",
")",
"{",
"sub_queries",
".",
"add",
"(",
"LastPointSubQuery",
".",
"parseTSUIDQuery",
"(",
"tsuid_query",
")",
")",
";",
"}",
"}",
"query",
".",
"setQueries",
"(",
"sub_queries",
")",
";",
"return",
"query",
";",
"}"
] |
Parses a last point query from the URI string
@param tsdb The TSDB to which we belong
@param http_query The HTTP query to work with
@return A LastPointQuery object to execute against
@throws BadRequestException if parsing failed
|
[
"Parses",
"a",
"last",
"point",
"query",
"from",
"the",
"URI",
"string"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/QueryRpc.java#L806-L844
|
13,675
|
OpenTSDB/opentsdb
|
src/tsd/AbstractHttpQuery.java
|
AbstractHttpQuery.getPrintableHeaders
|
public Map<String, String> getPrintableHeaders() {
final Map<String, String> headers = new HashMap<String, String>(
request.headers().entries().size());
for (final Entry<String, String> header : request.headers().entries()) {
if (header.getKey().toLowerCase().equals("cookie")) {
// null out the cookies
headers.put(header.getKey(), "*******");
} else {
// http://tools.ietf.org/html/rfc2616#section-4.2
if (headers.containsKey(header.getKey())) {
headers.put(header.getKey(),
headers.get(header.getKey()) + "," + header.getValue());
} else {
headers.put(header.getKey(), header.getValue());
}
}
}
return headers;
}
|
java
|
public Map<String, String> getPrintableHeaders() {
final Map<String, String> headers = new HashMap<String, String>(
request.headers().entries().size());
for (final Entry<String, String> header : request.headers().entries()) {
if (header.getKey().toLowerCase().equals("cookie")) {
// null out the cookies
headers.put(header.getKey(), "*******");
} else {
// http://tools.ietf.org/html/rfc2616#section-4.2
if (headers.containsKey(header.getKey())) {
headers.put(header.getKey(),
headers.get(header.getKey()) + "," + header.getValue());
} else {
headers.put(header.getKey(), header.getValue());
}
}
}
return headers;
}
|
[
"public",
"Map",
"<",
"String",
",",
"String",
">",
"getPrintableHeaders",
"(",
")",
"{",
"final",
"Map",
"<",
"String",
",",
"String",
">",
"headers",
"=",
"new",
"HashMap",
"<",
"String",
",",
"String",
">",
"(",
"request",
".",
"headers",
"(",
")",
".",
"entries",
"(",
")",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"final",
"Entry",
"<",
"String",
",",
"String",
">",
"header",
":",
"request",
".",
"headers",
"(",
")",
".",
"entries",
"(",
")",
")",
"{",
"if",
"(",
"header",
".",
"getKey",
"(",
")",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"cookie\"",
")",
")",
"{",
"// null out the cookies",
"headers",
".",
"put",
"(",
"header",
".",
"getKey",
"(",
")",
",",
"\"*******\"",
")",
";",
"}",
"else",
"{",
"// http://tools.ietf.org/html/rfc2616#section-4.2",
"if",
"(",
"headers",
".",
"containsKey",
"(",
"header",
".",
"getKey",
"(",
")",
")",
")",
"{",
"headers",
".",
"put",
"(",
"header",
".",
"getKey",
"(",
")",
",",
"headers",
".",
"get",
"(",
"header",
".",
"getKey",
"(",
")",
")",
"+",
"\",\"",
"+",
"header",
".",
"getValue",
"(",
")",
")",
";",
"}",
"else",
"{",
"headers",
".",
"put",
"(",
"header",
".",
"getKey",
"(",
")",
",",
"header",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}",
"}",
"return",
"headers",
";",
"}"
] |
Copies the header list and obfuscates the "cookie" header in case it
contains auth tokens, etc. Note that it flattens duplicate headers keys
as comma separated lists per the RFC
@return The full set of headers for this query with the cookie obfuscated
|
[
"Copies",
"the",
"header",
"list",
"and",
"obfuscates",
"the",
"cookie",
"header",
"in",
"case",
"it",
"contains",
"auth",
"tokens",
"etc",
".",
"Note",
"that",
"it",
"flattens",
"duplicate",
"headers",
"keys",
"as",
"comma",
"separated",
"lists",
"per",
"the",
"RFC"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/AbstractHttpQuery.java#L129-L147
|
13,676
|
OpenTSDB/opentsdb
|
src/tsd/AbstractHttpQuery.java
|
AbstractHttpQuery.getHeaders
|
public Map<String, String> getHeaders() {
final Map<String, String> headers = new HashMap<String, String>(
request.headers().entries().size());
for (final Entry<String, String> header : request.headers().entries()) {
// http://tools.ietf.org/html/rfc2616#section-4.2
if (headers.containsKey(header.getKey())) {
headers.put(header.getKey(),
headers.get(header.getKey()) + "," + header.getValue());
} else {
headers.put(header.getKey(), header.getValue());
}
}
return headers;
}
|
java
|
public Map<String, String> getHeaders() {
final Map<String, String> headers = new HashMap<String, String>(
request.headers().entries().size());
for (final Entry<String, String> header : request.headers().entries()) {
// http://tools.ietf.org/html/rfc2616#section-4.2
if (headers.containsKey(header.getKey())) {
headers.put(header.getKey(),
headers.get(header.getKey()) + "," + header.getValue());
} else {
headers.put(header.getKey(), header.getValue());
}
}
return headers;
}
|
[
"public",
"Map",
"<",
"String",
",",
"String",
">",
"getHeaders",
"(",
")",
"{",
"final",
"Map",
"<",
"String",
",",
"String",
">",
"headers",
"=",
"new",
"HashMap",
"<",
"String",
",",
"String",
">",
"(",
"request",
".",
"headers",
"(",
")",
".",
"entries",
"(",
")",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"final",
"Entry",
"<",
"String",
",",
"String",
">",
"header",
":",
"request",
".",
"headers",
"(",
")",
".",
"entries",
"(",
")",
")",
"{",
"// http://tools.ietf.org/html/rfc2616#section-4.2",
"if",
"(",
"headers",
".",
"containsKey",
"(",
"header",
".",
"getKey",
"(",
")",
")",
")",
"{",
"headers",
".",
"put",
"(",
"header",
".",
"getKey",
"(",
")",
",",
"headers",
".",
"get",
"(",
"header",
".",
"getKey",
"(",
")",
")",
"+",
"\",\"",
"+",
"header",
".",
"getValue",
"(",
")",
")",
";",
"}",
"else",
"{",
"headers",
".",
"put",
"(",
"header",
".",
"getKey",
"(",
")",
",",
"header",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}",
"return",
"headers",
";",
"}"
] |
Copies the header list so modifications won't affect the original set.
Note that it flattens duplicate headers keys as comma separated lists
per the RFC
@return The full set of headers for this query
|
[
"Copies",
"the",
"header",
"list",
"so",
"modifications",
"won",
"t",
"affect",
"the",
"original",
"set",
".",
"Note",
"that",
"it",
"flattens",
"duplicate",
"headers",
"keys",
"as",
"comma",
"separated",
"lists",
"per",
"the",
"RFC"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/AbstractHttpQuery.java#L155-L168
|
13,677
|
OpenTSDB/opentsdb
|
src/tsd/AbstractHttpQuery.java
|
AbstractHttpQuery.getHeaderValue
|
public String getHeaderValue(final String headerName) {
if (headerName == null) { return null; }
return request.headers().get(headerName);
}
|
java
|
public String getHeaderValue(final String headerName) {
if (headerName == null) { return null; }
return request.headers().get(headerName);
}
|
[
"public",
"String",
"getHeaderValue",
"(",
"final",
"String",
"headerName",
")",
"{",
"if",
"(",
"headerName",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"request",
".",
"headers",
"(",
")",
".",
"get",
"(",
"headerName",
")",
";",
"}"
] |
Return the value of the given HTTP Header
first match wins
@return Header value as string
|
[
"Return",
"the",
"value",
"of",
"the",
"given",
"HTTP",
"Header",
"first",
"match",
"wins"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/AbstractHttpQuery.java#L175-L178
|
13,678
|
OpenTSDB/opentsdb
|
src/tsd/AbstractHttpQuery.java
|
AbstractHttpQuery.getQueryString
|
public Map<String, List<String>> getQueryString() {
if (querystring == null) {
try {
querystring = new QueryStringDecoder(request.getUri()).getParameters();
} catch (IllegalArgumentException e) {
throw new BadRequestException("Bad query string: " + e.getMessage());
}
}
return querystring;
}
|
java
|
public Map<String, List<String>> getQueryString() {
if (querystring == null) {
try {
querystring = new QueryStringDecoder(request.getUri()).getParameters();
} catch (IllegalArgumentException e) {
throw new BadRequestException("Bad query string: " + e.getMessage());
}
}
return querystring;
}
|
[
"public",
"Map",
"<",
"String",
",",
"List",
"<",
"String",
">",
">",
"getQueryString",
"(",
")",
"{",
"if",
"(",
"querystring",
"==",
"null",
")",
"{",
"try",
"{",
"querystring",
"=",
"new",
"QueryStringDecoder",
"(",
"request",
".",
"getUri",
"(",
")",
")",
".",
"getParameters",
"(",
")",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"\"Bad query string: \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"return",
"querystring",
";",
"}"
] |
Returns the query string parameters passed in the URI.
|
[
"Returns",
"the",
"query",
"string",
"parameters",
"passed",
"in",
"the",
"URI",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/AbstractHttpQuery.java#L200-L209
|
13,679
|
OpenTSDB/opentsdb
|
src/tsd/AbstractHttpQuery.java
|
AbstractHttpQuery.getCharset
|
public Charset getCharset() {
// RFC2616 3.7
for (String type : this.request.headers().getAll("Content-Type")) {
int idx = type.toUpperCase().indexOf("CHARSET=");
if (idx > 1) {
String charset = type.substring(idx+8);
return Charset.forName(charset);
}
}
return Charset.forName("UTF-8");
}
|
java
|
public Charset getCharset() {
// RFC2616 3.7
for (String type : this.request.headers().getAll("Content-Type")) {
int idx = type.toUpperCase().indexOf("CHARSET=");
if (idx > 1) {
String charset = type.substring(idx+8);
return Charset.forName(charset);
}
}
return Charset.forName("UTF-8");
}
|
[
"public",
"Charset",
"getCharset",
"(",
")",
"{",
"// RFC2616 3.7",
"for",
"(",
"String",
"type",
":",
"this",
".",
"request",
".",
"headers",
"(",
")",
".",
"getAll",
"(",
"\"Content-Type\"",
")",
")",
"{",
"int",
"idx",
"=",
"type",
".",
"toUpperCase",
"(",
")",
".",
"indexOf",
"(",
"\"CHARSET=\"",
")",
";",
"if",
"(",
"idx",
">",
"1",
")",
"{",
"String",
"charset",
"=",
"type",
".",
"substring",
"(",
"idx",
"+",
"8",
")",
";",
"return",
"Charset",
".",
"forName",
"(",
"charset",
")",
";",
"}",
"}",
"return",
"Charset",
".",
"forName",
"(",
"\"UTF-8\"",
")",
";",
"}"
] |
Attempts to parse the character set from the request header. If not set
defaults to UTF-8
@return A Charset object
@throws UnsupportedCharsetException if the parsed character set is invalid
|
[
"Attempts",
"to",
"parse",
"the",
"character",
"set",
"from",
"the",
"request",
"header",
".",
"If",
"not",
"set",
"defaults",
"to",
"UTF",
"-",
"8"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/AbstractHttpQuery.java#L324-L334
|
13,680
|
OpenTSDB/opentsdb
|
src/tsd/AbstractHttpQuery.java
|
AbstractHttpQuery.done
|
public void done() {
final int processing_time = processingTimeMillis();
final String url = request.getUri();
final String msg = String.format("HTTP %s done in %d ms", url, processing_time);
if (url.startsWith("/api/put") && LOG.isDebugEnabled()) {
// NOTE: Suppresses too many log lines from /api/put.
LOG.debug(msg);
} else {
logInfo(msg);
}
logInfo("HTTP " + request.getUri() + " done in " + processing_time + "ms");
}
|
java
|
public void done() {
final int processing_time = processingTimeMillis();
final String url = request.getUri();
final String msg = String.format("HTTP %s done in %d ms", url, processing_time);
if (url.startsWith("/api/put") && LOG.isDebugEnabled()) {
// NOTE: Suppresses too many log lines from /api/put.
LOG.debug(msg);
} else {
logInfo(msg);
}
logInfo("HTTP " + request.getUri() + " done in " + processing_time + "ms");
}
|
[
"public",
"void",
"done",
"(",
")",
"{",
"final",
"int",
"processing_time",
"=",
"processingTimeMillis",
"(",
")",
";",
"final",
"String",
"url",
"=",
"request",
".",
"getUri",
"(",
")",
";",
"final",
"String",
"msg",
"=",
"String",
".",
"format",
"(",
"\"HTTP %s done in %d ms\"",
",",
"url",
",",
"processing_time",
")",
";",
"if",
"(",
"url",
".",
"startsWith",
"(",
"\"/api/put\"",
")",
"&&",
"LOG",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"// NOTE: Suppresses too many log lines from /api/put.",
"LOG",
".",
"debug",
"(",
"msg",
")",
";",
"}",
"else",
"{",
"logInfo",
"(",
"msg",
")",
";",
"}",
"logInfo",
"(",
"\"HTTP \"",
"+",
"request",
".",
"getUri",
"(",
")",
"+",
"\" done in \"",
"+",
"processing_time",
"+",
"\"ms\"",
")",
";",
"}"
] |
Method to call after writing the HTTP response to the wire. The default
is to simply log the request info. Can be overridden by subclasses.
|
[
"Method",
"to",
"call",
"after",
"writing",
"the",
"HTTP",
"response",
"to",
"the",
"wire",
".",
"The",
"default",
"is",
"to",
"simply",
"log",
"the",
"request",
"info",
".",
"Can",
"be",
"overridden",
"by",
"subclasses",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/AbstractHttpQuery.java#L356-L367
|
13,681
|
OpenTSDB/opentsdb
|
src/tsd/AbstractHttpQuery.java
|
AbstractHttpQuery.sendStatusOnly
|
public void sendStatusOnly(final HttpResponseStatus status) {
if (!chan.isConnected()) {
if(stats != null) {
stats.markSendFailed();
}
done();
return;
}
response.setStatus(status);
final boolean keepalive = HttpHeaders.isKeepAlive(request);
if (keepalive) {
HttpHeaders.setContentLength(response, 0);
}
final ChannelFuture future = chan.write(response);
if (stats != null) {
future.addListener(new SendSuccess());
}
if (!keepalive) {
future.addListener(ChannelFutureListener.CLOSE);
}
done();
}
|
java
|
public void sendStatusOnly(final HttpResponseStatus status) {
if (!chan.isConnected()) {
if(stats != null) {
stats.markSendFailed();
}
done();
return;
}
response.setStatus(status);
final boolean keepalive = HttpHeaders.isKeepAlive(request);
if (keepalive) {
HttpHeaders.setContentLength(response, 0);
}
final ChannelFuture future = chan.write(response);
if (stats != null) {
future.addListener(new SendSuccess());
}
if (!keepalive) {
future.addListener(ChannelFutureListener.CLOSE);
}
done();
}
|
[
"public",
"void",
"sendStatusOnly",
"(",
"final",
"HttpResponseStatus",
"status",
")",
"{",
"if",
"(",
"!",
"chan",
".",
"isConnected",
"(",
")",
")",
"{",
"if",
"(",
"stats",
"!=",
"null",
")",
"{",
"stats",
".",
"markSendFailed",
"(",
")",
";",
"}",
"done",
"(",
")",
";",
"return",
";",
"}",
"response",
".",
"setStatus",
"(",
"status",
")",
";",
"final",
"boolean",
"keepalive",
"=",
"HttpHeaders",
".",
"isKeepAlive",
"(",
"request",
")",
";",
"if",
"(",
"keepalive",
")",
"{",
"HttpHeaders",
".",
"setContentLength",
"(",
"response",
",",
"0",
")",
";",
"}",
"final",
"ChannelFuture",
"future",
"=",
"chan",
".",
"write",
"(",
"response",
")",
";",
"if",
"(",
"stats",
"!=",
"null",
")",
"{",
"future",
".",
"addListener",
"(",
"new",
"SendSuccess",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"keepalive",
")",
"{",
"future",
".",
"addListener",
"(",
"ChannelFutureListener",
".",
"CLOSE",
")",
";",
"}",
"done",
"(",
")",
";",
"}"
] |
Send just the status code without a body, used for 204 or 304
@param status The response code to reply with
|
[
"Send",
"just",
"the",
"status",
"code",
"without",
"a",
"body",
"used",
"for",
"204",
"or",
"304"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/AbstractHttpQuery.java#L405-L427
|
13,682
|
OpenTSDB/opentsdb
|
src/core/CompactionQueue.java
|
CompactionQueue.flush
|
public Deferred<ArrayList<Object>> flush() {
final int size = size();
if (size > 0) {
LOG.info("Flushing all old outstanding rows out of " + size + " rows");
}
final long now = System.currentTimeMillis();
return flush(now / 1000 - Const.MAX_TIMESPAN - 1, Integer.MAX_VALUE);
}
|
java
|
public Deferred<ArrayList<Object>> flush() {
final int size = size();
if (size > 0) {
LOG.info("Flushing all old outstanding rows out of " + size + " rows");
}
final long now = System.currentTimeMillis();
return flush(now / 1000 - Const.MAX_TIMESPAN - 1, Integer.MAX_VALUE);
}
|
[
"public",
"Deferred",
"<",
"ArrayList",
"<",
"Object",
">",
">",
"flush",
"(",
")",
"{",
"final",
"int",
"size",
"=",
"size",
"(",
")",
";",
"if",
"(",
"size",
">",
"0",
")",
"{",
"LOG",
".",
"info",
"(",
"\"Flushing all old outstanding rows out of \"",
"+",
"size",
"+",
"\" rows\"",
")",
";",
"}",
"final",
"long",
"now",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"return",
"flush",
"(",
"now",
"/",
"1000",
"-",
"Const",
".",
"MAX_TIMESPAN",
"-",
"1",
",",
"Integer",
".",
"MAX_VALUE",
")",
";",
"}"
] |
Forces a flush of the all old entries in the compaction queue.
@return A deferred that will be called back once everything has been
flushed (or something failed, in which case the deferred will carry the
exception). In case of success, the kind of object returned is
unspecified.
|
[
"Forces",
"a",
"flush",
"of",
"the",
"all",
"old",
"entries",
"in",
"the",
"compaction",
"queue",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/CompactionQueue.java#L127-L134
|
13,683
|
OpenTSDB/opentsdb
|
src/core/CompactionQueue.java
|
CompactionQueue.flush
|
private Deferred<ArrayList<Object>> flush(final long cut_off, int maxflushes) {
assert maxflushes > 0: "maxflushes must be > 0, but I got " + maxflushes;
// We can't possibly flush more entries than size().
maxflushes = Math.min(maxflushes, size());
if (maxflushes == 0) { // Because size() might be 0.
return Deferred.fromResult(new ArrayList<Object>(0));
}
final ArrayList<Deferred<Object>> ds =
new ArrayList<Deferred<Object>>(Math.min(maxflushes, max_concurrent_flushes));
int nflushes = 0;
int seed = (int) (System.nanoTime() % 3);
for (final byte[] row : this.keySet()) {
if (maxflushes == 0) {
break;
}
if (seed == row.hashCode() % 3) {
continue;
}
final long base_time = Bytes.getUnsignedInt(row,
Const.SALT_WIDTH() + metric_width);
if (base_time > cut_off) {
break;
} else if (nflushes == max_concurrent_flushes) {
// We kicked off the compaction of too many rows already, let's wait
// until they're done before kicking off more.
break;
}
// You'd think that it would be faster to grab an iterator on the map
// and then call remove() on the iterator to "unlink" the element
// directly from where the iterator is at, but no, the JDK implements
// it by calling remove(key) so it has to lookup the key again anyway.
if (super.remove(row) == null) { // We didn't remove anything.
continue; // So someone else already took care of this entry.
}
nflushes++;
maxflushes--;
size.decrementAndGet();
ds.add(tsdb.get(row).addCallbacks(compactcb, handle_read_error));
}
final Deferred<ArrayList<Object>> group = Deferred.group(ds);
if (nflushes == max_concurrent_flushes && maxflushes > 0) {
// We're not done yet. Once this group of flushes completes, we need
// to kick off more.
tsdb.getClient().flush(); // Speed up this batch by telling the client to flush.
final int maxflushez = maxflushes; // Make it final for closure.
final class FlushMoreCB implements Callback<Deferred<ArrayList<Object>>,
ArrayList<Object>> {
@Override
public Deferred<ArrayList<Object>> call(final ArrayList<Object> arg) {
return flush(cut_off, maxflushez);
}
@Override
public String toString() {
return "Continue flushing with cut_off=" + cut_off
+ ", maxflushes=" + maxflushez;
}
}
group.addCallbackDeferring(new FlushMoreCB());
}
return group;
}
|
java
|
private Deferred<ArrayList<Object>> flush(final long cut_off, int maxflushes) {
assert maxflushes > 0: "maxflushes must be > 0, but I got " + maxflushes;
// We can't possibly flush more entries than size().
maxflushes = Math.min(maxflushes, size());
if (maxflushes == 0) { // Because size() might be 0.
return Deferred.fromResult(new ArrayList<Object>(0));
}
final ArrayList<Deferred<Object>> ds =
new ArrayList<Deferred<Object>>(Math.min(maxflushes, max_concurrent_flushes));
int nflushes = 0;
int seed = (int) (System.nanoTime() % 3);
for (final byte[] row : this.keySet()) {
if (maxflushes == 0) {
break;
}
if (seed == row.hashCode() % 3) {
continue;
}
final long base_time = Bytes.getUnsignedInt(row,
Const.SALT_WIDTH() + metric_width);
if (base_time > cut_off) {
break;
} else if (nflushes == max_concurrent_flushes) {
// We kicked off the compaction of too many rows already, let's wait
// until they're done before kicking off more.
break;
}
// You'd think that it would be faster to grab an iterator on the map
// and then call remove() on the iterator to "unlink" the element
// directly from where the iterator is at, but no, the JDK implements
// it by calling remove(key) so it has to lookup the key again anyway.
if (super.remove(row) == null) { // We didn't remove anything.
continue; // So someone else already took care of this entry.
}
nflushes++;
maxflushes--;
size.decrementAndGet();
ds.add(tsdb.get(row).addCallbacks(compactcb, handle_read_error));
}
final Deferred<ArrayList<Object>> group = Deferred.group(ds);
if (nflushes == max_concurrent_flushes && maxflushes > 0) {
// We're not done yet. Once this group of flushes completes, we need
// to kick off more.
tsdb.getClient().flush(); // Speed up this batch by telling the client to flush.
final int maxflushez = maxflushes; // Make it final for closure.
final class FlushMoreCB implements Callback<Deferred<ArrayList<Object>>,
ArrayList<Object>> {
@Override
public Deferred<ArrayList<Object>> call(final ArrayList<Object> arg) {
return flush(cut_off, maxflushez);
}
@Override
public String toString() {
return "Continue flushing with cut_off=" + cut_off
+ ", maxflushes=" + maxflushez;
}
}
group.addCallbackDeferring(new FlushMoreCB());
}
return group;
}
|
[
"private",
"Deferred",
"<",
"ArrayList",
"<",
"Object",
">",
">",
"flush",
"(",
"final",
"long",
"cut_off",
",",
"int",
"maxflushes",
")",
"{",
"assert",
"maxflushes",
">",
"0",
":",
"\"maxflushes must be > 0, but I got \"",
"+",
"maxflushes",
";",
"// We can't possibly flush more entries than size().",
"maxflushes",
"=",
"Math",
".",
"min",
"(",
"maxflushes",
",",
"size",
"(",
")",
")",
";",
"if",
"(",
"maxflushes",
"==",
"0",
")",
"{",
"// Because size() might be 0.",
"return",
"Deferred",
".",
"fromResult",
"(",
"new",
"ArrayList",
"<",
"Object",
">",
"(",
"0",
")",
")",
";",
"}",
"final",
"ArrayList",
"<",
"Deferred",
"<",
"Object",
">",
">",
"ds",
"=",
"new",
"ArrayList",
"<",
"Deferred",
"<",
"Object",
">",
">",
"(",
"Math",
".",
"min",
"(",
"maxflushes",
",",
"max_concurrent_flushes",
")",
")",
";",
"int",
"nflushes",
"=",
"0",
";",
"int",
"seed",
"=",
"(",
"int",
")",
"(",
"System",
".",
"nanoTime",
"(",
")",
"%",
"3",
")",
";",
"for",
"(",
"final",
"byte",
"[",
"]",
"row",
":",
"this",
".",
"keySet",
"(",
")",
")",
"{",
"if",
"(",
"maxflushes",
"==",
"0",
")",
"{",
"break",
";",
"}",
"if",
"(",
"seed",
"==",
"row",
".",
"hashCode",
"(",
")",
"%",
"3",
")",
"{",
"continue",
";",
"}",
"final",
"long",
"base_time",
"=",
"Bytes",
".",
"getUnsignedInt",
"(",
"row",
",",
"Const",
".",
"SALT_WIDTH",
"(",
")",
"+",
"metric_width",
")",
";",
"if",
"(",
"base_time",
">",
"cut_off",
")",
"{",
"break",
";",
"}",
"else",
"if",
"(",
"nflushes",
"==",
"max_concurrent_flushes",
")",
"{",
"// We kicked off the compaction of too many rows already, let's wait",
"// until they're done before kicking off more.",
"break",
";",
"}",
"// You'd think that it would be faster to grab an iterator on the map",
"// and then call remove() on the iterator to \"unlink\" the element",
"// directly from where the iterator is at, but no, the JDK implements",
"// it by calling remove(key) so it has to lookup the key again anyway.",
"if",
"(",
"super",
".",
"remove",
"(",
"row",
")",
"==",
"null",
")",
"{",
"// We didn't remove anything.",
"continue",
";",
"// So someone else already took care of this entry.",
"}",
"nflushes",
"++",
";",
"maxflushes",
"--",
";",
"size",
".",
"decrementAndGet",
"(",
")",
";",
"ds",
".",
"add",
"(",
"tsdb",
".",
"get",
"(",
"row",
")",
".",
"addCallbacks",
"(",
"compactcb",
",",
"handle_read_error",
")",
")",
";",
"}",
"final",
"Deferred",
"<",
"ArrayList",
"<",
"Object",
">",
">",
"group",
"=",
"Deferred",
".",
"group",
"(",
"ds",
")",
";",
"if",
"(",
"nflushes",
"==",
"max_concurrent_flushes",
"&&",
"maxflushes",
">",
"0",
")",
"{",
"// We're not done yet. Once this group of flushes completes, we need",
"// to kick off more.",
"tsdb",
".",
"getClient",
"(",
")",
".",
"flush",
"(",
")",
";",
"// Speed up this batch by telling the client to flush.",
"final",
"int",
"maxflushez",
"=",
"maxflushes",
";",
"// Make it final for closure.",
"final",
"class",
"FlushMoreCB",
"implements",
"Callback",
"<",
"Deferred",
"<",
"ArrayList",
"<",
"Object",
">",
">",
",",
"ArrayList",
"<",
"Object",
">",
">",
"{",
"@",
"Override",
"public",
"Deferred",
"<",
"ArrayList",
"<",
"Object",
">",
">",
"call",
"(",
"final",
"ArrayList",
"<",
"Object",
">",
"arg",
")",
"{",
"return",
"flush",
"(",
"cut_off",
",",
"maxflushez",
")",
";",
"}",
"@",
"Override",
"public",
"String",
"toString",
"(",
")",
"{",
"return",
"\"Continue flushing with cut_off=\"",
"+",
"cut_off",
"+",
"\", maxflushes=\"",
"+",
"maxflushez",
";",
"}",
"}",
"group",
".",
"addCallbackDeferring",
"(",
"new",
"FlushMoreCB",
"(",
")",
")",
";",
"}",
"return",
"group",
";",
"}"
] |
Flushes all the rows in the compaction queue older than the cutoff time.
@param cut_off A UNIX timestamp in seconds (unsigned 32-bit integer).
@param maxflushes How many rows to flush off the queue at once.
This integer is expected to be strictly positive.
@return A deferred that will be called back once everything has been
flushed.
|
[
"Flushes",
"all",
"the",
"rows",
"in",
"the",
"compaction",
"queue",
"older",
"than",
"the",
"cutoff",
"time",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/CompactionQueue.java#L165-L225
|
13,684
|
OpenTSDB/opentsdb
|
src/tsd/AnnotationRpc.java
|
AnnotationRpc.executeBulk
|
void executeBulk(final TSDB tsdb, final HttpMethod method, HttpQuery query) {
if (method == HttpMethod.POST || method == HttpMethod.PUT) {
executeBulkUpdate(tsdb, method, query);
} else if (method == HttpMethod.DELETE) {
executeBulkDelete(tsdb, query);
} else {
throw new BadRequestException(HttpResponseStatus.METHOD_NOT_ALLOWED,
"Method not allowed", "The HTTP method [" + query.method().getName() +
"] is not permitted for this endpoint");
}
}
|
java
|
void executeBulk(final TSDB tsdb, final HttpMethod method, HttpQuery query) {
if (method == HttpMethod.POST || method == HttpMethod.PUT) {
executeBulkUpdate(tsdb, method, query);
} else if (method == HttpMethod.DELETE) {
executeBulkDelete(tsdb, query);
} else {
throw new BadRequestException(HttpResponseStatus.METHOD_NOT_ALLOWED,
"Method not allowed", "The HTTP method [" + query.method().getName() +
"] is not permitted for this endpoint");
}
}
|
[
"void",
"executeBulk",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"HttpMethod",
"method",
",",
"HttpQuery",
"query",
")",
"{",
"if",
"(",
"method",
"==",
"HttpMethod",
".",
"POST",
"||",
"method",
"==",
"HttpMethod",
".",
"PUT",
")",
"{",
"executeBulkUpdate",
"(",
"tsdb",
",",
"method",
",",
"query",
")",
";",
"}",
"else",
"if",
"(",
"method",
"==",
"HttpMethod",
".",
"DELETE",
")",
"{",
"executeBulkDelete",
"(",
"tsdb",
",",
"query",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"BadRequestException",
"(",
"HttpResponseStatus",
".",
"METHOD_NOT_ALLOWED",
",",
"\"Method not allowed\"",
",",
"\"The HTTP method [\"",
"+",
"query",
".",
"method",
"(",
")",
".",
"getName",
"(",
")",
"+",
"\"] is not permitted for this endpoint\"",
")",
";",
"}",
"}"
] |
Performs CRUD methods on a list of annotation objects to reduce calls to
the API.
@param tsdb The TSD to which we belong
@param method The request method
@param query The query to parse and respond to
|
[
"Performs",
"CRUD",
"methods",
"on",
"a",
"list",
"of",
"annotation",
"objects",
"to",
"reduce",
"calls",
"to",
"the",
"API",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/AnnotationRpc.java#L143-L153
|
13,685
|
OpenTSDB/opentsdb
|
src/tsd/AnnotationRpc.java
|
AnnotationRpc.executeBulkUpdate
|
void executeBulkUpdate(final TSDB tsdb, final HttpMethod method, HttpQuery query) {
final List<Annotation> notes;
try {
notes = query.serializer().parseAnnotationsV1();
} catch (IllegalArgumentException e){
throw new BadRequestException(e);
} catch (JSONException e){
throw new BadRequestException(e);
}
final List<Deferred<Annotation>> callbacks =
new ArrayList<Deferred<Annotation>>(notes.size());
/**
* Storage callback used to determine if the storage call was successful
* or not. Also returns the updated object from storage.
*/
class SyncCB implements Callback<Deferred<Annotation>, Boolean> {
final private Annotation note;
public SyncCB(final Annotation note) {
this.note = note;
}
@Override
public Deferred<Annotation> call(Boolean success) throws Exception {
if (!success) {
throw new BadRequestException(
HttpResponseStatus.INTERNAL_SERVER_ERROR,
"Failed to save an Annotation to storage",
"This may be caused by another process modifying storage data: "
+ note);
}
return Annotation.getAnnotation(tsdb, note.getTSUID(),
note.getStartTime());
}
}
/**
* Simple callback that will index the updated annotation
*/
class IndexCB implements Callback<Deferred<Annotation>, Annotation> {
@Override
public Deferred<Annotation> call(final Annotation note) throws Exception {
tsdb.indexAnnotation(note);
return Deferred.fromResult(note);
}
}
for (Annotation note : notes) {
try {
Deferred<Annotation> deferred =
note.syncToStorage(tsdb, method == HttpMethod.PUT)
.addCallbackDeferring(new SyncCB(note));
Deferred<Annotation> indexer =
deferred.addCallbackDeferring(new IndexCB());
callbacks.add(indexer);
} catch (IllegalStateException e) {
LOG.info("No changes for annotation: " + note);
} catch (IllegalArgumentException e) {
throw new BadRequestException(HttpResponseStatus.BAD_REQUEST,
e.getMessage(), "Annotation error: " + note, e);
}
}
try {
// wait untill all of the syncs have completed, then rebuild the list
// of annotations using the data synced from storage.
Deferred.group(callbacks).joinUninterruptibly();
notes.clear();
for (Deferred<Annotation> note : callbacks) {
notes.add(note.joinUninterruptibly());
}
query.sendReply(query.serializer().formatAnnotationsV1(notes));
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
java
|
void executeBulkUpdate(final TSDB tsdb, final HttpMethod method, HttpQuery query) {
final List<Annotation> notes;
try {
notes = query.serializer().parseAnnotationsV1();
} catch (IllegalArgumentException e){
throw new BadRequestException(e);
} catch (JSONException e){
throw new BadRequestException(e);
}
final List<Deferred<Annotation>> callbacks =
new ArrayList<Deferred<Annotation>>(notes.size());
/**
* Storage callback used to determine if the storage call was successful
* or not. Also returns the updated object from storage.
*/
class SyncCB implements Callback<Deferred<Annotation>, Boolean> {
final private Annotation note;
public SyncCB(final Annotation note) {
this.note = note;
}
@Override
public Deferred<Annotation> call(Boolean success) throws Exception {
if (!success) {
throw new BadRequestException(
HttpResponseStatus.INTERNAL_SERVER_ERROR,
"Failed to save an Annotation to storage",
"This may be caused by another process modifying storage data: "
+ note);
}
return Annotation.getAnnotation(tsdb, note.getTSUID(),
note.getStartTime());
}
}
/**
* Simple callback that will index the updated annotation
*/
class IndexCB implements Callback<Deferred<Annotation>, Annotation> {
@Override
public Deferred<Annotation> call(final Annotation note) throws Exception {
tsdb.indexAnnotation(note);
return Deferred.fromResult(note);
}
}
for (Annotation note : notes) {
try {
Deferred<Annotation> deferred =
note.syncToStorage(tsdb, method == HttpMethod.PUT)
.addCallbackDeferring(new SyncCB(note));
Deferred<Annotation> indexer =
deferred.addCallbackDeferring(new IndexCB());
callbacks.add(indexer);
} catch (IllegalStateException e) {
LOG.info("No changes for annotation: " + note);
} catch (IllegalArgumentException e) {
throw new BadRequestException(HttpResponseStatus.BAD_REQUEST,
e.getMessage(), "Annotation error: " + note, e);
}
}
try {
// wait untill all of the syncs have completed, then rebuild the list
// of annotations using the data synced from storage.
Deferred.group(callbacks).joinUninterruptibly();
notes.clear();
for (Deferred<Annotation> note : callbacks) {
notes.add(note.joinUninterruptibly());
}
query.sendReply(query.serializer().formatAnnotationsV1(notes));
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
[
"void",
"executeBulkUpdate",
"(",
"final",
"TSDB",
"tsdb",
",",
"final",
"HttpMethod",
"method",
",",
"HttpQuery",
"query",
")",
"{",
"final",
"List",
"<",
"Annotation",
">",
"notes",
";",
"try",
"{",
"notes",
"=",
"query",
".",
"serializer",
"(",
")",
".",
"parseAnnotationsV1",
"(",
")",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"e",
")",
";",
"}",
"catch",
"(",
"JSONException",
"e",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"e",
")",
";",
"}",
"final",
"List",
"<",
"Deferred",
"<",
"Annotation",
">",
">",
"callbacks",
"=",
"new",
"ArrayList",
"<",
"Deferred",
"<",
"Annotation",
">",
">",
"(",
"notes",
".",
"size",
"(",
")",
")",
";",
"/**\n * Storage callback used to determine if the storage call was successful\n * or not. Also returns the updated object from storage.\n */",
"class",
"SyncCB",
"implements",
"Callback",
"<",
"Deferred",
"<",
"Annotation",
">",
",",
"Boolean",
">",
"{",
"final",
"private",
"Annotation",
"note",
";",
"public",
"SyncCB",
"(",
"final",
"Annotation",
"note",
")",
"{",
"this",
".",
"note",
"=",
"note",
";",
"}",
"@",
"Override",
"public",
"Deferred",
"<",
"Annotation",
">",
"call",
"(",
"Boolean",
"success",
")",
"throws",
"Exception",
"{",
"if",
"(",
"!",
"success",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"HttpResponseStatus",
".",
"INTERNAL_SERVER_ERROR",
",",
"\"Failed to save an Annotation to storage\"",
",",
"\"This may be caused by another process modifying storage data: \"",
"+",
"note",
")",
";",
"}",
"return",
"Annotation",
".",
"getAnnotation",
"(",
"tsdb",
",",
"note",
".",
"getTSUID",
"(",
")",
",",
"note",
".",
"getStartTime",
"(",
")",
")",
";",
"}",
"}",
"/**\n * Simple callback that will index the updated annotation\n */",
"class",
"IndexCB",
"implements",
"Callback",
"<",
"Deferred",
"<",
"Annotation",
">",
",",
"Annotation",
">",
"{",
"@",
"Override",
"public",
"Deferred",
"<",
"Annotation",
">",
"call",
"(",
"final",
"Annotation",
"note",
")",
"throws",
"Exception",
"{",
"tsdb",
".",
"indexAnnotation",
"(",
"note",
")",
";",
"return",
"Deferred",
".",
"fromResult",
"(",
"note",
")",
";",
"}",
"}",
"for",
"(",
"Annotation",
"note",
":",
"notes",
")",
"{",
"try",
"{",
"Deferred",
"<",
"Annotation",
">",
"deferred",
"=",
"note",
".",
"syncToStorage",
"(",
"tsdb",
",",
"method",
"==",
"HttpMethod",
".",
"PUT",
")",
".",
"addCallbackDeferring",
"(",
"new",
"SyncCB",
"(",
"note",
")",
")",
";",
"Deferred",
"<",
"Annotation",
">",
"indexer",
"=",
"deferred",
".",
"addCallbackDeferring",
"(",
"new",
"IndexCB",
"(",
")",
")",
";",
"callbacks",
".",
"add",
"(",
"indexer",
")",
";",
"}",
"catch",
"(",
"IllegalStateException",
"e",
")",
"{",
"LOG",
".",
"info",
"(",
"\"No changes for annotation: \"",
"+",
"note",
")",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"HttpResponseStatus",
".",
"BAD_REQUEST",
",",
"e",
".",
"getMessage",
"(",
")",
",",
"\"Annotation error: \"",
"+",
"note",
",",
"e",
")",
";",
"}",
"}",
"try",
"{",
"// wait untill all of the syncs have completed, then rebuild the list",
"// of annotations using the data synced from storage.",
"Deferred",
".",
"group",
"(",
"callbacks",
")",
".",
"joinUninterruptibly",
"(",
")",
";",
"notes",
".",
"clear",
"(",
")",
";",
"for",
"(",
"Deferred",
"<",
"Annotation",
">",
"note",
":",
"callbacks",
")",
"{",
"notes",
".",
"add",
"(",
"note",
".",
"joinUninterruptibly",
"(",
")",
")",
";",
"}",
"query",
".",
"sendReply",
"(",
"query",
".",
"serializer",
"(",
")",
".",
"formatAnnotationsV1",
"(",
"notes",
")",
")",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"throw",
"new",
"BadRequestException",
"(",
"e",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Performs CRU methods on a list of annotation objects to reduce calls to
the API. Only supports body content and adding or updating annotation
objects. Deletions are separate.
@param tsdb The TSD to which we belong
@param method The request method
@param query The query to parse and respond to
|
[
"Performs",
"CRU",
"methods",
"on",
"a",
"list",
"of",
"annotation",
"objects",
"to",
"reduce",
"calls",
"to",
"the",
"API",
".",
"Only",
"supports",
"body",
"content",
"and",
"adding",
"or",
"updating",
"annotation",
"objects",
".",
"Deletions",
"are",
"separate",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/AnnotationRpc.java#L163-L242
|
13,686
|
OpenTSDB/opentsdb
|
src/tsd/AnnotationRpc.java
|
AnnotationRpc.parseBulkDeleteQS
|
private AnnotationBulkDelete parseBulkDeleteQS(final HttpQuery query) {
final AnnotationBulkDelete settings = new AnnotationBulkDelete();
settings.start_time = query.getRequiredQueryStringParam("start_time");
settings.end_time = query.getQueryStringParam("end_time");
if (query.hasQueryStringParam("tsuids")) {
String[] tsuids = query.getQueryStringParam("tsuids").split(",");
settings.tsuids = new ArrayList<String>(tsuids.length);
for (String tsuid : tsuids) {
settings.tsuids.add(tsuid.trim());
}
}
if (query.hasQueryStringParam("global")) {
settings.global = true;
}
return settings;
}
|
java
|
private AnnotationBulkDelete parseBulkDeleteQS(final HttpQuery query) {
final AnnotationBulkDelete settings = new AnnotationBulkDelete();
settings.start_time = query.getRequiredQueryStringParam("start_time");
settings.end_time = query.getQueryStringParam("end_time");
if (query.hasQueryStringParam("tsuids")) {
String[] tsuids = query.getQueryStringParam("tsuids").split(",");
settings.tsuids = new ArrayList<String>(tsuids.length);
for (String tsuid : tsuids) {
settings.tsuids.add(tsuid.trim());
}
}
if (query.hasQueryStringParam("global")) {
settings.global = true;
}
return settings;
}
|
[
"private",
"AnnotationBulkDelete",
"parseBulkDeleteQS",
"(",
"final",
"HttpQuery",
"query",
")",
"{",
"final",
"AnnotationBulkDelete",
"settings",
"=",
"new",
"AnnotationBulkDelete",
"(",
")",
";",
"settings",
".",
"start_time",
"=",
"query",
".",
"getRequiredQueryStringParam",
"(",
"\"start_time\"",
")",
";",
"settings",
".",
"end_time",
"=",
"query",
".",
"getQueryStringParam",
"(",
"\"end_time\"",
")",
";",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"tsuids\"",
")",
")",
"{",
"String",
"[",
"]",
"tsuids",
"=",
"query",
".",
"getQueryStringParam",
"(",
"\"tsuids\"",
")",
".",
"split",
"(",
"\",\"",
")",
";",
"settings",
".",
"tsuids",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
"tsuids",
".",
"length",
")",
";",
"for",
"(",
"String",
"tsuid",
":",
"tsuids",
")",
"{",
"settings",
".",
"tsuids",
".",
"add",
"(",
"tsuid",
".",
"trim",
"(",
")",
")",
";",
"}",
"}",
"if",
"(",
"query",
".",
"hasQueryStringParam",
"(",
"\"global\"",
")",
")",
"{",
"settings",
".",
"global",
"=",
"true",
";",
"}",
"return",
"settings",
";",
"}"
] |
Parses a query string for a bulk delet request
@param query The query to parse
@return A bulk delete query
|
[
"Parses",
"a",
"query",
"string",
"for",
"a",
"bulk",
"delet",
"request"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/tsd/AnnotationRpc.java#L377-L394
|
13,687
|
OpenTSDB/opentsdb
|
src/search/SearchQuery.java
|
SearchQuery.parseSearchType
|
public static SearchType parseSearchType(final String type) {
if (type == null || type.isEmpty()) {
throw new IllegalArgumentException("Type provided was null or empty");
}
if (type.toLowerCase().equals("tsmeta")) {
return SearchType.TSMETA;
} else if (type.toLowerCase().equals("tsmeta_summary")) {
return SearchType.TSMETA_SUMMARY;
} else if (type.toLowerCase().equals("tsuids")) {
return SearchType.TSUIDS;
} else if (type.toLowerCase().equals("uidmeta")) {
return SearchType.UIDMETA;
} else if (type.toLowerCase().equals("annotation")) {
return SearchType.ANNOTATION;
} else if (type.toLowerCase().equals("lookup")) {
return SearchType.LOOKUP;
} else {
throw new IllegalArgumentException("Unknown type: " + type);
}
}
|
java
|
public static SearchType parseSearchType(final String type) {
if (type == null || type.isEmpty()) {
throw new IllegalArgumentException("Type provided was null or empty");
}
if (type.toLowerCase().equals("tsmeta")) {
return SearchType.TSMETA;
} else if (type.toLowerCase().equals("tsmeta_summary")) {
return SearchType.TSMETA_SUMMARY;
} else if (type.toLowerCase().equals("tsuids")) {
return SearchType.TSUIDS;
} else if (type.toLowerCase().equals("uidmeta")) {
return SearchType.UIDMETA;
} else if (type.toLowerCase().equals("annotation")) {
return SearchType.ANNOTATION;
} else if (type.toLowerCase().equals("lookup")) {
return SearchType.LOOKUP;
} else {
throw new IllegalArgumentException("Unknown type: " + type);
}
}
|
[
"public",
"static",
"SearchType",
"parseSearchType",
"(",
"final",
"String",
"type",
")",
"{",
"if",
"(",
"type",
"==",
"null",
"||",
"type",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Type provided was null or empty\"",
")",
";",
"}",
"if",
"(",
"type",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"tsmeta\"",
")",
")",
"{",
"return",
"SearchType",
".",
"TSMETA",
";",
"}",
"else",
"if",
"(",
"type",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"tsmeta_summary\"",
")",
")",
"{",
"return",
"SearchType",
".",
"TSMETA_SUMMARY",
";",
"}",
"else",
"if",
"(",
"type",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"tsuids\"",
")",
")",
"{",
"return",
"SearchType",
".",
"TSUIDS",
";",
"}",
"else",
"if",
"(",
"type",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"uidmeta\"",
")",
")",
"{",
"return",
"SearchType",
".",
"UIDMETA",
";",
"}",
"else",
"if",
"(",
"type",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"annotation\"",
")",
")",
"{",
"return",
"SearchType",
".",
"ANNOTATION",
";",
"}",
"else",
"if",
"(",
"type",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"lookup\"",
")",
")",
"{",
"return",
"SearchType",
".",
"LOOKUP",
";",
"}",
"else",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unknown type: \"",
"+",
"type",
")",
";",
"}",
"}"
] |
Converts the human readable string to the proper enum
@param type The string to parse
@return The parsed enum
@throws IllegalArgumentException if the type is missing or wsa not
recognized
|
[
"Converts",
"the",
"human",
"readable",
"string",
"to",
"the",
"proper",
"enum"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/search/SearchQuery.java#L156-L176
|
13,688
|
OpenTSDB/opentsdb
|
src/core/RateSpan.java
|
RateSpan.populateNextRate
|
private void populateNextRate() {
final MutableDataPoint prev_data = new MutableDataPoint();
if (source.hasNext()) {
prev_data.reset(next_data);
next_data.reset(source.next());
final long t0 = prev_data.timestamp();
final long t1 = next_data.timestamp();
if (t1 <= t0) {
throw new IllegalStateException(
"Next timestamp (" + t1 + ") is supposed to be "
+ " strictly greater than the previous one (" + t0 + "), but it's"
+ " not. this=" + this);
}
// TODO: for backwards compatibility we'll convert the ms to seconds
// but in the future we should add a ratems flag that will calculate
// the rate as is.
final double time_delta_secs = ((double)(t1 - t0) / 1000.0);
double difference;
if (prev_data.isInteger() && next_data.isInteger()) {
// NOTE: Calculates in the long type to avoid precision loss
// while converting long values to double values if both values are long.
// NOTE: Ignores the integer overflow.
difference = next_data.longValue() - prev_data.longValue();
} else {
difference = next_data.toDouble() - prev_data.toDouble();
}
if (options.isCounter() && difference < 0) {
if (options.getDropResets()) {
populateNextRate();
return;
}
if (prev_data.isInteger() && next_data.isInteger()) {
// NOTE: Calculates in the long type to avoid precision loss
// while converting long values to double values if both values are long.
difference = options.getCounterMax() - prev_data.longValue() +
next_data.longValue();
} else {
difference = options.getCounterMax() - prev_data.toDouble() +
next_data.toDouble();
}
// If the rate is greater than the reset value, return a 0
final double rate = difference / time_delta_secs;
if (options.getResetValue() > RateOptions.DEFAULT_RESET_VALUE
&& rate > options.getResetValue()) {
next_rate.reset(next_data.timestamp(), 0.0D);
} else {
next_rate.reset(next_data.timestamp(), rate);
}
} else {
next_rate.reset(next_data.timestamp(), (difference / time_delta_secs));
}
} else {
// Invalidates the next rate with invalid timestamp.
next_rate.reset(INVALID_TIMESTAMP, 0);
}
}
|
java
|
private void populateNextRate() {
final MutableDataPoint prev_data = new MutableDataPoint();
if (source.hasNext()) {
prev_data.reset(next_data);
next_data.reset(source.next());
final long t0 = prev_data.timestamp();
final long t1 = next_data.timestamp();
if (t1 <= t0) {
throw new IllegalStateException(
"Next timestamp (" + t1 + ") is supposed to be "
+ " strictly greater than the previous one (" + t0 + "), but it's"
+ " not. this=" + this);
}
// TODO: for backwards compatibility we'll convert the ms to seconds
// but in the future we should add a ratems flag that will calculate
// the rate as is.
final double time_delta_secs = ((double)(t1 - t0) / 1000.0);
double difference;
if (prev_data.isInteger() && next_data.isInteger()) {
// NOTE: Calculates in the long type to avoid precision loss
// while converting long values to double values if both values are long.
// NOTE: Ignores the integer overflow.
difference = next_data.longValue() - prev_data.longValue();
} else {
difference = next_data.toDouble() - prev_data.toDouble();
}
if (options.isCounter() && difference < 0) {
if (options.getDropResets()) {
populateNextRate();
return;
}
if (prev_data.isInteger() && next_data.isInteger()) {
// NOTE: Calculates in the long type to avoid precision loss
// while converting long values to double values if both values are long.
difference = options.getCounterMax() - prev_data.longValue() +
next_data.longValue();
} else {
difference = options.getCounterMax() - prev_data.toDouble() +
next_data.toDouble();
}
// If the rate is greater than the reset value, return a 0
final double rate = difference / time_delta_secs;
if (options.getResetValue() > RateOptions.DEFAULT_RESET_VALUE
&& rate > options.getResetValue()) {
next_rate.reset(next_data.timestamp(), 0.0D);
} else {
next_rate.reset(next_data.timestamp(), rate);
}
} else {
next_rate.reset(next_data.timestamp(), (difference / time_delta_secs));
}
} else {
// Invalidates the next rate with invalid timestamp.
next_rate.reset(INVALID_TIMESTAMP, 0);
}
}
|
[
"private",
"void",
"populateNextRate",
"(",
")",
"{",
"final",
"MutableDataPoint",
"prev_data",
"=",
"new",
"MutableDataPoint",
"(",
")",
";",
"if",
"(",
"source",
".",
"hasNext",
"(",
")",
")",
"{",
"prev_data",
".",
"reset",
"(",
"next_data",
")",
";",
"next_data",
".",
"reset",
"(",
"source",
".",
"next",
"(",
")",
")",
";",
"final",
"long",
"t0",
"=",
"prev_data",
".",
"timestamp",
"(",
")",
";",
"final",
"long",
"t1",
"=",
"next_data",
".",
"timestamp",
"(",
")",
";",
"if",
"(",
"t1",
"<=",
"t0",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Next timestamp (\"",
"+",
"t1",
"+",
"\") is supposed to be \"",
"+",
"\" strictly greater than the previous one (\"",
"+",
"t0",
"+",
"\"), but it's\"",
"+",
"\" not. this=\"",
"+",
"this",
")",
";",
"}",
"// TODO: for backwards compatibility we'll convert the ms to seconds",
"// but in the future we should add a ratems flag that will calculate",
"// the rate as is.",
"final",
"double",
"time_delta_secs",
"=",
"(",
"(",
"double",
")",
"(",
"t1",
"-",
"t0",
")",
"/",
"1000.0",
")",
";",
"double",
"difference",
";",
"if",
"(",
"prev_data",
".",
"isInteger",
"(",
")",
"&&",
"next_data",
".",
"isInteger",
"(",
")",
")",
"{",
"// NOTE: Calculates in the long type to avoid precision loss",
"// while converting long values to double values if both values are long.",
"// NOTE: Ignores the integer overflow.",
"difference",
"=",
"next_data",
".",
"longValue",
"(",
")",
"-",
"prev_data",
".",
"longValue",
"(",
")",
";",
"}",
"else",
"{",
"difference",
"=",
"next_data",
".",
"toDouble",
"(",
")",
"-",
"prev_data",
".",
"toDouble",
"(",
")",
";",
"}",
"if",
"(",
"options",
".",
"isCounter",
"(",
")",
"&&",
"difference",
"<",
"0",
")",
"{",
"if",
"(",
"options",
".",
"getDropResets",
"(",
")",
")",
"{",
"populateNextRate",
"(",
")",
";",
"return",
";",
"}",
"if",
"(",
"prev_data",
".",
"isInteger",
"(",
")",
"&&",
"next_data",
".",
"isInteger",
"(",
")",
")",
"{",
"// NOTE: Calculates in the long type to avoid precision loss",
"// while converting long values to double values if both values are long.",
"difference",
"=",
"options",
".",
"getCounterMax",
"(",
")",
"-",
"prev_data",
".",
"longValue",
"(",
")",
"+",
"next_data",
".",
"longValue",
"(",
")",
";",
"}",
"else",
"{",
"difference",
"=",
"options",
".",
"getCounterMax",
"(",
")",
"-",
"prev_data",
".",
"toDouble",
"(",
")",
"+",
"next_data",
".",
"toDouble",
"(",
")",
";",
"}",
"// If the rate is greater than the reset value, return a 0",
"final",
"double",
"rate",
"=",
"difference",
"/",
"time_delta_secs",
";",
"if",
"(",
"options",
".",
"getResetValue",
"(",
")",
">",
"RateOptions",
".",
"DEFAULT_RESET_VALUE",
"&&",
"rate",
">",
"options",
".",
"getResetValue",
"(",
")",
")",
"{",
"next_rate",
".",
"reset",
"(",
"next_data",
".",
"timestamp",
"(",
")",
",",
"0.0D",
")",
";",
"}",
"else",
"{",
"next_rate",
".",
"reset",
"(",
"next_data",
".",
"timestamp",
"(",
")",
",",
"rate",
")",
";",
"}",
"}",
"else",
"{",
"next_rate",
".",
"reset",
"(",
"next_data",
".",
"timestamp",
"(",
")",
",",
"(",
"difference",
"/",
"time_delta_secs",
")",
")",
";",
"}",
"}",
"else",
"{",
"// Invalidates the next rate with invalid timestamp.",
"next_rate",
".",
"reset",
"(",
"INVALID_TIMESTAMP",
",",
"0",
")",
";",
"}",
"}"
] |
Populate the next rate.
|
[
"Populate",
"the",
"next",
"rate",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/core/RateSpan.java#L121-L180
|
13,689
|
OpenTSDB/opentsdb
|
src/uid/UniqueId.java
|
UniqueId.cacheSize
|
public long cacheSize() {
if (use_lru) {
return (int) (lru_name_cache.size() + lru_id_cache.size());
}
return name_cache.size() + id_cache.size();
}
|
java
|
public long cacheSize() {
if (use_lru) {
return (int) (lru_name_cache.size() + lru_id_cache.size());
}
return name_cache.size() + id_cache.size();
}
|
[
"public",
"long",
"cacheSize",
"(",
")",
"{",
"if",
"(",
"use_lru",
")",
"{",
"return",
"(",
"int",
")",
"(",
"lru_name_cache",
".",
"size",
"(",
")",
"+",
"lru_id_cache",
".",
"size",
"(",
")",
")",
";",
"}",
"return",
"name_cache",
".",
"size",
"(",
")",
"+",
"id_cache",
".",
"size",
"(",
")",
";",
"}"
] |
Returns the number of elements stored in the internal cache.
|
[
"Returns",
"the",
"number",
"of",
"elements",
"stored",
"in",
"the",
"internal",
"cache",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/uid/UniqueId.java#L249-L254
|
13,690
|
OpenTSDB/opentsdb
|
src/uid/UniqueId.java
|
UniqueId.dropCaches
|
public void dropCaches() {
if (use_lru) {
lru_name_cache.invalidateAll();
lru_id_cache.invalidateAll();
} else {
name_cache.clear();
id_cache.clear();
}
}
|
java
|
public void dropCaches() {
if (use_lru) {
lru_name_cache.invalidateAll();
lru_id_cache.invalidateAll();
} else {
name_cache.clear();
id_cache.clear();
}
}
|
[
"public",
"void",
"dropCaches",
"(",
")",
"{",
"if",
"(",
"use_lru",
")",
"{",
"lru_name_cache",
".",
"invalidateAll",
"(",
")",
";",
"lru_id_cache",
".",
"invalidateAll",
"(",
")",
";",
"}",
"else",
"{",
"name_cache",
".",
"clear",
"(",
")",
";",
"id_cache",
".",
"clear",
"(",
")",
";",
"}",
"}"
] |
Causes this instance to discard all its in-memory caches.
@since 1.1
|
[
"Causes",
"this",
"instance",
"to",
"discard",
"all",
"its",
"in",
"-",
"memory",
"caches",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/uid/UniqueId.java#L317-L325
|
13,691
|
OpenTSDB/opentsdb
|
src/uid/UniqueId.java
|
UniqueId.getNameAsync
|
public Deferred<String> getNameAsync(final byte[] id) {
if (id.length != id_width) {
throw new IllegalArgumentException("Wrong id.length = " + id.length
+ " which is != " + id_width
+ " required for '" + kind() + '\'');
}
final String name = getNameFromCache(id);
if (name != null) {
incrementCacheHits();
return Deferred.fromResult(name);
}
incrementCacheMiss();
class GetNameCB implements Callback<String, String> {
public String call(final String name) {
if (name == null) {
throw new NoSuchUniqueId(kind(), id);
}
if (use_mode) {
switch(mode) {
case READONLY:
addNameToCache(id, name);
break;
case WRITEONLY:
break;
default:
addNameToCache(id, name);
addIdToCache(name, id);
}
} else {
addNameToCache(id, name);
addIdToCache(name, id);
}
return name;
}
}
return getNameFromHBase(id).addCallback(new GetNameCB());
}
|
java
|
public Deferred<String> getNameAsync(final byte[] id) {
if (id.length != id_width) {
throw new IllegalArgumentException("Wrong id.length = " + id.length
+ " which is != " + id_width
+ " required for '" + kind() + '\'');
}
final String name = getNameFromCache(id);
if (name != null) {
incrementCacheHits();
return Deferred.fromResult(name);
}
incrementCacheMiss();
class GetNameCB implements Callback<String, String> {
public String call(final String name) {
if (name == null) {
throw new NoSuchUniqueId(kind(), id);
}
if (use_mode) {
switch(mode) {
case READONLY:
addNameToCache(id, name);
break;
case WRITEONLY:
break;
default:
addNameToCache(id, name);
addIdToCache(name, id);
}
} else {
addNameToCache(id, name);
addIdToCache(name, id);
}
return name;
}
}
return getNameFromHBase(id).addCallback(new GetNameCB());
}
|
[
"public",
"Deferred",
"<",
"String",
">",
"getNameAsync",
"(",
"final",
"byte",
"[",
"]",
"id",
")",
"{",
"if",
"(",
"id",
".",
"length",
"!=",
"id_width",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Wrong id.length = \"",
"+",
"id",
".",
"length",
"+",
"\" which is != \"",
"+",
"id_width",
"+",
"\" required for '\"",
"+",
"kind",
"(",
")",
"+",
"'",
"'",
")",
";",
"}",
"final",
"String",
"name",
"=",
"getNameFromCache",
"(",
"id",
")",
";",
"if",
"(",
"name",
"!=",
"null",
")",
"{",
"incrementCacheHits",
"(",
")",
";",
"return",
"Deferred",
".",
"fromResult",
"(",
"name",
")",
";",
"}",
"incrementCacheMiss",
"(",
")",
";",
"class",
"GetNameCB",
"implements",
"Callback",
"<",
"String",
",",
"String",
">",
"{",
"public",
"String",
"call",
"(",
"final",
"String",
"name",
")",
"{",
"if",
"(",
"name",
"==",
"null",
")",
"{",
"throw",
"new",
"NoSuchUniqueId",
"(",
"kind",
"(",
")",
",",
"id",
")",
";",
"}",
"if",
"(",
"use_mode",
")",
"{",
"switch",
"(",
"mode",
")",
"{",
"case",
"READONLY",
":",
"addNameToCache",
"(",
"id",
",",
"name",
")",
";",
"break",
";",
"case",
"WRITEONLY",
":",
"break",
";",
"default",
":",
"addNameToCache",
"(",
"id",
",",
"name",
")",
";",
"addIdToCache",
"(",
"name",
",",
"id",
")",
";",
"}",
"}",
"else",
"{",
"addNameToCache",
"(",
"id",
",",
"name",
")",
";",
"addIdToCache",
"(",
"name",
",",
"id",
")",
";",
"}",
"return",
"name",
";",
"}",
"}",
"return",
"getNameFromHBase",
"(",
"id",
")",
".",
"addCallback",
"(",
"new",
"GetNameCB",
"(",
")",
")",
";",
"}"
] |
Finds the name associated with a given ID.
@param id The ID associated with that name.
@see #getId(String)
@see #getOrCreateIdAsync(String)
@throws NoSuchUniqueId if the given ID is not assigned.
@throws HBaseException if there is a problem communicating with HBase.
@throws IllegalArgumentException if the ID given in argument is encoded
on the wrong number of bytes.
@since 1.1
|
[
"Finds",
"the",
"name",
"associated",
"with",
"a",
"given",
"ID",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/uid/UniqueId.java#L362-L398
|
13,692
|
OpenTSDB/opentsdb
|
src/uid/UniqueId.java
|
UniqueId.cacheMapping
|
private void cacheMapping(final String name, final byte[] id) {
addIdToCache(name, id);
addNameToCache(id, name);
}
|
java
|
private void cacheMapping(final String name, final byte[] id) {
addIdToCache(name, id);
addNameToCache(id, name);
}
|
[
"private",
"void",
"cacheMapping",
"(",
"final",
"String",
"name",
",",
"final",
"byte",
"[",
"]",
"id",
")",
"{",
"addIdToCache",
"(",
"name",
",",
"id",
")",
";",
"addNameToCache",
"(",
"id",
",",
"name",
")",
";",
"}"
] |
Adds the bidirectional mapping in the cache.
|
[
"Adds",
"the",
"bidirectional",
"mapping",
"in",
"the",
"cache",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/uid/UniqueId.java#L764-L767
|
13,693
|
OpenTSDB/opentsdb
|
src/uid/UniqueId.java
|
UniqueId.getSuggestScanner
|
private static Scanner getSuggestScanner(final HBaseClient client,
final byte[] tsd_uid_table, final String search,
final byte[] kind_or_null, final int max_results) {
final byte[] start_row;
final byte[] end_row;
if (search.isEmpty()) {
start_row = START_ROW;
end_row = END_ROW;
} else {
start_row = toBytes(search);
end_row = Arrays.copyOf(start_row, start_row.length);
end_row[start_row.length - 1]++;
}
final Scanner scanner = client.newScanner(tsd_uid_table);
scanner.setStartKey(start_row);
scanner.setStopKey(end_row);
scanner.setFamily(ID_FAMILY);
if (kind_or_null != null) {
scanner.setQualifier(kind_or_null);
}
scanner.setMaxNumRows(max_results <= 4096 ? max_results : 4096);
return scanner;
}
|
java
|
private static Scanner getSuggestScanner(final HBaseClient client,
final byte[] tsd_uid_table, final String search,
final byte[] kind_or_null, final int max_results) {
final byte[] start_row;
final byte[] end_row;
if (search.isEmpty()) {
start_row = START_ROW;
end_row = END_ROW;
} else {
start_row = toBytes(search);
end_row = Arrays.copyOf(start_row, start_row.length);
end_row[start_row.length - 1]++;
}
final Scanner scanner = client.newScanner(tsd_uid_table);
scanner.setStartKey(start_row);
scanner.setStopKey(end_row);
scanner.setFamily(ID_FAMILY);
if (kind_or_null != null) {
scanner.setQualifier(kind_or_null);
}
scanner.setMaxNumRows(max_results <= 4096 ? max_results : 4096);
return scanner;
}
|
[
"private",
"static",
"Scanner",
"getSuggestScanner",
"(",
"final",
"HBaseClient",
"client",
",",
"final",
"byte",
"[",
"]",
"tsd_uid_table",
",",
"final",
"String",
"search",
",",
"final",
"byte",
"[",
"]",
"kind_or_null",
",",
"final",
"int",
"max_results",
")",
"{",
"final",
"byte",
"[",
"]",
"start_row",
";",
"final",
"byte",
"[",
"]",
"end_row",
";",
"if",
"(",
"search",
".",
"isEmpty",
"(",
")",
")",
"{",
"start_row",
"=",
"START_ROW",
";",
"end_row",
"=",
"END_ROW",
";",
"}",
"else",
"{",
"start_row",
"=",
"toBytes",
"(",
"search",
")",
";",
"end_row",
"=",
"Arrays",
".",
"copyOf",
"(",
"start_row",
",",
"start_row",
".",
"length",
")",
";",
"end_row",
"[",
"start_row",
".",
"length",
"-",
"1",
"]",
"++",
";",
"}",
"final",
"Scanner",
"scanner",
"=",
"client",
".",
"newScanner",
"(",
"tsd_uid_table",
")",
";",
"scanner",
".",
"setStartKey",
"(",
"start_row",
")",
";",
"scanner",
".",
"setStopKey",
"(",
"end_row",
")",
";",
"scanner",
".",
"setFamily",
"(",
"ID_FAMILY",
")",
";",
"if",
"(",
"kind_or_null",
"!=",
"null",
")",
"{",
"scanner",
".",
"setQualifier",
"(",
"kind_or_null",
")",
";",
"}",
"scanner",
".",
"setMaxNumRows",
"(",
"max_results",
"<=",
"4096",
"?",
"max_results",
":",
"4096",
")",
";",
"return",
"scanner",
";",
"}"
] |
Creates a scanner that scans the right range of rows for suggestions.
@param client The HBase client to use.
@param tsd_uid_table Table where IDs are stored.
@param search The string to start searching at
@param kind_or_null The kind of UID to search or null for any kinds.
@param max_results The max number of results to return
|
[
"Creates",
"a",
"scanner",
"that",
"scans",
"the",
"right",
"range",
"of",
"rows",
"for",
"suggestions",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/uid/UniqueId.java#L1313-L1335
|
13,694
|
OpenTSDB/opentsdb
|
src/uid/UniqueId.java
|
UniqueId.hbasePutWithRetry
|
private void hbasePutWithRetry(final PutRequest put, short attempts, short wait)
throws HBaseException {
put.setBufferable(false); // TODO(tsuna): Remove once this code is async.
while (attempts-- > 0) {
try {
client.put(put).joinUninterruptibly();
return;
} catch (HBaseException e) {
if (attempts > 0) {
LOG.error("Put failed, attempts left=" + attempts
+ " (retrying in " + wait + " ms), put=" + put, e);
try {
Thread.sleep(wait);
} catch (InterruptedException ie) {
throw new RuntimeException("interrupted", ie);
}
wait *= 2;
} else {
throw e;
}
} catch (Exception e) {
LOG.error("WTF? Unexpected exception type, put=" + put, e);
}
}
throw new IllegalStateException("This code should never be reached!");
}
|
java
|
private void hbasePutWithRetry(final PutRequest put, short attempts, short wait)
throws HBaseException {
put.setBufferable(false); // TODO(tsuna): Remove once this code is async.
while (attempts-- > 0) {
try {
client.put(put).joinUninterruptibly();
return;
} catch (HBaseException e) {
if (attempts > 0) {
LOG.error("Put failed, attempts left=" + attempts
+ " (retrying in " + wait + " ms), put=" + put, e);
try {
Thread.sleep(wait);
} catch (InterruptedException ie) {
throw new RuntimeException("interrupted", ie);
}
wait *= 2;
} else {
throw e;
}
} catch (Exception e) {
LOG.error("WTF? Unexpected exception type, put=" + put, e);
}
}
throw new IllegalStateException("This code should never be reached!");
}
|
[
"private",
"void",
"hbasePutWithRetry",
"(",
"final",
"PutRequest",
"put",
",",
"short",
"attempts",
",",
"short",
"wait",
")",
"throws",
"HBaseException",
"{",
"put",
".",
"setBufferable",
"(",
"false",
")",
";",
"// TODO(tsuna): Remove once this code is async.",
"while",
"(",
"attempts",
"--",
">",
"0",
")",
"{",
"try",
"{",
"client",
".",
"put",
"(",
"put",
")",
".",
"joinUninterruptibly",
"(",
")",
";",
"return",
";",
"}",
"catch",
"(",
"HBaseException",
"e",
")",
"{",
"if",
"(",
"attempts",
">",
"0",
")",
"{",
"LOG",
".",
"error",
"(",
"\"Put failed, attempts left=\"",
"+",
"attempts",
"+",
"\" (retrying in \"",
"+",
"wait",
"+",
"\" ms), put=\"",
"+",
"put",
",",
"e",
")",
";",
"try",
"{",
"Thread",
".",
"sleep",
"(",
"wait",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"ie",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"interrupted\"",
",",
"ie",
")",
";",
"}",
"wait",
"*=",
"2",
";",
"}",
"else",
"{",
"throw",
"e",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"LOG",
".",
"error",
"(",
"\"WTF? Unexpected exception type, put=\"",
"+",
"put",
",",
"e",
")",
";",
"}",
"}",
"throw",
"new",
"IllegalStateException",
"(",
"\"This code should never be reached!\"",
")",
";",
"}"
] |
Attempts to run the PutRequest given in argument, retrying if needed.
Puts are synchronized.
@param put The PutRequest to execute.
@param attempts The maximum number of attempts.
@param wait The initial amount of time in ms to sleep for after a
failure. This amount is doubled after each failed attempt.
@throws HBaseException if all the attempts have failed. This exception
will be the exception of the last attempt.
|
[
"Attempts",
"to",
"run",
"the",
"PutRequest",
"given",
"in",
"argument",
"retrying",
"if",
"needed",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/uid/UniqueId.java#L1364-L1389
|
13,695
|
OpenTSDB/opentsdb
|
src/uid/UniqueId.java
|
UniqueId.uidToLong
|
public static long uidToLong(final byte[] uid, final short uid_length) {
if (uid.length != uid_length) {
throw new IllegalArgumentException("UID was " + uid.length
+ " bytes long but expected to be " + uid_length);
}
final byte[] uid_raw = new byte[8];
System.arraycopy(uid, 0, uid_raw, 8 - uid_length, uid_length);
return Bytes.getLong(uid_raw);
}
|
java
|
public static long uidToLong(final byte[] uid, final short uid_length) {
if (uid.length != uid_length) {
throw new IllegalArgumentException("UID was " + uid.length
+ " bytes long but expected to be " + uid_length);
}
final byte[] uid_raw = new byte[8];
System.arraycopy(uid, 0, uid_raw, 8 - uid_length, uid_length);
return Bytes.getLong(uid_raw);
}
|
[
"public",
"static",
"long",
"uidToLong",
"(",
"final",
"byte",
"[",
"]",
"uid",
",",
"final",
"short",
"uid_length",
")",
"{",
"if",
"(",
"uid",
".",
"length",
"!=",
"uid_length",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"UID was \"",
"+",
"uid",
".",
"length",
"+",
"\" bytes long but expected to be \"",
"+",
"uid_length",
")",
";",
"}",
"final",
"byte",
"[",
"]",
"uid_raw",
"=",
"new",
"byte",
"[",
"8",
"]",
";",
"System",
".",
"arraycopy",
"(",
"uid",
",",
"0",
",",
"uid_raw",
",",
"8",
"-",
"uid_length",
",",
"uid_length",
")",
";",
"return",
"Bytes",
".",
"getLong",
"(",
"uid_raw",
")",
";",
"}"
] |
Converts a UID to an integer value. The array must be the same length as
uid_length or an exception will be thrown.
@param uid The byte array to convert
@param uid_length Length the array SHOULD be according to the UID config
@return The UID converted to an integer
@throws IllegalArgumentException if the length of the byte array does not
match the uid_length value
@since 2.1
|
[
"Converts",
"a",
"UID",
"to",
"an",
"integer",
"value",
".",
"The",
"array",
"must",
"be",
"the",
"same",
"length",
"as",
"uid_length",
"or",
"an",
"exception",
"will",
"be",
"thrown",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/uid/UniqueId.java#L1457-L1466
|
13,696
|
OpenTSDB/opentsdb
|
src/uid/UniqueId.java
|
UniqueId.longToUID
|
public static byte[] longToUID(final long uid, final short width) {
// Verify that we're going to drop bytes that are 0.
final byte[] padded = Bytes.fromLong(uid);
for (int i = 0; i < padded.length - width; i++) {
if (padded[i] != 0) {
final String message = "UID " + Long.toString(uid) +
" was too large for " + width + " bytes";
LOG.error("OMG " + message);
throw new IllegalStateException(message);
}
}
// Shrink the ID on the requested number of bytes.
return Arrays.copyOfRange(padded, padded.length - width, padded.length);
}
|
java
|
public static byte[] longToUID(final long uid, final short width) {
// Verify that we're going to drop bytes that are 0.
final byte[] padded = Bytes.fromLong(uid);
for (int i = 0; i < padded.length - width; i++) {
if (padded[i] != 0) {
final String message = "UID " + Long.toString(uid) +
" was too large for " + width + " bytes";
LOG.error("OMG " + message);
throw new IllegalStateException(message);
}
}
// Shrink the ID on the requested number of bytes.
return Arrays.copyOfRange(padded, padded.length - width, padded.length);
}
|
[
"public",
"static",
"byte",
"[",
"]",
"longToUID",
"(",
"final",
"long",
"uid",
",",
"final",
"short",
"width",
")",
"{",
"// Verify that we're going to drop bytes that are 0.",
"final",
"byte",
"[",
"]",
"padded",
"=",
"Bytes",
".",
"fromLong",
"(",
"uid",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"padded",
".",
"length",
"-",
"width",
";",
"i",
"++",
")",
"{",
"if",
"(",
"padded",
"[",
"i",
"]",
"!=",
"0",
")",
"{",
"final",
"String",
"message",
"=",
"\"UID \"",
"+",
"Long",
".",
"toString",
"(",
"uid",
")",
"+",
"\" was too large for \"",
"+",
"width",
"+",
"\" bytes\"",
";",
"LOG",
".",
"error",
"(",
"\"OMG \"",
"+",
"message",
")",
";",
"throw",
"new",
"IllegalStateException",
"(",
"message",
")",
";",
"}",
"}",
"// Shrink the ID on the requested number of bytes.",
"return",
"Arrays",
".",
"copyOfRange",
"(",
"padded",
",",
"padded",
".",
"length",
"-",
"width",
",",
"padded",
".",
"length",
")",
";",
"}"
] |
Converts a Long to a byte array with the proper UID width
@param uid The UID to convert
@param width The width of the UID in bytes
@return The UID as a byte array
@throws IllegalStateException if the UID is larger than the width would
allow
@since 2.1
|
[
"Converts",
"a",
"Long",
"to",
"a",
"byte",
"array",
"with",
"the",
"proper",
"UID",
"width"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/uid/UniqueId.java#L1477-L1490
|
13,697
|
OpenTSDB/opentsdb
|
src/uid/UniqueId.java
|
UniqueId.addIdToRegexp
|
public static void addIdToRegexp(final StringBuilder buf, final byte[] id) {
boolean backslash = false;
for (final byte b : id) {
buf.append((char) (b & 0xFF));
if (b == 'E' && backslash) { // If we saw a `\' and now we have a `E'.
// So we just terminated the quoted section because we just added \E
// to `buf'. So let's put a literal \E now and start quoting again.
buf.append("\\\\E\\Q");
} else {
backslash = b == '\\';
}
}
buf.append("\\E");
}
|
java
|
public static void addIdToRegexp(final StringBuilder buf, final byte[] id) {
boolean backslash = false;
for (final byte b : id) {
buf.append((char) (b & 0xFF));
if (b == 'E' && backslash) { // If we saw a `\' and now we have a `E'.
// So we just terminated the quoted section because we just added \E
// to `buf'. So let's put a literal \E now and start quoting again.
buf.append("\\\\E\\Q");
} else {
backslash = b == '\\';
}
}
buf.append("\\E");
}
|
[
"public",
"static",
"void",
"addIdToRegexp",
"(",
"final",
"StringBuilder",
"buf",
",",
"final",
"byte",
"[",
"]",
"id",
")",
"{",
"boolean",
"backslash",
"=",
"false",
";",
"for",
"(",
"final",
"byte",
"b",
":",
"id",
")",
"{",
"buf",
".",
"append",
"(",
"(",
"char",
")",
"(",
"b",
"&",
"0xFF",
")",
")",
";",
"if",
"(",
"b",
"==",
"'",
"'",
"&&",
"backslash",
")",
"{",
"// If we saw a `\\' and now we have a `E'.",
"// So we just terminated the quoted section because we just added \\E",
"// to `buf'. So let's put a literal \\E now and start quoting again.",
"buf",
".",
"append",
"(",
"\"\\\\\\\\E\\\\Q\"",
")",
";",
"}",
"else",
"{",
"backslash",
"=",
"b",
"==",
"'",
"'",
";",
"}",
"}",
"buf",
".",
"append",
"(",
"\"\\\\E\"",
")",
";",
"}"
] |
Appends the given UID to the given string buffer, followed by "\\E".
@param buf The buffer to append
@param id The UID to add as a binary regex pattern
@since 2.1
|
[
"Appends",
"the",
"given",
"UID",
"to",
"the",
"given",
"string",
"buffer",
"followed",
"by",
"\\\\",
"E",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/uid/UniqueId.java#L1498-L1511
|
13,698
|
OpenTSDB/opentsdb
|
src/uid/UniqueId.java
|
UniqueId.stringToUniqueIdType
|
public static UniqueIdType stringToUniqueIdType(final String type) {
if (type.toLowerCase().equals("metric") ||
type.toLowerCase().equals("metrics")) {
return UniqueIdType.METRIC;
} else if (type.toLowerCase().equals("tagk")) {
return UniqueIdType.TAGK;
} else if (type.toLowerCase().equals("tagv")) {
return UniqueIdType.TAGV;
} else {
throw new IllegalArgumentException("Invalid type requested: " + type);
}
}
|
java
|
public static UniqueIdType stringToUniqueIdType(final String type) {
if (type.toLowerCase().equals("metric") ||
type.toLowerCase().equals("metrics")) {
return UniqueIdType.METRIC;
} else if (type.toLowerCase().equals("tagk")) {
return UniqueIdType.TAGK;
} else if (type.toLowerCase().equals("tagv")) {
return UniqueIdType.TAGV;
} else {
throw new IllegalArgumentException("Invalid type requested: " + type);
}
}
|
[
"public",
"static",
"UniqueIdType",
"stringToUniqueIdType",
"(",
"final",
"String",
"type",
")",
"{",
"if",
"(",
"type",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"metric\"",
")",
"||",
"type",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"metrics\"",
")",
")",
"{",
"return",
"UniqueIdType",
".",
"METRIC",
";",
"}",
"else",
"if",
"(",
"type",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"tagk\"",
")",
")",
"{",
"return",
"UniqueIdType",
".",
"TAGK",
";",
"}",
"else",
"if",
"(",
"type",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"tagv\"",
")",
")",
"{",
"return",
"UniqueIdType",
".",
"TAGV",
";",
"}",
"else",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid type requested: \"",
"+",
"type",
")",
";",
"}",
"}"
] |
Attempts to convert the given string to a type enumerator
@param type The string to convert
@return a valid UniqueIdType if matched
@throws IllegalArgumentException if the string did not match a type
@since 2.0
|
[
"Attempts",
"to",
"convert",
"the",
"given",
"string",
"to",
"a",
"type",
"enumerator"
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/uid/UniqueId.java#L1520-L1531
|
13,699
|
OpenTSDB/opentsdb
|
src/uid/UniqueId.java
|
UniqueId.getTSUIDFromKey
|
public static byte[] getTSUIDFromKey(final byte[] row_key,
final short metric_width, final short timestamp_width) {
int idx = 0;
// validation
final int tag_pair_width = TSDB.tagk_width() + TSDB.tagv_width();
final int tags_length = row_key.length -
(Const.SALT_WIDTH() + metric_width + timestamp_width);
if (tags_length < tag_pair_width || (tags_length % tag_pair_width) != 0) {
throw new IllegalArgumentException(
"Row key is missing tags or it is corrupted " + Arrays.toString(row_key));
}
final byte[] tsuid = new byte[
row_key.length - timestamp_width - Const.SALT_WIDTH()];
for (int i = Const.SALT_WIDTH(); i < row_key.length; i++) {
if (i < Const.SALT_WIDTH() + metric_width ||
i >= (Const.SALT_WIDTH() + metric_width + timestamp_width)) {
tsuid[idx] = row_key[i];
idx++;
}
}
return tsuid;
}
|
java
|
public static byte[] getTSUIDFromKey(final byte[] row_key,
final short metric_width, final short timestamp_width) {
int idx = 0;
// validation
final int tag_pair_width = TSDB.tagk_width() + TSDB.tagv_width();
final int tags_length = row_key.length -
(Const.SALT_WIDTH() + metric_width + timestamp_width);
if (tags_length < tag_pair_width || (tags_length % tag_pair_width) != 0) {
throw new IllegalArgumentException(
"Row key is missing tags or it is corrupted " + Arrays.toString(row_key));
}
final byte[] tsuid = new byte[
row_key.length - timestamp_width - Const.SALT_WIDTH()];
for (int i = Const.SALT_WIDTH(); i < row_key.length; i++) {
if (i < Const.SALT_WIDTH() + metric_width ||
i >= (Const.SALT_WIDTH() + metric_width + timestamp_width)) {
tsuid[idx] = row_key[i];
idx++;
}
}
return tsuid;
}
|
[
"public",
"static",
"byte",
"[",
"]",
"getTSUIDFromKey",
"(",
"final",
"byte",
"[",
"]",
"row_key",
",",
"final",
"short",
"metric_width",
",",
"final",
"short",
"timestamp_width",
")",
"{",
"int",
"idx",
"=",
"0",
";",
"// validation",
"final",
"int",
"tag_pair_width",
"=",
"TSDB",
".",
"tagk_width",
"(",
")",
"+",
"TSDB",
".",
"tagv_width",
"(",
")",
";",
"final",
"int",
"tags_length",
"=",
"row_key",
".",
"length",
"-",
"(",
"Const",
".",
"SALT_WIDTH",
"(",
")",
"+",
"metric_width",
"+",
"timestamp_width",
")",
";",
"if",
"(",
"tags_length",
"<",
"tag_pair_width",
"||",
"(",
"tags_length",
"%",
"tag_pair_width",
")",
"!=",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Row key is missing tags or it is corrupted \"",
"+",
"Arrays",
".",
"toString",
"(",
"row_key",
")",
")",
";",
"}",
"final",
"byte",
"[",
"]",
"tsuid",
"=",
"new",
"byte",
"[",
"row_key",
".",
"length",
"-",
"timestamp_width",
"-",
"Const",
".",
"SALT_WIDTH",
"(",
")",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"Const",
".",
"SALT_WIDTH",
"(",
")",
";",
"i",
"<",
"row_key",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
"<",
"Const",
".",
"SALT_WIDTH",
"(",
")",
"+",
"metric_width",
"||",
"i",
">=",
"(",
"Const",
".",
"SALT_WIDTH",
"(",
")",
"+",
"metric_width",
"+",
"timestamp_width",
")",
")",
"{",
"tsuid",
"[",
"idx",
"]",
"=",
"row_key",
"[",
"i",
"]",
";",
"idx",
"++",
";",
"}",
"}",
"return",
"tsuid",
";",
"}"
] |
Extracts the TSUID from a storage row key that includes the timestamp.
@param row_key The row key to process
@param metric_width The width of the metric
@param timestamp_width The width of the timestamp
@return The TSUID as a byte array
@throws IllegalArgumentException if the row key is missing tags or it is
corrupt such as a salted key when salting is disabled or vice versa.
|
[
"Extracts",
"the",
"TSUID",
"from",
"a",
"storage",
"row",
"key",
"that",
"includes",
"the",
"timestamp",
"."
] |
3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3
|
https://github.com/OpenTSDB/opentsdb/blob/3fc2d491c3c1ad397252c0a80203a69a3f9e3ef3/src/uid/UniqueId.java#L1575-L1596
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.