@Override public SoftLock<T> copyForWrite(SoftLock<T> obj) { T oldValue = valueCopier.copyForWrite(obj.getOldValue()); XAValueHolder<T> valueHolder = obj.getNewValueHolder(); XAValueHolder<T> newValueHolder = valueHolder == null ? null : new XAValueHolder<>(valueHolder, valueCopier.copyForWrite(valueHolder .get())); return new SoftLock<>(obj.getTransactionId(), oldValue, newValueHolder); }
@Override public SoftLock<T> read(ByteBuffer binary) throws ClassNotFoundException, SerializerException { SoftLock<T> serializedSoftLock = softLockSerializerRef.get().read(binary); return serializedSoftLock.copyAfterDeserialization(valueSerializer, serializedSoftLock); }
@Override public ByteBuffer serialize(SoftLock<T> softLock) throws SerializerException { return softLockSerializerRef.get().serialize(softLock.copyForSerialization(valueSerializer)); }
@Override public Duration getExpiryForCreation(K key, SoftLock<V> softLock) { if (softLock.getTransactionId() != null) { // phase 1 prepare, create -> forever return ExpiryPolicy.INFINITE; } else { // phase 2 commit, or during a TX's lifetime, create -> some time Duration duration; try { duration = configuredExpiry.getExpiryForCreation(key, softLock.getOldValue()); } catch (RuntimeException re) { LOGGER.error("Expiry computation caused an exception - Expiry duration will be 0 ", re); return Duration.ZERO; } return duration; } }
@Override public Duration getExpiryForUpdate(K key, Supplier<? extends SoftLock<V>> oldSoftLockSupplier, SoftLock<V> newSoftLock) { SoftLock<V> oldSoftLock = oldSoftLockSupplier.get(); if (oldSoftLock.getTransactionId() == null) { if (oldSoftLock.getOldValue() == null) { duration = configuredExpiry.getExpiryForCreation(key, oldSoftLock.getOldValue()); } catch (RuntimeException re) { LOGGER.error("Expiry computation caused an exception - Expiry duration will be 0 ", re); } else { V value = oldSoftLock.getNewValueHolder() == null ? null : oldSoftLock .getNewValueHolder().get(); Duration duration; try {
protected SoftLock<V> copyAfterDeserialization(Serializer<V> valueSerializer, SoftLock<V> serializedSoftLock) throws ClassNotFoundException { V oldValue = null; if (serializedSoftLock.oldValueSerialized != null) { oldValue = valueSerializer.read(ByteBuffer.wrap(serializedSoftLock.oldValueSerialized)); } XAValueHolder<V> newValueHolder = null; if (this.newValueHolder != null) { newValueHolder = this.newValueHolder.copyAfterDeserialization(valueSerializer); } return new SoftLock<>(transactionId, oldValue, newValueHolder); }
StoreEventSourceWrapper(StoreEventSource<K, SoftLock<V>> underlying) { this.underlying = underlying; underlying.addEventFilter((type, key, oldValue, newValue) -> { if (newValue != null) { return newValue.getOldValue() != null; } else if (oldValue != null) { return oldValue.getOldValue() != null; } return false; }); }
for (K key : keys) { SoftLock<V> preparedSoftLock = getFromUnderlyingStore(key); V oldValue = preparedSoftLock == null ? null : preparedSoftLock.getOldValue(); SoftLock<V> definitiveSoftLock = oldValue == null ? null : new SoftLock<>(null, oldValue, null); if (preparedSoftLock.getTransactionId() != null && !preparedSoftLock.getTransactionId().equals(transactionId)) { LOGGER.debug("rollback skipping prepared softlock with non-matching TX ID (concurrent modification?)"); evictFromUnderlyingStore(key);
for (K key : keys) { SoftLock<V> preparedSoftLock = getFromUnderlyingStore(key); XAValueHolder<V> newValueHolder = preparedSoftLock == null ? null : preparedSoftLock.getNewValueHolder(); SoftLock<V> definitiveSoftLock = newValueHolder == null ? null : new SoftLock<>(null, newValueHolder.get(), null); if (preparedSoftLock.getTransactionId() != null && !preparedSoftLock.getTransactionId().equals(transactionId)) { LOGGER.debug("commit skipping prepared softlock with non-matching TX ID (concurrent modification?)"); evictFromUnderlyingStore(key);
currentContext.addCommand(key, new StoreEvictCommand<>(softLockValueHolder.get().getOldValue())); xaValueHolder = new XAValueHolder<>(softLockValueHolder, softLockValueHolder.get().getNewValueHolder().get()); } else { if (updated) { xaValueHolder = currentContext.newValueHolderOf(key); } else { xaValueHolder = new XAValueHolder<>(softLockValueHolder, softLockValueHolder.get().getOldValue());
@Override public boolean equals(SoftLock<T> object, ByteBuffer binary) throws ClassNotFoundException, SerializerException { return object.equals(read(binary)); } }
private static boolean isInDoubt(SoftLock<?> softLock) { return softLock.getTransactionId() != null; }
protected SoftLock<V> copyForSerialization(Serializer<V> valueSerializer) { ByteBuffer serializedOldValue = null; if (oldValue != null) { serializedOldValue = valueSerializer.serialize(oldValue); } XAValueHolder<V> serializedXaValueHolder = null; if (newValueHolder != null) { serializedXaValueHolder = newValueHolder.copyForSerialization(valueSerializer); } return new SoftLock<>(transactionId, serializedOldValue, serializedXaValueHolder); }
@Override public V getOldValue() { SoftLock<V> oldValue = delegate.getOldValue(); if (oldValue == null) { return null; } else { return oldValue.getOldValue(); } } }
for (K key : keys) { SoftLock<V> preparedSoftLock = getFromUnderlyingStore(key); V oldValue = preparedSoftLock == null ? null : preparedSoftLock.getOldValue(); SoftLock<V> definitiveSoftLock = oldValue == null ? null : new SoftLock<>(null, oldValue, null); if (preparedSoftLock.getTransactionId() != null && !preparedSoftLock.getTransactionId().equals(transactionId)) { LOGGER.debug("rollback skipping prepared softlock with non-matching TX ID (concurrent modification?)"); evictFromUnderlyingStore(key);
for (K key : keys) { SoftLock<V> preparedSoftLock = getFromUnderlyingStore(key); XAValueHolder<V> newValueHolder = preparedSoftLock == null ? null : preparedSoftLock.getNewValueHolder(); SoftLock<V> definitiveSoftLock = newValueHolder == null ? null : new SoftLock<>(null, newValueHolder.get(), null); if (preparedSoftLock.getTransactionId() != null && !preparedSoftLock.getTransactionId().equals(transactionId)) { LOGGER.debug("commit skipping prepared softlock with non-matching TX ID (concurrent modification?)"); evictFromUnderlyingStore(key);
@Override public Duration getExpiryForAccess(K key, Supplier<? extends SoftLock<V>> softLock) { if (softLock.get().getTransactionId() != null) { // phase 1 prepare, access -> forever return ExpiryPolicy.INFINITE; } else { // phase 2 commit, or during a TX's lifetime, access -> some time Duration duration; try { duration = configuredExpiry.getExpiryForAccess(key, () -> softLock.get().getOldValue()); } catch (RuntimeException re) { LOGGER.error("Expiry computation caused an exception - Expiry duration will be 0 ", re); return Duration.ZERO; } return duration; } }
@Override public Duration getExpiryForUpdate(K key, Supplier<? extends SoftLock<V>> oldSoftLockSupplier, SoftLock<V> newSoftLock) { SoftLock<V> oldSoftLock = oldSoftLockSupplier.get(); if (oldSoftLock.getTransactionId() == null) { if (oldSoftLock.getOldValue() == null) { duration = configuredExpiry.getExpiryForCreation(key, oldSoftLock.getOldValue()); } catch (RuntimeException re) { LOGGER.error("Expiry computation caused an exception - Expiry duration will be 0 ", re); } else { V value = oldSoftLock.getNewValueHolder() == null ? null : oldSoftLock .getNewValueHolder().get(); Duration duration; try {
currentContext.addCommand(key, new StoreEvictCommand<>(softLockValueHolder.get().getOldValue())); xaValueHolder = new XAValueHolder<>(softLockValueHolder, softLockValueHolder.get().getNewValueHolder().get()); } else { if (updated) { xaValueHolder = currentContext.newValueHolderOf(key); } else { xaValueHolder = new XAValueHolder<>(softLockValueHolder, softLockValueHolder.get().getOldValue());
@Override public boolean equals(SoftLock<T> object, ByteBuffer binary) throws SerializerException, ClassNotFoundException { return object.equals(read(binary)); }