Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Better batching with timelock (#3305)
Browse files Browse the repository at this point in the history
* Better batching with timelock

Internally we were seeing that atm it takes about 2.5 seconds to delete
1k things. This is almost surely exclusively due to the overhead of
calling timelock once per cell.

* better releasenots

* comment

* fix compile
  • Loading branch information
j-baker authored and jeremyk-91 committed Jun 22, 2018
1 parent a4e9547 commit bb36fd1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1757,18 +1757,33 @@ public void deleteRange(final TableReference tableRef, final RangeRequest range)
@Override
public void deleteAllTimestamps(TableReference tableRef, Map<Cell, Long> maxTimestampExclusiveByCell,
boolean deleteSentinels) {
if (maxTimestampExclusiveByCell.isEmpty()) {
return;
}

Map<InetSocketAddress, Map<Cell, Long>> keysByHost = HostPartitioner.partitionMapByHost(
clientPool, maxTimestampExclusiveByCell.entrySet());

// this is required by the interface of the CassandraMutationTimestampProvider, although it exists for tests
long maxTimestampForAllCells = maxTimestampExclusiveByCell.values().stream().mapToLong(x -> x).max().getAsLong();
long rangeTombstoneCassandraTimestamp =
mutationTimestampProvider.getRangeTombstoneTimestamp(maxTimestampForAllCells);
for (Map.Entry<InetSocketAddress, Map<Cell, Long>> entry : keysByHost.entrySet()) {
deleteAllTimestampsOnSingleHost(tableRef, entry.getKey(), entry.getValue(), deleteSentinels);
deleteAllTimestampsOnSingleHost(
tableRef,
entry.getKey(),
entry.getValue(),
deleteSentinels,
rangeTombstoneCassandraTimestamp);
}
}

public void deleteAllTimestampsOnSingleHost(
TableReference tableRef,
InetSocketAddress host,
Map<Cell, Long> maxTimestampExclusiveByCell,
boolean deleteSentinels) {
boolean deleteSentinels,
long rangeTombstoneCassandraTs) {
if (maxTimestampExclusiveByCell.isEmpty()) {
return;
}
Expand All @@ -1778,7 +1793,8 @@ public void deleteAllTimestampsOnSingleHost(

@Override
public Void apply(CassandraClient client) throws Exception {
insertRangeTombstones(client, maxTimestampExclusiveByCell, tableRef, deleteSentinels);
insertRangeTombstones(client, maxTimestampExclusiveByCell, tableRef,
deleteSentinels, rangeTombstoneCassandraTs);
return null;
}

Expand All @@ -1797,11 +1813,11 @@ public String toString() {
}

private void insertRangeTombstones(CassandraClient client, Map<Cell, Long> maxTimestampExclusiveByCell,
TableReference tableRef, boolean deleteSentinel) throws TException {
TableReference tableRef, boolean deleteSentinel, long rangeTombstoneCassandraTs) throws TException {
MutationMap mutationMap = new MutationMap();

maxTimestampExclusiveByCell.forEach((cell, maxTimestampExclusive) -> {
Mutation mutation = getMutation(cell, maxTimestampExclusive, deleteSentinel);
Mutation mutation = getMutation(cell, maxTimestampExclusive, deleteSentinel, rangeTombstoneCassandraTs);

mutationMap.addMutationForCell(cell, tableRef, mutation);
});
Expand All @@ -1810,15 +1826,16 @@ private void insertRangeTombstones(CassandraClient client, Map<Cell, Long> maxTi
deleteConsistency);
}

private Mutation getMutation(Cell cell, long maxTimestampExclusive, boolean deleteSentinel) {
private Mutation getMutation(Cell cell, long maxTimestampExclusive,
boolean deleteSentinel, long rangeTombstoneCassandraTimestamp) {
if (deleteSentinel) {
return Mutations.rangeTombstoneIncludingSentinelForColumn(cell.getColumnName(), maxTimestampExclusive,
mutationTimestampProvider.getRangeTombstoneTimestamp(maxTimestampExclusive));
rangeTombstoneCassandraTimestamp);
}
return Mutations.rangeTombstoneForColumn(
cell.getColumnName(),
maxTimestampExclusive,
mutationTimestampProvider.getRangeTombstoneTimestamp(maxTimestampExclusive));
rangeTombstoneCassandraTimestamp);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions docs/source/release_notes/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ develop
* - Type
- Change

* - |fixed|
- With targeted sweep, We now only call timelock once per set of range tombstones we leave,
rather than once per cell.
(`Pull Request <https://github.com/palantir/atlasdb/pull/3305>`__)

* - |fixed|
- We now consider only one row at a time when getting rows from the KVS with sweepable cells.
(`Pull Request <https://github.com/palantir/atlasdb/pull/3302>`__)
Expand Down

0 comments on commit bb36fd1

Please sign in to comment.