net.opentsdb.tree
public final class Leaf extends Object implements Comparable<Leaf>
Leaves are stored as individual columns in the same row as a branch. When a branch is loaded with leaves, each leaf is parsed and optionally the UID names are loaded from the TSD. Leaf columns are stored with the column qualifier: "leaf:<display_name.hashCode()>". When a leaf is written to storage, a CompareAndSet is executed with a null value expected for the compare. If the compare returns false, we load the leaf at that location and determine if it's the same leaf. If so, it's all good and we ignore the put. If the TSUID is different, we record a collision in the tree so that the user knows their rule set matched a timeseries that was already recorded.
Constructor and Description |
---|
Leaf()
Default empty constructor necessary for des/serialization
|
Leaf(String display_name,
String tsuid)
Optional constructor used when building a tree
|
Modifier and Type | Method and Description |
---|---|
byte[] |
columnQualifier()
Calculates the column qualifier for this leaf.
|
int |
compareTo(Leaf leaf)
Sorts on the
display_name alphabetically |
boolean |
equals(Object obj)
Just compares the TSUID of the two objects as we don't care about the rest
|
String |
getDisplayName() |
String |
getMetric() |
Map<String,String> |
getTags() |
String |
getTsuid() |
int |
hashCode() |
static byte[] |
LEAF_PREFIX() |
static com.stumbleupon.async.Deferred<Leaf> |
parseFromStorage(TSDB tsdb,
org.hbase.async.KeyValue column,
boolean load_uids)
Attempts to parse the leaf from the given column, optionally loading the
UID names.
|
void |
setDisplayName(String display_name) |
void |
setMetric(String metric) |
void |
setTags(HashMap<String,String> tags) |
void |
setTsuid(String tsuid) |
com.stumbleupon.async.Deferred<Boolean> |
storeLeaf(TSDB tsdb,
byte[] branch_id,
Tree tree)
Attempts to write the leaf to storage using a CompareAndSet call.
|
String |
toString() |
public int hashCode()
public boolean equals(Object obj)
public int compareTo(Leaf leaf)
display_name
alphabeticallycompareTo
in interface Comparable<Leaf>
leaf
- The leaf to compare againstpublic String toString()
public byte[] columnQualifier()
IllegalArgumentException
- if the display_name
hasn't been
set yetpublic com.stumbleupon.async.Deferred<Boolean> storeLeaf(TSDB tsdb, byte[] branch_id, Tree tree)
tsdb
- The TSDB to use for storage accessbranch_id
- ID of the branch this leaf belongs totree
- Tree the leaf and branch belong toorg.hbase.async.HBaseException
- if there was an issueJSONException
- if the object could not be serializedpublic static com.stumbleupon.async.Deferred<Leaf> parseFromStorage(TSDB tsdb, org.hbase.async.KeyValue column, boolean load_uids)
tsdb
- The TSDB to use for storage accesscolumn
- Column to parse a leaf fromload_uids
- Whether or not to load UID names from the TSDIllegalArgumentException
- if the column was missing dataNoSuchUniqueId
- If any of the UID name mappings do not existorg.hbase.async.HBaseException
- if there was an issueJSONException
- if the object could not be serializedpublic static byte[] LEAF_PREFIX()
public String getMetric()
public String getDisplayName()
public String getTsuid()
public void setMetric(String metric)
metric
- The metric associated with this TSUIDpublic void setTags(HashMap<String,String> tags)
tags
- The tags associated with this TSUIDpublic void setDisplayName(String display_name)
display_name
- Public display name for the leafpublic void setTsuid(String tsuid)
tsuid
- the tsuid to set