Search in sources :

Example 16 with BinaryInputArchive

use of org.apache.jute.BinaryInputArchive in project zookeeper by apache.

the class LoadFromLogNoServerTest method testPad.

/**
 * Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile
 * fixes it.
 */
@Test
public void testPad() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    FileTxnLog txnLog = new FileTxnLog(tmpDir);
    TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123, Time.currentElapsedTime(), ZooDefs.OpCode.create);
    Record txn = new CreateTxn("/Test", new byte[0], null, false, 1);
    txnLog.append(txnHeader, txn);
    FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." + Long.toHexString(txnHeader.getZxid()));
    BinaryInputArchive ia = BinaryInputArchive.getArchive(in);
    FileHeader header = new FileHeader();
    header.deserialize(ia, "fileheader");
    LOG.info("Received magic : {} Expected : {}", header.getMagic(), FileTxnLog.TXNLOG_MAGIC);
    assertTrue(header.getMagic() == FileTxnLog.TXNLOG_MAGIC, "Missing magic number ");
}
Also used : BinaryInputArchive(org.apache.jute.BinaryInputArchive) CreateTxn(org.apache.zookeeper.txn.CreateTxn) FileTxnLog(org.apache.zookeeper.server.persistence.FileTxnLog) Record(org.apache.jute.Record) File(java.io.File) FileHeader(org.apache.zookeeper.server.persistence.FileHeader) FileInputStream(java.io.FileInputStream) TxnHeader(org.apache.zookeeper.txn.TxnHeader) Test(org.junit.jupiter.api.Test)

Example 17 with BinaryInputArchive

use of org.apache.jute.BinaryInputArchive in project zookeeper by apache.

the class ClientCnxnSocket method readConnectResult.

void readConnectResult() throws IOException {
    if (LOG.isTraceEnabled()) {
        StringBuilder buf = new StringBuilder("0x[");
        for (byte b : incomingBuffer.array()) {
            buf.append(Integer.toHexString(b)).append(",");
        }
        buf.append("]");
        if (LOG.isTraceEnabled()) {
            LOG.trace("readConnectResult {} {}", incomingBuffer.remaining(), buf.toString());
        }
    }
    ByteBufferInputStream bbis = new ByteBufferInputStream(incomingBuffer);
    BinaryInputArchive bbia = BinaryInputArchive.getArchive(bbis);
    ConnectResponse conRsp = new ConnectResponse();
    conRsp.deserialize(bbia, "connect");
    // read "is read-only" flag
    boolean isRO = false;
    try {
        isRO = bbia.readBool("readOnly");
    } catch (IOException e) {
        // this is ok -- just a packet from an old server which
        // doesn't contain readOnly field
        LOG.warn("Connected to an old server; r-o mode will be unavailable");
    }
    this.sessionId = conRsp.getSessionId();
    sendThread.onConnected(conRsp.getTimeOut(), this.sessionId, conRsp.getPasswd(), isRO);
}
Also used : BinaryInputArchive(org.apache.jute.BinaryInputArchive) ConnectResponse(org.apache.zookeeper.proto.ConnectResponse) ByteBufferInputStream(org.apache.zookeeper.server.ByteBufferInputStream) IOException(java.io.IOException)

Example 18 with BinaryInputArchive

use of org.apache.jute.BinaryInputArchive in project zookeeper by apache.

the class SaslQuorumAuthLearner method receive.

private QuorumAuthPacket receive(DataInputStream din) throws IOException {
    QuorumAuthPacket authPacket = new QuorumAuthPacket();
    BinaryInputArchive bia = BinaryInputArchive.getArchive(din);
    authPacket.deserialize(bia, QuorumAuth.QUORUM_AUTH_MESSAGE_TAG);
    return authPacket;
}
Also used : BinaryInputArchive(org.apache.jute.BinaryInputArchive) QuorumAuthPacket(org.apache.zookeeper.server.quorum.QuorumAuthPacket)

Example 19 with BinaryInputArchive

use of org.apache.jute.BinaryInputArchive in project zookeeper by apache.

the class QuorumAuth method nextPacketIsAuth.

public static boolean nextPacketIsAuth(DataInputStream din) throws IOException {
    din.mark(32);
    BinaryInputArchive bia = new BinaryInputArchive(din);
    boolean firstIsAuth = (bia.readLong("NO_TAG") == QuorumAuth.QUORUM_AUTH_MAGIC_NUMBER);
    din.reset();
    return firstIsAuth;
}
Also used : BinaryInputArchive(org.apache.jute.BinaryInputArchive)

Example 20 with BinaryInputArchive

use of org.apache.jute.BinaryInputArchive in project zookeeper by apache.

the class TxnLogSource method isTransactionFile.

public static boolean isTransactionFile(String file) throws IOException {
    RandomAccessFileReader reader = new RandomAccessFileReader(new File(file));
    BinaryInputArchive logStream = new BinaryInputArchive(reader);
    FileHeader fhdr = new FileHeader();
    fhdr.deserialize(logStream, "fileheader");
    reader.close();
    return fhdr.getMagic() == FileTxnLog.TXNLOG_MAGIC;
}
Also used : BinaryInputArchive(org.apache.jute.BinaryInputArchive) File(java.io.File) FileHeader(org.apache.zookeeper.server.persistence.FileHeader)

Aggregations

BinaryInputArchive (org.apache.jute.BinaryInputArchive)25 BinaryOutputArchive (org.apache.jute.BinaryOutputArchive)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileHeader (org.apache.zookeeper.server.persistence.FileHeader)7 Test (org.junit.jupiter.api.Test)7 IOException (java.io.IOException)6 FileInputStream (java.io.FileInputStream)5 Record (org.apache.jute.Record)5 ByteBufferInputStream (org.apache.zookeeper.server.ByteBufferInputStream)5 TxnHeader (org.apache.zookeeper.txn.TxnHeader)5 ByteBuffer (java.nio.ByteBuffer)4 EOFException (java.io.EOFException)3 File (java.io.File)3 Adler32 (java.util.zip.Adler32)3 Checksum (java.util.zip.Checksum)3 Timeout (org.junit.jupiter.api.Timeout)3 ACL (org.apache.zookeeper.data.ACL)2 ConnectRequest (org.apache.zookeeper.proto.ConnectRequest)2 ReplyHeader (org.apache.zookeeper.proto.ReplyHeader)2