private void updateGetStats(TableStats s, Map<Cell, Value> r) { s.totalGetCells.addAndGet(r.size()); long totalSize = 0; for (Map.Entry<Cell, Value> e : r.entrySet()) { totalSize += e.getValue().getContents().length; } s.totalGetValueBytes.addAndGet(totalSize); }
@Override protected void performOneCall() { byte[] result = keyValueService.get(TABLE, ImmutableMap.of(cell, 200L)) .get(cell).getContents(); Preconditions.checkState(result.length == data.length); } }
private String get(String row, String column, long ts) { Cell cell = Cell.create(row.getBytes(StandardCharsets.UTF_8), column.getBytes(StandardCharsets.UTF_8)); Value val = kvs.get(TABLE_NAME, ImmutableMap.of(cell, ts)).get(cell); return val == null ? null : new String(val.getContents(), StandardCharsets.UTF_8); }
private long getValue(Map<Cell, Value> entry) { SweepShardProgressTable.Value value = SweepShardProgressTable.Value.BYTES_HYDRATOR.hydrateFromBytes( Iterables.getOnlyElement(entry.values()).getContents()); return value.getValue(); }
@Override public void putWithTimestamps(TableReference tableRef, Multimap<Cell, Value> cellValues) { delegate().putWithTimestamps(tableRef, cellValues); writesByTable.add(tableRef, cellValues.size()); recordModifications(cellValues.size()); recordModificationsSize(cellValues.entries().stream() .mapToLong(cellEntry -> cellEntry.getValue().getContents().length).sum()); }
public Long get(Long startTimestamp) { Cell cell = getTransactionCell(startTimestamp); Map<Cell, Value> returnMap = keyValueService.get(TransactionConstants.TRANSACTION_TABLE, ImmutableMap.of(cell, MAX_TIMESTAMP)); if (returnMap.containsKey(cell)) { return TransactionConstants.getTimestampForValue(returnMap.get(cell).getContents()); } else { return null; } }
private static BiConsumer<LoggingFunction, Map<Cell, Value>> logCellResultSize(long overhead) { return (logger, result) -> { long sizeInBytes = 0; for (Entry<Cell, Value> entry : result.entrySet()) { sizeInBytes += Cells.getApproxSizeOfCell(entry.getKey()) + entry.getValue().getContents().length + overhead; } logger.log("and returned {} bytes.", LoggingArgs.sizeInBytes(sizeInBytes)); }; }
@Override public InsertValuesStep4<Record, byte[], byte[], Long, byte[]> addValuesForInsert(InsertValuesStep4<Record, byte[], byte[], Long, byte[]> query) { for (Entry<Cell, Value> entry : data.entries()) { query = query.values(entry.getKey().getRowName(), entry.getKey().getColumnName(), entry.getValue().getTimestamp(), entry.getValue().getContents()); } return query; }
@Override public void put(Collection<Map.Entry<Cell, Value>> data) { List<Object[]> args = Lists.newArrayListWithCapacity(data.size()); for (Entry<Cell, Value> entry : data) { Cell cell = entry.getKey(); Value val = entry.getValue(); args.add(new Object[] { cell.getRowName(), cell.getColumnName(), val.getTimestamp(), val.getContents() }); } put(args); }
private byte[] getRowsForCell(Cell cell) { return keyValueService.getRows(TEST_TABLE, ImmutableSet.of(cell.getRowName()), ColumnSelection.all(), TEST_TIMESTAMP + 3) .get(cell).getContents(); }
private Map<Cell, Value> getAllAtlasDeletes(TableReference tableRef) { Set<Cell> allCells = getAllCells(tableRef); Map<Cell, Value> latest = kvs.get().get(tableRef, Maps.asMap(allCells, ignore -> Long.MAX_VALUE)); return Maps.filterEntries(latest, ent -> Arrays.equals(ent.getValue().getContents(), PtBytes.EMPTY_BYTE_ARRAY)); }
Pair<String, Long> getDirect(TableReference tableRef, String rowName, String columnName, long timestamp) { Cell cell = createCell(rowName, columnName); Value valueBytes = keyValueService.get(tableRef, ImmutableMap.of(cell, timestamp)).get(cell); return valueBytes != null ? Pair.create(PtBytes.toString(valueBytes.getContents()), valueBytes.getTimestamp()) : null; }
@Test public void putUnlessExistsLargeValue() { Assume.assumeTrue(checkAndSetSupported()); byte[] megabyteValue = new byte[1048576]; keyValueService.putUnlessExists(TEST_TABLE, ImmutableMap.of(TEST_CELL, megabyteValue)); Value storedValue = keyValueService.get(TEST_TABLE, ImmutableMap.of(TEST_CELL, Long.MAX_VALUE)).get(TEST_CELL); assertArrayEquals(megabyteValue, storedValue.getContents()); }
private String get(KeyValueService kvs, TableReference table, String row, long ts) { Cell cell = Cell.create(row.getBytes(StandardCharsets.UTF_8), COL.getBytes(StandardCharsets.UTF_8)); Value val = kvs.get(table, ImmutableMap.of(cell, ts)).get(cell); return val == null ? null : new String(val.getContents()); }
private void assertReadAtTimestampReturnsTombstoneAtTimestamp(TableReference tableRef, long readTs, long tombTs) { Value readValue = Iterables.getOnlyElement(readFromDefaultCell(tableRef, readTs).values()); assertThat(readValue.getTimestamp()).isEqualTo(tombTs); assertThat(readValue.getContents()).isEmpty(); }
@Override public Map<TableReference, Long> getWatermarks(Set<TableReference> tableReferences) { Set<Cell> cells = tableReferences.stream().map(table -> cell(table)).collect(Collectors.toSet()); Map<Cell, Value> fetched = kvs.get(CLEARS, Maps.asMap(cells, ignored -> Long.MAX_VALUE)); return KeyedStream.stream(fetched) .map((cell, value) -> RowResult.of(cell, value.getContents())) .map(TableClearsRowResult::of) .mapKeys((cell, rowResult) -> tableRef(rowResult.getRowName())) .map(TableClearsRowResult::getLastClearedTimestamp) .collectToMap(); }
@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 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); }
private long readValueFromDefaultCell(TableReference tableRef, long ts) { byte[] cellContents = Iterables.getOnlyElement(readFromDefaultCell(tableRef, ts).values()).getContents(); assertThat(cellContents).as("Reading value from table %s at timestamp %s", tableRef, ts).isNotEmpty(); return PtBytes.toLong(cellContents); }
private static Column createColumnAtSpecificCassandraTimestamp(Cell cell, Value value, long cassandraTimestamp) { byte[] contents = value.getContents(); long atlasTimestamp = value.getTimestamp(); ByteBuffer colName = makeCompositeBuffer(cell.getColumnName(), atlasTimestamp); Column col = new Column(); col.setName(colName); col.setValue(contents); col.setTimestamp(cassandraTimestamp); return col; }