@Test public void createColumnForDeleteThrowsIfCreatingWithNonEmptyValue() { assertThatThrownBy(() -> CassandraKeyValueServices.createColumnForDelete(CELL, Value.create(DATA, 1000), 2000)) .isInstanceOf(IllegalStateException.class); } }
tableRefToMetadata, (tableRef, metadata) -> CassandraKeyValueServices.getMetadataCell(tableRef)); Map<TableReference, Cell> tableRefToOldCell = Maps.transformEntries( tableRefToMetadata, (tableRef, metadata) -> CassandraKeyValueServices.getOldMetadataCell(tableRef));
static void runWithWaitingForSchemas( RunnableCheckedException<TException> task, CassandraKeyValueServiceConfig config, CassandraClient client, String unsafeSchemaChangeDescription) throws TException { waitForSchemaVersions(config, client, "before " + unsafeSchemaChangeDescription); task.run(); waitForSchemaVersions(config, client, "after " + unsafeSchemaChangeDescription); }
private static void extractTimestampResults(@Output Multimap<Cell, Long> ret, Map<ByteBuffer, List<ColumnOrSuperColumn>> results) { for (Entry<ByteBuffer, List<ColumnOrSuperColumn>> result : results.entrySet()) { byte[] row = CassandraKeyValueServices.getBytesFromByteBuffer(result.getKey()); for (ColumnOrSuperColumn col : result.getValue()) { Pair<byte[], Long> pair = CassandraKeyValueServices.decomposeName(col.column); ret.put(Cell.create(row, pair.lhSide), pair.rhSide); } } }
if (uniqueSchemaWithQuorumAgreementAndOtherNodesUnreachable(config, versions)) { return; sleepTime = sleepAndGetNextBackoffTime(sleepTime); } while (System.currentTimeMillis() < start + config.schemaMutationTimeoutMillis()); schemaVersions = addNodeInformation(schemaVersions, String.format("%nAt schema version %s:", version.getKey()), version.getValue()); String configNodes = addNodeInformation(new StringBuilder(), "Nodes specified in config file:", config.servers().stream().map(InetSocketAddress::getHostName).collect(Collectors.toList()))
Cell cell = e.getKey(); Column col = overrideTimestamps ? CassandraKeyValueServices.createColumnForDelete( cell, e.getValue(), overrideTimestamp) : CassandraKeyValueServices.createColumn(cell, e.getValue());
public static void insertGenericMetadataIntoLegacyCell(KeyValueService kvs, TableReference tableRef, byte[] data) { Cell legacyMetadataCell = CassandraKeyValueServices.getOldMetadataCell(tableRef); kvs.put(AtlasDbConstants.DEFAULT_METADATA_TABLE, ImmutableMap.of(legacyMetadataCell, data), System.currentTimeMillis()); } }
@Test public void createColumnWithGivenValueCreatesItWithAssociatedCassandraTimestamp() { assertThat(CassandraKeyValueServices.createColumn(CELL, Value.create(DATA, 1000)).getTimestamp()) .isEqualTo(1000); assertThat(CassandraKeyValueServices.createColumn(CELL, Value.create(DATA, 5000)).getTimestamp()) .isEqualTo(5000); }
private void insertMetadataIntoNewCell(TableReference tableRef) { Cell metadataCell = CassandraKeyValueServices.getMetadataCell(tableRef); kvs.put(AtlasDbConstants.DEFAULT_METADATA_TABLE, ImmutableMap.of(metadataCell, AtlasDbConstants.GENERIC_TABLE_METADATA), System.currentTimeMillis()); } }
static Column createColumn(Cell cell, Value value) { return createColumnAtSpecificCassandraTimestamp(cell, value, value.getTimestamp()); }
private void logTraceResults(long duration, Set<TableReference> tableRefs, ByteBuffer recvTrace, boolean failed) { if (failed || duration > tracingPrefs.getMinimumDurationToTraceMillis()) { log.info("Traced a call to {} that {}took {} ms. It will appear in system_traces with UUID={}", tableRefs.stream().map(TableReference::getQualifiedName).collect(Collectors.joining(", ")), failed ? "failed and " : "", duration, CassandraKeyValueServices.convertCassandraByteBufferUuidToString(recvTrace)); } } }
/** * Convenience method to get the name buffer for the specified column and * decompose it into the name and timestamp. */ public static Pair<byte[], Long> decomposeName(Column column) { ByteBuffer nameBuffer; if (column.isSetName()) { nameBuffer = column.bufferForName(); } else { // the column buffer has not yet been set/cached // so we must fallback on the slowpath and force // the transform to bytes and wrap ourselves nameBuffer = ByteBuffer.wrap(column.getName()); } return decompose(nameBuffer); }
for (Entry<byte[], Column> e : rowsToLastCompositeColumns.entrySet()) { byte[] row = e.getKey(); byte[] col = CassandraKeyValueServices.decomposeName(e.getValue()).getLhSide();
public void extractResults(Iterable<byte[]> canonicalRows, Map<ByteBuffer, List<ColumnOrSuperColumn>> colsByKey, long startTs) { // Make sure returned maps are keyed by the given rows Map<ByteBuffer, byte[]> canonicalRowsByHash = Maps.uniqueIndex(canonicalRows, ByteBuffer::wrap); for (Map.Entry<ByteBuffer, List<ColumnOrSuperColumn>> colEntry : colsByKey.entrySet()) { byte[] rawRow = CassandraKeyValueServices.getBytesFromByteBuffer(colEntry.getKey()); byte[] row = canonicalRowsByHash.get(ByteBuffer.wrap(rawRow)); List<ColumnOrSuperColumn> columns = colEntry.getValue(); if (!columns.isEmpty()) { rowsToLastCompositeColumns.put(row, columns.get(columns.size() - 1).getColumn()); } else { emptyRows.add(row); } rowsToRawColumnCount.put(row, columns.size()); for (ColumnOrSuperColumn c : columns) { Pair<byte[], Long> pair = CassandraKeyValueServices.decomposeName(c.getColumn()); internalExtractResult(startTs, row, pair.lhSide, c.getColumn().getValue(), pair.rhSide); } } }
Cell cell = e.getKey(); Column col = overrideTimestamps ? CassandraKeyValueServices.createColumnForDelete( cell, e.getValue(), overrideTimestamp) : CassandraKeyValueServices.createColumn(cell, e.getValue());
if (uniqueSchemaWithQuorumAgreementAndOtherNodesUnreachable(config, versions)) { return; sleepTime = sleepAndGetNextBackoffTime(sleepTime); } while (System.currentTimeMillis() < start + config.schemaMutationTimeoutMillis()); schemaVersions = addNodeInformation(schemaVersions, String.format("%nAt schema version %s:", version.getKey()), version.getValue()); String configNodes = addNodeInformation(new StringBuilder(), "Nodes specified in config file:", config.servers().stream().map(InetSocketAddress::getHostName).collect(Collectors.toList()))
@Test @SuppressWarnings("Slf4jConstantLogMessage") public void upgradeFromOlderInternalSchemaDoesNotErrorOnTablesWithOldMetadata() { TableReference tableRef = TableReference.createFromFullyQualifiedName("test.oldTimeyTable"); keyValueService.put( AtlasDbConstants.DEFAULT_METADATA_TABLE, ImmutableMap.of(CassandraKeyValueServices.getOldMetadataCell(tableRef), ORIGINAL_METADATA), System.currentTimeMillis()); keyValueService.createTable(tableRef, ORIGINAL_METADATA); ((CassandraKeyValueServiceImpl) keyValueService).upgradeFromOlderInternalSchema(); verify(logger, never()).error(anyString(), any(Object.class)); }
private MutationMap convertToMutations(List<TableCellAndValue> batch, long timestamp) { MutationMap mutationMap = new MutationMap(); for (TableCellAndValue tableCellAndValue : batch) { Cell cell = tableCellAndValue.cell; Column col = CassandraKeyValueServices.createColumn( cell, Value.create(tableCellAndValue.value, timestamp)); ColumnOrSuperColumn colOrSup = new ColumnOrSuperColumn(); colOrSup.setColumn(col); Mutation mutation = new Mutation(); mutation.setColumn_or_supercolumn(colOrSup); mutationMap.addMutationForCell(cell, tableCellAndValue.tableRef, mutation); } return mutationMap; }
@Test @SuppressWarnings("Slf4jConstantLogMessage") public void upgradeFromOlderInternalSchemaDoesNotErrorOnTablesWithUpperCaseCharacters() { TableReference tableRef = TableReference.createFromFullyQualifiedName("test.uPgrAdefRomolDerintErnalscHema"); keyValueService.put( AtlasDbConstants.DEFAULT_METADATA_TABLE, ImmutableMap.of(CassandraKeyValueServices.getMetadataCell(tableRef), ORIGINAL_METADATA), System.currentTimeMillis()); keyValueService.createTable(tableRef, ORIGINAL_METADATA); ((CassandraKeyValueServiceImpl) keyValueService).upgradeFromOlderInternalSchema(); verify(logger, never()).error(anyString(), any(Object.class)); }
/** * Creates a {@link Column} for an Atlas tombstone. * These columns have an Atlas timestamp of zero, but should not have a Cassandra timestamp of zero as that may * interfere with compactions. We want these to be at least reasonably consistent with Atlas's overall logical * time. * * In practice, usage may involve obtaining a (reasonably) fresh timestamp and using that as the timestamp for the * deletion. */ static Column createColumnForDelete(Cell cell, Value value, long cassandraTimestamp) { Preconditions.checkState( Arrays.equals(value.getContents(), PtBytes.EMPTY_BYTE_ARRAY), "Attempted to createColumnForDelete on a non-delete value, for cell %s and value %s", cell, value); return createColumnAtSpecificCassandraTimestamp(cell, value, cassandraTimestamp); }