use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class SchemaApiTestImpl method getRangeSecondColumn.
@Override
protected Map<String, StringValue> getRangeSecondColumn(Transaction transaction, String startRowKey, String endRowKey) {
SchemaApiTestTable table = tableFactory.getSchemaApiTestTable(transaction);
ColumnSelection secondColSelection = SchemaApiTestTable.getColumnSelection(SchemaApiTestTable.SchemaApiTestNamedColumn.COLUMN2);
RangeRequest rangeRequest = RangeRequest.builder().startRowInclusive(SchemaApiTestRow.of(startRowKey).persistToBytes()).endRowExclusive(SchemaApiTestRow.of(endRowKey).persistToBytes()).retainColumns(secondColSelection).build();
BatchingVisitableView<SchemaApiTestRowResult> rangeRequestResult = table.getRange(rangeRequest);
return rangeRequestResult.immutableCopy().stream().collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn2));
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class SchemaApiTestImpl method getMultipleRowsFirstColumn.
@Override
protected Map<String, Long> getMultipleRowsFirstColumn(Transaction transaction, List<String> rowKeys) {
SchemaApiTestTable table = tableFactory.getSchemaApiTestTable(transaction);
ColumnSelection firstColSelection = SchemaApiTestTable.getColumnSelection(SchemaApiTestTable.SchemaApiTestNamedColumn.COLUMN1);
List<SchemaApiTestRowResult> result = table.getRows(rowKeys.stream().map(SchemaApiTestRow::of).collect(Collectors.toList()), firstColSelection);
return result.stream().collect(Collectors.toMap(entry -> entry.getRowName().getComponent1(), SchemaApiTestTable.SchemaApiTestRowResult::getColumn1));
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class SweepPriorityCalculator method getSweepScores.
private Map<TableReference, Double> getSweepScores(Transaction tx, Set<TableReference> allTables, List<SweepPriority> oldPriorities, List<SweepPriority> newPriorities) {
Set<TableReference> unsweptTables = Sets.difference(allTables, newPriorities.stream().map(SweepPriority::tableRef).collect(Collectors.toSet()));
if (!unsweptTables.isEmpty()) {
// Always sweep unswept tables first
logUnsweptTables(unsweptTables);
return unsweptTables.stream().collect(Collectors.toMap(Function.identity(), tableReference -> 100.0));
}
Map<TableReference, SweepPriority> newPrioritiesByTableName = newPriorities.stream().collect(Collectors.toMap(SweepPriority::tableRef, Function.identity()));
// Compute priority for tables that do have a priority table.
Map<TableReference, Double> scores = new HashMap<>(oldPriorities.size());
Collection<TableReference> toDelete = Lists.newArrayList();
for (SweepPriority oldPriority : oldPriorities) {
TableReference tableReference = oldPriority.tableRef();
if (allTables.contains(tableReference)) {
SweepPriority newPriority = newPrioritiesByTableName.get(tableReference);
scores.put(tableReference, getSweepPriorityScore(oldPriority, newPriority));
} else {
toDelete.add(tableReference);
}
}
// Clean up rows for tables that no longer exist.
sweepPriorityStore.delete(tx, toDelete);
return scores;
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class SerializableTransaction method verifyColumnRanges.
private void verifyColumnRanges(Transaction readOnlyTransaction) {
// verify each set of reads to ensure they are the same.
for (Entry<TableReference, ConcurrentMap<byte[], ConcurrentMap<BatchColumnRangeSelection, byte[]>>> tableAndRange : columnRangeEndsByTable.entrySet()) {
TableReference table = tableAndRange.getKey();
Map<byte[], ConcurrentMap<BatchColumnRangeSelection, byte[]>> columnRangeEnds = tableAndRange.getValue();
Map<Cell, byte[]> writes = writesByTable.get(table);
Map<BatchColumnRangeSelection, List<byte[]>> rangesToRows = Maps.newHashMap();
for (Entry<byte[], ConcurrentMap<BatchColumnRangeSelection, byte[]>> rowAndRangeEnds : columnRangeEnds.entrySet()) {
byte[] row = rowAndRangeEnds.getKey();
Map<BatchColumnRangeSelection, byte[]> rangeEnds = columnRangeEnds.get(row);
for (Entry<BatchColumnRangeSelection, byte[]> e : rangeEnds.entrySet()) {
BatchColumnRangeSelection range = e.getKey();
byte[] rangeEnd = e.getValue();
if (rangeEnd.length != 0 && !RangeRequests.isTerminalRow(false, rangeEnd)) {
range = BatchColumnRangeSelection.create(range.getStartCol(), RangeRequests.getNextStartRow(false, rangeEnd), range.getBatchHint());
}
if (rangesToRows.get(range) != null) {
rangesToRows.get(range).add(row);
} else {
rangesToRows.put(range, ImmutableList.of(row));
}
}
}
for (Entry<BatchColumnRangeSelection, List<byte[]>> e : rangesToRows.entrySet()) {
BatchColumnRangeSelection range = e.getKey();
List<byte[]> rows = e.getValue();
Map<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> result = readOnlyTransaction.getRowsColumnRange(table, rows, range);
for (Entry<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> res : result.entrySet()) {
byte[] row = res.getKey();
BatchingVisitableView<Entry<Cell, byte[]>> bv = BatchingVisitableView.of(res.getValue());
NavigableMap<Cell, ByteBuffer> readsInRange = Maps.transformValues(getReadsInColumnRange(table, row, range), input -> ByteBuffer.wrap(input));
boolean isEqual = bv.transformBatch(input -> filterWritesFromCells(input, writes)).isEqual(readsInRange.entrySet());
if (!isEqual) {
handleTransactionConflict(table);
}
}
}
}
}
use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.
the class SerializableTransaction method throwIfReadWriteConflictForSerializable.
@Override
protected void throwIfReadWriteConflictForSerializable(long commitTimestamp) {
Transaction ro = getReadOnlyTransaction(commitTimestamp);
verifyRanges(ro);
verifyColumnRanges(ro);
verifyCells(ro);
verifyRows(ro);
}
Aggregations