use of org.apache.ignite.internal.metastorage.server.Operation in project ignite-3 by apache.
the class RocksDbKeyValueStorage method invoke.
/**
* {@inheritDoc}
*/
@Override
public boolean invoke(Condition condition, Collection<Operation> success, Collection<Operation> failure) {
rwLock.writeLock().lock();
try {
Entry[] entries = getAll(Arrays.asList(condition.keys())).toArray(new Entry[] {});
boolean branch = condition.test(entries);
Collection<Operation> ops = branch ? success : failure;
applyOperations(ops);
return branch;
} catch (RocksDBException e) {
throw new IgniteInternalException(e);
} finally {
rwLock.writeLock().unlock();
}
}
use of org.apache.ignite.internal.metastorage.server.Operation in project ignite-3 by apache.
the class RocksDbKeyValueStorage method applyOperations.
private void applyOperations(Collection<Operation> ops) throws RocksDBException {
long curRev = rev + 1;
boolean modified = false;
long counter = updCntr;
List<byte[]> updatedKeys = new ArrayList<>();
try (WriteBatch batch = new WriteBatch()) {
for (Operation op : ops) {
byte[] key = op.key();
switch(op.type()) {
case PUT:
counter++;
addDataToBatch(batch, key, op.value(), curRev, counter);
updatedKeys.add(key);
modified = true;
break;
case REMOVE:
counter++;
boolean removed = addToBatchForRemoval(batch, key, curRev, counter);
if (!removed) {
counter--;
} else {
updatedKeys.add(key);
}
modified |= removed;
break;
case NO_OP:
break;
default:
throw new IllegalArgumentException("Unknown operation type: " + op.type());
}
}
if (modified) {
for (byte[] key : updatedKeys) {
updateKeysIndex(batch, key, curRev);
}
fillAndWriteBatch(batch, curRev, counter);
}
}
}
Aggregations