public static void copyStatPersisted(StatPersisted from, StatPersisted to) { to.setAversion(from.getAversion()); to.setCtime(from.getCtime()); to.setCversion(from.getCversion()); to.setCzxid(from.getCzxid()); to.setMtime(from.getMtime()); to.setMzxid(from.getMzxid()); to.setPzxid(from.getPzxid()); to.setVersion(from.getVersion()); to.setEphemeralOwner(from.getEphemeralOwner()); }
/** * convert the old stat to new stat * * @param oldStat the old stat * @return the new stat */ private StatPersisted convertStat(StatPersistedV1 oldStat) { StatPersisted stat = new StatPersisted(); stat.setAversion(oldStat.getAversion()); stat.setCtime(oldStat.getCtime()); stat.setCversion(oldStat.getCversion()); stat.setCzxid(oldStat.getCzxid()); stat.setEphemeralOwner(oldStat.getEphemeralOwner()); stat.setMtime(oldStat.getMtime()); stat.setMzxid(oldStat.getMzxid()); stat.setVersion(oldStat.getVersion()); return stat; }
/** * @param path * @param data * @param acl * @param ephemeralOwner the session id that owns this node. -1 indicates this is not an ephemeral * node. * @param zxid * @param time * @return the patch of the created node * @throws KeeperException */ public String createNode( String path, byte data[], List<ACL> acl, long ephemeralOwner, long zxid, long time) throws KeeperException.NoNodeException, KeeperException.NodeExistsException { int lastSlash = path.lastIndexOf('/'); String parentName = path.substring(0, lastSlash); String childName = path.substring(lastSlash + 1); StatPersisted stat = new StatPersisted(); stat.setCtime(time); stat.setMtime(time); stat.setCzxid(zxid); stat.setMzxid(zxid); stat.setPzxid(zxid); stat.setVersion(0); stat.setAversion(0); stat.setEphemeralOwner(ephemeralOwner); DataNode parent = nodes.get(parentName); if (parent == null) { throw new KeeperException.NoNodeException(); } synchronized (parent) { if (parent.children.contains(childName)) { throw new KeeperException.NodeExistsException(); } int cver = parent.stat.getCversion(); cver++; parent.stat.setCversion(cver); parent.stat.setPzxid(zxid); Long longval = convertAcls(acl); DataNode child = new DataNode(parent, data, longval, stat); parent.children.add(childName); nodes.put(path, child); if (ephemeralOwner != 0) { HashSet<String> list = ephemerals.get(ephemeralOwner); if (list == null) { list = new HashSet<String>(); ephemerals.put(ephemeralOwner, list); } synchronized (list) { list.add(path); } } } // now check if its one of the zookeeper node child if (parentName.startsWith(quotaZookeeper)) { // now check if its the limit node if (Quotas.limitNode.equals(childName)) { // this is the limit node // get the parent and add it to the trie pTrie.addPath(parentName.substring(quotaZookeeper.length())); } if (Quotas.statNode.equals(childName)) { updateQuotaForPath(parentName.substring(quotaZookeeper.length())); } } // also check to update the quotas for this node String lastPrefix = pTrie.findMaxPrefix(path); if (!rootZookeeper.equals(lastPrefix) && !("".equals(lastPrefix))) { // ok we have some match and need to update updateCount(lastPrefix, 1); updateBytes(lastPrefix, data == null ? 0 : data.length); } dataWatches.triggerWatch(path, Event.EventType.NodeCreated); childWatches.triggerWatch( parentName.equals("") ? "/" : parentName, Event.EventType.NodeChildrenChanged); return path; }