Search in sources :

Example 1 with ErrorTxn

use of org.apache.zookeeper.txn.ErrorTxn in project zookeeper by apache.

the class LeaderRequestProcessor method processRequest.

@Override
public void processRequest(Request request) throws RequestProcessorException {
    // Check if this is a local session and we are trying to create
    // an ephemeral node, in which case we upgrade the session
    Request upgradeRequest = null;
    try {
        upgradeRequest = lzks.checkUpgradeSession(request);
    } catch (KeeperException ke) {
        if (request.getHdr() != null) {
            LOG.debug("Updating header");
            request.getHdr().setType(OpCode.error);
            request.setTxn(new ErrorTxn(ke.code().intValue()));
        }
        request.setException(ke);
        LOG.info("Error creating upgrade request " + ke.getMessage());
    } catch (IOException ie) {
        LOG.error("Unexpected error in upgrade", ie);
    }
    if (upgradeRequest != null) {
        nextProcessor.processRequest(upgradeRequest);
    }
    nextProcessor.processRequest(request);
}
Also used : ErrorTxn(org.apache.zookeeper.txn.ErrorTxn) Request(org.apache.zookeeper.server.Request) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 2 with ErrorTxn

use of org.apache.zookeeper.txn.ErrorTxn in project zookeeper by apache.

the class ObserverRequestProcessor method processRequest.

/**
     * Simply queue the request, which will be processed in FIFO order.
     */
public void processRequest(Request request) {
    if (!finished) {
        Request upgradeRequest = null;
        try {
            upgradeRequest = zks.checkUpgradeSession(request);
        } catch (KeeperException ke) {
            if (request.getHdr() != null) {
                request.getHdr().setType(OpCode.error);
                request.setTxn(new ErrorTxn(ke.code().intValue()));
            }
            request.setException(ke);
            LOG.info("Error creating upgrade request", ke);
        } catch (IOException ie) {
            LOG.error("Unexpected error in upgrade", ie);
        }
        if (upgradeRequest != null) {
            queuedRequests.add(upgradeRequest);
        }
        queuedRequests.add(request);
    }
}
Also used : ErrorTxn(org.apache.zookeeper.txn.ErrorTxn) Request(org.apache.zookeeper.server.Request) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 3 with ErrorTxn

use of org.apache.zookeeper.txn.ErrorTxn in project zookeeper by apache.

the class Zab1_0Test method testInitialAcceptedCurrent.

@Test
public void testInitialAcceptedCurrent() throws Exception {
    File tmpDir = File.createTempFile("test", ".dir", testData);
    tmpDir.delete();
    tmpDir.mkdir();
    try {
        FileTxnSnapLog logFactory = new FileTxnSnapLog(tmpDir, tmpDir);
        File version2 = new File(tmpDir, "version-2");
        version2.mkdir();
        logFactory.save(new DataTree(), new ConcurrentHashMap<Long, Integer>());
        long zxid = ZxidUtils.makeZxid(3, 3);
        logFactory.append(new Request(1, 1, ZooDefs.OpCode.error, new TxnHeader(1, 1, zxid, 1, ZooDefs.OpCode.error), new ErrorTxn(1), zxid));
        logFactory.commit();
        ZKDatabase zkDb = new ZKDatabase(logFactory);
        QuorumPeer peer = new QuorumPeer();
        peer.setZKDatabase(zkDb);
        peer.setTxnFactory(logFactory);
        peer.getLastLoggedZxid();
        Assert.assertEquals(3, peer.getAcceptedEpoch());
        Assert.assertEquals(3, peer.getCurrentEpoch());
        Assert.assertEquals(3, Integer.parseInt(readContentsOfFile(new File(version2, QuorumPeer.CURRENT_EPOCH_FILENAME))));
        Assert.assertEquals(3, Integer.parseInt(readContentsOfFile(new File(version2, QuorumPeer.ACCEPTED_EPOCH_FILENAME))));
    } finally {
        TestUtils.deleteFileRecursively(tmpDir);
    }
}
Also used : ErrorTxn(org.apache.zookeeper.txn.ErrorTxn) DataTree(org.apache.zookeeper.server.DataTree) Request(org.apache.zookeeper.server.Request) File(java.io.File) ZKDatabase(org.apache.zookeeper.server.ZKDatabase) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog) TxnHeader(org.apache.zookeeper.txn.TxnHeader) Test(org.junit.Test)

Example 4 with ErrorTxn

use of org.apache.zookeeper.txn.ErrorTxn in project zookeeper by apache.

the class SerializeUtils method deserializeTxn.

