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);
}
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);
}
}
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);
}
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();
}
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>());
}
Aggregations