zk request processing class PrepRequestProcessor

Keywords: Programming Session Attribute

As the first request processor of leader, PrepRequestProcessor can identify whether the current client request is a transaction request. If so, it will carry out a series of preprocessing, create the request transaction header, transaction body, session detection, ACL check and version detection.

attribute

 

Construction method

Method

Submitted request queue

LinkedBlockingQueue<Request> submittedRequests = new LinkedBlockingQueue<Request>();

Next processor

private final RequestProcessor nextProcessor;

zk services

ZooKeeperServer zks;

Constructor

public PrepRequestProcessor(ZooKeeperServer zks, RequestProcessor nextProcessor) {
    super(
        "ProcessThread(sid:" + zks.getServerId()
        + " cport:" + zks.getClientPort()
        + "):", zks.getZooKeeperServerListener());
    this.nextProcessor = nextProcessor;
    this.zks = zks;
}

//Processing request
public void run() {
    try {
        while (true) {
            ServerMetrics.getMetrics().PREP_PROCESSOR_QUEUE_SIZE.add(submittedRequests.size());
           //Take out the request information
            Request request = submittedRequests.take();
            ServerMetrics.getMetrics().PREP_PROCESSOR_QUEUE_TIME
                .add(Time.currentElapsedTime() - request.prepQueueStartTime);
            long traceMask = ZooTrace.CLIENT_REQUEST_TRACE_MASK;
            if (request.type == OpCode.ping) {
                traceMask = ZooTrace.CLIENT_PING_TRACE_MASK;
            }
            if (LOG.isTraceEnabled()) {
                ZooTrace.logRequest(LOG, traceMask, 'P', request, "");
            }
            if (Request.requestOfDeath == request) {
                break;
            }

            request.prepStartTime = Time.currentElapsedTime();
            pRequest(request);
        }
    } catch (RequestProcessorException e) {
        if (e.getCause() instanceof XidRolloverException) {
            LOG.info(e.getCause().getMessage());
        }
        handleException(this.getName(), e);
    } catch (Exception e) {
        handleException(this.getName(), e);
    }
    LOG.info("PrepRequestProcessor exited loop!");
}

The main method is to re process the request and establish the transaction request by request type. Different types of processing methods are different.

pRequest(request);

Transaction request: createContainer, create, create2, createTTL, deleteContainer,

delete

Non transactional request:...

pRequest2TxnCreate(int type, Request request, Record record, boolean deserialize) throws IOException, KeeperException;

Posted by bigray on Mon, 21 Oct 2019 13:06:36 -0700