Search in sources :

Example 1 with ROLLBACK

use of io.atomix.core.map.impl.ConsistentMapOperations.ROLLBACK in project atomix by atomix.

the class ConsistentMapService method rollback.

/**
 * Handles an rollback commit (ha!).
 *
 * @param commit transaction rollback commit
 * @return rollback result
 */
protected RollbackResult rollback(Commit<? extends TransactionRollback> commit) {
    TransactionId transactionId = commit.value().transactionId();
    TransactionScope transactionScope = activeTransactions.remove(transactionId);
    if (transactionScope == null) {
        return RollbackResult.UNKNOWN_TRANSACTION_ID;
    } else if (!transactionScope.isPrepared()) {
        discardTombstones();
        return RollbackResult.OK;
    } else {
        try {
            transactionScope.transactionLog().records().forEach(record -> {
                if (record.type() != MapUpdate.Type.VERSION_MATCH) {
                    preparedKeys.remove(record.key());
                }
            });
            return RollbackResult.OK;
        } finally {
            discardTombstones();
        }
    }
}
Also used : TransactionId(io.atomix.core.transaction.TransactionId) ServiceExecutor(io.atomix.primitive.service.ServiceExecutor) Arrays(java.util.Arrays) TransactionBegin(io.atomix.core.map.impl.ConsistentMapOperations.TransactionBegin) REMOVE_LISTENER(io.atomix.core.map.impl.ConsistentMapOperations.REMOVE_LISTENER) TransactionPrepareAndCommit(io.atomix.core.map.impl.ConsistentMapOperations.TransactionPrepareAndCommit) IS_EMPTY(io.atomix.core.map.impl.ConsistentMapOperations.IS_EMPTY) Remove(io.atomix.core.map.impl.ConsistentMapOperations.Remove) Duration(java.time.Duration) Map(java.util.Map) KEY_SET(io.atomix.core.map.impl.ConsistentMapOperations.KEY_SET) Session(io.atomix.primitive.session.Session) BEGIN(io.atomix.core.map.impl.ConsistentMapOperations.BEGIN) COMMIT(io.atomix.core.map.impl.ConsistentMapOperations.COMMIT) ENTRY_SET(io.atomix.core.map.impl.ConsistentMapOperations.ENTRY_SET) REPLACE_VERSION(io.atomix.core.map.impl.ConsistentMapOperations.REPLACE_VERSION) ADD_LISTENER(io.atomix.core.map.impl.ConsistentMapOperations.ADD_LISTENER) ReplaceVersion(io.atomix.core.map.impl.ConsistentMapOperations.ReplaceVersion) Predicate(java.util.function.Predicate) Collection(java.util.Collection) REMOVE(io.atomix.core.map.impl.ConsistentMapOperations.REMOVE) RemoveValue(io.atomix.core.map.impl.ConsistentMapOperations.RemoveValue) Set(java.util.Set) CONTAINS_KEY(io.atomix.core.map.impl.ConsistentMapOperations.CONTAINS_KEY) PUT_AND_GET(io.atomix.core.map.impl.ConsistentMapOperations.PUT_AND_GET) Versioned(io.atomix.utils.time.Versioned) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ContainsValue(io.atomix.core.map.impl.ConsistentMapOperations.ContainsValue) Preconditions.checkState(com.google.common.base.Preconditions.checkState) BufferOutput(io.atomix.storage.buffer.BufferOutput) List(java.util.List) CHANGE(io.atomix.core.map.impl.ConsistentMapEvents.CHANGE) GET_OR_DEFAULT(io.atomix.core.map.impl.ConsistentMapOperations.GET_OR_DEFAULT) KryoNamespaces(io.atomix.utils.serializer.KryoNamespaces) TransactionPrepare(io.atomix.core.map.impl.ConsistentMapOperations.TransactionPrepare) Get(io.atomix.core.map.impl.ConsistentMapOperations.Get) Serializer(io.atomix.utils.serializer.Serializer) GET(io.atomix.core.map.impl.ConsistentMapOperations.GET) GET_ALL_PRESENT(io.atomix.core.map.impl.ConsistentMapOperations.GET_ALL_PRESENT) REMOVE_VALUE(io.atomix.core.map.impl.ConsistentMapOperations.REMOVE_VALUE) GetOrDefault(io.atomix.core.map.impl.ConsistentMapOperations.GetOrDefault) PUT_IF_ABSENT(io.atomix.core.map.impl.ConsistentMapOperations.PUT_IF_ABSENT) BufferInput(io.atomix.storage.buffer.BufferInput) TransactionCommit(io.atomix.core.map.impl.ConsistentMapOperations.TransactionCommit) Type(io.atomix.core.map.impl.MapUpdate.Type) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CLEAR(io.atomix.core.map.impl.ConsistentMapOperations.CLEAR) Lists(com.google.common.collect.Lists) MapEvent(io.atomix.core.map.MapEvent) Replace(io.atomix.core.map.impl.ConsistentMapOperations.Replace) KryoNamespace(io.atomix.utils.serializer.KryoNamespace) REPLACE_VALUE(io.atomix.core.map.impl.ConsistentMapOperations.REPLACE_VALUE) ROLLBACK(io.atomix.core.map.impl.ConsistentMapOperations.ROLLBACK) Scheduled(io.atomix.utils.concurrent.Scheduled) REMOVE_VERSION(io.atomix.core.map.impl.ConsistentMapOperations.REMOVE_VERSION) TransactionRollback(io.atomix.core.map.impl.ConsistentMapOperations.TransactionRollback) ContainsKey(io.atomix.core.map.impl.ConsistentMapOperations.ContainsKey) Iterator(java.util.Iterator) Commit(io.atomix.primitive.service.Commit) Throwables(com.google.common.base.Throwables) RemoveVersion(io.atomix.core.map.impl.ConsistentMapOperations.RemoveVersion) SIZE(io.atomix.core.map.impl.ConsistentMapOperations.SIZE) Maps(com.google.common.collect.Maps) CONTAINS_VALUE(io.atomix.core.map.impl.ConsistentMapOperations.CONTAINS_VALUE) REPLACE(io.atomix.core.map.impl.ConsistentMapOperations.REPLACE) VALUES(io.atomix.core.map.impl.ConsistentMapOperations.VALUES) PREPARE(io.atomix.core.map.impl.ConsistentMapOperations.PREPARE) Put(io.atomix.core.map.impl.ConsistentMapOperations.Put) PUT(io.atomix.core.map.impl.ConsistentMapOperations.PUT) PREPARE_AND_COMMIT(io.atomix.core.map.impl.ConsistentMapOperations.PREPARE_AND_COMMIT) AbstractPrimitiveService(io.atomix.primitive.service.AbstractPrimitiveService) TransactionLog(io.atomix.core.transaction.TransactionLog) GetAllPresent(io.atomix.core.map.impl.ConsistentMapOperations.GetAllPresent) ReplaceValue(io.atomix.core.map.impl.ConsistentMapOperations.ReplaceValue) TransactionId(io.atomix.core.transaction.TransactionId)

