use of org.apache.jute_voltpatches.BinaryInputArchive in project voltdb by VoltDB.
the class AgreementSite method processZKSnapshot.
private void processZKSnapshot() {
ByteArrayInputStream bais = new ByteArrayInputStream(m_recoverySnapshot);
try {
DataInputStream dis = new DataInputStream(bais);
BinaryInputArchive bia = new BinaryInputArchive(dis);
m_server.getZKDatabase().deserializeSnapshot(bia);
m_server.createSessionTracker();
} catch (Exception e) {
org.voltdb.VoltDB.crashLocalVoltDB("Error loading agreement database", false, e);
}
m_recoverySnapshot = null;
m_recoveryStage = RecoveryStage.RECOVERED;
m_recovering = false;
m_recoverBeforeTxn = null;
m_recoveryComplete.countDown();
m_agreementLog.info("Loaded ZK snapshot");
}
use of org.apache.jute_voltpatches.BinaryInputArchive in project voltdb by VoltDB.
the class ZooKeeperServer method byteBuffer2Record.
public static void byteBuffer2Record(ByteBuffer bb, Record record) throws IOException {
BinaryInputArchive ia;
ia = BinaryInputArchive.getArchive(new ByteBufferInputStream(bb));
record.deserialize(ia, "request");
}
use of org.apache.jute_voltpatches.BinaryInputArchive in project voltdb by VoltDB.
the class LogFormatter method main.
/**
* @param args
*/
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.err.println("USAGE: LogFormatter log_file");
System.exit(2);
}
FileInputStream fis = new FileInputStream(args[0]);
BinaryInputArchive logStream = BinaryInputArchive.getArchive(fis);
FileHeader fhdr = new FileHeader();
fhdr.deserialize(logStream, "fileheader");
if (fhdr.getMagic() != FileTxnLog.TXNLOG_MAGIC) {
System.err.println("Invalid magic number for " + args[0]);
System.exit(2);
}
System.out.println("ZooKeeper Transactional Log File with dbid " + fhdr.getDbid() + " txnlog format version " + fhdr.getVersion());
int count = 0;
while (true) {
long crcValue;
byte[] bytes;
try {
crcValue = logStream.readLong("crcvalue");
bytes = logStream.readBuffer("txnEntry");
} catch (EOFException e) {
System.out.println("EOF reached after " + count + " txns.");
return;
}
if (bytes.length == 0) {
// Since we preallocate, we define EOF to be an
// empty transaction
System.out.println("EOF reached after " + count + " txns.");
return;
}
Checksum crc = new Adler32();
crc.update(bytes, 0, bytes.length);
if (crcValue != crc.getValue()) {
throw new IOException("CRC doesn't match " + crcValue + " vs " + crc.getValue());
}
InputArchive iab = BinaryInputArchive.getArchive(new ByteArrayInputStream(bytes));
TxnHeader hdr = new TxnHeader();
SerializeUtils.deserializeTxn(iab, hdr);
System.out.println(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG).format(new Date(hdr.getTime())) + " session 0x" + Long.toHexString(hdr.getClientId()) + " cxid 0x" + Long.toHexString(hdr.getCxid()) + " zxid 0x" + Long.toHexString(hdr.getZxid()) + " " + TraceFormatter.op2String(hdr.getType()));
if (logStream.readByte("EOR") != 'B') {
LOG.error("Last transaction was partial.");
throw new EOFException("Last transaction was partial.");
}
count++;
}
}
use of org.apache.jute_voltpatches.BinaryInputArchive in project voltdb by VoltDB.
the class NIOServerCnxn method readConnectRequest.
private void readConnectRequest() throws IOException, InterruptedException {
BinaryInputArchive bia = BinaryInputArchive.getArchive(new ByteBufferInputStream(incomingBuffer));
ConnectRequest connReq = new ConnectRequest();
connReq.deserialize(bia, "connect");
if (LOG.isDebugEnabled()) {
LOG.debug("Session establishment request from client " + sock.socket().getRemoteSocketAddress() + " client's lastZxid is 0x" + Long.toHexString(connReq.getLastZxidSeen()));
}
if (zk == null) {
throw new IOException("ZooKeeperServer not running");
}
if (connReq.getLastZxidSeen() > zk.getZKDatabase().getDataTreeLastProcessedZxid()) {
String msg = "Refusing session request for client " + sock.socket().getRemoteSocketAddress() + " as it has seen zxid 0x" + Long.toHexString(connReq.getLastZxidSeen()) + " our last zxid is 0x" + Long.toHexString(zk.getZKDatabase().getDataTreeLastProcessedZxid()) + " client must try another server";
LOG.info(msg);
throw new CloseRequestException(msg);
}
sessionTimeout = connReq.getTimeOut();
byte[] passwd = connReq.getPasswd();
int minSessionTimeout = zk.getMinSessionTimeout();
if (sessionTimeout < minSessionTimeout) {
sessionTimeout = minSessionTimeout;
}
int maxSessionTimeout = zk.getMaxSessionTimeout();
if (sessionTimeout > maxSessionTimeout) {
sessionTimeout = maxSessionTimeout;
}
// We don't want to receive any packets until we are sure that the
// session is setup
disableRecv();
if (connReq.getSessionId() != 0) {
throw new IOException("Reopening sessions is not supported anymore");
} else {
LOG.info("Client attempting to establish new session at " + sock.socket().getRemoteSocketAddress());
zk.createSession(this, passwd, sessionTimeout);
}
initialized = true;
}
use of org.apache.jute_voltpatches.BinaryInputArchive in project voltdb by VoltDB.
the class NIOServerCnxn method readRequest.
private void readRequest() throws IOException {
// We have the request, now process and setup for next
InputStream bais = new ByteBufferInputStream(incomingBuffer);
BinaryInputArchive bia = BinaryInputArchive.getArchive(bais);
RequestHeader h = new RequestHeader();
h.deserialize(bia, "header");
// Through the magic of byte buffers, txn will not be
// pointing
// to the start of the txn
incomingBuffer = incomingBuffer.slice();
if (h.getType() == OpCode.auth) {
AuthPacket authPacket = new AuthPacket();
ZooKeeperServer.byteBuffer2Record(incomingBuffer, authPacket);
String scheme = authPacket.getScheme();
AuthenticationProvider ap = ProviderRegistry.getProvider(scheme);
if (ap == null || (ap.handleAuthentication(this, authPacket.getAuth()) != KeeperException.Code.OK)) {
if (ap == null) {
LOG.warn("No authentication provider for scheme: " + scheme + " has " + ProviderRegistry.listProviders());
} else {
LOG.warn("Authentication failed for scheme: " + scheme);
}
// send a response...
ReplyHeader rh = new ReplyHeader(h.getXid(), 0, KeeperException.Code.AUTHFAILED.intValue());
sendResponse(rh, null, null);
// ... and close connection
sendCloseSession();
disableRecv();
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Authentication succeeded for scheme: " + scheme);
}
ReplyHeader rh = new ReplyHeader(h.getXid(), 0, KeeperException.Code.OK.intValue());
sendResponse(rh, null, null);
}
return;
} else {
Request si = new Request(this, sessionId, h.getXid(), h.getType(), incomingBuffer, authInfo);
si.setOwner(ServerCnxn.me);
zk.submitRequest(si);
}
if (h.getXid() >= 0) {
synchronized (this) {
outstandingRequests++;
}
synchronized (this.factory) {
// check throttling
if (zk.getInProcess() > factory.outstandingLimit) {
if (LOG.isDebugEnabled()) {
LOG.debug("Throttling recv " + zk.getInProcess());
}
disableRecv();
// following lines should not be needed since we are
// already reading
// } else {
// enableRecv();
}
}
}
}
Aggregations