public void store() { for (Map.Entry<Long, Map<Cell, byte[]>> e : cellsByTimestamp.entrySet()) { kvs.put(table, e.getValue(), e.getKey()); } }
protected void writeToKvs(Map<Cell, byte[]> writeMap) { try { writeKvs.put(destTable, writeMap, migrationTimestamp); } catch (KeyAlreadyExistsException e) { retryWriteToKvs(writeMap); } }
public void putAll(Map<Long, Long> timestampMap) throws KeyAlreadyExistsException { Map<Cell, byte[]> kvMap = new HashMap<>(); for (Map.Entry<Long, Long> entry : timestampMap.entrySet()) { kvMap.put( getTransactionCell(entry.getKey()), TransactionConstants.getValueForTimestamp(entry.getValue())); } keyValueService.put(TransactionConstants.TRANSACTION_TABLE, kvMap, 0); // This can throw unchecked exceptions }
@Override public void put(TableReference tableRef, Map<Cell, byte[]> values, long timestamp) { delegate().put(tableRef, values, timestamp); writesByTable.add(tableRef, values.size()); recordModifications(values.size()); recordModificationsSize(values.entrySet().stream().mapToLong(cellEntry -> cellEntry.getValue().length) .sum()); }
@Override public void put(TableReference tableRef, Map<Cell, byte[]> values, long timestamp) { try { delegate().put(tableMapper.getMappedTableName(tableRef), values, timestamp); } catch (TableMappingNotFoundException e) { throw new IllegalArgumentException(e); } }
private Map<TableReference, ? extends Map<Cell, byte[]>> tombstoneToDefaultCell(TableReference tableRef, long ts) { Map<Cell, byte[]> singleWrite = ImmutableMap.of(DEFAULT_CELL, PtBytes.EMPTY_BYTE_ARRAY); spiedKvs.put(tableRef, singleWrite, ts); return ImmutableMap.of(tableRef, singleWrite); }
protected void retryWriteToKvs(Map<Cell, byte[]> writeMap) { Multimap<Cell, Long> keys = Multimaps.forMap(Maps2.createConstantValueMap( writeMap.keySet(), migrationTimestamp)); writeKvs.delete(destTable, keys); writeKvs.put(destTable, writeMap, migrationTimestamp); }
@Override public void put(TableReference tableRef, Map<Cell, byte[]> values, long timestamp) { //noinspection unused - try-with-resources closes trace try (CloseableTrace trace = startLocalTrace("put({}, {} values, ts {})", LoggingArgs.safeTableOrPlaceholder(tableRef), values.size(), timestamp)) { delegate().put(tableRef, values, timestamp); } }
@Test public void deleteTimestampRangesLeavesSentinels() { long latestTs = 15L; keyValueService.addGarbageCollectionSentinelValues(TEST_TABLE, ImmutableSet.of(TEST_CELL)); keyValueService.put(TEST_TABLE, ImmutableMap.of(TEST_CELL, val(1, 0)), latestTs); keyValueService.deleteAllTimestamps(TEST_TABLE, ImmutableMap.of(TEST_CELL, latestTs), false); assertThat(getAllTimestampsForTestCell(), contains(Value.INVALID_VALUE_TIMESTAMP, latestTs)); assertThat(keyValueService.get(TEST_TABLE, ImmutableMap.of(TEST_CELL, Value.INVALID_VALUE_TIMESTAMP + 1L)) .get(TEST_CELL), equalTo(Value.create(new byte[0], Value.INVALID_VALUE_TIMESTAMP))); }
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 tableCreationAppearsToSucceedButIsNoop() { kvs.createTable(UPPER_UPPER, AtlasDbConstants.GENERIC_TABLE_METADATA); kvs.createTable(LOWER_LOWER, AtlasDbConstants.GENERIC_TABLE_METADATA); kvs.put(UPPER_UPPER, ImmutableMap.of(CELL, BYTE_ARRAY), 1); assertThat(kvs.get(UPPER_UPPER, ImmutableMap.of(CELL, 2L)).get(CELL).getContents()).contains(BYTE_ARRAY); assertThatThrownBy(() -> kvs.get(LOWER_LOWER, ImmutableMap.of(CELL, 2L))) .isInstanceOf(RetryLimitReachedException.class); assertThatThrownBy(() -> kvs.put(LOWER_LOWER, ImmutableMap.of(CELL, SECOND_BYTE_ARRAY), 1)) .isInstanceOf(RetryLimitReachedException.class); }
@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)); }
@Override public void setupTableData() { getKvs().truncateTable(getTableRef()); Map<Cell, byte[]> batch = Tables.generateRandomBatch(random, 1); getKvs().put(getTableRef(), batch, Tables.DUMMY_TIMESTAMP); data = Multimaps.forMap(Maps.transformValues(batch, $ -> Tables.DUMMY_TIMESTAMP)); }
@Override public void setupTableData() { getKvs().truncateTable(getTableRef()); Map<Cell, byte[]> batch = Tables.generateRandomBatch(random, BATCH_SIZE); getKvs().put(getTableRef(), batch, Tables.DUMMY_TIMESTAMP); data = Multimaps.forMap(Maps.transformValues(batch, $ -> Tables.DUMMY_TIMESTAMP)); }
@Test public void tableReferencesAreCaseSensitiveForPutAndGet() { createTablesIgnoringException(); kvs.put(UPPER_UPPER, ImmutableMap.of(CELL, BYTE_ARRAY), 1); kvs.put(LOWER_LOWER, ImmutableMap.of(CELL, SECOND_BYTE_ARRAY), 1); assertThat(kvs.get(UPPER_UPPER, ImmutableMap.of(CELL, 2L)).get(CELL).getContents()).contains(BYTE_ARRAY); assertThat(kvs.get(LOWER_UPPER, ImmutableMap.of(CELL, 2L))).doesNotContainKey(CELL); assertThat(kvs.get(LOWER_LOWER, ImmutableMap.of(CELL, 2L)).get(CELL).getContents()).contains(SECOND_BYTE_ARRAY); }
@Test public void delegatesMethodsToTheKvsAssociatedWithTheTable() { TableSplittingKeyValueService splittingKvs = TableSplittingKeyValueService.create( ImmutableList.of(defaultKvs, tableDelegate), ImmutableMap.of(TABLE, tableDelegate) ); mockery.checking(new Expectations() {{ oneOf(tableDelegate).put(TABLE, VALUES, TIMESTAMP); }}); splittingKvs.put(TABLE, VALUES, TIMESTAMP); }
@Benchmark @Threads(1) @Warmup(time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(time = 6, timeUnit = TimeUnit.SECONDS) public Object singleRandomPut(EmptyTables tables) { Map<Cell, byte[]> batch = tables.generateBatchToInsert(1); tables.getKvs().put(tables.getFirstTableRef(), batch, DUMMY_TIMESTAMP); return batch; }
@Test public void defaultsToTheFirstKvsInTheListIfNoMappingsMatch() { TableSplittingKeyValueService splittingKvs = TableSplittingKeyValueService.create( ImmutableList.of(defaultKvs, tableDelegate), ImmutableMap.of(TableReference.createWithEmptyNamespace("not-this"), tableDelegate) ); mockery.checking(new Expectations() {{ oneOf(defaultKvs).put(TABLE, VALUES, TIMESTAMP); }}); splittingKvs.put(TABLE, VALUES, TIMESTAMP); }