@Override public void markForUpdate(DataContainer container, boolean writeSkewCheck) { if (isFlagSet(CHANGED)) return; // already copied Fqn fqn = getFqn(); // mark node as changed. setFlag(CHANGED); if (writeSkewCheck) { // check for write skew. InternalNode underlyingNode = container.peekInternalNode(fqn, true); if (underlyingNode != null && underlyingNode != node) { String errormsg = new StringBuilder().append("Detected write skew on Fqn [").append(fqn).append("]. Another process has changed the node since we last read it!").toString(); if (log.isWarnEnabled()) log.warn(errormsg + ". Unable to copy node for update."); throw new DataVersioningException(errormsg); } } // make a backup copy backup = node; node = copyNode(backup); }
/** * Utility method to peek a node and throw an exception if the version isn't what is expected. * * @param ctx context to use * @return node peeked, null if nonexistent * @throws org.jboss.cache.optimistic.DataVersioningException * if there is a version mismatch */ protected NodeSPI peekVersioned(InvocationContext ctx) { NodeSPI n = ctx.lookUpNode(fqn); if (n != null && isVersioned() && n.getVersion().newerThan(dataVersion)) { String errMsg = new StringBuilder("Node found, but version is not equal to or less than the expected [").append(dataVersion).append("]. Is [").append(n.getVersion()).append("] instead!").toString(); throw new DataVersioningException(errMsg); } return n; } }
throw new DataVersioningException(errMsg);
throw new DataVersioningException("Underlying node for " + fqn + " is null, and this node wasn't newly created in this transaction! We have a concurrent deletion event."); throw new DataVersioningException("Transaction attempted to create " + fqn + " anew. It has already been created since this transaction started, by another (possibly remote) transaction. We have a concurrent creation event."); throw new DataVersioningException("Underlying node doesn't exist but a tombstone does; workspace node should be marked as created!"); if (underlyingNode.getVersion().newerThan(workspaceNode.getVersion())) throw new DataVersioningException("Version mismatch for node " + fqn + ": underlying node with version " + workspaceNode.getNode().getVersion() + " is newer than workspace node, with version " + workspaceNode.getVersion()); throw new DataVersioningException("Unable to compare versions since the underlying node has been deleted by a concurrent transaction!"); else if (trace) log.trace("The data node [" + fqn + "] is null, but this is ok since the workspace node is marked as deleted as well"); throw new DataVersioningException("Version mismatch for node " + fqn + ": underlying node with version " + workspaceNode.getNode().getVersion() + " is newer than workspace node, with version " + workspaceNode.getVersion());