@Override public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws BackendException { for (Map.Entry<String, Map<StaticBuffer, KCVMutation>> storeMut : mutations.entrySet()) { KeyColumnValueStore store = stores.get(storeMut.getKey()); Preconditions.checkNotNull(store); for (Map.Entry<StaticBuffer, KCVMutation> keyMut : storeMut.getValue().entrySet()) { store.mutate(keyMut.getKey(), keyMut.getValue().getAdditions(), keyMut.getValue().getDeletions(), txh); } } }
@Override public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws BackendException { final Map<String, KVMutation> converted = new HashMap<>(mutations.size()); for (Map.Entry<String, Map<StaticBuffer, KCVMutation>> storeEntry : mutations.entrySet()) { OrderedKeyValueStoreAdapter store = openDatabase(storeEntry.getKey()); Preconditions.checkNotNull(store); KVMutation mut = new KVMutation(); for (Map.Entry<StaticBuffer, KCVMutation> entry : storeEntry.getValue().entrySet()) { StaticBuffer key = entry.getKey(); KCVMutation mutation = entry.getValue(); if (mutation.hasAdditions()) { for (Entry addition : mutation.getAdditions()) { mut.addition(store.concatenate(key,addition)); } } if (mutation.hasDeletions()) { for (StaticBuffer del : mutation.getDeletions()) { mut.deletion(store.concatenate(key, del)); } } } converted.put(storeEntry.getKey(), mut); } manager.mutateMany(converted, txh); }
@Override public Collection<MutateWorker> createMutationWorkers(final Map<StaticBuffer, KCVMutation> mutationMap, final DynamoDbStoreTransaction txh) { final List<MutateWorker> workers = new LinkedList<>(); for (Map.Entry<StaticBuffer, KCVMutation> entry : mutationMap.entrySet()) { final StaticBuffer hashKey = entry.getKey(); final KCVMutation mutation = entry.getValue(); // Filter out deletions that are also added - TODO why use a set? final Set<StaticBuffer> add = mutation.getAdditions().stream() .map(Entry::getColumn).collect(Collectors.toSet()); final List<StaticBuffer> mutableDeletions = mutation.getDeletions().stream() .filter(del -> !add.contains(del)) .collect(Collectors.toList()); if (mutation.hasAdditions()) { workers.addAll(createWorkersForAdditions(hashKey, mutation.getAdditions(), txh)); } if (!mutableDeletions.isEmpty()) { workers.addAll(createWorkersForDeletions(hashKey, mutableDeletions, txh)); } } return workers; }
public Map<String, ExpectedAttributeValue> build(final KCVMutation mutation) { final Map<String, ExpectedAttributeValue> expected = Maps.newHashMapWithExpectedSize(mutation.getTotalMutations()); for (Entry addedColumn : mutation.getAdditions()) { final StaticBuffer columnKey = addedColumn.getColumn(); addExpectedValueIfPresent(columnKey, expected); } for (StaticBuffer deletedKey : mutation.getDeletions()) { addExpectedValueIfPresent(deletedKey, expected); } return expected; }
for (StaticBuffer b : mutation.getDeletions()) {
private void mutateManyLogged(final Map<String, Map<StaticBuffer, KCVMutation>> mutations, final StoreTransaction txh) throws BackendException { final MaskedTimestamp commitTime = new MaskedTimestamp(txh); final BatchStatement batchStatement = new BatchStatement(Type.LOGGED); batchStatement.setConsistencyLevel(getTransaction(txh).getWriteConsistencyLevel()); batchStatement.addAll(Iterator.ofAll(mutations.entrySet()).flatMap(tableNameAndMutations -> { final String tableName = tableNameAndMutations.getKey(); final Map<StaticBuffer, KCVMutation> tableMutations = tableNameAndMutations.getValue(); final CQLKeyColumnValueStore columnValueStore = Option.of(this.openStores.get(tableName)) .getOrElseThrow(() -> new IllegalStateException("Store cannot be found: " + tableName)); return Iterator.ofAll(tableMutations.entrySet()).flatMap(keyAndMutations -> { final StaticBuffer key = keyAndMutations.getKey(); final KCVMutation keyMutations = keyAndMutations.getValue(); final Iterator<Statement> deletions = Iterator.of(commitTime.getDeletionTime(this.times)) .flatMap(deleteTime -> Iterator.ofAll(keyMutations.getDeletions()).map(deletion -> columnValueStore.deleteColumn(key, deletion, deleteTime))); final Iterator<Statement> additions = Iterator.of(commitTime.getAdditionTime(this.times)) .flatMap(addTime -> Iterator.ofAll(keyMutations.getAdditions()).map(addition -> columnValueStore.insertColumn(key, addition, addTime))); return Iterator.concat(deletions, additions); }); })); final Future<ResultSet> result = Future.fromJavaFuture(this.executorService, this.session.executeAsync(batchStatement)); result.await(); if (result.isFailure()) { throw EXCEPTION_MAPPER.apply(result.getCause().get()); } sleepAfterWrite(txh, commitTime); }
new SingleUpdateBuilder().deletions(mutation.getDeletions()) .additions(mutation.getAdditions()) .build();
private void mutateManyUnlogged(final Map<String, Map<StaticBuffer, KCVMutation>> mutations, final StoreTransaction txh) throws BackendException { final MaskedTimestamp commitTime = new MaskedTimestamp(txh); final Future<Seq<ResultSet>> result = Future.sequence(this.executorService, Iterator.ofAll(mutations.entrySet()).flatMap(tableNameAndMutations -> { final String tableName = tableNameAndMutations.getKey(); final Map<StaticBuffer, KCVMutation> tableMutations = tableNameAndMutations.getValue(); final CQLKeyColumnValueStore columnValueStore = Option.of(this.openStores.get(tableName)) .getOrElseThrow(() -> new IllegalStateException("Store cannot be found: " + tableName)); return Iterator.ofAll(tableMutations.entrySet()).flatMap(keyAndMutations -> { final StaticBuffer key = keyAndMutations.getKey(); final KCVMutation keyMutations = keyAndMutations.getValue(); final Iterator<Statement> deletions = Iterator.of(commitTime.getDeletionTime(this.times)) .flatMap(deleteTime -> Iterator.ofAll(keyMutations.getDeletions()).map(deletion -> columnValueStore.deleteColumn(key, deletion, deleteTime))); final Iterator<Statement> additions = Iterator.of(commitTime.getAdditionTime(this.times)) .flatMap(addTime -> Iterator.ofAll(keyMutations.getAdditions()).map(addition -> columnValueStore.insertColumn(key, addition, addTime))); return Iterator.concat(deletions, additions) .grouped(this.batchSize) .map(group -> Future.fromJavaFuture(this.executorService, this.session.executeAsync( new BatchStatement(Type.UNLOGGED) .addAll(group) .setConsistencyLevel(getTransaction(txh).getWriteConsistencyLevel())))); }); })); result.await(); if (result.isFailure()) { throw EXCEPTION_MAPPER.apply(result.getCause().get()); } sleepAfterWrite(txh, commitTime); }