下面列出了org.apache.hadoop.hbase.Cell#getQualifierLength ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public List<SpanProtos.Span> getSpans(long traceid) throws IOException {
startClient();
List<SpanProtos.Span> spans = new ArrayList<SpanProtos.Span>();
Get get = new Get(Bytes.toBytes(traceid));
get.addFamily(this.cf);
try {
for (Cell cell : htable.get(get).listCells()) {
InputStream in = new ByteArrayInputStream(cell.getQualifierArray(),
cell.getQualifierOffset(),
cell.getQualifierLength());
spans.add(SpanProtos.Span.parseFrom(in));
}
} catch (IOException e) {
LOG.warn("Failed to get spans from HBase. " + e.getMessage());
stopClient();
}
return spans;
}
public ValueGetter createGetterFromKeyValues(final byte[] rowKey, Collection<? extends Cell> pendingUpdates) {
final Map<ReferencingColumn, ImmutableBytesPtr> valueMap = Maps.newHashMapWithExpectedSize(pendingUpdates
.size());
for (Cell kv : pendingUpdates) {
// create new pointers to each part of the kv
ImmutableBytesPtr family = new ImmutableBytesPtr(kv.getRowArray(),kv.getFamilyOffset(),kv.getFamilyLength());
ImmutableBytesPtr qual = new ImmutableBytesPtr(kv.getRowArray(), kv.getQualifierOffset(), kv.getQualifierLength());
ImmutableBytesPtr value = new ImmutableBytesPtr(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength());
valueMap.put(new ReferencingColumn(family, qual), value);
}
return new ValueGetter() {
@Override
public ImmutableBytesPtr getLatestValue(ColumnReference ref) {
if(ref.equals(dataEmptyKeyValueRef)) return null;
return valueMap.get(ReferencingColumn.wrap(ref));
}
@Override
public byte[] getRowKey() {
return rowKey;
}
};
}
public Cell getKeyForNextColumn(Cell cell) {
// We aren't sure whether any DeleteFamily cells exist, so we can't skip to next column.
// TODO: Current way disable us to seek to next column quickly. Is there any better solution?
// see HBASE-18471 for more details
// see TestFromClientSide3#testScanAfterDeletingSpecifiedRow
// see TestFromClientSide3#testScanAfterDeletingSpecifiedRowV2
if (cell.getQualifierLength() == 0) {
Cell nextKey = PrivateCellUtil.createNextOnRowCol(cell);
if (nextKey != cell) {
return nextKey;
}
// The cell is at the end of row/family/qualifier, so it is impossible to find any DeleteFamily cells.
// Let us seek to next column.
}
ColumnCount nextColumn = columns.getColumnHint();
if (nextColumn == null) {
return PrivateCellUtil.createLastOnRowCol(cell);
} else {
return PrivateCellUtil.createFirstOnRowCol(cell, nextColumn.getBuffer(),
nextColumn.getOffset(), nextColumn.getLength());
}
}
public static void mutatePutValue(Put somePut, byte[] family, byte[] qualifier, byte[] newValue) {
NavigableMap<byte[], List<Cell>> familyCellMap = somePut.getFamilyCellMap();
List<Cell> cells = familyCellMap.get(family);
List<Cell> newCells = Lists.newArrayList();
if (cells != null) {
for (Cell cell : cells) {
if (Bytes.compareTo(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength(),
qualifier, 0, qualifier.length) == 0) {
Cell replacementCell = new KeyValue(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(),
cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength(), cell.getQualifierArray(),
cell.getQualifierOffset(), cell.getQualifierLength(), cell.getTimestamp(),
KeyValue.Type.codeToType(cell.getType().getCode()), newValue, 0, newValue.length);
newCells.add(replacementCell);
} else {
newCells.add(cell);
}
}
familyCellMap.put(family, newCells);
}
}
@Override
public List<TransactionId> mapRow(Result result, int rowNum) throws Exception {
if (result.isEmpty()) {
return Collections.emptyList();
}
Cell[] rawCells = result.rawCells();
List<TransactionId> traceIdList = new ArrayList<>(rawCells.length);
for (Cell cell : rawCells) {
final byte[] qualifierArray = cell.getQualifierArray();
final int qualifierOffset = cell.getQualifierOffset();
final int qualifierLength = cell.getQualifierLength();
// increment by value of key
TransactionId traceId = parseVarTransactionId(qualifierArray, qualifierOffset, qualifierLength);
traceIdList.add(traceId);
logger.debug("found traceId {}", traceId);
}
return traceIdList;
}
/**
* Returns whether a cell contains a qualifier that is a shadow cell
* column qualifier or not.
* @param cell the cell to check if contains the shadow cell qualifier
* @return whether the cell passed contains a shadow cell qualifier or not
*/
public static boolean isShadowCell(Cell cell) {
byte[] qualifier = cell.getQualifierArray();
int qualOffset = cell.getQualifierOffset();
int qualLength = cell.getQualifierLength();
return endsWith(qualifier, qualOffset, qualLength, SHADOW_CELL_SUFFIX);
}
static int getRoughSize(final Cell [] cells) {
int size = 0;
for (Cell c: cells) {
size += c.getRowLength() + c.getFamilyLength() + c.getQualifierLength() + c.getValueLength();
size += Bytes.SIZEOF_LONG + Bytes.SIZEOF_BYTE;
}
return size;
}
public RowColBloomHashKey(Cell cell) {
super(cell);
rowLength = cell.getRowLength();
// We don't consider the family length for ROWCOL bloom. So subtract the famLen from the
// length calculation. Timestamp and type are of no relevance here
qualLength = cell.getQualifierLength();
}
private int compareTypeBytes(Cell key, Cell right) {
if (key.getFamilyLength() + key.getQualifierLength() == 0
&& key.getTypeByte() == Type.Minimum.getCode()) {
// left is "bigger", i.e. it appears later in the sorted order
return 1;
}
if (right.getFamilyLength() + right.getQualifierLength() == 0
&& right.getTypeByte() == Type.Minimum.getCode()) {
return -1;
}
return 0;
}
private AcceptApplication createAcceptedApplication(Cell cell) {
Buffer reader = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
String host = reader.readPrefixedString();
String bindApplicationName = reader.readPrefixedString();
short bindServiceTypeCode = reader.readShort();
final Application bindApplication = applicationFactory.createApplication(bindApplicationName, bindServiceTypeCode);
return new AcceptApplication(host, bindApplication);
}
@Override
public List<JoinStatBo> mapRow(Result result, int rowNum) throws Exception {
if (result.isEmpty()) {
return Collections.emptyList();
}
final byte[] distributedRowKey = result.getRow();
final String applicationId = this.hbaseOperationFactory.getApplicationId(distributedRowKey);
final long baseTimestamp = this.hbaseOperationFactory.getBaseTimestamp(distributedRowKey);
List<JoinStatBo> dataPoints = new ArrayList<>();
for (Cell cell : result.rawCells()) {
if (CellUtil.matchingFamily(cell, HbaseColumnFamily.APPLICATION_STAT_STATISTICS.getName())) {
Buffer qualifierBuffer = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
Buffer valueBuffer = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
long timestampDelta = this.decoder.decodeQualifier(qualifierBuffer);
ApplicationStatDecodingContext decodingContext = new ApplicationStatDecodingContext();
decodingContext.setApplicationId(applicationId);
decodingContext.setBaseTimestamp(baseTimestamp);
decodingContext.setTimestampDelta(timestampDelta);
List<JoinStatBo> candidates = this.decoder.decodeValue(valueBuffer, decodingContext);
for (JoinStatBo candidate : candidates) {
long timestamp = candidate.getTimestamp();
if (this.filter.filter(timestamp)) {
continue;
}
dataPoints.add(candidate);
}
}
}
// Reverse sort as timestamp is stored in a reversed order.
dataPoints.sort(REVERSE_TIMESTAMP_COMPARATOR);
return dataPoints;
}
@Override
public List<T> mapRow(Result result, int rowNum) throws Exception {
if (result.isEmpty()) {
return Collections.emptyList();
}
final byte[] distributedRowKey = result.getRow();
final String agentId = this.hbaseOperationFactory.getAgentId(distributedRowKey);
final long baseTimestamp = this.hbaseOperationFactory.getBaseTimestamp(distributedRowKey);
List<T> dataPoints = new ArrayList<>();
for (Cell cell : result.rawCells()) {
if (CellUtil.matchingFamily(cell, HbaseColumnFamily.AGENT_STAT_STATISTICS.getName())) {
Buffer qualifierBuffer = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
Buffer valueBuffer = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
long timestampDelta = this.decoder.decodeQualifier(qualifierBuffer);
AgentStatDecodingContext decodingContext = new AgentStatDecodingContext();
decodingContext.setAgentId(agentId);
decodingContext.setBaseTimestamp(baseTimestamp);
decodingContext.setTimestampDelta(timestampDelta);
List<T> candidates = this.decoder.decodeValue(valueBuffer, decodingContext);
for (T candidate : candidates) {
if (filter(candidate)) {
continue;
}
dataPoints.add(candidate);
}
}
}
// Reverse sort as timestamp is stored in a reversed order.
dataPoints.sort(REVERSE_TIMESTAMP_COMPARATOR);
return dataPoints;
}
private Cell getChangedKey(Cell next, boolean changeBottomKeys) {
// If it is a top store file change the StartKey with SplitKey in Key
//and produce the new value corresponding to the change in key
byte[] changedKey = getNewRowkeyByRegionStartKeyReplacedWithSplitKey(next, changeBottomKeys);
KeyValue changedKv =
new KeyValue(changedKey, 0, changedKey.length, next.getFamilyArray(),
next.getFamilyOffset(), next.getFamilyLength(), next.getQualifierArray(),
next.getQualifierOffset(), next.getQualifierLength(),
next.getTimestamp(), Type.codeToType(next.getTypeByte()),
next.getValueArray(), next.getValueOffset(), next.getValueLength(),
next.getTagsArray(), next.getTagsOffset(), next.getTagsLength());
return changedKv;
}
/**
* @return Sum of all elements that make up a key; does not include infrastructure, tags or
* values.
*/
private static int getSumOfCellKeyElementLengths(final Cell cell) {
return cell.getRowLength() + cell.getFamilyLength() + cell.getQualifierLength()
+ KeyValue.TIMESTAMP_TYPE_SIZE;
}
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof CellId))
return false;
CellId otherCellId = (CellId) o;
Cell otherCell = otherCellId.getCell();
// Row comparison
if (!CellUtil.matchingRow(otherCell, cell)) {
return false;
}
// Family comparison
if (!CellUtil.matchingFamily(otherCell, cell)) {
return false;
}
// Qualifier comparison
int qualifierLength = cell.getQualifierLength();
int qualifierOffset = cell.getQualifierOffset();
int otherQualifierLength = otherCell.getQualifierLength();
int otherQualifierOffset = otherCell.getQualifierOffset();
if (isShadowCell()) {
qualifierLength = qualifierLengthFromShadowCellQualifier(cell.getQualifierArray(),
cell.getQualifierOffset(),
cell.getQualifierLength());
qualifierOffset = qualifierOffsetFromShadowCellQualifier(cell.getQualifierArray(), cell.getQualifierOffset(),
cell.getQualifierLength());
}
if (otherCellId.isShadowCell()) {
otherQualifierLength = qualifierLengthFromShadowCellQualifier(otherCell.getQualifierArray(),
otherCell.getQualifierOffset(),
otherCell.getQualifierLength());
otherQualifierOffset = qualifierOffsetFromShadowCellQualifier(otherCell.getQualifierArray(), otherCell.getQualifierOffset(),
otherCell.getQualifierLength());
}
if (!Bytes.equals(cell.getQualifierArray(), qualifierOffset, qualifierLength,
otherCell.getQualifierArray(), otherQualifierOffset, otherQualifierLength)) {
return false;
}
// Timestamp comparison
return otherCell.getTimestamp() == cell.getTimestamp();
}
protected Cell mergeList(final List<Cell> cells) {
synchronized (MUTEX) {
Mergeable currentMergeable = null;
final Cell firstCell = cells.get(0);
for (final Cell cell : cells) {
final Mergeable mergeable =
getMergeable(
cell,
// TODO consider avoiding extra byte array
// allocations (which would require
// persistence utils to be able to use
// bytebuffer instead of byte[])
CellUtil.cloneValue(cell));
if (mergeable != null) {
if (currentMergeable == null) {
currentMergeable = mergeable;
} else {
currentMergeable.merge(mergeable);
}
}
}
final byte[] valueBinary = getBinary(currentMergeable);
// this is basically a lengthy verbose form of cloning
// in-place (without allocating new byte arrays) and
// simply replacing the value with the new mergeable
// value
return new KeyValue(
firstCell.getRowArray(),
firstCell.getRowOffset(),
firstCell.getRowLength(),
firstCell.getFamilyArray(),
firstCell.getFamilyOffset(),
firstCell.getFamilyLength(),
firstCell.getQualifierArray(),
firstCell.getQualifierOffset(),
firstCell.getQualifierLength(),
firstCell.getTimestamp(),
Type.codeToType(firstCell.getTypeByte()),
valueBinary,
0,
valueBinary.length,
firstCell.getTagsArray(),
firstCell.getTagsOffset(),
firstCell.getTagsLength());
}
}
public static boolean matchingQualifier(Cell keyValue, byte[] qualifier) {
return !(qualifier == null || keyValue == null || qualifier.length != keyValue.getQualifierLength()) &&
ArrayUtil.equals(CellUtils.getBuffer(keyValue), keyValue.getQualifierOffset(), qualifier, 0, keyValue.getQualifierLength());
}
public static boolean matchingQualifierKeyValue(Cell keyValue, Cell other) {
return !(keyValue == null || other == null || keyValue.getQualifierLength() != other.getQualifierLength()) &&
ArrayUtil.equals(CellUtils.getBuffer(keyValue), keyValue.getQualifierOffset(),
CellUtils.getBuffer(other), other.getQualifierOffset(), other.getQualifierLength());
}
private void writeKeyExcludingCommon(Cell cell, int commonPrefix, DataOutputStream out)
throws IOException {
short rLen = cell.getRowLength();
if (commonPrefix < rLen + KeyValue.ROW_LENGTH_SIZE) {
// Previous and current rows are different. Need to write the differing part followed by
// cf,q,ts and type
PrivateCellUtil.writeRowKeyExcludingCommon(cell, rLen, commonPrefix, out);
byte fLen = cell.getFamilyLength();
out.writeByte(fLen);
PrivateCellUtil.writeFamily(out, cell, fLen);
PrivateCellUtil.writeQualifier(out, cell, cell.getQualifierLength());
out.writeLong(cell.getTimestamp());
out.writeByte(cell.getTypeByte());
} else {
// The full row key part is common. CF part will be common for sure as we deal with Cells in
// same family. Just need write the differing part in q, ts and type
commonPrefix = commonPrefix - (rLen + KeyValue.ROW_LENGTH_SIZE)
- (cell.getFamilyLength() + KeyValue.FAMILY_LENGTH_SIZE);
int qLen = cell.getQualifierLength();
int commonQualPrefix = Math.min(commonPrefix, qLen);
int qualPartLenToWrite = qLen - commonQualPrefix;
if (qualPartLenToWrite > 0) {
PrivateCellUtil.writeQualifierSkippingBytes(out, cell, qLen, commonQualPrefix);
}
commonPrefix -= commonQualPrefix;
// Common part in TS also?
if (commonPrefix > 0) {
int commonTimestampPrefix = Math.min(commonPrefix, KeyValue.TIMESTAMP_SIZE);
if (commonTimestampPrefix < KeyValue.TIMESTAMP_SIZE) {
byte[] curTsBuf = Bytes.toBytes(cell.getTimestamp());
out.write(curTsBuf, commonTimestampPrefix, KeyValue.TIMESTAMP_SIZE
- commonTimestampPrefix);
}
commonPrefix -= commonTimestampPrefix;
if (commonPrefix == 0) {
out.writeByte(cell.getTypeByte());
}
} else {
out.writeLong(cell.getTimestamp());
out.writeByte(cell.getTypeByte());
}
}
}
@Override
public LinkDataMap mapRow(Result result, int rowNum) throws Exception {
if (result.isEmpty()) {
return new LinkDataMap();
}
logger.debug("mapRow:{}", rowNum);
final byte[] rowKey = getOriginalKey(result.getRow());
final Buffer row = new FixedBuffer(rowKey);
final Application caller = readCallerApplication(row);
final long timestamp = TimeUtils.recoveryTimeMillis(row.readLong());
// key is destApplicationName.
final LinkDataMap linkDataMap = new LinkDataMap();
for (Cell cell : result.rawCells()) {
final Buffer buffer = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
final Application callee = readCalleeApplication(buffer);
if (filter.filter(callee)) {
continue;
}
String calleeHost = buffer.readPrefixedString();
short histogramSlot = buffer.readShort();
boolean isError = histogramSlot == (short) -1;
String callerAgentId = buffer.readPrefixedString();
long requestCount = getValueToLong(cell);
if (logger.isDebugEnabled()) {
logger.debug(" Fetched Caller.(New) {} {} -> {} (slot:{}/{}) calleeHost:{}", caller, callerAgentId, callee, histogramSlot, requestCount, calleeHost);
}
final short slotTime = (isError) ? (short) -1 : histogramSlot;
if (StringUtils.isEmpty(calleeHost)) {
calleeHost = callee.getName();
}
linkDataMap.addLinkData(caller, callerAgentId, callee, calleeHost, timestamp, slotTime, requestCount);
}
return linkDataMap;
}