@Override public long getSequenceId() { return this.cell.getSequenceId(); }
@Override public long getSequenceId() { return cell.getSequenceId(); }
/** * Look at the next Cell in this scanner, but do not iterate the scanner * @return the currently observed Cell */ @Override public Cell peek() { // sanity check, the current should be always valid if (closed) { return null; } if (current!=null && current.getSequenceId() > readPoint) { throw new RuntimeException("current is invalid: read point is "+readPoint+", " + "while current sequence id is " +current.getSequenceId()); } return current; }
CellWrapper(Cell cell) { assert !(cell instanceof ExtendedCell); this.cell = cell; this.sequenceId = cell.getSequenceId(); this.timestamp = cell.getTimestamp(); }
public void addVersionDelete(Cell cell) { SortedSet<Long> set = deletesMap.get(cell.getTimestamp()); if (set == null) { set = new TreeSet<>(); deletesMap.put(cell.getTimestamp(), set); } set.add(cell.getSequenceId()); // The init set should be the puts whose mvcc is smaller than this Delete. Because // there may be some Puts masked by them. The Puts whose mvcc is larger than this Delete can // not be copied to this node because we may delete one version and the oldest put may not be // masked. SortedSet<Long> nextValue = mvccCountingMap.ceilingEntry(cell.getSequenceId()).getValue(); SortedSet<Long> thisValue = new TreeSet<>(nextValue.headSet(cell.getSequenceId())); mvccCountingMap.put(cell.getSequenceId(), thisValue); }
@Override public void addVersionDelete(Cell cell) { SortedMap<Long, TagInfo> set = deletesMap.get(cell.getTimestamp()); if (set == null) { set = new TreeMap<>(); deletesMap.put(cell.getTimestamp(), set); } set.put(cell.getSequenceId(), new TagInfo(cell)); // The init set should be the puts whose mvcc is smaller than this Delete. Because // there may be some Puts masked by them. The Puts whose mvcc is larger than this Delete can // not be copied to this node because we may delete one version and the oldest put may not be // masked. SortedSet<Long> nextValue = mvccCountingMap.ceilingEntry(cell.getSequenceId()).getValue(); SortedSet<Long> thisValue = new TreeSet<>(nextValue.headSet(cell.getSequenceId())); mvccCountingMap.put(cell.getSequenceId(), thisValue); }
@Override public int compare(final Cell a, final Cell b, boolean ignoreSequenceid) { int diff = compareRows(a, b); if (diff != 0) { return diff; } diff = compareWithoutRow(a, b); if (diff != 0) { return diff; } // Negate following comparisons so later edits show up first mvccVersion: later sorts first return ignoreSequenceid? diff: Longs.compare(b.getSequenceId(), a.getSequenceId()); }
@Override public int compare(final Cell a, final Cell b, boolean ignoreSequenceid) { int diff = 0; // "Peel off" the most common path. if (a instanceof ByteBufferKeyValue && b instanceof ByteBufferKeyValue) { diff = BBKVComparator.compare((ByteBufferKeyValue)a, (ByteBufferKeyValue)b, ignoreSequenceid); if (diff != 0) { return diff; } } else { diff = compareRows(a, b); if (diff != 0) { return diff; } diff = compareWithoutRow(a, b); if (diff != 0) { return diff; } } // Negate following comparisons so later edits show up first mvccVersion: later sorts first return ignoreSequenceid? diff: Long.compare(b.getSequenceId(), a.getSequenceId()); }
@Override public void add(Cell cell) { prepare(cell); byte type = cell.getTypeByte(); switch (Type.codeToType(type)) { // By the order of seen. We put null cq at first. case DeleteFamily: // Delete all versions of all columns of the specified family delFamMap.put(cell.getSequenceId(), new DeleteVersionsNode(cell.getTimestamp(), cell.getSequenceId())); break; case DeleteFamilyVersion: // Delete all columns of the specified family and specified version delFamMap.ceilingEntry(cell.getSequenceId()).getValue().addVersionDelete(cell); break; // These two kinds of markers are mix with Puts. case DeleteColumn: // Delete all versions of the specified column delColMap.put(cell.getSequenceId(), new DeleteVersionsNode(cell.getTimestamp(), cell.getSequenceId())); break; case Delete: // Delete the specified version of the specified column. delColMap.ceilingEntry(cell.getSequenceId()).getValue().addVersionDelete(cell); break; default: throw new AssertionError("Unknown delete marker type for " + cell); } }
/**************** copy the cell to create a new keyvalue *********************/ public static KeyValue copyToNewKeyValue(final Cell cell) { byte[] bytes = copyToNewByteArray(cell); KeyValue kvCell = new KeyValue(bytes, 0, bytes.length); kvCell.setSequenceId(cell.getSequenceId()); return kvCell; }
@Override public void add(Cell cell) { prepare(cell); byte type = cell.getTypeByte(); switch (KeyValue.Type.codeToType(type)) { // By the order of seen. We put null cq at first. case DeleteFamily: // Delete all versions of all columns of the specified family delFamMap.put(cell.getSequenceId(), new VisibilityDeleteVersionsNode(cell.getTimestamp(), cell.getSequenceId(), new TagInfo(cell))); break; case DeleteFamilyVersion: // Delete all columns of the specified family and specified version delFamMap.ceilingEntry(cell.getSequenceId()).getValue().addVersionDelete(cell); break; // These two kinds of markers are mix with Puts. case DeleteColumn: // Delete all versions of the specified column delColMap.put(cell.getSequenceId(), new VisibilityDeleteVersionsNode(cell.getTimestamp(), cell.getSequenceId(), new TagInfo(cell))); break; case Delete: // Delete the specified version of the specified column. delColMap.ceilingEntry(cell.getSequenceId()).getValue().addVersionDelete(cell); break; default: throw new AssertionError("Unknown delete marker type for " + cell); } }
/** * Copies the key to a new KeyValue * @param cell * @return the KeyValue that consists only the key part of the incoming cell */ public static KeyValue toNewKeyCell(final Cell cell) { byte[] bytes = new byte[keyLength(cell)]; appendKeyTo(cell, bytes, 0); KeyValue kv = new KeyValue.KeyOnlyKeyValue(bytes, 0, bytes.length); // Set the seq id. The new key cell could be used in comparisons so it // is important that it uses the seqid also. If not the comparsion would fail kv.setSequenceId(cell.getSequenceId()); return kv; }
/** * Clone the passed cell by copying its data into the passed buf and create a cell with a chunkid * out of it * @see #copyBBECToChunkCell(ByteBufferExtendedCell, ByteBuffer, int, int) */ private static Cell copyToChunkCell(Cell cell, ByteBuffer buf, int offset, int len) { int tagsLen = cell.getTagsLength(); if (cell instanceof ExtendedCell) { ((ExtendedCell) cell).write(buf, offset); } else { // Normally all Cell impls within Server will be of type ExtendedCell. Just considering the // other case also. The data fragments within Cell is copied into buf as in KeyValue // serialization format only. KeyValueUtil.appendTo(cell, buf, offset, true); } return createChunkCell(buf, offset, len, tagsLen, cell.getSequenceId()); }
public int write(Cell cell) throws IOException { // We write tags seperately because though there is no tag in KV // if the hfilecontext says include tags we need the tags length to be // written int size = KeyValueUtil.oswrite(cell, out, false); // Write the additional tag into the stream if (encodingCtx.getHFileContext().isIncludesTags()) { int tagsLength = cell.getTagsLength(); out.writeShort(tagsLength); if (tagsLength > 0) { PrivateCellUtil.writeTags(out, cell, tagsLength); } size += tagsLength + KeyValue.TAGS_LENGTH_SIZE; } if (encodingCtx.getHFileContext().isIncludesMvcc()) { WritableUtils.writeVLong(out, cell.getSequenceId()); size += WritableUtils.getVIntSize(cell.getSequenceId()); } return size; }
/** * @param cell * @return The Key portion of the passed <code>cell</code> as a String. */ public static String getCellKeyAsString(Cell cell) { StringBuilder sb = new StringBuilder(Bytes.toStringBinary( cell.getRowArray(), cell.getRowOffset(), cell.getRowLength())); sb.append('/'); sb.append(cell.getFamilyLength() == 0? "": Bytes.toStringBinary(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength())); // KeyValue only added ':' if family is non-null. Do same. if (cell.getFamilyLength() > 0) sb.append(':'); sb.append(cell.getQualifierLength() == 0? "": Bytes.toStringBinary(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength())); sb.append('/'); sb.append(KeyValue.humanReadableTimestamp(cell.getTimestamp())); sb.append('/'); sb.append(Type.codeToType(cell.getTypeByte())); if (!(cell instanceof KeyValue.KeyOnlyKeyValue)) { sb.append("/vlen="); sb.append(cell.getValueLength()); } sb.append("/seqid="); sb.append(cell.getSequenceId()); return sb.toString(); }
protected boolean skipKVsNewerThanReadpoint() throws IOException { // We want to ignore all key-values that are newer than our current // readPoint Cell startKV = cur; while(enforceMVCC && cur != null && (cur.getSequenceId() > readPt)) { boolean hasNext = hfs.next(); setCurrentCell(hfs.getCell()); if (hasNext && this.stopSkippingKVsIfNextRow && getComparator().compareRows(cur, startKV) > 0) { return false; } } if (cur == null) { return false; } return true; }
@Override public void write(Cell cell) throws IOException { checkFlushed(); // Row write(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()); // Column family write(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()); // Qualifier write(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()); // Version this.out.write(Bytes.toBytes(cell.getTimestamp())); // Type this.out.write(cell.getTypeByte()); // Value write(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); // MvccVersion this.out.write(Bytes.toBytes(cell.getSequenceId())); }
@Override public void write(Cell cell) throws IOException { checkFlushed(); // Row write(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()); // Column family write(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()); // Qualifier write(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()); // Version this.out.write(Bytes.toBytes(cell.getTimestamp())); // Type this.out.write(cell.getTypeByte()); // Value write(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); // Tags write(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength()); // MvccVersion this.out.write(Bytes.toBytes(cell.getSequenceId())); }
@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); } }
public KeyValue(Cell c) { this(c.getRowArray(), c.getRowOffset(), c.getRowLength(), c.getFamilyArray(), c.getFamilyOffset(), c.getFamilyLength(), c.getQualifierArray(), c.getQualifierOffset(), c.getQualifierLength(), c.getTimestamp(), Type.codeToType(c.getTypeByte()), c.getValueArray(), c.getValueOffset(), c.getValueLength(), c.getTagsArray(), c.getTagsOffset(), c.getTagsLength()); this.seqId = c.getSequenceId(); }