use of org.apache.jute_voltpatches.BinaryOutputArchive in project voltdb by VoltDB.
the class AgreementSite method shipZKDatabaseSnapshot.
private void shipZKDatabaseSnapshot(long joiningAgreementSite, long txnId) throws IOException {
m_recoveryLog.info("Shipping ZK snapshot from " + CoreUtils.hsIdToString(m_hsId) + " to " + CoreUtils.hsIdToString(joiningAgreementSite));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
BinaryOutputArchive boa = new BinaryOutputArchive(dos);
m_server.getZKDatabase().serializeSnapshot(boa);
dos.flush();
byte[] databaseBytes = org.xerial.snappy.Snappy.compress(baos.toByteArray());
ByteBuffer metadata = ByteBuffer.allocate(9);
metadata.put(BINARY_PAYLOAD_SNAPSHOT);
metadata.putLong(txnId);
BinaryPayloadMessage bpm = new BinaryPayloadMessage(metadata.array(), databaseBytes);
m_mailbox.send(joiningAgreementSite, bpm);
m_siteRequestingRecovery = null;
m_recoverBeforeTxn = null;
}
use of org.apache.jute_voltpatches.BinaryOutputArchive in project voltdb by VoltDB.
the class NIOServerCnxn method finishSessionInit.
@Override
public void finishSessionInit(boolean valid) {
// register with JMX
try {
jmxConnectionBean = new ConnectionBean(this, zk);
MBeanRegistry.getInstance().register(jmxConnectionBean, zk.jmxServerBean);
} catch (Exception e) {
LOG.warn("Failed to register with JMX", e);
jmxConnectionBean = null;
}
try {
ConnectResponse rsp = new ConnectResponse(0, valid ? sessionTimeout : // send 0 if session is no
0, // send 0 if session is no
valid ? sessionId : 0, // longer valid
valid ? zk.generatePasswd(sessionId) : new byte[16]);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive bos = BinaryOutputArchive.getArchive(baos);
bos.writeInt(-1, "len");
rsp.serialize(bos, "connect");
baos.close();
ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());
bb.putInt(bb.remaining() - 4).rewind();
sendBuffer(bb);
if (!valid) {
LOG.info("Invalid session 0x" + Long.toHexString(sessionId) + " for client " + sock.socket().getRemoteSocketAddress() + ", probably expired");
sendCloseSession();
} else {
LOG.info("Established session 0x" + Long.toHexString(sessionId) + " with negotiated timeout " + sessionTimeout + " for client " + sock.socket().getRemoteSocketAddress());
}
// Now that the session is ready we can start receiving packets
synchronized (this.factory) {
sk.selector().wakeup();
enableRecv();
}
} catch (Exception e) {
LOG.warn("Exception while establishing session, closing", e);
close();
}
}
use of org.apache.jute_voltpatches.BinaryOutputArchive in project voltdb by VoltDB.
the class NIOServerCnxn method sendResponse.
/*
* (non-Javadoc)
*
* @see org.apache.zookeeper.server.ServerCnxnIface#sendResponse(org.apache.zookeeper.proto.ReplyHeader,
* org.apache.jute.Record, java.lang.String)
*/
@Override
public synchronized void sendResponse(ReplyHeader h, Record r, String tag) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Make space for length
BinaryOutputArchive bos = BinaryOutputArchive.getArchive(baos);
try {
baos.write(fourBytes);
bos.writeRecord(h, "header");
if (r != null) {
bos.writeRecord(r, tag);
}
baos.close();
} catch (IOException e) {
LOG.error("Error serializing response");
}
byte[] b = baos.toByteArray();
ByteBuffer bb = ByteBuffer.wrap(b);
bb.putInt(b.length - 4).rewind();
sendBuffer(bb);
if (h.getXid() > 0) {
synchronized (this) {
outstandingRequests--;
}
// check throttling
synchronized (this.factory) {
if (zk.getInProcess() < factory.outstandingLimit || outstandingRequests < 1) {
sk.selector().wakeup();
enableRecv();
}
}
}
} catch (Exception e) {
LOG.warn("Unexpected exception. Destruction averted.", e);
}
}
Aggregations