@Override protected void transactionAborted(final SnapshotBackedWriteTransaction<String> tx) { LOG.debug("Tx: {} is closed.", tx.getIdentifier()); }
private void checkNotReady() { checkState(readyImpl != null, "Transaction %s is no longer open. No further modifications allowed.", getIdentifier()); }
private final void checkNotReady() { checkState(readyImpl != null, "Transaction %s is no longer open. No further modifications allowed.", getIdentifier()); }
@Override public void onComplete(final Throwable failure, final ActorSelection success) throws Throwable { if (failure != null) { LOG.info("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure); transactionAborted(transaction); return; } LOG.debug("Transaction {} resolved to actor {}", transaction.getIdentifier(), success); } }, actorContext.getClientDispatcher());
@Override protected DOMStoreThreePhaseCommitCohort transactionReady(final SnapshotBackedWriteTransaction<String> tx, final DataTreeModification modification) { LOG.debug("Tx: {} is submitted. Modifications: {}", tx.getIdentifier(), modification); return new InMemoryDOMStoreThreePhaseCommitCohort(this, tx, modification); }
@Override @SuppressWarnings("checkstyle:IllegalCatch") public void merge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) { checkNotReady(); final DataTreeModification tree = mutableTree; LOG.debug("Tx: {} Merge: {}:{}", getIdentifier(), path, data); try { tree.merge(path, data); // FIXME: Add checked exception } catch (RuntimeException e) { LOG.error("Tx: {}, failed to write {}:{} in {}", getIdentifier(), path, data, tree, e); // Rethrow original ones if they are subclasses of RuntimeException // or Error Throwables.propagateIfPossible(e); // FIXME: Introduce proper checked exception throw new IllegalArgumentException("Illegal input data.", e); } }
@Override public void close() { @SuppressWarnings("unchecked") final TransactionReadyPrototype<T> wasReady = READY_UPDATER.getAndSet(this, null); if (wasReady != null) { LOG.debug("Store transaction: {} : Closed", getIdentifier()); TREE_UPDATER.lazySet(this, null); wasReady.transactionAborted(this); } else { LOG.debug("Store transaction: {} : Closed after submit", getIdentifier()); } }
@Override public void delete(final YangInstanceIdentifier path) { checkNotReady(); final DataTreeModification tree = mutableTree; LOG.debug("Tx: {} Delete: {}", getIdentifier(), path); try { tree.delete(path); // FIXME: Add checked exception } catch (Exception e) { LOG.error("Tx: {}, failed to delete {} in {}", getIdentifier(), path, tree, e); // Rethrow original ones if they are subclasses of RuntimeException // or Error Throwables.propagateIfPossible(e); // FIXME: Introduce proper checked exception throw new IllegalArgumentException("Illegal path to delete.", e); } }
@Override @SuppressWarnings("checkstyle:IllegalCatch") public void delete(final YangInstanceIdentifier path) { checkNotReady(); final DataTreeModification tree = mutableTree; LOG.debug("Tx: {} Delete: {}", getIdentifier(), path); try { tree.delete(path); // FIXME: Add checked exception } catch (RuntimeException e) { LOG.error("Tx: {}, failed to delete {} in {}", getIdentifier(), path, tree, e); // Rethrow original ones if they are subclasses of RuntimeException // or Error Throwables.propagateIfPossible(e); // FIXME: Introduce proper checked exception throw new IllegalArgumentException("Illegal path to delete.", e); } }
@Override public void write(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) { checkNotReady(); final DataTreeModification tree = mutableTree; LOG.debug("Tx: {} Write: {}:{}", getIdentifier(), path, data); try { tree.write(path, data); // FIXME: Add checked exception } catch (Exception e) { LOG.error("Tx: {}, failed to write {}:{} in {}", getIdentifier(), path, data, tree, e); // Rethrow original ones if they are subclasses of RuntimeException // or Error Throwables.propagateIfPossible(e); // FIXME: Introduce proper checked exception throw new IllegalArgumentException("Illegal input data.", e); } }
@Override public void merge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) { checkNotReady(); final DataTreeModification tree = mutableTree; LOG.debug("Tx: {} Merge: {}:{}", getIdentifier(), path, data); try { tree.merge(path, data); // FIXME: Add checked exception } catch (Exception e) { LOG.error("Tx: {}, failed to write {}:{} in {}", getIdentifier(), path, data, tree, e); // Rethrow original ones if they are subclasses of RuntimeException // or Error Throwables.propagateIfPossible(e); // FIXME: Introduce proper checked exception throw new IllegalArgumentException("Illegal input data.", e); } }
@Override public void close() { @SuppressWarnings("unchecked") final TransactionReadyPrototype<T> wasReady = READY_UPDATER.getAndSet(this, null); if (wasReady != null) { LOG.debug("Store transaction: {} : Closed", getIdentifier()); TREE_UPDATER.lazySet(this, null); wasReady.transactionAborted(this); } else { LOG.debug("Store transaction: {} : Closed after submit", getIdentifier()); } }
@Override @SuppressWarnings("checkstyle:IllegalCatch") public void write(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) { checkNotReady(); final DataTreeModification tree = mutableTree; LOG.debug("Tx: {} Write: {}:{}", getIdentifier(), path, data); try { tree.write(path, data); // FIXME: Add checked exception } catch (RuntimeException e) { LOG.error("Tx: {}, failed to write {}:{} in {}", getIdentifier(), path, data, tree, e); // Rethrow original ones if they are subclasses of RuntimeException // or Error Throwables.propagateIfPossible(e); // FIXME: Introduce proper checked exception throw new IllegalArgumentException("Illegal input data.", e); } }
@Override public void onComplete(final Throwable failure, final Object message) throws Throwable { if (failure != null) { LOG.error("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure); transactionAborted(transaction); } else if (CommitTransactionReply.isSerializedType(message)) { LOG.debug("Transaction {} committed successfully", transaction.getIdentifier()); transactionCommitted(transaction); } else { LOG.error("Transaction {} resulted in unhandled message type {}, aborting", message.getClass()); transactionAborted(transaction); } } }, actorContext.getClientDispatcher());
@Override public DOMStoreThreePhaseCommitCohort ready() { @SuppressWarnings("unchecked") final TransactionReadyPrototype<T> wasReady = READY_UPDATER.getAndSet(this, null); checkState(wasReady != null, "Transaction %s is no longer open", getIdentifier()); LOG.debug("Store transaction: {} : Ready", getIdentifier()); final DataTreeModification tree = mutableTree; TREE_UPDATER.lazySet(this, null); tree.ready(); return wasReady.transactionReady(this, tree); }
@Override @SuppressWarnings("checkstyle:IllegalCatch") public DOMStoreThreePhaseCommitCohort ready() { @SuppressWarnings("unchecked") final TransactionReadyPrototype<T> wasReady = READY_UPDATER.getAndSet(this, null); checkState(wasReady != null, "Transaction %s is no longer open", getIdentifier()); LOG.debug("Store transaction: {} : Ready", getIdentifier()); final DataTreeModification tree = mutableTree; TREE_UPDATER.lazySet(this, null); try { tree.ready(); return wasReady.transactionReady(this, tree, null); } catch (RuntimeException e) { LOG.debug("Store transaction: {}: unexpected failure when readying", getIdentifier(), e); return wasReady.transactionReady(this, tree, e); } }
private Future<Object> initiateCommit(final boolean immediate) { if(operationError != null) { return Futures.failed(operationError); } final ReadyLocalTransaction message = new ReadyLocalTransaction(transaction.getIdentifier(), modification, immediate); return actorContext.executeOperationAsync(leader, message, actorContext.getTransactionCommitOperationTimeout()); }
@Override public final ListenableFuture<Boolean> canCommit() { try { store.validate(modification); LOG.debug("Store Transaction: {} can be committed", getTransaction().getIdentifier()); return CAN_COMMIT_FUTURE; } catch (ConflictingModificationAppliedException e) { LOG.warn("Store Tx: {} Conflicting modification for {}.", getTransaction().getIdentifier(), e.getPath()); warnDebugContext(getTransaction()); return Futures.immediateFailedFuture(new OptimisticLockFailedException("Optimistic lock failed.", e)); } catch (DataValidationFailedException e) { LOG.warn("Store Tx: {} Data Precondition failed for {}.", getTransaction().getIdentifier(), e.getPath(), e); warnDebugContext(getTransaction()); // For debugging purposes, allow dumping of the modification. Coupled with the above // precondition log, it should allow us to understand what went on. LOG.trace("Store Tx: {} modifications: {} tree: {}", modification, store); return Futures.immediateFailedFuture(new TransactionCommitFailedException("Data did not pass validation.", e)); } catch (Exception e) { LOG.warn("Unexpected failure in validation phase", e); return Futures.immediateFailedFuture(e); } }
Future<ActorSelection> initiateCoordinatedCommit() { final Future<Object> messageFuture = initiateCommit(false); final Future<ActorSelection> ret = TransactionReadyReplyMapper.transform(messageFuture, actorContext, transaction.getIdentifier()); ret.onComplete(new OnComplete<ActorSelection>() { @Override public void onComplete(final Throwable failure, final ActorSelection success) throws Throwable { if (failure != null) { LOG.info("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure); transactionAborted(transaction); return; } LOG.debug("Transaction {} resolved to actor {}", transaction.getIdentifier(), success); } }, actorContext.getClientDispatcher()); return ret; }