/** * Adds an EOC to the specified Composite. * * @param composite the composite * @param eocBound the EOC bound * @return a new <code>Composite</code> with the EOC corresponding to the eocBound */ private static Composite addEOC(Composite composite, Bound eocBound) { return eocBound == Bound.END ? composite.end() : composite.start(); }
private ColumnSlice makeStaticSlice() { // Note: we could use staticPrefix.start() for the start bound, but EMPTY gives us the // same effect while saving a few CPU cycles. return isReversed ? new ColumnSlice(cfm.comparator.staticPrefix().end(), Composites.EMPTY) : new ColumnSlice(Composites.EMPTY, cfm.comparator.staticPrefix().end()); }
public RangeTombstone deserializeBody(DataInput in, Composite min, Descriptor.Version version) throws IOException { Composite max = type.serializer().deserialize(in); DeletionTime dt = DeletionTime.serializer.deserialize(in); // If the max equals the min.end(), we can avoid keeping an extra ByteBuffer in memory by using // min.end() instead of max Composite minEnd = min.end(); max = minEnd.equals(max) ? minEnd : max; return new RangeTombstone(min, max, dt); }
/** * 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)); }
/** * Splits this filter into two SliceQueryFilters: one that slices only the static columns, and one that slices the * remainder of the normal data. * * This should only be called when the filter is reversed and the filter is known to cover static columns (through * hasStaticSlice()). * * @return a pair of (static, normal) SliceQueryFilters */ public Pair<SliceQueryFilter, SliceQueryFilter> splitOutStaticSlice(CFMetaData cfm) { assert reversed; Composite staticSliceEnd = cfm.comparator.staticPrefix().end(); List<ColumnSlice> nonStaticSlices = new ArrayList<>(slices.length); for (ColumnSlice slice : slices) { if (sliceIncludesStatics(slice, cfm)) nonStaticSlices.add(new ColumnSlice(slice.start, staticSliceEnd)); else nonStaticSlices.add(slice); } return Pair.create( new SliceQueryFilter(staticSliceEnd, Composites.EMPTY, true, count, compositesToGroup), new SliceQueryFilter(nonStaticSlices.toArray(new ColumnSlice[nonStaticSlices.size()]), true, count, compositesToGroup)); }
/** Returns true if the slice includes static columns, false otherwise. */ private boolean sliceIncludesStatics(ColumnSlice slice, CFMetaData cfm) { return cfm.hasStaticColumns() && slice.includes(reversed ? cfm.comparator.reverseComparator() : cfm.comparator, cfm.comparator.staticPrefix().end()); }
/** Returns true if the slice includes static columns, false otherwise. */ private boolean sliceIncludesStatics(ColumnSlice slice, boolean reversed, CFMetaData cfm) { return cfm.hasStaticColumns() && slice.includes(reversed ? cfm.comparator.reverseComparator() : cfm.comparator, cfm.comparator.staticPrefix().end()); }
/** * 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; }
/** * Writes the current partition count and size estimates into SIZE_ESTIMATES_CF */ public static void updateSizeEstimates(String keyspace, String table, Map<Range<Token>, Pair<Long, Long>> estimates) { long timestamp = FBUtilities.timestampMicros(); CFMetaData estimatesTable = CFMetaData.SizeEstimatesCf; Mutation mutation = new Mutation(Keyspace.SYSTEM_KS, UTF8Type.instance.decompose(keyspace)); // delete all previous values with a single range tombstone. mutation.deleteRange(SIZE_ESTIMATES_CF, estimatesTable.comparator.make(table).start(), estimatesTable.comparator.make(table).end(), timestamp - 1); // add a CQL row for each primary token range. ColumnFamily cells = mutation.addOrGet(estimatesTable); for (Map.Entry<Range<Token>, Pair<Long, Long>> entry : estimates.entrySet()) { Range<Token> range = entry.getKey(); Pair<Long, Long> values = entry.getValue(); Composite prefix = estimatesTable.comparator.make(table, range.left.toString(), range.right.toString()); CFRowAdder adder = new CFRowAdder(cells, prefix, timestamp); adder.add("partitions_count", values.left) .add("mean_partition_size", values.right); } mutation.apply(); }
/** * Fetches a subset of schema (table data, columns metadata or triggers) for the keyspace+table pair. * * @param schemaCfName the schema table to get the data from (schema_columnfamilies, schema_columns or schema_triggers) * @param ksName the keyspace of the table we are interested in * @param cfName the table we are interested in * @return a Row containing the schema data of a particular type for the table */ public static Row readSchemaRow(String schemaCfName, String ksName, String cfName) { DecoratedKey key = StorageService.getPartitioner().decorateKey(getSchemaKSKey(ksName)); ColumnFamilyStore schemaCFS = SystemKeyspace.schemaCFS(schemaCfName); Composite prefix = schemaCFS.getComparator().make(cfName); ColumnFamily cf = schemaCFS.getColumnFamily(key, prefix, prefix.end(), false, Integer.MAX_VALUE, System.currentTimeMillis()); return new Row(key, cf); }
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; }
private Composite makePrefix(CompositesIndex index, ByteBuffer key, ExtendedFilter filter, boolean isStart) { if (key.remaining() == 0) return Composites.EMPTY; Composite prefix; IDiskAtomFilter columnFilter = filter.columnFilter(key); if (columnFilter instanceof SliceQueryFilter) { SliceQueryFilter sqf = (SliceQueryFilter)columnFilter; Composite columnName = isStart ? sqf.start() : sqf.finish(); prefix = columnName.isEmpty() ? index.getIndexComparator().make(key) : index.makeIndexColumnPrefix(key, columnName); } else { prefix = index.getIndexComparator().make(key); } return isStart ? prefix.start() : prefix.end(); }
ColumnSlice dataSlice = new ColumnSlice(start, entry.indexedEntryPrefix.end());
/** * 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; }