public static Value createWithCopyOfData(byte[] contents, long timestamp) { return Value.create(Arrays.copyOf(contents, contents.length), timestamp); }
@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; }
@JsonCreator public static Value create(@JsonProperty("contents") byte[] contents, @JsonProperty("timestamp") long timestamp) { return new Value(MoreObjects.firstNonNull(contents, PtBytes.EMPTY_BYTE_ARRAY), timestamp); }
private void putIfNotUpdate( DbReadTable readTable, DbWriteTable writeTable, TableReference tableRef, List<Entry<Cell, Value>> batch, KeyAlreadyExistsException ex) { Map<Cell, Long> timestampByCell = Maps.newHashMap(); for (Entry<Cell, Value> entry : batch) { timestampByCell.put(entry.getKey(), entry.getValue().getTimestamp() + 1); } Map<Cell, Value> results = extractResults(readTable, tableRef, readTable.getLatestCells(timestampByCell, true)); ListIterator<Entry<Cell, Value>> iter = batch.listIterator(); while (iter.hasNext()) { Entry<Cell, Value> entry = iter.next(); Cell key = entry.getKey(); Value value = entry.getValue(); if (results.containsKey(key)) { if (results.get(key).equals(value)) { iter.remove(); } else { throw new KeyAlreadyExistsException( "primary key violation for key " + key + " with value " + value, ex); } } } writeTable.put(batch); }
private void fillOverflowValues(ConnectionSupplier conns, TableReference tableRef, Map<Cell, OverflowValue> overflowValues, @Output Map<Cell, Value> values) { Iterator<Entry<Cell, OverflowValue>> overflowIterator = overflowValues.entrySet().iterator(); while (overflowIterator.hasNext()) { Entry<Cell, OverflowValue> entry = overflowIterator.next(); Value value = values.get(entry.getKey()); if (value != null && value.getTimestamp() > entry.getValue().ts()) { overflowIterator.remove(); } } Map<Long, byte[]> resolvedOverflowValues = overflowValueLoader.loadOverflowValues( conns, tableRef, Collections2.transform(overflowValues.values(), OverflowValue::id)); for (Entry<Cell, OverflowValue> entry : overflowValues.entrySet()) { Cell cell = entry.getKey(); OverflowValue ov = entry.getValue(); byte[] val = resolvedOverflowValues.get(ov.id()); Preconditions.checkNotNull(val, "Failed to load overflow data: cell=%s, overflowId=%s", cell, ov.id()); values.put(cell, Value.create(val, ov.ts())); } }
private static boolean isFinishedTablePlaceholder(Value value) { return Arrays.equals(value.getContents(), FINISHED_TABLE); } }
private static void runOnce(Context context, ClosableIterator<RowResult<Value>> iter) { Multimap<Cell, Value> batchToCreate = ArrayListMultimap.create(); Multimap<Cell, Long> batchToDelete = ArrayListMultimap.create(); while (iter.hasNext()) { RowResult<Value> rowResult = iter.next(); byte[] row = rowResult.getRowName(); for (Entry<byte[], Value> entry : rowResult.getColumns().entrySet()) { byte[] col = entry.getKey(); Value value = entry.getValue(); long timestamp = value.getTimestamp(); String[] tableNames = StringUtils.split( PtBytes.toString(value.getContents()), AtlasDbConstants.OLD_SCRUB_TABLE_SEPARATOR_CHAR); for (String tableName : tableNames) { byte[] tableBytes = EncodingUtils.encodeVarString(tableName); byte[] newCol = EncodingUtils.add(tableBytes, col); Cell newCell = Cell.create(row, newCol); batchToCreate.put(newCell, Value.create(DUMMY_CONTENTS, timestamp)); } batchToDelete.put(Cell.create(row, col), timestamp); if (batchToDelete.size() >= context.batchSize) { flush(context, batchToCreate, batchToDelete); } } } if (!batchToDelete.isEmpty()) { flush(context, batchToCreate, batchToDelete); } }
private static boolean isSweepSentinel(Value value) { return value.getTimestamp() == Value.INVALID_VALUE_TIMESTAMP; }
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); }
Long overflowId = hasOverflow ? row.getLongObject("overflow") : null; if (overflowId == null) { Value value = Value.create(row.getBytes(VAL), row.getLong(TIMESTAMP)); Value oldValue = values.put(cell, value); if (oldValue != null && oldValue.getTimestamp() > value.getTimestamp()) { values.put(cell, oldValue);
private Set<Long> getStartTimestampsForValues(Iterable<Value> values) { Set<Long> results = Sets.newHashSet(); for (Value v : values) { results.add(v.getTimestamp()); } return results; }
@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); }
public static Collection<Map.Entry<Cell, Value>> toConstantTimestampValues( final Collection<Map.Entry<Cell, byte[]>> cells, final long timestamp) { return Collections2.transform(cells, entry -> Maps.immutableEntry(entry.getKey(), Value.create(entry.getValue(), timestamp))); }
@Override protected void performOneCall() { byte[] result = keyValueService.get(TABLE, ImmutableMap.of(cell, 200L)) .get(cell).getContents(); Preconditions.checkState(result.length == data.length); } }
Long overflowId = hasOverflow ? row.getLongObject("overflow") : null; if (overflowId == null) { Value value = Value.create(row.getBytes(VAL), row.getLong(TIMESTAMP)); Value oldValue = results.put(cell, value); if (oldValue != null && oldValue.getTimestamp() > value.getTimestamp()) { results.put(cell, oldValue);
private Value getValueForEntry(TableReference tableRef, Map.Entry<Cell, Value> entry) { return kvs.get().get(tableRef, ImmutableMap.of(entry.getKey(), entry.getValue().getTimestamp())) .get(entry.getKey()); }
@JsonCreator public static Value create(@JsonProperty("contents") byte[] contents, @JsonProperty("timestamp") long timestamp) { return new Value(MoreObjects.firstNonNull(contents, PtBytes.EMPTY_BYTE_ARRAY), timestamp); }
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; }
private void putIfNotUpdate( DbReadTable readTable, DbWriteTable writeTable, TableReference tableRef, List<Entry<Cell, byte[]>> batch, long timestamp, KeyAlreadyExistsException ex) { List<Entry<Cell, Value>> batchValues = Lists.transform(batch, input -> Maps.immutableEntry(input.getKey(), Value.create(input.getValue(), timestamp))); putIfNotUpdate(readTable, writeTable, tableRef, batchValues, ex); }
private byte[] getForCell(Cell cell) { return keyValueService.get(TEST_TABLE, ImmutableMap.of(cell, TEST_TIMESTAMP + 3)).get(cell).getContents(); }