public static Record deserializeTxn(byte[] txnBytes, TxnHeader hdr) throws IOException {
    final ByteArrayInputStream bais = new ByteArrayInputStream(txnBytes);
    InputArchive ia = BinaryInputArchive.getArchive(bais);
    hdr.deserialize(ia, "hdr");
    bais.mark(bais.available());
    Record txn = null;
    switch(hdr.getType()) {
        case OpCode.createSession:
            // This isn't really an error txn; it just has the same
            // format. The error represents the timeout
            txn = new CreateSessionTxn();
            break;
        case OpCode.closeSession:
            return null;
        case OpCode.create:
        case OpCode.create2:
            txn = new CreateTxn();
            break;
        case OpCode.createTTL:
            txn = new CreateTTLTxn();
            break;
        case OpCode.createContainer:
            txn = new CreateContainerTxn();
            break;
        case OpCode.delete:
        case OpCode.deleteContainer:
            txn = new DeleteTxn();
            break;
        case OpCode.reconfig:
        case OpCode.setData:
            txn = new SetDataTxn();
            break;
        case OpCode.setACL:
            txn = new SetACLTxn();
            break;
        case OpCode.error:
            txn = new ErrorTxn();
            break;
        case OpCode.multi:
            txn = new MultiTxn();
            break;
        default:
            throw new IOException("Unsupported Txn with type=%d" + hdr.getType());
    }
    if (txn != null) {
        try {
            txn.deserialize(ia, "txn");
        } catch (EOFException e) {
            // perhaps this is a V0 Create
            if (hdr.getType() == OpCode.create) {
                CreateTxn create = (CreateTxn) txn;
                bais.reset();
                CreateTxnV0 createv0 = new CreateTxnV0();
                createv0.deserialize(ia, "txn");
                // cool now make it V1. a -1 parentCVersion will
                // trigger fixup processing in processTxn
                create.setPath(createv0.getPath());
                create.setData(createv0.getData());
                create.setAcl(createv0.getAcl());
                create.setEphemeral(createv0.getEphemeral());
                create.setParentCVersion(-1);
            } else {
                throw e;
            }
        }
    }
    return txn;
}
Also used : CreateContainerTxn(org.apache.zookeeper.txn.CreateContainerTxn) MultiTxn(org.apache.zookeeper.txn.MultiTxn) InputArchive(org.apache.jute.InputArchive) BinaryInputArchive(org.apache.jute.BinaryInputArchive) SetDataTxn(org.apache.zookeeper.txn.SetDataTxn) IOException(java.io.IOException) CreateTxnV0(org.apache.zookeeper.txn.CreateTxnV0) CreateTTLTxn(org.apache.zookeeper.txn.CreateTTLTxn) DeleteTxn(org.apache.zookeeper.txn.DeleteTxn) CreateSessionTxn(org.apache.zookeeper.txn.CreateSessionTxn) CreateTxn(org.apache.zookeeper.txn.CreateTxn) ErrorTxn(org.apache.zookeeper.txn.ErrorTxn) ByteArrayInputStream(java.io.ByteArrayInputStream) EOFException(java.io.EOFException) Record(org.apache.jute.Record) SetACLTxn(org.apache.zookeeper.txn.SetACLTxn)

Example 5 with ErrorTxn

use of org.apache.zookeeper.txn.ErrorTxn in project zookeeper by apache.

the class PrepRequestProcessorTest method testPRequest.

@Test
public void testPRequest() throws Exception {
    pLatch = new CountDownLatch(1);
    processor = new PrepRequestProcessor(zks, new MyRequestProcessor());
    Request foo = new Request(null, 1l, 1, OpCode.create, ByteBuffer.allocate(3), null);
    processor.pRequest(foo);
    Assert.assertEquals("Request should have marshalling error", new ErrorTxn(KeeperException.Code.MARSHALLINGERROR.intValue()), outcome.getTxn());
    Assert.assertTrue("request hasn't been processed in chain", pLatch.await(5, TimeUnit.SECONDS));
}
Also used : ErrorTxn(org.apache.zookeeper.txn.ErrorTxn) SetDataRequest(org.apache.zookeeper.proto.SetDataRequest) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

ErrorTxn (org.apache.zookeeper.txn.ErrorTxn)9 IOException (java.io.IOException)7 KeeperException (org.apache.zookeeper.KeeperException)6 Record (org.apache.jute.Record)4 TxnHeader (org.apache.zookeeper.txn.TxnHeader)4 ByteBuffer (java.nio.ByteBuffer)3 Request (org.apache.zookeeper.server.Request)3 CreateContainerTxn (org.apache.zookeeper.txn.CreateContainerTxn)3 CreateTTLTxn (org.apache.zookeeper.txn.CreateTTLTxn)3 CreateTxn (org.apache.zookeeper.txn.CreateTxn)3 DeleteTxn (org.apache.zookeeper.txn.DeleteTxn)3 MultiTxn (org.apache.zookeeper.txn.MultiTxn)3 SetACLTxn (org.apache.zookeeper.txn.SetACLTxn)3 SetDataTxn (org.apache.zookeeper.txn.SetDataTxn)3 Stat (org.apache.zookeeper.data.Stat)2 SetDataRequest (org.apache.zookeeper.proto.SetDataRequest)2 ChangeRecord (org.apache.zookeeper.server.ZooKeeperServer.ChangeRecord)2 CheckVersionTxn (org.apache.zookeeper.txn.CheckVersionTxn)2 CreateSessionTxn (org.apache.zookeeper.txn.CreateSessionTxn)2 Txn (org.apache.zookeeper.txn.Txn)2