titan如何存储顶点id(将顶点id转换为HBase键列)?

时间:2015-01-22 11:25:21

标签: hbase titan

我正在使用titan版本0.5.0和HBase。 我有一个区域由于有很多边缘的顶点而没有分裂,我想知道这个顶点的id是多少。 如何将HBase键列转换为titan vertex id?

我的HBase密钥列为\x00\x8C\x1D\xB3\xBDZ<\x10

1 个答案:

答案 0 :(得分:2)

用于将HBase键列转换为Titan顶点id的函数在getKey类(在titan-core)下为IDManager

以下是取出后的代码。 仅适用于NormalVertex

String hexKey = "008C1DB3BD5A3C10";
byte[] byteArr = BaseEncoding.base16().decode(hexKey);
StaticArrayBuffer buff = new StaticArrayBuffer(byteArr,0,hexKey.length());

// The code from titan with some simplifications
long partitionBits = 6;
long normalVertexOffset = 3l;
long TOTAL_BITS = Long.SIZE - 1;

long value = b.getLong(0);
long partitionOffset = Long.Size - partitionBits;
IDManager.VertexIDType type = IDManager.VertexIDType.NormalVertex;
long partition = partitionOffset < Long.SIZE ? value >>> partitionOffset : 0;
long USERVERTEX_PADDING_BITWIDTH = normalVertexOffset;
long count = ( value >>> USERVERTEX_PADDING_BITWIDTH & ((1l <<(partitionOffset - USERVERTEX_PADDING_BITWIDTH )) -1 );

long partitionIDBound = (1l << (partitionBits));
long id = (count << partitionBits) + partition;
if(type != null) id = type.addPadding(id);
System.out.println("Key is " + id);