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); }
Optional<TableReference> get(int tableId) { SweepIdToNameColumn column = SweepIdToNameColumn.of(tableId); Cell cell = Cell.create(rowAsBytes, column.persistToBytes()); Map<Cell, Value> values = kvs.get(ID_TO_NAME, Collections.singletonMap(cell, Long.MAX_VALUE)); return Optional.ofNullable(values.get(cell)) .map(Value::getContents) .map(SweepIdToNameColumnValue::hydrateValue) .map(TableReference::fromString); }
@Override public Map<Cell, Value> get(TableReference tableRef, Map<Cell, Long> timestampByCell) { try { return delegate().get(tableMapper.getMappedTableName(tableRef), timestampByCell); } catch (TableMappingNotFoundException e) { throw new IllegalArgumentException(e); } }
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; } }
Optional<SweepTableIdentifier> currentMapping(TableReference table) { SweepNameToIdRow row = SweepNameToIdRow.of(table.getQualifiedName()); Cell cell = Cell.create(row.persistToBytes(), SweepNameToIdNamedColumn.ID.getShortName()); return Optional.ofNullable(kvs.get(NAME_TO_ID, Collections.singletonMap(cell, Long.MAX_VALUE)).get(cell)) .map(Value::getContents) .map(SweepTableIdentifier.BYTES_HYDRATOR::hydrateFromBytes); } }
@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))); }
@Test public void testGetWithMultipleVersions() { putTestDataForMultipleTimestamps(); Map<Cell, Value> values = keyValueService.get(TEST_TABLE, ImmutableMap.of(TEST_CELL, TEST_TIMESTAMP + 2)); assertEquals("Incorrect number of values returned.", 1, values.size()); assertEquals("Incorrect value returned.", Value.create(val(0, 7), TEST_TIMESTAMP + 1), values.get(TEST_CELL)); }
@Test public void get() throws Exception { Map<Cell, Value> expectedResult = ImmutableMap.of(CELL, VALUE); Map<Cell, Long> cells = ImmutableMap.of(CELL, 1L); when(delegate.get(TABLE_REF, cells)).thenReturn(expectedResult); Map<Cell, Value> result = kvs.get(TABLE_REF, cells); assertThat(result, equalTo(expectedResult)); checkSpan("atlasdb-kvs.get({table}, 1 cells)"); verify(delegate).get(TABLE_REF, cells); verifyNoMoreInteractions(delegate); }
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()); }
@Test public void getTraceLogPresentOnTraceLevelEvenIfQueryIsSlow() { Appender mockAppender = setLogLevelAndGetAppender(Level.TRACE); doAnswer(waitASecondAndAHalfAndReturn).when(delegate).get(TABLE_REF, timestampByCell); kvs.get(TABLE_REF, timestampByCell); verify(mockAppender).doAppend(traceLogMatcher.get()); verify(mockAppender).doAppend(slowLogMatcher.get()); }
@Override public Map<Cell, Value> get(TableReference tableRef, Map<Cell, Long> timestampByCell) { long startTime = System.currentTimeMillis(); return KvsProfilingLogger.maybeLog(() -> delegate.get(tableRef, timestampByCell), (logger, stopwatch) -> logger.log("Call to KVS.get at time {}, on table {}, requesting {} cells took {} ms ", LoggingArgs.startTimeMillis(startTime), LoggingArgs.tableRef(tableRef), LoggingArgs.cellCount(timestampByCell.size()), LoggingArgs.durationMillis(stopwatch)), logCellResultSize(4L)); }
@Benchmark @Threads(1) @Warmup(time = 20, timeUnit = TimeUnit.SECONDS) @Measurement(time = 180, timeUnit = TimeUnit.SECONDS) public Object getAllColumnsExplicitly(ModeratelyWideRowTable table) { Map<Cell, Value> result = table.getKvs().get(table.getTableRef(), table.getAllCellsAtMaxTimestamp()); Preconditions.checkState(result.size() == table.getNumCols(), "Should be %s columns, but were: %s", table.getNumCols(), result.size()); return result; }
@Test public void getNoLoggingHappensIfQueryFastAndInfoLevel() { Appender mockAppender = setLogLevelAndGetAppender(Level.INFO); kvs.get(TABLE_REF, timestampByCell); verifyNoMoreInteractions(mockAppender); } }
@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); }
@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 getTraceLogPresentOnTraceLevel() { Appender mockAppender = setLogLevelAndGetAppender(Level.TRACE); kvs.get(TABLE_REF, timestampByCell); verify(mockAppender).doAppend(traceLogMatcher.get()); }