MCPcopy Create free account
hub / github.com/OpenTSDB/opentsdb / getScanner

Method getScanner

src/meta/TSUIDQuery.java:741–786  ·  view source on GitHub ↗

Configures the scanner for a specific metric and optional tags @return A configured scanner

()

Source from the content-addressed store, hash-verified

739 * @return A configured scanner
740 */
741 private Scanner getScanner() {
742 final Scanner scanner = tsdb.getClient().newScanner(tsdb.metaTable());
743 scanner.setStartKey(metric_uid);
744
745 // increment the metric UID by one so we can scan all of the rows for the
746 // given metric
747 final long stop = UniqueId.uidToLong(metric_uid, TSDB.metrics_width()) + 1;
748 scanner.setStopKey(UniqueId.longToUID(stop, TSDB.metrics_width()));
749 scanner.setFamily(TSMeta.FAMILY());
750
751 // set the filter if we have tags
752 if (!tags.isEmpty()) {
753 final short name_width = TSDB.tagk_width();
754 final short value_width = TSDB.tagv_width();
755 final short tagsize = (short) (name_width + value_width);
756 // Generate a regexp for our tags. Say we have 2 tags: { 0 0 1 0 0 2 }
757 // and { 4 5 6 9 8 7 }, the regexp will be:
758 // "^.{7}(?:.{6})*\\Q\000\000\001\000\000\002\\E(?:.{6})*\\Q\004\005\006\011\010\007\\E(?:.{6})*$"
759 final StringBuilder buf = new StringBuilder(
760 15 // "^.{N}" + "(?:.{M})*" + "$"
761 + ((13 + tagsize) // "(?:.{M})*\\Q" + tagsize bytes + "\\E"
762 * (tags.size())));
763
764 // Alright, let's build this regexp. From the beginning...
765 buf.append("(?s)" // Ensure we use the DOTALL flag.
766 + "^.{")
767 // ... start by skipping the metric ID.
768 .append(TSDB.metrics_width())
769 .append("}");
770 final Iterator<byte[]> tags = this.tag_uids.iterator();
771 byte[] tag = tags.hasNext() ? tags.next() : null;
772 // Tags and group_bys are already sorted. We need to put them in the
773 // regexp in order by ID, which means we just merge two sorted lists.
774 do {
775 // Skip any number of tags.
776 buf.append("(?:.{").append(tagsize).append("})*\\Q");
777 UniqueId.addIdToRegexp(buf, tag);
778 tag = tags.hasNext() ? tags.next() : null;
779 } while (tag != null); // Stop when they both become null.
780 // Skip any number of tags before the end.
781 buf.append("(?:.{").append(tagsize).append("})*$");
782 scanner.setKeyRegexp(buf.toString(), CHARSET);
783 }
784
785 return scanner;
786 }
787}

Callers 1

callMethod · 0.45

Calls 15

uidToLongMethod · 0.95
metrics_widthMethod · 0.95
longToUIDMethod · 0.95
FAMILYMethod · 0.95
tagk_widthMethod · 0.95
tagv_widthMethod · 0.95
addIdToRegexpMethod · 0.95
metaTableMethod · 0.80
setFamilyMethod · 0.80
isEmptyMethod · 0.80
sizeMethod · 0.65
iteratorMethod · 0.65

Tested by

no test coverage detected