Commit e887f339 authored by Benjamin Reed's avatar Benjamin Reed
Browse files

[ 1949253 ] Move to log4j for logging.


git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@670930 13f79535-47bb-0310-9956-ffa450edef68
parent b873f60a
Welcome to ZooKeeper!
-------------------
Run "ant" command in this directory to build the server/client. "zookeeper-dev.jar" will be output to this directory on a successful build.
-------------------
Starting the server:
1) in the conf directory make a copy of zoo_sample.cfg (ie zoo.cfg) and edit as necessary. Default values will support a "standalone" instance.
2) start the server with the following comand line:
java -cp zookeeper-dev.jar:java/lib/log4j-1.2.15.jar:conf com.yahoo.zookeeper.server.quorum.QuorumPeer conf/zoo.cfg
Notice that the server is picking up the log4j.properties file from the conf directory (default).
-----------------------
Starting a client shell
1) run the following command
java -cp zookeeper-dev.jar:java/lib/log4j-1.2.15.jar:conf -Dlog4j.configuration=log4j_console.properties com.yahoo.zookeeper.ZooKeeper <server>:<port>
where server and port correspond to the ZooKeeper configuration.
Notice that the client is picking up the log4j_console.properties file from the conf directory (default).
......@@ -111,6 +111,7 @@
<javac srcdir="${src.dir}" destdir="${build.classes}" target="1.5" source="1.5" debug="on">
<classpath>
<fileset dir="${build.classes}" />
<pathelement path="${lib.dir}/log4j-1.2.15.jar" />
</classpath>
</javac>
<copy todir="${build.classes}">
......
/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "log4j" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
......@@ -32,6 +32,8 @@ import java.util.Random;
import java.util.Set;
import java.util.concurrent.LinkedBlockingQueue;
import org.apache.log4j.Logger;
import com.yahoo.jute.BinaryInputArchive;
import com.yahoo.jute.BinaryOutputArchive;
import com.yahoo.jute.Record;
......@@ -58,6 +60,7 @@ import com.yahoo.zookeeper.proto.SetACLResponse;
import com.yahoo.zookeeper.proto.SetDataResponse;
import com.yahoo.zookeeper.proto.WatcherEvent;
import com.yahoo.zookeeper.server.ByteBufferInputStream;
import com.yahoo.zookeeper.server.ZooKeeperServer;
import com.yahoo.zookeeper.server.ZooLog;
/**
......@@ -67,6 +70,8 @@ import com.yahoo.zookeeper.server.ZooLog;
*
*/
public class ClientCnxn {
private static final Logger LOG = Logger.getLogger(ZooKeeperServer.class);
private ArrayList<InetSocketAddress> serverAddrs = new ArrayList<InetSocketAddress>();
static class AuthData {
......@@ -180,7 +185,7 @@ public class ClientCnxn {
this.bb.putInt(this.bb.capacity() - 4);
this.bb.rewind();
} catch (IOException e) {
ZooLog.logException(e, "this should be impossible!");
LOG.error("this should be impossible!", e);
}
}
}
......@@ -239,7 +244,7 @@ public class ClientCnxn {
final static UncaughtExceptionHandler uncaughtExceptionHandler = new UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
ZooLog.logException(e, "from " + t.getName());
LOG.error("from " + t.getName(), e);
}
};
......@@ -267,8 +272,7 @@ public class ClientCnxn {
rc = p.replyHeader.getErr();
}
if (p.cb == null) {
ZooLog
.logError("Somehow a null cb got to EventThread!");
LOG.error("Somehow a null cb got to EventThread!");
} else if (p.response instanceof ExistsResponse
|| p.response instanceof SetDataResponse
|| p.response instanceof SetACLResponse) {
......@@ -548,7 +552,7 @@ public class ClientCnxn {
}
private void primeConnection(SelectionKey k) throws IOException {
ZooLog.logWarn("Priming connection to "
LOG.warn("Priming connection to "
+ ((SocketChannel) sockKey.channel()));
lastConnectIndex = currentConnectIndex;
ConnectRequest conReq = new ConnectRequest(0, lastZxid,
......@@ -627,7 +631,7 @@ public class ClientCnxn {
sock.configureBlocking(false);
sock.socket().setSoLinger(false, -1);
sock.socket().setTcpNoDelay(true);
ZooLog.logWarn("Trying to connect to " + addr);
LOG.warn("Trying to connect to " + addr);
sockKey = sock.register(selector, SelectionKey.OP_CONNECT);
if (sock.connect(addr)) {
primeConnection(sockKey);
......@@ -697,7 +701,7 @@ public class ClientCnxn {
}
selected.clear();
} catch (Exception e) {
ZooLog.logWarn("Closing: " + e.getMessage());
LOG.warn("Closing: " + e.getMessage());
cleanup();
if (zooKeeper.state.isAlive()) {
waitingEvents.add(new WatcherEvent(Event.EventNone,
......
......@@ -24,9 +24,12 @@ import java.net.Socket;
import java.nio.ByteBuffer;
import java.util.StringTokenizer;
import org.apache.log4j.Logger;
import com.yahoo.zookeeper.server.ZooLog;
public class ServerAdminClient {
private static final Logger LOG = Logger.getLogger(ServerAdminClient.class);
private static long getMask(String mask) {
long retv = 0;
......
......@@ -747,6 +747,7 @@ public class ZooKeeper {
} else if (args.length < 3) {
usage();
}
ZooKeeper zooKeeper = new ZooKeeper(args[0], 5000, new MyWatcher());
boolean watch = processCmd(args, zooKeeper);
if (!watch) {
......
......@@ -24,6 +24,8 @@ import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.log4j.Logger;
import com.yahoo.jute.InputArchive;
import com.yahoo.jute.OutputArchive;
import com.yahoo.jute.Record;
......@@ -51,6 +53,8 @@ import com.yahoo.zookeeper.txn.TxnHeader;
* through the hashtable. The tree is traversed only when serializing to disk.
*/
public class DataTree {
private static final Logger LOG = Logger.getLogger(DataTree.class);
/**
* This hashtable provides a fast lookup to the datanodes. The tree is the
* source of truth and is where all the locking occurs
......@@ -405,8 +409,8 @@ public class DataTree {
// These are expected errors since we take a lazy snapshot
if (initialized
|| (e.getCode() != Code.NoNode && e.getCode() != Code.NodeExists)) {
ZooLog.logWarn(debug);
ZooLog.logException(e);
LOG.warn(debug);
LOG.error("FIXMSG",e);
}
}
return rc;
......@@ -423,7 +427,7 @@ public class DataTree {
+ Long.toHexString(session),
ZooLog.SESSION_TRACE_MASK);
} catch (KeeperException e) {
ZooLog.logException(e);
LOG.error("FIXMSG",e);
}
}
}
......
......@@ -20,6 +20,8 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import org.apache.log4j.Logger;
import com.yahoo.jute.Record;
import com.yahoo.zookeeper.KeeperException;
import com.yahoo.zookeeper.ZooDefs;
......@@ -36,11 +38,11 @@ import com.yahoo.zookeeper.proto.GetChildrenRequest;
import com.yahoo.zookeeper.proto.GetChildrenResponse;
import com.yahoo.zookeeper.proto.GetDataRequest;
import com.yahoo.zookeeper.proto.GetDataResponse;
import com.yahoo.zookeeper.proto.SyncRequest;
import com.yahoo.zookeeper.proto.SyncResponse;
import com.yahoo.zookeeper.proto.ReplyHeader;
import com.yahoo.zookeeper.proto.SetACLResponse;
import com.yahoo.zookeeper.proto.SetDataResponse;
import com.yahoo.zookeeper.proto.SyncRequest;
import com.yahoo.zookeeper.proto.SyncResponse;
import com.yahoo.zookeeper.server.DataTree.ProcessTxnResult;
import com.yahoo.zookeeper.server.NIOServerCnxn.Factory;
import com.yahoo.zookeeper.txn.CreateSessionTxn;
......@@ -56,6 +58,8 @@ import com.yahoo.zookeeper.txn.ErrorTxn;
* outstandingRequests member of ZooKeeperServer.
*/
public class FinalRequestProcessor implements RequestProcessor {
private static final Logger LOG = Logger.getLogger(FinalRequestProcessor.class);
ZooKeeperServer zks;
public FinalRequestProcessor(ZooKeeperServer zks) {
......@@ -63,7 +67,7 @@ public class FinalRequestProcessor implements RequestProcessor {
}
public void processRequest(Request request) {
// ZooLog.logWarn("Zoo>>> cxid = " + request.cxid + " type = " +
// LOG.warn("Zoo>>> cxid = " + request.cxid + " type = " +
// request.type + " id = " + request.sessionId + " cnxn " +
// request.cnxn);
// request.addRQRec(">final");
......@@ -77,7 +81,7 @@ public class FinalRequestProcessor implements RequestProcessor {
while (!zks.outstandingChanges.isEmpty()
&& zks.outstandingChanges.get(0).zxid <= request.zxid) {
if (zks.outstandingChanges.get(0).zxid < request.zxid) {
ZooLog.logError("Zxid outstanding "
LOG.error("Zxid outstanding "
+ zks.outstandingChanges.get(0).zxid
+ " is less than current " + request.zxid);
}
......@@ -91,7 +95,7 @@ public class FinalRequestProcessor implements RequestProcessor {
zks.sessionTracker.addSession(request.sessionId, cst
.getTimeOut());
} else {
ZooLog.logWarn("*****>>>>> Got "
LOG.warn("*****>>>>> Got "
+ request.txn.getClass() + " "
+ request.txn.toString());
}
......@@ -213,15 +217,15 @@ public class FinalRequestProcessor implements RequestProcessor {
} catch (KeeperException e) {
err = e.getCode();
} catch (Exception e) {
ZooLog.logWarn("****************************** " + request);
LOG.warn("****************************** " + request);
StringBuffer sb = new StringBuffer();
ByteBuffer bb = request.request;
bb.rewind();
while (bb.hasRemaining()) {
sb.append(Integer.toHexString(bb.get() & 0xff));
}
ZooLog.logWarn(sb.toString());
ZooLog.logException(e);
LOG.warn(sb.toString());
LOG.error("FIXMSG",e);
err = Code.MarshallingError;
}
ReplyHeader hdr = new ReplyHeader(request.cxid, request.zxid, err);
......@@ -229,7 +233,7 @@ public class FinalRequestProcessor implements RequestProcessor {
try {
request.cnxn.sendResponse(hdr, rsp, "response");
} catch (IOException e) {
ZooLog.logException(e);
LOG.error("FIXMSG",e);
}
}
......
......@@ -22,11 +22,14 @@ import java.io.FileInputStream;
import java.text.DateFormat;
import java.util.Date;
import org.apache.log4j.Logger;
import com.yahoo.jute.BinaryInputArchive;
import com.yahoo.jute.InputArchive;
import com.yahoo.zookeeper.txn.TxnHeader;
public class LogFormatter {
private static final Logger LOG = Logger.getLogger(LogFormatter.class);
/**
* @param args
......@@ -59,7 +62,7 @@ public class LogFormatter {
+ Long.toHexString(hdr.getZxid())
+ " " + TraceFormatter.op2String(hdr.getType()));
if (logStream.readByte("EOR") != 'B') {
ZooLog.logError("Last transaction was partial.");
LOG.error("Last transaction was partial.");
throw new EOFException();
}
}
......
......@@ -36,6 +36,8 @@ import java.util.LinkedList;
import java.util.Set;
import java.util.concurrent.LinkedBlockingQueue;
import org.apache.log4j.Logger;
import com.yahoo.jute.BinaryInputArchive;
import com.yahoo.jute.BinaryOutputArchive;
import com.yahoo.jute.Record;
......@@ -58,6 +60,8 @@ import com.yahoo.zookeeper.server.auth.ProviderRegistry;
* client, but only one thread doing the communication.
*/
public class NIOServerCnxn implements Watcher, ServerCnxn {
private static final Logger LOG = Logger.getLogger(NIOServerCnxn.class);
static public class Factory extends Thread {
ZooKeeperServer zks;
......@@ -145,13 +149,13 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
}
selected.clear();
} catch (Exception e) {
ZooLog.logException(e);
LOG.error("FIXMSG",e);
}
}
ZooLog.logTextTraceMessage("NIOServerCnxn factory exitedloop.",
ZooLog.textTraceMask);
clear();
ZooLog.logError("=====> Goodbye cruel world <======");
LOG.error("=====> Goodbye cruel world <======");
// System.exit(0);
}
......@@ -185,7 +189,7 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
this.join();
} catch (InterruptedException e) {
} catch (Exception e) {
ZooLog.logException(e);
LOG.error("FIXMSG",e);
}
if (zks != null) {
zks.shutdown();
......@@ -251,7 +255,7 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
sk.interestOps(sk.interestOps() | SelectionKey.OP_WRITE);
}
} catch (RuntimeException e) {
ZooLog.logException(e);
LOG.error("FIXMSG",e);
throw e;
}
}
......@@ -378,7 +382,7 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
} catch (CancelledKeyException e) {
close();
} catch (IOException e) {
// ZooLog.logException(e);
// LOG.error("FIXMSG",e);
close();
}
}
......@@ -401,10 +405,10 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
if (ap == null
|| ap.handleAuthentication(this, authPacket.getAuth()) != KeeperException.Code.Ok) {
if (ap == null)
ZooLog.logError("No authentication provider for scheme: "
LOG.error("No authentication provider for scheme: "
+ scheme);
else
ZooLog.logError("Authentication failed for scheme: "
LOG.error("Authentication failed for scheme: "
+ scheme);
// send a response...
ReplyHeader rh = new ReplyHeader(h.getXid(), 0,
......@@ -414,7 +418,7 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
sendBuffer(NIOServerCnxn.closeConn);
disableRecv();
} else {
ZooLog.logError("Authentication succeeded for scheme: "
LOG.error("Authentication succeeded for scheme: "
+ scheme);
ReplyHeader rh = new ReplyHeader(h.getXid(), 0,
KeeperException.Code.Ok);
......@@ -458,13 +462,13 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
.getArchive(new ByteBufferInputStream(incomingBuffer));
ConnectRequest connReq = new ConnectRequest();
connReq.deserialize(bia, "connect");
ZooLog.logWarn("Connected to " + sock.socket().getRemoteSocketAddress()
LOG.warn("Connected to " + sock.socket().getRemoteSocketAddress()
+ " lastZxid " + connReq.getLastZxidSeen());
if (zk == null) {
throw new IOException("ZooKeeperServer not running");
}
if (connReq.getLastZxidSeen() > zk.dataTree.lastProcessedZxid) {
ZooLog.logError("Client has seen "
LOG.error("Client has seen "
+ Long.toHexString(connReq.getLastZxidSeen())
+ " our last zxid is "
+ Long.toHexString(zk.dataTree.lastProcessedZxid));
......@@ -484,10 +488,10 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
if (connReq.getSessionId() != 0) {
setSessionId(connReq.getSessionId());
zk.reopenSession(this, sessionId, passwd, sessionTimeout);
ZooLog.logWarn("Renewing session " + Long.toHexString(sessionId));
LOG.warn("Renewing session " + Long.toHexString(sessionId));
} else {
zk.createSession(this, passwd, sessionTimeout);
ZooLog.logWarn("Creating new session "
LOG.warn("Creating new session "
+ Long.toHexString(sessionId));
}
initialized = true;
......@@ -671,7 +675,7 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
try {
sock.socket().close();
} catch (IOException e) {
ZooLog.logException(e);
LOG.error("FIXMSG",e);
}
try {
sock.close();
......@@ -680,7 +684,7 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
// this section arise.
// factory.selector.wakeup();
} catch (IOException e) {
ZooLog.logException(e);
LOG.error("FIXMSG",e);
}
sock = null;
if (sk != null) {
......@@ -715,7 +719,7 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
}
baos.close();
} catch (IOException e) {
ZooLog.logError("Error serializing response");
LOG.error("Error serializing response");
}
byte b[] = baos.toByteArray();
ByteBuffer bb = ByteBuffer.wrap(b);
......@@ -761,7 +765,7 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());
bb.putInt(bb.remaining() - 4).rewind();
sendBuffer(bb);
ZooLog.logWarn("Finished init of " + Long.toHexString(sessionId)
LOG.warn("Finished init of " + Long.toHexString(sessionId)
+ ": " + valid);
if (!valid) {
sendBuffer(closeConn);
......@@ -772,7 +776,7 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
enableRecv();
}
} catch (Exception e) {
ZooLog.logException(e);
LOG.error("FIXMSG",e);
close();
}
}
......
......@@ -23,6 +23,8 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.concurrent.LinkedBlockingQueue;
import org.apache.log4j.Logger;
import com.yahoo.jute.Record;
import com.yahoo.zookeeper.KeeperException;
import com.yahoo.zookeeper.ZooDefs;
......@@ -55,6 +57,8 @@ import com.yahoo.zookeeper.txn.TxnHeader;
* in the queue to be applied when generating a transaction.
*/
public class PrepRequestProcessor extends Thread implements RequestProcessor {
private static final Logger LOG = Logger.getLogger(PrepRequestProcessor.class);
static boolean skipACL;
static {
skipACL = System.getProperty("zookeeper.skipACL", "no").equals("yes");
......@@ -90,7 +94,7 @@ public class PrepRequestProcessor extends Thread implements RequestProcessor {
pRequest(request);
}
} catch (InterruptedException e) {
ZooLog.logException(e);
LOG.error("FIXMSG",e);
}
ZooLog.logTextTraceMessage("PrepRequestProcessor exited loop!",
ZooLog.textTraceMask);
......@@ -166,7 +170,7 @@ public class PrepRequestProcessor extends Thread implements RequestProcessor {
*/
@SuppressWarnings("unchecked")
protected void pRequest(Request request) {
// ZooLog.logWarn("Prep>>> cxid = " + request.cxid + " type = " +
// LOG.warn("Prep>>> cxid = " + request.cxid + " type = " +
// request.type + " id = " + request.sessionId);
TxnHeader txnHeader = null;
Record txn = null;
......@@ -334,7 +338,7 @@ public class PrepRequestProcessor extends Thread implements RequestProcessor {
path2Delete, null, 0, null));
}
}
ZooLog.logWarn("Processed session termination request for id: "
LOG.warn("Processed session termination request for id: "
+ Long.toHexString(request.sessionId));
break;
case OpCode.sync:
......@@ -351,7 +355,7 @@ public class PrepRequestProcessor extends Thread implements RequestProcessor {
txn = new ErrorTxn(e.getCode());
}
} catch (Exception e) {
ZooLog.logWarn("*********************************" + request);
LOG.warn("*********************************" + request);
StringBuffer sb = new StringBuffer();
ByteBuffer bb = request.request;
if(bb!=null){
......@@ -361,8 +365,8 @@ public class PrepRequestProcessor extends Thread implements RequestProcessor {
}
}else
sb.append("request buffer is null");
ZooLog.logWarn(sb.toString());
ZooLog.logException(e);
LOG.warn(sb.toString());
LOG.error("FIXMSG",e);
if (txnHeader != null) {
txnHeader.setType(OpCode.error);
txn = new ErrorTxn(Code.MarshallingError);
......@@ -403,7 +407,7 @@ public class PrepRequestProcessor extends Thread implements RequestProcessor {
for (Id cid : authInfo) {
AuthenticationProvider ap = ProviderRegistry.getProvider(cid.getScheme());
if (ap == null) {
ZooLog.logError("Missing AuthenticationProvider for "
LOG.error("Missing AuthenticationProvider for "
+ cid.getScheme());
} else if (ap.isAuthenticated()) {
toAdd.add(new ACL(a.getPerms(), cid));
......
......@@ -19,12 +19,12 @@ package com.yahoo.zookeeper.server;
public class ServerConfig {
private int clientPort;
private String dataDir;
private String dataLogDir;
private String dataLogDir;
protected ServerConfig(int port, String dataDir,String dataLogDir) {
this.clientPort = port;
this.dataDir = dataDir;
this.dataLogDir=dataLogDir;
this.dataLogDir=dataLogDir;
}
protected boolean isStandaloneServer(){
return true;
......
......@@ -23,6 +23,8 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.log4j.Logger;
import com.yahoo.zookeeper.KeeperException;
/**
......@@ -32,6 +34,8 @@ import com.yahoo.zookeeper.KeeperException;
* in a given interval.
*/
public class SessionTrackerImpl extends Thread implements SessionTracker {
private static final Logger LOG = Logger.getLogger(SessionTrackerImpl.class);
HashMap<Long, Session> sessionsById = new HashMap<Long, Session>();
HashMap<Long, SessionSet> sessionSets = new HashMap<Long, SessionSet>();
......@@ -126,7 +130,7 @@ public class SessionTrackerImpl extends Thread implements SessionTracker {