Aggregations

Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Throwables (com.google.common.base.Throwables)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 MapEvent (io.atomix.core.map.MapEvent)1 CHANGE (io.atomix.core.map.impl.ConsistentMapEvents.CHANGE)1 ADD_LISTENER (io.atomix.core.map.impl.ConsistentMapOperations.ADD_LISTENER)1 BEGIN (io.atomix.core.map.impl.ConsistentMapOperations.BEGIN)1 CLEAR (io.atomix.core.map.impl.ConsistentMapOperations.CLEAR)1 COMMIT (io.atomix.core.map.impl.ConsistentMapOperations.COMMIT)1 CONTAINS_KEY (io.atomix.core.map.impl.ConsistentMapOperations.CONTAINS_KEY)1 CONTAINS_VALUE (io.atomix.core.map.impl.ConsistentMapOperations.CONTAINS_VALUE)1 ContainsKey (io.atomix.core.map.impl.ConsistentMapOperations.ContainsKey)1 ContainsValue (io.atomix.core.map.impl.ConsistentMapOperations.ContainsValue)1 ENTRY_SET (io.atomix.core.map.impl.ConsistentMapOperations.ENTRY_SET)1 GET (io.atomix.core.map.impl.ConsistentMapOperations.GET)1 GET_ALL_PRESENT (io.atomix.core.map.impl.ConsistentMapOperations.GET_ALL_PRESENT)1 GET_OR_DEFAULT (io.atomix.core.map.impl.ConsistentMapOperations.GET_OR_DEFAULT)1 Get (io.atomix.core.map.impl.ConsistentMapOperations.Get)1