public ColumnFamily cloneMeShallow() { return cloneMeShallow(false); }
public ColumnFamily cloneMeShallow(boolean reversed) { return cloneMeShallow(getFactory(), reversed); }
@VisibleForTesting List<Row> discardFirst(List<Row> rows, int toDiscard) { if (toDiscard == 0 || rows.isEmpty()) return rows; int i = 0; DecoratedKey firstKey = null; ColumnFamily firstCf = null; while (toDiscard > 0 && i < rows.size()) { Row first = rows.get(i++); firstKey = first.key; firstCf = first.cf.cloneMeShallow(isReversed()); toDiscard -= isReversed() ? discardLast(first.cf, toDiscard, firstCf) : discardFirst(first.cf, toDiscard, firstCf); } // If there is less live data than to discard, all is discarded if (toDiscard > 0) return Collections.<Row>emptyList(); // i is the index of the first row that we are sure to keep. On top of that, // we also keep firstCf is it hasn't been fully emptied by the last iteration above. int count = firstCf.getColumnCount(); int newSize = rows.size() - (count == 0 ? i : i - 1); List<Row> newRows = new ArrayList<Row>(newSize); if (count != 0) newRows.add(new Row(firstKey, firstCf)); newRows.addAll(rows.subList(i, rows.size())); return newRows; }
@VisibleForTesting List<Row> discardLast(List<Row> rows, int toDiscard) { if (toDiscard == 0 || rows.isEmpty()) return rows; int i = rows.size()-1; DecoratedKey lastKey = null; ColumnFamily lastCf = null; while (toDiscard > 0 && i >= 0) { Row last = rows.get(i--); lastKey = last.key; lastCf = last.cf.cloneMeShallow(isReversed()); toDiscard -= isReversed() ? discardFirst(last.cf, toDiscard, lastCf) : discardLast(last.cf, toDiscard, lastCf); } // If there is less live data than to discard, all is discarded if (toDiscard > 0) return Collections.<Row>emptyList(); // i is the index of the last row that we are sure to keep. On top of that, // we also keep lastCf is it hasn't been fully emptied by the last iteration above. int count = lastCf.getColumnCount(); int newSize = count == 0 ? i+1 : i+2; List<Row> newRows = new ArrayList<Row>(newSize); newRows.addAll(rows.subList(0, i+1)); if (count != 0) newRows.add(new Row(lastKey, lastCf)); return newRows; }
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 collectOutOfOrderCells(OnDiskAtom atom, OnDiskAtomIterator iterator) { ColumnFamily cf = iterator.getColumnFamily().cloneMeShallow(ArrayBackedSortedColumns.factory, false); cf.addAtom(atom); while (iterator.hasNext()) cf.addAtom(iterator.next()); return 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; }
/** * Filter a cached row, which will not be modified by the filter, but may be modified by throwing out * tombstones that are no longer relevant. * The returned column family won't be thread safe. */ ColumnFamily filterColumnFamily(ColumnFamily cached, QueryFilter filter) { if (cached == null) return null; ColumnFamily cf = cached.cloneMeShallow(ArrayBackedSortedColumns.factory, filter.filter.isReversed()); int gcBefore = gcBefore(filter.timestamp); filter.collateOnDiskAtom(cf, filter.getIterator(cached), gcBefore); return removeDeletedCF(cf, gcBefore); }
public ColumnFamily prune(DecoratedKey rowKey, ColumnFamily data) { if (optimizedFilter == null) return data; ColumnFamily pruned = data.cloneMeShallow(); IDiskAtomFilter filter = dataRange.columnFilter(rowKey.getKey()); Iterator<Cell> iter = filter.getColumnIterator(data); filter.collectReducedColumns(pruned, QueryFilter.gatherTombstones(pruned, iter), rowKey, cfs.gcBefore(timestamp), timestamp); return pruned; }
/** * @param key row to index * @param cfs ColumnFamily to index row in * @param idxNames columns to index, in comparator order */ public static void indexRow(DecoratedKey key, ColumnFamilyStore cfs, Set<String> idxNames) { if (logger.isDebugEnabled()) logger.debug("Indexing row {} ", cfs.metadata.getKeyValidator().getString(key.getKey())); try (OpOrder.Group opGroup = cfs.keyspace.writeOrder.start()) { Set<SecondaryIndex> indexes = cfs.indexManager.getIndexesByNames(idxNames); Iterator<ColumnFamily> pager = QueryPagers.pageRowLocally(cfs, key.getKey(), DEFAULT_PAGE_SIZE); while (pager.hasNext()) { ColumnFamily cf = pager.next(); ColumnFamily cf2 = cf.cloneMeShallow(); for (Cell cell : cf) { if (cfs.indexManager.indexes(cell.name(), indexes)) cf2.addColumn(cell); } cfs.indexManager.indexRow(key.getKey(), cf2, opGroup); } } }
private ColumnFamily processModifications(ColumnFamily changesCF) { ColumnFamilyStore cfs = Keyspace.open(getKeyspaceName()).getColumnFamilyStore(changesCF.id()); ColumnFamily resultCF = changesCF.cloneMeShallow(); List<CounterUpdateCell> counterUpdateCells = new ArrayList<>(changesCF.getColumnCount()); for (Cell cell : changesCF) { if (cell instanceof CounterUpdateCell) counterUpdateCells.add((CounterUpdateCell)cell); else resultCF.addColumn(cell); } if (counterUpdateCells.isEmpty()) return resultCF; // only DELETEs ClockAndCount[] currentValues = getCurrentValues(counterUpdateCells, cfs); for (int i = 0; i < counterUpdateCells.size(); i++) { ClockAndCount currentValue = currentValues[i]; CounterUpdateCell update = counterUpdateCells.get(i); long clock = currentValue.clock + 1L; long count = currentValue.count + update.delta(); resultCF.addColumn(new BufferCounterCell(update.name(), CounterContext.instance().createGlobal(CounterId.getLocalId(), clock, count), update.timestamp())); } return resultCF; }
static ColumnFamily resolveSuperset(Iterable<ColumnFamily> versions, long now) { assert Iterables.size(versions) > 0; ColumnFamily resolved = null; for (ColumnFamily cf : versions) { if (cf == null) continue; if (resolved == null) resolved = cf.cloneMeShallow(); else resolved.delete(cf); } if (resolved == null) return null; // mimic the collectCollatedColumn + removeDeleted path that getColumnFamily takes. // this will handle removing columns and subcolumns that are suppressed by a row or // supercolumn tombstone. QueryFilter filter = new QueryFilter(null, resolved.metadata().cfName, new IdentityQueryFilter(), now); List<CloseableIterator<Cell>> iters = new ArrayList<>(Iterables.size(versions)); for (ColumnFamily version : versions) if (version != null) iters.add(FBUtilities.closeableIterator(version.iterator())); filter.collateColumns(resolved, iters, Integer.MIN_VALUE); return ColumnFamilyStore.removeDeleted(resolved, Integer.MIN_VALUE); }
if (previous == null) AtomicBTreeColumns empty = cf.cloneMeShallow(AtomicBTreeColumns.factory, false); final DecoratedKey cloneKey = allocator.clone(key, opGroup);
ColumnFamily returnCF = container.cloneMeShallow(); Tracing.trace("Collating all results"); filter.collateOnDiskAtom(returnCF, container.iterator(), gcBefore);