public void deleteRange(String cfName, Composite start, Composite end, long timestamp) { int localDeleteTime = (int) (System.currentTimeMillis() / 1000); addOrGet(cfName).addAtom(new RangeTombstone(start, end, timestamp, localDeleteTime)); }
private void parseMeta(Map<?, ?> map, ColumnFamily cf, ByteBuffer superColumnName) { // deletionInfo is the only metadata we store for now if (map.containsKey("deletionInfo")) { Map<?, ?> unparsedDeletionInfo = (Map<?, ?>) map.get("deletionInfo"); Number number = (Number) unparsedDeletionInfo.get("markedForDeleteAt"); long markedForDeleteAt = number instanceof Long ? (Long) number : number.longValue(); int localDeletionTime = (Integer) unparsedDeletionInfo.get("localDeletionTime"); if (superColumnName == null) cf.setDeletionInfo(new DeletionInfo(markedForDeleteAt, localDeletionTime)); else cf.addAtom(new RangeTombstone(SuperColumns.startOf(superColumnName), SuperColumns.endOf(superColumnName), markedForDeleteAt, localDeletionTime)); } }
/** * Drop specified trigger from the schema using given mutation. * * @param mutation The schema mutation * @param cfName The name of the parent ColumnFamily * @param timestamp The timestamp to use for the tombstone */ public void deleteFromSchema(Mutation mutation, String cfName, long timestamp) { ColumnFamily cf = mutation.addOrGet(SystemKeyspace.SCHEMA_TRIGGERS_CF); int ldt = (int) (System.currentTimeMillis() / 1000); Composite prefix = CFMetaData.SchemaTriggersCf.comparator.make(cfName, name); cf.addAtom(new RangeTombstone(prefix, prefix.end(), timestamp, ldt)); }
public static void deserializerSuperColumnFamily(DataInput in, ColumnFamily cf, ColumnSerializer.Flag flag, int version) throws IOException { // Note that there was no way to insert a range tombstone in a SCF in 1.2 cf.delete(cf.getComparator().deletionInfoSerializer().deserialize(in, version)); assert !cf.deletionInfo().rangeIterator().hasNext(); Iterator<OnDiskAtom> iter = onDiskIterator(in, in.readInt(), flag, Integer.MIN_VALUE, cf.getComparator()); while (iter.hasNext()) cf.addAtom(iter.next()); }
/** * Drop specified column from the schema using given mutation. * * @param mutation The schema mutation * @param timestamp The timestamp to use for column modification */ public void deleteFromSchema(Mutation mutation, long timestamp) { ColumnFamily cf = mutation.addOrGet(CFMetaData.SchemaColumnsCf); int ldt = (int) (System.currentTimeMillis() / 1000); // Note: we do want to use name.toString(), not name.bytes directly for backward compatibility (For CQL3, this won't make a difference). Composite prefix = CFMetaData.SchemaColumnsCf.comparator.make(cfName, name.toString()); cf.addAtom(new RangeTombstone(prefix, prefix.end(), timestamp, ldt)); }
public static Mutation dropFromSchema(UserType droppedType, long timestamp) { Mutation mutation = new Mutation(Keyspace.SYSTEM_KS, SystemKeyspace.getSchemaKSKey(droppedType.keyspace)); ColumnFamily cf = mutation.addOrGet(SystemKeyspace.SCHEMA_USER_TYPES_CF); int ldt = (int) (System.currentTimeMillis() / 1000); Composite prefix = CFMetaData.SchemaUserTypesCf.comparator.make(droppedType.name); cf.addAtom(new RangeTombstone(prefix, prefix.end(), timestamp, ldt)); return mutation; }
void saveOutOfOrderRow(DecoratedKey key, OnDiskAtomIterator atoms, String message) { // TODO bitch if the row is too large? if it is there's not much we can do ... outputHandler.warn(message); // adding atoms in sorted order is worst-case for TMBSC, but we shouldn't need to do this very often // and there's no sense in failing on mis-sorted cells when a TreeMap could safe us ColumnFamily cf = atoms.getColumnFamily().cloneMeShallow(ArrayBackedSortedColumns.factory, false); while (atoms.hasNext()) { OnDiskAtom atom = atoms.next(); cf.addAtom(atom); } outOfOrderRows.add(new Row(key, cf)); }
private static ColumnFamily updatesWithPaxosTime(ColumnFamily updates, UUID ballot) { ColumnFamily cf = updates.cloneMeShallow(); long t = UUIDGen.microsTimestamp(ballot); // For the tombstones, we use t-1 so that when insert a collection literall, the range tombstone that deletes the previous values of // the collection and we want that to have a lower timestamp and our new values. Since tombstones wins over normal insert, using t-1 // should not be a problem in general (see #6069). cf.deletionInfo().updateAllTimestamp(t-1); for (Cell cell : updates) cf.addAtom(cell.withUpdatedTimestamp(t)); return cf; }
public void execute(ByteBuffer rowKey, ColumnFamily cf, Composite prefix, UpdateParameters params) throws InvalidRequestException { if (column.type.isMultiCell()) { // delete + add CellName name = cf.getComparator().create(prefix, column); cf.addAtom(params.makeTombstoneForOverwrite(name.slice())); } Adder.doAdd(t, cf, prefix, column, params); } }
public void execute(ByteBuffer rowKey, ColumnFamily cf, Composite prefix, UpdateParameters params) throws InvalidRequestException { if (column.type.isMultiCell()) { // delete + put CellName name = cf.getComparator().create(prefix, column); cf.addAtom(params.makeTombstoneForOverwrite(name.slice())); } Putter.doPut(t, cf, prefix, column, params); } }
public void execute(ByteBuffer rowKey, ColumnFamily cf, Composite prefix, UpdateParameters params) throws InvalidRequestException { if (column.type.isMultiCell()) { // delete + append CellName name = cf.getComparator().create(prefix, column); cf.addAtom(params.makeTombstoneForOverwrite(name.slice())); } Appender.doAppend(t, cf, prefix, column, params); } }
public void execute(ByteBuffer rowKey, ColumnFamily cf, Composite prefix, UpdateParameters params) throws InvalidRequestException { CellName cname = cf.getComparator().create(prefix, column); if (column.type.isMultiCell()) cf.addAtom(params.makeRangeTombstone(cname.slice())); else cf.addColumn(params.makeTombstone(cname)); } };
public void addUpdateForKey(ColumnFamily cf, ByteBuffer key, Composite prefix, UpdateParameters params) throws InvalidRequestException { List<Operation> deletions = getOperations(); if (deletions.isEmpty()) { // We delete the slice selected by the prefix. // However, for performance reasons, we distinguish 2 cases: // - It's a full internal row delete // - It's a full cell name (i.e it's a dense layout and the prefix is full) if (prefix.isEmpty()) { // No columns specified, delete the row cf.delete(new DeletionInfo(params.timestamp, params.localDeletionTime)); } else if (cfm.comparator.isDense() && prefix.size() == cfm.clusteringColumns().size()) { cf.addAtom(params.makeTombstone(cfm.comparator.create(prefix, null))); } else { cf.addAtom(params.makeRangeTombstone(prefix.slice())); } } else { for (Operation op : deletions) op.execute(key, cf, prefix, params); } }
static void doPut(Term t, ColumnFamily cf, Composite prefix, ColumnDefinition column, UpdateParameters params) throws InvalidRequestException { Term.Terminal value = t.bind(params.options); Maps.Value mapValue = (Maps.Value) value; if (column.type.isMultiCell()) { if (value == null) return; for (Map.Entry<ByteBuffer, ByteBuffer> entry : mapValue.map.entrySet()) { CellName cellName = cf.getComparator().create(prefix, column, entry.getKey()); cf.addColumn(params.makeColumn(cellName, entry.getValue())); } } else { // for frozen maps, we're overwriting the whole cell CellName cellName = cf.getComparator().create(prefix, column); if (value == null) cf.addAtom(params.makeTombstone(cellName)); else cf.addColumn(params.makeColumn(cellName, mapValue.getWithProtocolVersion(Server.CURRENT_VERSION))); } } }
public CFRowAdder resetCollection(String cql3ColumnName) { ColumnDefinition def = getDefinition(cql3ColumnName); assert def.type.isCollection() && def.type.isMultiCell(); Composite name = cf.getComparator().create(prefix, def); cf.addAtom(new RangeTombstone(name.start(), name.end(), timestamp - 1, ldt)); return this; }
static void doAppend(Term t, ColumnFamily cf, Composite prefix, ColumnDefinition column, UpdateParameters params) throws InvalidRequestException { Term.Terminal value = t.bind(params.options); Lists.Value listValue = (Lists.Value)value; if (column.type.isMultiCell()) { // If we append null, do nothing. Note that for Setter, we've // already removed the previous value so we're good here too if (value == null) return; List<ByteBuffer> toAdd = listValue.elements; for (int i = 0; i < toAdd.size(); i++) { ByteBuffer uuid = ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes()); cf.addColumn(params.makeColumn(cf.getComparator().create(prefix, column, uuid), toAdd.get(i))); } } else { // for frozen lists, we're overwriting the whole cell value CellName name = cf.getComparator().create(prefix, column); if (value == null) cf.addAtom(params.makeTombstone(name)); else cf.addColumn(params.makeColumn(name, listValue.getWithProtocolVersion(Server.CURRENT_VERSION))); } } }
/** * Remove all CF attributes from schema * * @param timestamp Timestamp to use * * @return Mutation to use to completely remove cf from schema */ public Mutation dropFromSchema(long timestamp) { Mutation mutation = new Mutation(Keyspace.SYSTEM_KS, SystemKeyspace.getSchemaKSKey(ksName)); ColumnFamily cf = mutation.addOrGet(SchemaColumnFamiliesCf); int ldt = (int) (System.currentTimeMillis() / 1000); Composite prefix = SchemaColumnFamiliesCf.comparator.make(cfName); cf.addAtom(new RangeTombstone(prefix, prefix.end(), timestamp, ldt)); for (ColumnDefinition cd : allColumns()) cd.deleteFromSchema(mutation, timestamp); for (TriggerDefinition td : triggers.values()) td.deleteFromSchema(mutation, cfName, timestamp); for (String indexName : Keyspace.open(this.ksName).getColumnFamilyStore(this.cfName).getBuiltIndexes()) { ColumnFamily indexCf = mutation.addOrGet(IndexCf); indexCf.addTombstone(indexCf.getComparator().makeCellName(indexName), ldt, timestamp); } return mutation; }
static void doAdd(Term t, ColumnFamily cf, Composite prefix, ColumnDefinition column, UpdateParameters params) throws InvalidRequestException { Term.Terminal value = t.bind(params.options); Sets.Value setValue = (Sets.Value)value; if (column.type.isMultiCell()) { if (value == null) return; Set<ByteBuffer> toAdd = setValue.elements; for (ByteBuffer bb : toAdd) { CellName cellName = cf.getComparator().create(prefix, column, bb); cf.addColumn(params.makeColumn(cellName, ByteBufferUtil.EMPTY_BYTE_BUFFER)); } } else { // for frozen sets, we're overwriting the whole cell CellName cellName = cf.getComparator().create(prefix, column); if (value == null) cf.addAtom(params.makeTombstone(cellName)); else cf.addColumn(params.makeColumn(cellName, ((Value) value).getWithProtocolVersion(Server.CURRENT_VERSION))); } } }