private void performVersionUpdate(NodeSPI underlyingNode, WorkspaceNode workspaceNode) { if (workspaceNode.isVersioningImplicit()) { if (trace) log.trace("Versioning is implicit; incrementing."); underlyingNode.setVersion(((DefaultDataVersion) workspaceNode.getVersion()).increment()); } else { if (trace) log.trace("Versioning is explicit; not attempting an increment."); underlyingNode.setVersion(workspaceNode.getVersion()); } if (trace) log.trace("Setting version of node " + underlyingNode.getFqn() + " from " + workspaceNode.getVersion() + " to " + underlyingNode.getVersion()); }
public void rollback() { if (targetNode != null) { Object childName = targetNode.getFqn().getLastElement(); if (trace) { log.trace("rollback(parent: " + parentFqn + ", child: " + childName + ", node=" + targetNode + ")"); } if (parentFqn == null || childName == null) { log.error("parent fqn or childName or childNode was null"); return; } NodeSPI parentNode = dataContainer.peek(parentFqn); if (parentNode == null) { log.warn("node " + parentFqn + " not found"); return; } parentNode.addChild(childName, targetNode); targetNode.markAsDeleted(false, true); targetNode.clearDataDirect(); if (originalData != null) targetNode.putAllDirect(originalData); targetNode.setValid(true, true); } } }
if (!n.isValid()) // && configuration.getNodeLockingScheme().isVersionedScheme()) if (n.containsKeyDirect(key)) if (!n.isDataLoaded())
public void rollback() { if (trace) log.trace("rollback(" + globalTransaction + ", " + fqn + ", " + data + ")"); NodeSPI n = dataContainer.peek(fqn, false, true); if (n != null) { n.clearDataDirect(); if (oldData != null) n.putAllDirect(oldData); } } }
private void removeDataLegacy(Fqn fqn) { NodeSPI n = peek(fqn); if (n == null) { log.warn("node " + fqn + " not found"); return; } n.clearDataDirect(); n.setDataLoaded(false); }
if ( !( ( ( NodeSPI ) regionRoot ).getVersion() instanceof NonLockingDataVersion ) ) { ((NodeSPI) regionRoot).setVersion(NonLockingDataVersion.INSTANCE);
if (underlyingNode.getFqn().isRoot()) underlyingNode.setValid(false, true); NodeSPI parent = underlyingNode.getParentDirect(); if (parent == null) parent.removeChildDirect(underlyingNode.getFqn().getLastElement()); if (trace) log.trace("Applying children deltas to parent node " + underlyingNode.getFqn()); Map childNode = underlyingNode.getChildrenMapDirect(); for (Object o : childNode.values()) cn.setValid(false, true); if (!useTombstones) underlyingNode.removeChildDirect(cn.getFqn().getLastElement()); underlyingNode.addChildDirect(childNode); childNode.setValid(true, false); NodeSPI childNode = underlyingNode.getChildDirect(child.getLastElement()); if (childNode != null) childNode.setValid(false, true); if (!useTombstones) underlyingNode.removeChildDirect(child.getLastElement()); updateVersion = underlyingNode.isLockForChildInsertRemove(); underlyingNode.clearDataDirect(); underlyingNode.putAllDirect(mergedData);
nodeSPI = (NodeSPI) dataContainer.getRoot().getChild(fqn); else if (node.getVersion() == null) throw new NullPointerException("Node " + node.getFqn() + " has a null data version, and is of type " + node.getClass().getSimpleName() + ". This command expects versioned nodes."); if (dataVersion != null && node.getVersion().newerThan(dataVersion)) // dataVersion *could* be null if the invalidate was triggered by removing a node that did not exist in the first place. String errMsg = new StringBuilder("Node found, but version is not equal to or less than the expected [").append(dataVersion).append("]. Is [").append(node.getVersion()).append("] instead!").toString(); log.warn(errMsg); throw new DataVersioningException(errMsg); node.setVersion(dataVersion); return null;
if (node.hasChildrenDirect() || fqn.isRoot()) node.clearDataDirect(); node.setDataLoaded(false); return false; parentNode.removeChildDirect(fqn.getLastElement()); parentNode.setChildrenLoaded(false); node.setValid(false, false); node.markAsDeleted(true); return true;
if (node != null && node.isChildrenLoaded()) node.removeChildrenDirect();//getChildrenMapDirect().clear(); node.setChildrenLoaded(true); NodeSPI child = node.addChildDirect(childFqn); if ((isMove || isActivation) && recursive) child.setInternalState(loadData(ctxt, child.getFqn())); child.setDataLoaded(true); loadChildren(child.getFqn(), child, true, isMove, ctxt); node.setChildrenLoaded(true);
private void integrateTransientState(NodeSPI target, ObjectInputStream in) throws Exception target.removeChildrenDirect(); target.clearData(); cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true); cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true); target.putAll(attributes); target.setInternalState(attributes); Fqn tgtFqn = target.getFqn(); boolean move = tgtFqn.isChildOrEquals(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN) && !tferFqn.isChildOrEquals(tgtFqn); target.setDataLoaded(false); target.setChildrenLoaded(false);
if (node.hasChildrenDirect() || fqn.isRoot()) node.clearDataDirect(); node.setDataLoaded(false); return false; parentNode.setChildrenLoaded(false); node.setValid(false, false); node.markAsDeleted(true); node.setDataLoaded(false); node.getDelegationTarget().clear(); return true;
/** * Test if this node needs to be 'undeleted' * reverse the "remove" if the node has been previously removed in the same tx, if this operation is a put() */ public static void manageReverseRemove(InvocationContext ctx, NodeSPI childNode, boolean reverseRemoveCheck, List createdNodes, CommandsFactory commandsFactory) { if (ctx.getGlobalTransaction() != null) //if no tx then reverse remove does not make sense { Fqn fqn = childNode.getFqn(); TransactionContext transactionContext = ctx.getTransactionContext(); boolean needToReverseRemove = reverseRemoveCheck && childNode.isDeleted() && transactionContext != null && transactionContext.getRemovedNodes().contains(fqn); if (!needToReverseRemove) return; childNode.markAsDeleted(false); //if we'll rollback the tx data should be added to the node again Map oldData = new HashMap(childNode.getDataDirect()); PutDataMapCommand command = commandsFactory.buildPutDataMapCommand(ctx.getGlobalTransaction(), fqn, oldData); // txTable.get(gtx).addUndoOperation(command); --- now need to make sure this is added to the normal mods list instead transactionContext.addModification(command); //we're prepared for rollback, now reset the node childNode.clearDataDirect(); if (createdNodes != null) { createdNodes.add(childNode); } } } }
if (newParent == null || newParent.isDeleted()) if (node == null || node.isDeleted()) NodeSPI oldParent = node.getParentDirect(); Object nodeName = toMoveFqn.getLastElement(); oldParent.removeChildDirect(nodeName); newParent.addChild(nodeName, node); adjustFqn(node, newParent.getFqn());
/** * Constructs with a node and workspace. */ public WorkspaceNodeImpl(NodeSPI<K, V> node, TransactionWorkspace workspace, NodeFactory<K, V> nodeFactory) { NodeInvocationDelegate delegate = (NodeInvocationDelegate) node; if (!(delegate.getDelegationTarget() instanceof VersionedNode)) { throw new IllegalArgumentException("node " + delegate.getDelegationTarget() + " not VersionedNode"); } this.node = node; this.workspace = workspace; Map<K, V> nodeData = node.getDataDirect(); if (!nodeData.isEmpty()) optimisticDataMap = new HashMap<K, V>(nodeData); this.version = node.getVersion(); if (version == null) { throw new IllegalStateException("VersionedNode version null"); } initFlags(); this.nodeFactory = nodeFactory; }
if (underlyingNode != null && underlyingNode.isValid() && workspaceNode.isCreated() && workspaceNode.isModified()) if (underlyingNode != null && !underlyingNode.isValid()) 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()); else 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());
/** * Removes the node referenced by the specified Fqn. */ public Object perform(InvocationContext ctx) { if (trace) log.trace("perform(" + globalTransaction + ", " + fqn + ")"); // Find the node targetNode = peekVersioned(ctx); if (targetNode == null || targetNode.isDeleted()) { if (trace) log.trace("node " + fqn + " not found"); return false; } notifyBeforeRemove(targetNode, ctx); boolean found = targetNode.isValid() && !targetNode.isDeleted(); recursivelyMarkAsRemoved(targetNode, ctx); // make sure we clear all data on this node! targetNode.clearDataDirect(); notifyAfterRemove(ctx); return found; }
/** * 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; } }
public Set<NodeLock> acquireAll(Object caller, long timeout, LockType lock_type, boolean excludeInternalFqns) throws LockingException, TimeoutException, InterruptedException { boolean acquired; if (lock_type == LockType.NONE || (excludeInternalFqns && node.getCache().getInternalFqns().contains(getFqn()))) { return Collections.emptySet(); } Set<NodeLock> retval = new HashSet<NodeLock>(); acquired = acquire(caller, timeout, lock_type); if (acquired) { retval.add(this); } for (NodeSPI n : node.getChildrenDirect()) { retval.addAll(n.getLock().acquireAll(caller, timeout, lock_type, excludeInternalFqns)); } return retval; }
Map existingData = nodeSPI.getDataDirect(); nodeSPI.clearDataDirect(); nodeSPI.putAllDirect(data); if (notifier.shouldNotifyOnNodeModified()) notifier.notifyNodeModified(fqn, false, NodeModifiedEvent.ModificationType.PUT_MAP, nodeSPI.getDataDirect(), ctx);