下面列出了org.apache.hadoop.hbase.Cell#getSequenceId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Reset the map if it is different with the last Cell.
* Save the cq array/offset/length for next Cell.
*
* @return If this put has duplicate ts with last cell, return the mvcc of last cell.
* Else return MAX_VALUE.
*/
protected long prepare(Cell cell) {
boolean matchCq =
PrivateCellUtil.matchingQualifier(cell, lastCqArray, lastCqOffset, lastCqLength);
if (!matchCq) {
// The last cell is family-level delete and this is not, or the cq is changed,
// we should construct delColMap as a deep copy of delFamMap.
delColMap.clear();
for (Map.Entry<Long, DeleteVersionsNode> e : delFamMap.entrySet()) {
delColMap.put(e.getKey(), e.getValue().getDeepCopy());
}
countCurrentCol = 0;
}
if (matchCq && !PrivateCellUtil.isDelete(lastCqType) && lastCqType == cell.getTypeByte()
&& lastCqTs == cell.getTimestamp()) {
// Put with duplicate timestamp, ignore.
return lastCqMvcc;
}
lastCqArray = cell.getQualifierArray();
lastCqOffset = cell.getQualifierOffset();
lastCqLength = cell.getQualifierLength();
lastCqTs = cell.getTimestamp();
lastCqMvcc = cell.getSequenceId();
lastCqType = cell.getTypeByte();
return Long.MAX_VALUE;
}
@Override
public MatchCode match(Cell cell) throws IOException {
MatchCode returnCode = preCheck(cell);
if (returnCode != null) {
return returnCode;
}
long mvccVersion = cell.getSequenceId();
byte typeByte = cell.getTypeByte();
if (PrivateCellUtil.isDelete(typeByte)) {
if (mvccVersion > maxReadPointToTrackVersions) {
// we should not use this delete marker to mask any cell yet.
return MatchCode.INCLUDE;
}
trackDelete(cell);
return MatchCode.INCLUDE;
}
returnCode = checkDeleted(deletes, cell);
if (returnCode != null) {
return returnCode;
}
// Skip checking column since we do not remove column during compaction.
return columns.checkVersions(cell, cell.getTimestamp(), typeByte,
mvccVersion > maxReadPointToTrackVersions);
}
@Override
public MatchCode match(Cell cell) throws IOException {
MatchCode returnCode = preCheck(cell);
if (returnCode != null) {
return returnCode;
}
long mvccVersion = cell.getSequenceId();
byte typeByte = cell.getTypeByte();
if (PrivateCellUtil.isDelete(typeByte)) {
if (mvccVersion > maxReadPointToTrackVersions) {
return MatchCode.INCLUDE;
}
trackDelete(cell);
if (dropDeletesInOutput == DropDeletesInOutput.IN) {
// here we are running like major compaction
trackDelete(cell);
returnCode = tryDropDelete(cell);
if (returnCode != null) {
return returnCode;
}
} else {
return MatchCode.INCLUDE;
}
} else {
returnCode = checkDeleted(deletes, cell);
if (returnCode != null) {
return returnCode;
}
}
// Skip checking column since we do not remove column during compaction.
return columns.checkVersions(cell, cell.getTimestamp(), typeByte,
mvccVersion > maxReadPointToTrackVersions);
}
/**
* Private internal method for iterating over the segment,
* skipping the cells with irrelevant MVCC
*/
protected void updateCurrent() {
Cell next = null;
try {
while (iter.hasNext()) {
next = iter.next();
if (next.getSequenceId() <= this.readPoint) {
current = next;
return;// skip irrelevant versions
}
// for backwardSeek() stay in the boundaries of a single row
if (stopSkippingKVsIfNextRow &&
segment.compareRows(next, stopSkippingKVsRow) > 0) {
current = null;
return;
}
} // end of while
current = null; // nothing found
} finally {
if (next != null) {
// in all cases, remember the last KV we iterated to, needed for reseek()
last = next;
}
}
}
/**
* @return unencoded size added
*/
protected final int afterEncodingKeyValue(Cell cell, DataOutputStream out,
HFileBlockDefaultEncodingContext encodingCtx) throws IOException {
int size = 0;
if (encodingCtx.getHFileContext().isIncludesTags()) {
int tagsLength = cell.getTagsLength();
ByteBufferUtils.putCompressedInt(out, tagsLength);
// There are some tags to be written
if (tagsLength > 0) {
TagCompressionContext tagCompressionContext = encodingCtx.getTagCompressionContext();
// When tag compression is enabled, tagCompressionContext will have a not null value. Write
// the tags using Dictionary compression in such a case
if (tagCompressionContext != null) {
// Not passing tagsLength considering that parsing of the tagsLength is not costly
PrivateCellUtil.compressTags(out, cell, tagCompressionContext);
} else {
PrivateCellUtil.writeTags(out, cell, tagsLength);
}
}
size += tagsLength + KeyValue.TAGS_LENGTH_SIZE;
}
if (encodingCtx.getHFileContext().isIncludesMvcc()) {
// Copy memstore timestamp from the byte buffer to the output stream.
long memstoreTS = cell.getSequenceId();
WritableUtils.writeVLong(out, memstoreTS);
// TODO use a writeVLong which returns the #bytes written so that 2 time parsing can be
// avoided.
size += WritableUtils.getVIntSize(memstoreTS);
}
return size;
}
public void upsert(Cell cell, long readpoint, MemStoreSizing memStoreSizing,
boolean sizeAddedPreOperation) {
internalAdd(cell, false, memStoreSizing, sizeAddedPreOperation);
// Get the Cells for the row/family/qualifier regardless of timestamp.
// For this case we want to clean up any other puts
Cell firstCell = PrivateCellUtil.createFirstOnRowColTS(cell, HConstants.LATEST_TIMESTAMP);
SortedSet<Cell> ss = this.tailSet(firstCell);
Iterator<Cell> it = ss.iterator();
// versions visible to oldest scanner
int versionsVisible = 0;
while (it.hasNext()) {
Cell cur = it.next();
if (cell == cur) {
// ignore the one just put in
continue;
}
// check that this is the row and column we are interested in, otherwise bail
if (CellUtil.matchingRows(cell, cur) && CellUtil.matchingQualifier(cell, cur)) {
// only remove Puts that concurrent scanners cannot possibly see
if (cur.getTypeByte() == KeyValue.Type.Put.getCode() && cur.getSequenceId() <= readpoint) {
if (versionsVisible >= 1) {
// if we get here we have seen at least one version visible to the oldest scanner,
// which means we can prove that no scanner will see this version
// false means there was a change, so give us the size.
// TODO when the removed cell ie.'cur' having its data in MSLAB, we can not release that
// area. Only the Cell object as such going way. We need to consider cellLen to be
// decreased there as 0 only. Just keeping it as existing code now. We need to know the
// removed cell is from MSLAB or not. Will do once HBASE-16438 is in
int cellLen = getCellLength(cur);
long heapSize = heapSizeChange(cur, true);
long offHeapSize = offHeapSizeChange(cur, true);
incMemStoreSize(-cellLen, -heapSize, -offHeapSize, -1);
if (memStoreSizing != null) {
memStoreSizing.decMemStoreSize(cellLen, heapSize, offHeapSize, 1);
}
it.remove();
} else {
versionsVisible++;
}
}
} else {
// past the row or column, done
break;
}
}
}
@Override
public MatchCode match(Cell cell) throws IOException {
MatchCode returnCode = preCheck(cell);
if (returnCode != null) {
return returnCode;
}
long timestamp = cell.getTimestamp();
long mvccVersion = cell.getSequenceId();
byte typeByte = cell.getTypeByte();
// The delete logic is pretty complicated now.
// This is corroborated by the following:
// 1. The store might be instructed to keep deleted rows around.
// 2. A scan can optionally see past a delete marker now.
// 3. If deleted rows are kept, we have to find out when we can
// remove the delete markers.
// 4. Family delete markers are always first (regardless of their TS)
// 5. Delete markers should not be counted as version
// 6. Delete markers affect puts of the *same* TS
// 7. Delete marker need to be version counted together with puts
// they affect
//
if (PrivateCellUtil.isDelete(typeByte)) {
if (mvccVersion > maxReadPointToTrackVersions) {
// We can not drop this delete marker yet, and also we should not use this delete marker to
// mask any cell yet.
return MatchCode.INCLUDE;
}
trackDelete(cell);
returnCode = tryDropDelete(cell);
if (returnCode != null) {
return returnCode;
}
} else {
returnCode = checkDeleted(deletes, cell);
if (returnCode != null) {
return returnCode;
}
}
// Skip checking column since we do not remove column during compaction.
return columns.checkVersions(cell, timestamp, typeByte,
mvccVersion > maxReadPointToTrackVersions);
}