net.opentsdb.uid
public final class UniqueId extends Object implements UniqueIdInterface
Don't attempt to use equals()
or hashCode()
on
this class.
UniqueIdInterface
Modifier and Type | Class and Description |
---|---|
static class |
UniqueId.UniqueIdType
Enumerator for different types of UIDS @since 2.0
|
Constructor and Description |
---|
UniqueId(org.hbase.async.HBaseClient client,
byte[] table,
String kind,
int width)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
cacheHits()
The number of times we avoided reading from HBase thanks to the cache.
|
int |
cacheMisses()
The number of times we had to read from HBase and populate the cache.
|
int |
cacheSize()
Returns the number of elements stored in the internal cache.
|
void |
dropCaches()
Causes this instance to discard all its in-memory caches.
|
byte[] |
getId(String name)
Finds the ID associated with a given name.
|
com.stumbleupon.async.Deferred<byte[]> |
getIdAsync(String name) |
String |
getName(byte[] id)
Finds the name associated with a given ID.
|
com.stumbleupon.async.Deferred<String> |
getNameAsync(byte[] id)
Finds the name associated with a given ID.
|
byte[] |
getOrCreateId(String name)
Finds the ID associated with a given name or creates it.
|
com.stumbleupon.async.Deferred<byte[]> |
getOrCreateIdAsync(String name)
Finds the ID associated with a given name or creates it.
|
static List<byte[]> |
getTagPairsFromTSUID(String tsuid,
short metric_width,
short tagk_width,
short tagv_width)
Extracts a list of tagk/tagv pairs from a tsuid
|
static byte[] |
getTSUIDFromKey(byte[] row_key,
short metric_width,
short timestamp_width)
Extracts the TSUID from a storage row key that includes the timestamp.
|
static com.stumbleupon.async.Deferred<Map<String,Long>> |
getUsedUIDs(TSDB tsdb,
byte[][] kinds)
Returns a map of max UIDs from storage for the given list of UID types
|
String |
kind()
Returns what kind of Unique ID is served by this instance.
|
long |
maxPossibleId()
The largest possible ID given the number of bytes the IDs are represented on.
|
void |
rename(String oldname,
String newname)
Reassigns the UID to a different name (non-atomic).
|
void |
setTSDB(TSDB tsdb) |
static byte[] |
stringToUid(String uid)
Converts a hex string to a byte array
If the
uid is less than uid_length * 2 characters wide, it
will be padded with 0s to conform to the spec. |
static byte[] |
stringToUid(String uid,
short uid_length)
Converts a hex string to a byte array
If the
uid is less than uid_length * 2 characters wide, it
will be padded with 0s to conform to the spec. |
static UniqueId.UniqueIdType |
stringToUniqueIdType(String type)
Attempts to convert the given string to a type enumerator
|
List<String> |
suggest(String search)
Attempts to find suggestions of names given a search term.
|
List<String> |
suggest(String search,
int max_results)
Attempts to find suggestions of names given a search term.
|
com.stumbleupon.async.Deferred<List<String>> |
suggestAsync(String search,
int max_results)
Attempts to find suggestions of names given a search term.
|
String |
toString()
Returns a human readable string representation of the object.
|
static String |
uidToString(byte[] uid)
Converts a byte array to a hex encoded, upper case string with padding
|
short |
width()
Returns the number of bytes on which each Unique ID is encoded.
|
public UniqueId(org.hbase.async.HBaseClient client, byte[] table, String kind, int width)
client
- The HBase client to use.table
- The name of the HBase table to use.kind
- The kind of Unique ID this instance will deal with.width
- The number of bytes on which Unique IDs should be encoded.IllegalArgumentException
- if width is negative or too small/large
or if kind is an empty string.public int cacheHits()
public int cacheMisses()
public int cacheSize()
public String kind()
UniqueIdInterface
kind
in interface UniqueIdInterface
public short width()
UniqueIdInterface
width
in interface UniqueIdInterface
public void setTSDB(TSDB tsdb)
tsdb
- Whether or not to track new UIDMeta objectspublic long maxPossibleId()
public void dropCaches()
public String getName(byte[] id) throws NoSuchUniqueId, org.hbase.async.HBaseException
This method is blocking. Its use within OpenTSDB itself
is discouraged, please use getNameAsync(byte[])
instead.
getName
in interface UniqueIdInterface
id
- The ID associated with that name.NoSuchUniqueId
- if the given ID is not assigned.org.hbase.async.HBaseException
- if there is a problem communicating with HBase.IllegalArgumentException
- if the ID given in argument is encoded
on the wrong number of bytes.getId(String)
,
getOrCreateId(String)
public com.stumbleupon.async.Deferred<String> getNameAsync(byte[] id)
id
- The ID associated with that name.NoSuchUniqueId
- if the given ID is not assigned.org.hbase.async.HBaseException
- if there is a problem communicating with HBase.IllegalArgumentException
- if the ID given in argument is encoded
on the wrong number of bytes.getId(String)
,
getOrCreateIdAsync(String)
public byte[] getId(String name) throws NoSuchUniqueName, org.hbase.async.HBaseException
UniqueIdInterface
The length of the byte array is fixed in advance by the implementation.
getId
in interface UniqueIdInterface
name
- The name to lookup in the table.byte[]
array.NoSuchUniqueName
- if the name requested doesn't have an ID assigned.org.hbase.async.HBaseException
- if there is a problem communicating with HBase.UniqueIdInterface.getName(byte[])
public com.stumbleupon.async.Deferred<byte[]> getIdAsync(String name)
public byte[] getOrCreateId(String name) throws org.hbase.async.HBaseException
This method is blocking. Its use within OpenTSDB itself
is discouraged, please use getOrCreateIdAsync(java.lang.String)
instead.
The length of the byte array is fixed in advance by the implementation.
getOrCreateId
in interface UniqueIdInterface
name
- The name to lookup in the table or to assign an ID to.org.hbase.async.HBaseException
- if there is a problem communicating with HBase.IllegalStateException
- if all possible IDs are already assigned.IllegalStateException
- if the ID found in HBase is encoded on the
wrong number of bytes.public com.stumbleupon.async.Deferred<byte[]> getOrCreateIdAsync(String name)
The length of the byte array is fixed in advance by the implementation.
name
- The name to lookup in the table or to assign an ID to.org.hbase.async.HBaseException
- if there is a problem communicating with HBase.IllegalStateException
- if all possible IDs are already assigned.IllegalStateException
- if the ID found in HBase is encoded on the
wrong number of bytes.public List<String> suggest(String search) throws org.hbase.async.HBaseException
This method is blocking. Its use within OpenTSDB itself
is discouraged, please use suggestAsync(java.lang.String, int)
instead.
search
- The search term (possibly empty).org.hbase.async.HBaseException
- if there was a problem getting suggestions from
HBase.public List<String> suggest(String search, int max_results) throws org.hbase.async.HBaseException
search
- The search term (possibly empty).max_results
- The number of results to return. Must be 1 or greaterorg.hbase.async.HBaseException
- if there was a problem getting suggestions from
HBase.IllegalArgumentException
- if the count was less than 1public com.stumbleupon.async.Deferred<List<String>> suggestAsync(String search, int max_results)
search
- The search term (possibly empty).org.hbase.async.HBaseException
- if there was a problem getting suggestions from
HBase.public void rename(String oldname, String newname)
Whatever was the UID of oldname
will be given to newname
.
oldname
will no longer be assigned a UID.
Beware that the assignment change is not atommic. If two threads or processes attempt to rename the same UID differently, the result is unspecified and might even be inconsistent. This API is only here for administrative purposes, not for normal programmatic interactions.
oldname
- The old name to rename.newname
- The new name.NoSuchUniqueName
- if oldname
wasn't assigned.IllegalArgumentException
- if newname
was already assigned.org.hbase.async.HBaseException
- if there was a problem with HBase while trying to
update the mapping.public String toString()
public static String uidToString(byte[] uid)
uid
- The ID to convertNullPointerException
- if the ID was nullpublic static byte[] stringToUid(String uid)
uid
is less than uid_length * 2
characters wide, it
will be padded with 0s to conform to the spec. E.g. if the tagk width is 3
and the given uid
string is "1", the string will be padded to
"000001" and then converted to a byte array to reach 3 bytes.
All uid
s are padded to 1 byte. If given "1", and uid_length
is 0, the uid will be padded to "01" then converted.uid
- The UID to convertNullPointerException
- if the ID was nullIllegalArgumentException
- if the string is not valid hexpublic static UniqueId.UniqueIdType stringToUniqueIdType(String type)
type
- The string to convertIllegalArgumentException
- if the string did not match a typepublic static byte[] stringToUid(String uid, short uid_length)
uid
is less than uid_length * 2
characters wide, it
will be padded with 0s to conform to the spec. E.g. if the tagk width is 3
and the given uid
string is "1", the string will be padded to
"000001" and then converted to a byte array to reach 3 bytes.
All uid
s are padded to 1 byte. If given "1", and uid_length
is 0, the uid will be padded to "01" then converted.uid
- The UID to convertuid_length
- An optional length, in bytes, that the UID must conform
to. Set to 0 if not used.NullPointerException
- if the ID was nullIllegalArgumentException
- if the string is not valid hexpublic static byte[] getTSUIDFromKey(byte[] row_key, short metric_width, short timestamp_width)
row_key
- The row key to processmetric_width
- The width of the metrictimestamp_width
- The width of the timestampArrayIndexOutOfBoundsException
- if the row_key is invalidpublic static List<byte[]> getTagPairsFromTSUID(String tsuid, short metric_width, short tagk_width, short tagv_width)
tsuid
- The tsuid to parsemetric_width
- The width of the metric tag in bytestagk_width
- The width of tagks in bytestagv_width
- The width of tagvs in bytesIllegalArgumentException
- if the TSUID is malformedpublic static com.stumbleupon.async.Deferred<Map<String,Long>> getUsedUIDs(TSDB tsdb, byte[][] kinds)
tsdb
- The TSDB to which we belongkinds
- A list of qualifiers to fetch