Search in sources :

Example 6 with ProcessTxnResult

use of org.apache.zookeeper.server.DataTree.ProcessTxnResult in project zookeeper by apache.

the class FileTxnSnapLog method processTransaction.

/**
 * process the transaction on the datatree
 * @param hdr the hdr of the transaction
 * @param dt the datatree to apply transaction to
 * @param sessions the sessions to be restored
 * @param txn the transaction to be applied
 */
public void processTransaction(TxnHeader hdr, DataTree dt, Map<Long, Integer> sessions, Record txn) throws KeeperException.NoNodeException {
    ProcessTxnResult rc;
    switch(hdr.getType()) {
        case OpCode.createSession:
            sessions.put(hdr.getClientId(), ((CreateSessionTxn) txn).getTimeOut());
            if (LOG.isTraceEnabled()) {
                ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, "playLog --- create session in log: 0x" + Long.toHexString(hdr.getClientId()) + " with timeout: " + ((CreateSessionTxn) txn).getTimeOut());
            }
            // give dataTree a chance to sync its lastProcessedZxid
            rc = dt.processTxn(hdr, txn);
            break;
        case OpCode.closeSession:
            sessions.remove(hdr.getClientId());
            if (LOG.isTraceEnabled()) {
                ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, "playLog --- close session in log: 0x" + Long.toHexString(hdr.getClientId()));
            }
            rc = dt.processTxn(hdr, txn);
            break;
        default:
            rc = dt.processTxn(hdr, txn);
    }
    /*
         * Snapshots are lazily created. So when a snapshot is in progress,
         * there is a chance for later transactions to make into the
         * snapshot. Then when the snapshot is restored, NONODE/NODEEXISTS
         * errors could occur. It should be safe to ignore these.
         */
    if (rc.err != Code.OK.intValue()) {
        LOG.debug("Ignoring processTxn failure hdr: {}, error: {}, path: {}", hdr.getType(), rc.err, rc.path);
    }
}
Also used : CreateSessionTxn(org.apache.zookeeper.txn.CreateSessionTxn) ProcessTxnResult(org.apache.zookeeper.server.DataTree.ProcessTxnResult)

Aggregations

ProcessTxnResult (org.apache.zookeeper.server.DataTree.ProcessTxnResult)6 CreateSessionTxn (org.apache.zookeeper.txn.CreateSessionTxn)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 Record (org.apache.jute.Record)1 KeeperException (org.apache.zookeeper.KeeperException)1 Code (org.apache.zookeeper.KeeperException.Code)1 SessionMovedException (org.apache.zookeeper.KeeperException.SessionMovedException)1 MultiOperationRecord (org.apache.zookeeper.MultiOperationRecord)1 MultiResponse (org.apache.zookeeper.MultiResponse)1 Op (org.apache.zookeeper.Op)1 OpResult (org.apache.zookeeper.OpResult)1 CheckResult (org.apache.zookeeper.OpResult.CheckResult)1 CreateResult (org.apache.zookeeper.OpResult.CreateResult)1 DeleteResult (org.apache.zookeeper.OpResult.DeleteResult)1 ErrorResult (org.apache.zookeeper.OpResult.ErrorResult)1 GetChildrenResult (org.apache.zookeeper.OpResult.GetChildrenResult)1