CreateRequest createRequest = (CreateRequest)op.toRequestRecord(); CreateMode createMode = CreateMode.fromFlag(createRequest.getFlags()); if (createMode.isEphemeral()) { containsEphemeralCreate = true; break; request.request.rewind(); CreateMode createMode = CreateMode.fromFlag(createRequest.getFlags()); if (!createMode.isEphemeral()) { return null;
private void validateCreateRequest(String path, CreateMode createMode, Request request, long ttl) throws KeeperException { if (createMode.isTTL() && !EphemeralType.extendedEphemeralTypesEnabled()) { throw new KeeperException.UnimplementedException(); } try { EphemeralType.validateTTL(createMode, ttl); } catch (IllegalArgumentException e) { throw new BadArgumentsException(path); } if (createMode.isEphemeral()) { // Exception is set when local session failed to upgrade // so we just need to report the error if (request.getException() != null) { throw request.getException(); } zks.sessionTracker.checkGlobalSession(request.sessionId, request.getOwner()); } else { zks.sessionTracker.checkSession(request.sessionId, request.getOwner()); } }
@Test public void testBasicCreateMode() { CreateMode cm = CreateMode.PERSISTENT; Assert.assertEquals(cm.toFlag(), 0); Assert.assertFalse(cm.isEphemeral()); Assert.assertFalse(cm.isSequential()); Assert.assertFalse(cm.isContainer()); cm = CreateMode.EPHEMERAL; Assert.assertEquals(cm.toFlag(), 1); Assert.assertTrue(cm.isEphemeral()); Assert.assertFalse(cm.isSequential()); Assert.assertFalse(cm.isContainer()); cm = CreateMode.PERSISTENT_SEQUENTIAL; Assert.assertEquals(cm.toFlag(), 2); Assert.assertFalse(cm.isEphemeral()); Assert.assertTrue(cm.isSequential()); Assert.assertFalse(cm.isContainer()); cm = CreateMode.EPHEMERAL_SEQUENTIAL; Assert.assertEquals(cm.toFlag(), 3); Assert.assertTrue(cm.isEphemeral()); Assert.assertTrue(cm.isSequential()); Assert.assertFalse(cm.isContainer()); cm = CreateMode.CONTAINER; Assert.assertEquals(cm.toFlag(), 4); Assert.assertFalse(cm.isEphemeral()); Assert.assertFalse(cm.isSequential()); Assert.assertTrue(cm.isContainer()); }
request.setTxn(new CreateTTLTxn(path, data, listACL, newCversion, ttl)); } else { request.setTxn(new CreateTxn(path, data, listACL, createMode.isEphemeral(), newCversion)); if (createMode.isEphemeral()) { s.setEphemeralOwner(request.sessionId);
request.txn = new CreateTxn(path, createRequest.getData(), listACL, createMode.isEphemeral(), newCversion); StatPersisted s = new StatPersisted(); if (createMode.isEphemeral()) { s.setEphemeralOwner(request.sessionId);
public void addChild(ZNode zNode) throws KeeperException { if (createMode.isEphemeral()) { throw new KeeperException.NoChildrenForEphemeralsException(); } if (children.containsKey(zNode.getName())) { throw new KeeperException.NodeExistsException(); } children.put(zNode.getName(), zNode); stat.setNumChildren(children.size()); signalNodeEvent(EventType.NodeChildrenChanged); }
private ZNode( long sessionId, ZNode parent, String name, byte[] data, List<ACL> acl, CreateMode createMode ) { this.parent = parent; this.name = name; this.data = data; this.acl = acl; this.createMode = createMode; stat.setEphemeralOwner(createMode.isEphemeral() ? sessionId : 0); stat.setDataLength((data == null) ? 0 : data.length); stat.setNumChildren(0); stat.setVersion(version.get()); }
/** * Validate that this schema's create mode setting matches and that the data is valid * * @param mode CreateMode being used * @param path the znode full path * @param data data being set * @param acl the creation acls * @throws SchemaViolation if schema's create mode setting does not match or data is invalid */ public void validateCreate(CreateMode mode, String path, byte[] data, List<ACL> acl) { if ( mode.isEphemeral() && (ephemeral == Allowance.CANNOT) ) { throw new SchemaViolation(this, new SchemaViolation.ViolatorData(path, data, acl), "Cannot be ephemeral"); } if ( !mode.isEphemeral() && (ephemeral == Allowance.MUST) ) { throw new SchemaViolation(this, new SchemaViolation.ViolatorData(path, data, acl), "Must be ephemeral"); } if ( mode.isSequential() && (sequential == Allowance.CANNOT) ) { throw new SchemaViolation(this, new SchemaViolation.ViolatorData(path, data, acl), "Cannot be sequential"); } if ( !mode.isSequential() && (sequential == Allowance.MUST) ) { throw new SchemaViolation(this, new SchemaViolation.ViolatorData(path, data, acl), "Must be sequential"); } validateGeneral(path, data, acl); }
/** * Since ZkConnection session is shared in this ZkClient, do not create ephemeral node using a SharedZKClient. */ @Override public String create(final String path, Object datat, final List<ACL> acl, final CreateMode mode) { if (mode.isEphemeral()) { throw new HelixException( "Create ephemeral nodes using a " + SharedZkClient.class.getSimpleName() + " ZkClient is not supported."); } return super.create(path, datat, acl, mode); }
@Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { if ( event.getResultCode() == KeeperException.Code.NONODE.intValue() ) { createNode(); } else { boolean isEphemeral = event.getStat().getEphemeralOwner() != 0; if ( isEphemeral != mode.isEphemeral() ) { log.warn("Existing node ephemeral state doesn't match requested state. Maybe the node was created outside of PersistentNode? " + basePath); } } } };
@Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { if ( event.getResultCode() == KeeperException.Code.NONODE.intValue() ) { createNode(); } else { boolean isEphemeral = event.getStat().getEphemeralOwner() != 0; if ( isEphemeral != mode.isEphemeral() ) { log.warn("Existing node ephemeral state doesn't match requested state. Maybe the node was created outside of PersistentNode? " + basePath); } } } };
@Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { if ( event.getResultCode() == KeeperException.Code.NONODE.intValue() ) { createNode(); } else { boolean isEphemeral = event.getStat().getEphemeralOwner() != 0; if ( isEphemeral != mode.isEphemeral() ) { log.warn("Existing node ephemeral state doesn't match requested state. Maybe the node was created outside of PersistentNode? " + basePath); } } } };
public void ensurePathExists(NodePath path, CreateMode mode, byte[] content) throws ServiceLocatorException, InterruptedException { try { if (!nodeExists(path)) { createNode(path, mode, content); } else { if (mode.isEphemeral()) { deleteNode(path, false); createNode(path, mode, content); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Ephemeral node " + path + " was recreated."); } } else if (LOG.isLoggable(Level.FINE)) { LOG.fine("Node " + path + " already exists."); } if (!Arrays.equals(EMPTY_CONTENT, content) && (content.length != 0)) setNodeData(path, content); } } catch (KeeperException e) { if (!e.code().equals(Code.NODEEXISTS)) { throw locatorException(e); } else { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Some other client created node" + path + " concurrently."); } } } }
public void ensurePathExists(NodePath path, CreateMode mode, byte[] content) throws ServiceLocatorException, InterruptedException { try { if (!nodeExists(path)) { createNode(path, mode, content); } else { if (mode.isEphemeral()) { deleteNode(path, false); createNode(path, mode, content); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Ephemeral node " + path + " was recreated."); } } else if (LOG.isLoggable(Level.FINE)) { LOG.fine("Node " + path + " already exists."); } if (!Arrays.equals(EMPTY_CONTENT, content) && (content.length != 0)) setNodeData(path, content); } } catch (KeeperException e) { if (!e.code().equals(Code.NODEEXISTS)) { throw locatorException(e); } else { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Some other client created node" + path + " concurrently."); } } } }
@Override public Schema schema() { if ( schema == null ) { schema = Schema.builder(path.toSchemaPathPattern()) .dataValidator(this) .ephemeral(createMode.isEphemeral() ? Schema.Allowance.MUST : Schema.Allowance.CANNOT) .canBeDeleted(true) .sequential(createMode.isSequential() ? Schema.Allowance.MUST : Schema.Allowance.CANNOT) .watched(Schema.Allowance.CAN) .build(); } return schema; }
createMode.isEphemeral()); StatPersisted s = new StatPersisted(); if (createMode.isEphemeral()) { s.setEphemeralOwner(request.sessionId);