Search in sources :

Example 31 with Request

use of org.apache.zookeeper.server.Request in project zookeeper by apache.

the class CommitProcessorMetricsTest method testPendingSessionQueueSize.

@Test
public void testPendingSessionQueueSize() throws Exception {
    setupProcessors(0, 0);
    // one write request for session 1
    Request req1 = createWriteRequest(1L, 1);
    processRequestWithWait(req1);
    // two write requests for session 2
    Request req2 = createWriteRequest(2L, 2);
    processRequestWithWait(req2);
    Request req3 = createWriteRequest(2L, 3);
    processRequestWithWait(req3);
    commitWithWait(req1);
    // there are two sessions with pending requests
    checkMetrics("pending_session_queue_size", 2L, 2L, 2d, 1, 2);
    commitWithWait(req2);
    // there is on session with pending requests
    checkMetrics("pending_session_queue_size", 1L, 2L, 1.5d, 2, 3);
    commitWithWait(req3);
    // there is one session with pending requests
    checkMetrics("pending_session_queue_size", 1L, 2L, 1.333d, 3, 4);
}
Also used : Request(org.apache.zookeeper.server.Request) Test(org.junit.jupiter.api.Test)

Example 32 with Request

use of org.apache.zookeeper.server.Request in project zookeeper by apache.

the class FollowerRequestProcessor method processRequest.

public void processRequest(Request request) {
    if (!finished) {
        // Before sending the request, check if the request requires a
        // global session and what we have is a local session. If so do
        // an upgrade.
        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 33 with Request

use of org.apache.zookeeper.server.Request in project zookeeper by apache.

the class FollowerZooKeeperServer method logRequest.

public void logRequest(TxnHeader hdr, Record txn) {
    Request request = new Request(hdr.getClientId(), hdr.getCxid(), hdr.getType(), hdr, txn, hdr.getZxid());
    if ((request.zxid & 0xffffffffL) != 0) {
        pendingTxns.add(request);
    }
    syncProcessor.processRequest(request);
}
Also used : Request(org.apache.zookeeper.server.Request)

Example 34 with Request

use of org.apache.zookeeper.server.Request in project zookeeper by apache.

the class SessionUpgradeQuorumTest method testOnlyUpgradeSessionOnce.

@Test
public void testOnlyUpgradeSessionOnce() throws IOException, InterruptedException, KeeperException {
    // create a client, and create an ephemeral node to trigger the
    // upgrading process
    final String node = "/node-1";
    ZooKeeper zk = new ZooKeeper("127.0.0.1:" + clientPorts[0], ClientBase.CONNECTION_TIMEOUT, this);
    waitForOne(zk, States.CONNECTED);
    long sessionId = zk.getSessionId();
    QuorumZooKeeperServer server = (QuorumZooKeeperServer) mt[0].main.quorumPeer.getActiveServer();
    Request create1 = createEphemeralRequest("/data-1", sessionId);
    Request create2 = createEphemeralRequest("/data-2", sessionId);
    assertNotNull(server.checkUpgradeSession(create1), "failed to upgrade on a ephemeral create");
    assertNull(server.checkUpgradeSession(create2), "tried to upgrade again");
    // clean al the setups and close the zk
    zk.close();
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) CreateRequest(org.apache.zookeeper.proto.CreateRequest) Request(org.apache.zookeeper.server.Request) Test(org.junit.jupiter.api.Test)

Example 35 with Request

use of org.apache.zookeeper.server.Request in project zookeeper by apache.

the class SessionUpgradeQuorumTest method createEphemeralRequest.

private Request createEphemeralRequest(String path, long sessionId) throws IOException {
    ByteArrayOutputStream boas = new ByteArrayOutputStream();
    BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas);
    CreateRequest createRequest = new CreateRequest(path, "data".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL.toFlag());
    createRequest.serialize(boa, "request");
    ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray());
    return new Request(null, sessionId, 1, ZooDefs.OpCode.create2, bb, new ArrayList<Id>());
}
Also used : BinaryOutputArchive(org.apache.jute.BinaryOutputArchive) CreateRequest(org.apache.zookeeper.proto.CreateRequest) CreateRequest(org.apache.zookeeper.proto.CreateRequest) Request(org.apache.zookeeper.server.Request) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Id(org.apache.zookeeper.data.Id) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Request (org.apache.zookeeper.server.Request)51 Test (org.junit.jupiter.api.Test)25 CreateRequest (org.apache.zookeeper.proto.CreateRequest)15 IOException (java.io.IOException)9 ByteBuffer (java.nio.ByteBuffer)9 GetDataRequest (org.apache.zookeeper.proto.GetDataRequest)9 SetDataRequest (org.apache.zookeeper.proto.SetDataRequest)9 TxnHeader (org.apache.zookeeper.txn.TxnHeader)9 HashSet (java.util.HashSet)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 BinaryOutputArchive (org.apache.jute.BinaryOutputArchive)6 Record (org.apache.jute.Record)6 KeeperException (org.apache.zookeeper.KeeperException)5 SetDataTxn (org.apache.zookeeper.txn.SetDataTxn)5 Id (org.apache.zookeeper.data.Id)4 ErrorTxn (org.apache.zookeeper.txn.ErrorTxn)4 OutputArchive (org.apache.jute.OutputArchive)3 ZooKeeper (org.apache.zookeeper.ZooKeeper)3 TxnLogEntry (org.apache.zookeeper.server.TxnLogEntry)3 QuorumVerifier (org.apache.zookeeper.server.quorum.flexible.QuorumVerifier)3