Search in sources :

Example 1 with BinaryOutputArchive

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;
}
Also used : BinaryOutputArchive(org.apache.jute_voltpatches.BinaryOutputArchive) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer) BinaryPayloadMessage(org.voltcore.messaging.BinaryPayloadMessage)

Example 2 with BinaryOutputArchive

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();
    }
}
Also used : BinaryOutputArchive(org.apache.jute_voltpatches.BinaryOutputArchive) ConnectResponse(org.apache.zookeeper_voltpatches.proto.ConnectResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer) CancelledKeyException(java.nio.channels.CancelledKeyException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) IOException(java.io.IOException)

Example 3 with BinaryOutputArchive

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);
    }
}
Also used : BinaryOutputArchive(org.apache.jute_voltpatches.BinaryOutputArchive) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) CancelledKeyException(java.nio.channels.CancelledKeyException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) IOException(java.io.IOException)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ByteBuffer (java.nio.ByteBuffer)3 BinaryOutputArchive (org.apache.jute_voltpatches.BinaryOutputArchive)3 IOException (java.io.IOException)2 CancelledKeyException (java.nio.channels.CancelledKeyException)2 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)2 DataOutputStream (java.io.DataOutputStream)1 ConnectResponse (org.apache.zookeeper_voltpatches.proto.ConnectResponse)1 BinaryPayloadMessage (org.voltcore.messaging.BinaryPayloadMessage)1