/** * Creates a new unassigned node in the OFFLINE state for the specified * entityGroup. * * <p> * Does not transition nodes from other states. If a node already exists for * this entityGroup, a {@link org.apache.zookeeper.KeeperException.NodeExistsException} will be thrown. * * <p> * Sets a watcher on the unassigned entityGroup node if the method is * successful. * * <p> * This method should only be used during cluster startup and the enabling of * a table. * * @param zkw zk reference * @param entityGroup entityGroup to be created as offline * @param serverName server transition will happen on * @throws org.apache.zookeeper.KeeperException if unexpected zookeeper exception * @throws org.apache.zookeeper.KeeperException.NodeExistsException if node already exists */ public static void createNodeOffline(ZooKeeperWatcher zkw, EntityGroupInfo entityGroup, ServerName serverName) throws KeeperException, KeeperException.NodeExistsException { createNodeOffline(zkw, entityGroup, serverName, EventType.M_ZK_ENTITYGROUP_OFFLINE); }
/** * Creates a znode with OPENED state. * * @param TEST_UTIL * @param entityGroup * @param serverName * @return * @throws java.io.IOException * @throws ZooKeeperConnectionException * @throws org.apache.zookeeper.KeeperException * @throws org.apache.zookeeper.KeeperException.NodeExistsException */ public static ZooKeeperWatcher createAndForceNodeToOpenedState( WaspTestingUtility TEST_UTIL, EntityGroup entityGroup, ServerName serverName) throws ZooKeeperConnectionException, IOException, KeeperException, NodeExistsException { ZooKeeperWatcher zkw = getZooKeeperWatcher(TEST_UTIL); ZKAssign.createNodeOffline(zkw, entityGroup.getEntityGroupInfo(), serverName); int version = ZKAssign.transitionNodeOpening(zkw, entityGroup.getEntityGroupInfo(), serverName); ZKAssign.transitionNodeOpened(zkw, entityGroup.getEntityGroupInfo(), serverName, version); return zkw; }
private void openEntityGroup(Server server, FServerServices rss, FTable ftd, EntityGroupInfo egi) throws IOException, NodeExistsException, KeeperException, DeserializationException { // Create it OFFLINE node, which is what Master set before sending OPEN RPC ZKAssign.createNodeOffline(server.getZooKeeper(), egi, server.getServerName()); OpenEntityGroupHandler openHandler = new OpenEntityGroupHandler(server, rss, egi, ftd); openHandler.process(); // This parse is not used? EntityGroupTransaction.parseFrom(ZKAssign.getData(server.getZooKeeper(), egi.getEncodedName())); // delete the node, which is what Master do after the entityGroup is opened ZKAssign.deleteNode(server.getZooKeeper(), egi.getEncodedName(), EventType.FSERVER_ZK_ENTITYGROUP_OPENED); } }
@Test public void testFailedOpenEntityGroup() throws Exception { Server server = new MockServer(WTU); FServerServices rsServices = new MockFServerServices(); // Create it OFFLINE, which is what it expects ZKAssign.createNodeOffline(server.getZooKeeper(), TEST_EGI, server.getServerName()); // Create the handler OpenEntityGroupHandler handler = new OpenEntityGroupHandler(server, rsServices, TEST_EGI, TEST_FTD) { @Override EntityGroup openEntityGroup() { // Fake failure of opening a entityGroup due to an IOE, which is caught return null; } }; handler.process(); // Handler should have transitioned it to FAILED_OPEN EntityGroupTransaction rt = EntityGroupTransaction.parseFrom(ZKAssign .getData(server.getZooKeeper(), TEST_EGI.getEncodedName())); assertEquals(EventType.FSERVER_ZK_ENTITYGROUP_FAILED_OPEN, rt.getEventType()); }
@Test public void testFailedUpdateMeta() throws Exception { Server server = new MockServer(WTU); FServerServices rsServices = new MockFServerServices(); // Create it OFFLINE, which is what it expects ZKAssign.createNodeOffline(server.getZooKeeper(), TEST_EGI, server.getServerName()); // Create the handler OpenEntityGroupHandler handler = new OpenEntityGroupHandler(server, rsServices, TEST_EGI, TEST_FTD) { @Override boolean updateMeta(final EntityGroup e) { // Fake failure of updating META return false; } }; handler.process(); // Handler should have transitioned it to FAILED_OPEN EntityGroupTransaction rt = EntityGroupTransaction.parseFrom(ZKAssign .getData(server.getZooKeeper(), TEST_EGI.getEncodedName())); assertEquals(EventType.FSERVER_ZK_ENTITYGROUP_FAILED_OPEN, rt.getEventType()); } }
ZKAssign.createNodeOffline(server.getZooKeeper(), egi, server.getServerName());