/** * deseriluize from an inputarchive * @param oldTree the tree to be created * @param ia the input archive to be read from * @param sessions the sessions to be created * @throws IOException */ private void deserializeSnapshot(DataTreeV1 oldTree, InputArchive ia, Map<Long, Integer> sessions) throws IOException { int count = ia.readInt("count"); while (count > 0) { long id = ia.readLong("id"); int to = ia.readInt("timeout"); sessions.put(id, to); if (LOG.isTraceEnabled()) { ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, "loadData --- session in archive: " + id + " with timeout: " + to); } count--; } oldTree.deserialize(ia, "tree"); }
/** * validate a session for a client * * @param clientId * the client to be revalidated * @param timeout * the timeout for which the session is valid * @return * @throws IOException */ void validateSession(ServerCnxn cnxn, long clientId, int timeout) throws IOException { LOG.info("Revalidating client: 0x" + Long.toHexString(clientId)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.writeLong(clientId); dos.writeInt(timeout); dos.close(); QuorumPacket qp = new QuorumPacket(Leader.REVALIDATE, -1, baos .toByteArray(), null); pendingRevalidations.put(clientId, cnxn); if (LOG.isTraceEnabled()) { ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, "To validate session 0x" + Long.toHexString(clientId)); } writePacket(qp, true); }
protected void revalidate(QuorumPacket qp) throws IOException { ByteArrayInputStream bis = new ByteArrayInputStream(qp .getData()); DataInputStream dis = new DataInputStream(bis); long sessionId = dis.readLong(); boolean valid = dis.readBoolean(); ServerCnxn cnxn = pendingRevalidations .remove(sessionId); if (cnxn == null) { LOG.warn("Missing session 0x" + Long.toHexString(sessionId) + " for validation"); } else { zk.finishSessionInit(cnxn, valid); } if (LOG.isTraceEnabled()) { ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, "Session 0x" + Long.toHexString(sessionId) + " is valid: " + valid); } }
public static void deserializeSnapshot(DataTree dt,InputArchive ia, Map<Long, Integer> sessions) throws IOException { int count = ia.readInt("count"); while (count > 0) { long id = ia.readLong("id"); int to = ia.readInt("timeout"); sessions.put(id, to); if (LOG.isTraceEnabled()) { ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, "loadData --- session in archive: " + id + " with timeout: " + to); } count--; } dt.deserialize(ia, "tree"); }
private static long getMask(String mask) { long retv = 0; if (mask.equalsIgnoreCase("CLIENT_REQUEST_TRACE_MASK")) { retv = ZooTrace.CLIENT_REQUEST_TRACE_MASK; } else if (mask.equalsIgnoreCase("CLIENT_DATA_PACKET_TRACE_MASK")) { retv = ZooTrace.CLIENT_DATA_PACKET_TRACE_MASK; } else if (mask.equalsIgnoreCase("CLIENT_PING_TRACE_MASK")) { retv = ZooTrace.CLIENT_PING_TRACE_MASK; } else if (mask.equalsIgnoreCase("SERVER_PACKET_TRACE_MASK")) { retv = ZooTrace.SERVER_PACKET_TRACE_MASK; } else if (mask.equalsIgnoreCase("SESSION_TRACE_MASK")) { retv = ZooTrace.SESSION_TRACE_MASK; } else if (mask.equalsIgnoreCase("EVENT_DELIVERY_TRACE_MASK")) { retv = ZooTrace.EVENT_DELIVERY_TRACE_MASK; } else if (mask.equalsIgnoreCase("SERVER_PING_TRACE_MASK")) { retv = ZooTrace.SERVER_PING_TRACE_MASK; } else if (mask.equalsIgnoreCase("WARNING_TRACE_MASK")) { retv = ZooTrace.WARNING_TRACE_MASK; } return retv; }
protected void revalidate(QuorumPacket qp) throws IOException { ByteArrayInputStream bis = new ByteArrayInputStream(qp .getData()); DataInputStream dis = new DataInputStream(bis); long sessionId = dis.readLong(); boolean valid = dis.readBoolean(); ServerCnxn cnxn = pendingRevalidations.remove(sessionId); if (cnxn == null) { LOG.warn("Missing session 0x" + Long.toHexString(sessionId) + " for validation"); } else { zk.finishSessionInit(cnxn, valid); } if (LOG.isTraceEnabled()) { ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, "Session 0x" + Long.toHexString(sessionId) + " is valid: " + valid); } }
@Override public CommandResponse run(ZooKeeperServer zkServer, Map<String, String> kwargs) { CommandResponse response = initializeResponse(); long traceMask; if (!kwargs.containsKey("traceMask")) { response.put("error", "setTraceMask requires long traceMask argument"); return response; } try { traceMask = Long.parseLong(kwargs.get("traceMask")); } catch (NumberFormatException e) { response.put("error", "setTraceMask requires long traceMask argument, got " + kwargs.get("traceMask")); return response; } ZooTrace.setTextTraceLevel(traceMask); response.put("tracemask", traceMask); return response; }
public static void deserializeSnapshot(DataTree dt,InputArchive ia, Map<Long, Integer> sessions) throws IOException { // 读取session个数 int count = ia.readInt("count"); while (count > 0) { // session id long id = ia.readLong("id"); // session超时时间 int to = ia.readInt("timeout"); // 解析session集合 sessions.put(id, to); if (LOG.isTraceEnabled()) { ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, "loadData --- session in archive: " + id + " with timeout: " + to); } count--; } // 反序列化tree dt.deserialize(ia, "tree"); }