@Override public ByteBuffer getValue(Cell element) { return org.apache.cassandra.utils.ByteBufferUtil.clone(element.value()); }
@Override public ByteBuffer getColumn(Cell element) { return org.apache.cassandra.utils.ByteBufferUtil.clone(element.name().toByteBuffer()); }
@Override public Object getMetaData(Cell element, EntryMetaData meta) { switch (meta) { case TIMESTAMP: return element.timestamp(); case TTL: return ((element instanceof ExpiringCell) ? ((ExpiringCell) element).getTimeToLive() : 0); default: throw new UnsupportedOperationException("Unsupported meta data: " + meta); } } }
static boolean shouldCleanupOldValue(Cell oldCell, Cell newCell) { // If any one of name/value/timestamp are different, then we // should delete from the index. If not, then we can infer that // at least one of the cells is an ExpiringColumn and that the // difference is in the expiry time. In this case, we don't want to // delete the old value from the index as the tombstone we insert // will just hide the inserted value. // Completely identical cells (including expiring columns with // identical ttl & localExpirationTime) will not get this far due // to the oldCell.equals(newColumn) in StandardUpdater.update return !oldCell.name().equals(newCell.name()) || !oldCell.value().equals(newCell.value()) || oldCell.timestamp() != newCell.timestamp(); }
public List<ColumnOrSuperColumn> thriftifyColumns(Collection<Cell> cells, boolean reverseOrder, long now) { ArrayList<ColumnOrSuperColumn> thriftColumns = new ArrayList<ColumnOrSuperColumn>(cells.size()); for (Cell cell : cells) { if (!cell.isLive(now)) continue; thriftColumns.add(thriftifyColumnWithName(cell, cell.name().toByteBuffer())); } // we have to do the reversing here, since internally we pass results around in ColumnFamily // objects, which always sort their cells in the "natural" order // TODO this is inconvenient for direct users of StorageProxy if (reverseOrder) Collections.reverse(thriftColumns); return thriftColumns; }
public boolean equals(Cell cell) { return timestamp() == cell.timestamp() && name().equals(cell.name()) && value().equals(cell.value()) && serializationFlags() == cell.serializationFlags(); }
@Override public Cell reconcile(Cell cell) { long ts1 = timestamp(), ts2 = cell.timestamp(); if (ts1 != ts2) return ts1 < ts2 ? cell : this; // we should prefer tombstones if (cell instanceof DeletedCell) return cell; int c = value().compareTo(cell.value()); if (c != 0) return c < 0 ? cell : this; // If we have same timestamp and value, prefer the longest ttl if (cell instanceof ExpiringCell) { int let1 = localExpirationTime, let2 = cell.getLocalDeletionTime(); if (let1 < let2) return cell; } return this; }
public Cell diffCounter(Cell cell) { assert this instanceof CounterCell : "Wrong class type: " + getClass(); if (timestamp() < cell.timestamp()) return cell; // Note that if at that point, cell can't be a tombstone. Indeed, // cell is the result of merging us with other nodes results, and // merging a CounterCell with a tombstone never return a tombstone // unless that tombstone timestamp is greater that the CounterCell // one. assert cell instanceof CounterCell : "Wrong class type: " + cell.getClass(); if (((CounterCell) this).timestampOfLastDelete() < ((CounterCell) cell).timestampOfLastDelete()) return cell; CounterContext.Relationship rel = CounterCell.contextManager.diff(cell.value(), value()); return (rel == CounterContext.Relationship.GREATER_THAN || rel == CounterContext.Relationship.DISJOINT) ? cell : null; }
public Cell apply(Cell existing, Cell update) { Cell reconciled = existing.reconcile(update); indexer.update(existing, reconciled); if (existing != reconciled) { reconciled = reconciled.localCopy(metadata, allocator, writeOp); dataSize += reconciled.cellDataSize() - existing.cellDataSize(); heapSize += reconciled.unsharedHeapSizeExcludingData() - existing.unsharedHeapSizeExcludingData(); if (inserted == null) inserted = new ArrayList<>(); inserted.add(reconciled); discard(existing); //Getting the minimum delta for an update containing multiple columns colUpdateTimeDelta = Math.min(Math.abs(existing.timestamp() - update.timestamp()), colUpdateTimeDelta); } return reconciled; }
@Override public boolean apply(Cell input) { if (!input.isLive(tsMillis)) return false; // Don't do this. getTimeToLive() is a duration divorced from any particular clock. // For instance, if TTL=10 seconds, getTimeToLive() will have value 10 (not 10 + epoch seconds), and // this will always return false. //if (input instanceof ExpiringCell) // return tsSeconds < ((ExpiringCell)input).getTimeToLive(); return true; } }
public void deleteForCleanup(ByteBuffer rowKey, Cell cell, OpOrder.Group opGroup) { if (!cell.isLive()) return; DecoratedKey valueKey = getIndexKeyFor(getIndexedValue(rowKey, cell)); int localDeletionTime = (int) (System.currentTimeMillis() / 1000); ColumnFamily cfi = ArrayBackedSortedColumns.factory.create(indexCfs.metadata, false, 1); cfi.addTombstone(makeIndexColumnName(rowKey, cell), localDeletionTime, cell.timestamp()); indexCfs.apply(valueKey, cfi, SecondaryIndexManager.nullUpdater, opGroup, null); if (logger.isDebugEnabled()) logger.debug("removed index entry for cleaned-up value {}:{}", valueKey, cfi); }
protected void addColumn(Cell cell) throws IOException { if (columnFamily.metadata().isSuper()) { if (currentSuperColumn == null) throw new IllegalStateException("Trying to add a cell to a super column family, but no super cell has been started."); cell = cell.withUpdatedName(columnFamily.getComparator().makeCellName(currentSuperColumn, cell.name().toByteBuffer())); } columnFamily.addColumn(cell); }
public void add(Cell c) { current.add(isDead(c) ? null : value(c)); if (timestamps != null) { timestamps[current.size() - 1] = isDead(c) ? Long.MIN_VALUE : c.timestamp(); } if (ttls != null) { int ttl = -1; if (!isDead(c) && c instanceof ExpiringCell) ttl = c.getLocalDeletionTime() - (int) (now / 1000); ttls[current.size() - 1] = ttl; } }
public Cell apply(Cell insert) { indexer.insert(insert); insert = insert.localCopy(metadata, allocator, writeOp); this.dataSize += insert.cellDataSize(); this.heapSize += insert.unsharedHeapSizeExcludingData(); if (inserted == null) inserted = new ArrayList<>(); inserted.add(insert); return insert; }
public long dataSize() { long size = 0; for (Cell cell : this) size += cell.cellDataSize(); return size; }