/** * serialize the snapshot * @param oa the output archive to which the snapshot needs to be serialized * @throws IOException * @throws InterruptedException */ public void serializeSnapshot(OutputArchive oa) throws IOException, InterruptedException { SerializeUtils.serializeSnapshot(getDataTree(), oa, getSessionWithTimeOuts()); }
public void takeSnapshot(){ try { txnLogFactory.save(zkDb.getDataTree(), zkDb.getSessionWithTimeOuts()); } catch (IOException e) { LOG.error("Severe unrecoverable error, exiting", e); // This is a severe error that we cannot recover from, // so we need to exit System.exit(10); } }
/** * serialize the snapshot * @param oa the output archive to which the snapshot needs to be serialized * @throws IOException * @throws InterruptedException */ public void serializeSnapshot(OutputArchive oa) throws IOException, InterruptedException { SerializeUtils.serializeSnapshot(getDataTree(), oa, getSessionWithTimeOuts()); }
/** * deserialize a snapshot from an input archive * @param ia the input archive you want to deserialize from * @throws IOException */ public void deserializeSnapshot(InputArchive ia) throws IOException { clear(); SerializeUtils.deserializeSnapshot(getDataTree(),ia,getSessionWithTimeOuts()); initialized = true; }
@Override protected void registerJMX() { // register with JMX try { jmxDataTreeBean = new DataTreeBean(getZKDatabase().getDataTree()); MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean); } catch (Exception e) { LOG.warn("Failed to register with JMX", e); jmxDataTreeBean = null; } }
@Override protected void registerJMX() { // register with JMX try { jmxDataTreeBean = new DataTreeBean(getZKDatabase().getDataTree()); MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean); } catch (Exception e) { LOG.warn("Failed to register with JMX", e); jmxDataTreeBean = null; } }
@Override protected void registerJMX() { // register with JMX try { jmxDataTreeBean = new DataTreeBean(getZKDatabase().getDataTree()); MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean); } catch (Exception e) { LOG.warn("Failed to register with JMX", e); jmxDataTreeBean = null; } }
public void takeSnapshot(boolean syncSnap){ long start = Time.currentElapsedTime(); try { txnLogFactory.save(zkDb.getDataTree(), zkDb.getSessionWithTimeOuts(), syncSnap); } catch (IOException e) { LOG.error("Severe unrecoverable error, exiting", e); // This is a severe error that we cannot recover from, // so we need to exit System.exit(ExitCode.TXNLOG_ERROR_TAKING_SNAPSHOT.getValue()); } long elapsed = Time.currentElapsedTime() - start; LOG.info("Snapshot taken in " + elapsed + " ms"); ServerMetrics.SNAPSHOT_TIME.add(elapsed); }
@Override public void commandRun() { if (!isZKServerRunning()) { pw.println(ZK_NOT_SERVING); } else { DataTree dt = zkServer.getZKDatabase().getDataTree(); if (len == FourLetterCommands.wchsCmd) { dt.dumpWatchesSummary(pw); } else if (len == FourLetterCommands.wchpCmd) { dt.dumpWatches(pw, true); } else { dt.dumpWatches(pw, false); } pw.println(); } } }
protected void registerJMX() { // register with JMX try { jmxServerBean = new ZooKeeperServerBean(this); MBeanRegistry.getInstance().register(jmxServerBean, null); try { jmxDataTreeBean = new DataTreeBean(zkDb.getDataTree()); MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean); } catch (Exception e) { LOG.warn("Failed to register with JMX", e); jmxDataTreeBean = null; } } catch (Exception e) { LOG.warn("Failed to register with JMX", e); jmxServerBean = null; } }
@Override protected void registerJMX() { // register with JMX try { jmxDataTreeBean = new DataTreeBean(getZKDatabase().getDataTree()); MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean); } catch (Exception e) { LOG.warn("Failed to register with JMX", e); jmxDataTreeBean = null; } }
@Override protected void registerJMX() { // register with JMX try { jmxDataTreeBean = new DataTreeBean(getZKDatabase().getDataTree()); MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean); } catch (Exception e) { LOG.warn("Failed to register with JMX", e); jmxDataTreeBean = null; } }
@Override protected void registerJMX() { // register with JMX try { jmxDataTreeBean = new DataTreeBean(getZKDatabase().getDataTree()); MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean); } catch (Exception e) { LOG.warn("Failed to register with JMX", e); jmxDataTreeBean = null; } }
/** * deserialize a snapshot from an input archive * @param ia the input archive you want to deserialize from * @throws IOException */ public void deserializeSnapshot(InputArchive ia) throws IOException { clear(); SerializeUtils.deserializeSnapshot(getDataTree(),ia,getSessionWithTimeOuts()); initialized = true; }
@Override public CommandResponse run(ZooKeeperServer zkServer, Map<String, String> kwargs) { DataTree dt = zkServer.getZKDatabase().getDataTree(); CommandResponse response = initializeResponse(); response.put("path_to_session_ids", dt.getWatchesByPath().toMap()); return response; } }
@Override public CommandResponse run(ZooKeeperServer zkServer, Map<String, String> kwargs) { DataTree dt = zkServer.getZKDatabase().getDataTree(); CommandResponse response = initializeResponse(); response.putAll(dt.getWatchesSummary().toMap()); return response; } }
@Override public CommandResponse run(ZooKeeperServer zkServer, Map<String, String> kwargs) { DataTree dt = zkServer.getZKDatabase().getDataTree(); CommandResponse response = initializeResponse(); response.put("session_id_to_watched_paths", dt.getWatches().toMap()); return response; } }
private void addSerializeListener(int sid, String parent, String child) { final ZooKeeper zkClient = zk[followerA]; CustomDataTree dt = (CustomDataTree) mt[sid].main.quorumPeer.getZkDb().getDataTree(); dt.addListener(parent, new NodeSerializeListener() { @Override public void nodeSerialized(String path) { try { zkClient.delete(child, -1); LOG.info("Deleted the child node after the parent is serialized"); } catch (Exception e) { LOG.error("Error when deleting node {}", e); } } }); }
@Test(timeout = 30000) public void testMultiWithContainerSimple() throws KeeperException, InterruptedException { Op createContainer = Op.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER); zk.multi(Collections.singletonList(createContainer)); DataTree dataTree = serverFactory.getZooKeeperServer().getZKDatabase().getDataTree(); Assert.assertEquals(dataTree.getContainers().size(), 1); }
/** * Checks if a session is registered with the server as a watcher. * * @param long sessionId the session ID to check * @param path the path to check for watchers * @param type the type of watcher * @return true if the client session is a watcher on path for the type */ private boolean isServerSessionWatcher(long sessionId, String path, WatcherType type) { Set<ServerCnxn> cnxns = new HashSet<>(); CollectionUtils.addAll(cnxns, serverFactory.getConnections().iterator()); for (ServerCnxn cnxn : cnxns) { if (cnxn.getSessionId() == sessionId) { return getServer(serverFactory).getZKDatabase().getDataTree() .containsWatcher(path, type, cnxn); } } return false; } }