Package edu.brown.hstore.txns

Examples of edu.brown.hstore.txns.LocalTransaction


        }
        // -------------------------------
        // LOCAL TRANSACTION
        // -------------------------------
        else if (is_remote == false) {
            LocalTransaction local_ts = (LocalTransaction)ts;
           
            // If the transaction is local, store the result directly in the local TransactionState
            if (status == Status.OK) {
                if (trace.val)
                    LOG.trace(String.format("%s - Storing %d dependency results locally for successful work fragment",
                              ts, result.size()));
                assert(result.size() == outputDepIds.length);
                DependencyTracker otherTracker = this.hstore_site.getDependencyTracker(ts.getBasePartition());
                for (int i = 0; i < outputDepIds.length; i++) {
                    if (trace.val)
                        LOG.trace(String.format("%s - Storing DependencyId #%d [numRows=%d]\n%s",
                                  ts, outputDepIds[i], result.dependencies[i].getRowCount(),
                                  result.dependencies[i]));
                    try {
                        otherTracker.addResult(local_ts, this.partitionId, outputDepIds[i], result.dependencies[i]);
                    } catch (Throwable ex) {
//                        ex.printStackTrace();
                        String msg = String.format("Failed to stored Dependency #%d for %s [idx=%d, fragmentId=%d]",
                                                   outputDepIds[i], ts, i, fragmentIds[i]);
                        LOG.error(String.format("%s - WorkFragment:%d\nExpectedIds:%s\nOutputDepIds: %s\nResultDepIds: %s\n%s",
                                  msg, fragment.hashCode(),
                                  fragment.getOutputDepIdList(), Arrays.toString(outputDepIds),
                                  Arrays.toString(result.depIds), fragment));
                        throw new ServerFaultException(msg, ex);
                    }
                } // FOR
            } else {
                local_ts.setPendingError(error, true);
            }
        }
        // -------------------------------
        // REMOTE TRANSACTION
        // -------------------------------
View Full Code Here


                            useAfterQueue = false;
                            continue;
                        }
                        // Otherwise it's as speculative txn.
                        // Let's figure out what we need to do with it.
                        LocalTransaction spec_ts = (LocalTransaction)next;
                        boolean shouldCommit = false;
                        long spec_token = spec_ts.getFirstUndoToken(this.partitionId);
                        if (debug.val)
                            LOG.debug(String.format("Speculative Txn %s [undoToken=%d, %s]",
                                      spec_ts, spec_token, spec_ts.getSpeculationType()));
                       
                        // Speculative txns should never be executed without an undo token
                        assert(spec_token != HStoreConstants.DISABLE_UNDO_LOGGING_TOKEN);
                        assert(spec_ts.isSpeculative()) : spec_ts + " is not marked as speculative!";
                       
                        // If the speculative undoToken is null, then this txn didn't execute
                        // any queries. That means we can always commit it
                        if (spec_token == HStoreConstants.NULL_UNDO_LOGGING_TOKEN) {
                            if (debug.val)
                                LOG.debug(String.format("Speculative Txn %s has a null undoToken at partition %d",
                                          spec_ts, this.partitionId));
                            toCommit.add(spec_ts);
                            continue;
                        }
                       
                        // Otherwise, look to see if this txn was speculatively executed before the
                        // first undo token of the distributed txn. That means we know that this guy
                        // didn't read any modifications made by the dtxn.
                        if (spec_token < dtxnUndoToken) {
                            if (debug.val)
                                LOG.debug(String.format("Speculative Txn %s has an undoToken less than the dtxn %s " +
                                          "at partition %d [%d < %d]",
                                          spec_ts, ts, this.partitionId, spec_token, dtxnUndoToken));
                            shouldCommit = true;
                        }
                        // Ok so at this point we know that our spec txn came *after* the distributed txn
                        // started. So we need to use our checker to see whether there is a conflict
                        else if (this.specExecSkipAfter || this.specExecChecker.hasConflictAfter(ts, spec_ts, this.partitionId) == false) {
                            if (debug.val)
                                LOG.debug(String.format("Speculative Txn %s does not conflict with dtxn %s at partition %d",
                                          spec_ts, ts, this.partitionId));
                            shouldCommit = true;
                        }
                        if (useAfterQueue == false || shouldCommit == false) {
                            ClientResponseImpl spec_cr = spec_ts.getClientResponse();
                            MispredictionException error = new MispredictionException(spec_ts.getTransactionId(),
                                                                                      spec_ts.getTouchedPartitions());
                            spec_ts.setPendingError(error, false);
                            spec_cr.setStatus(Status.ABORT_SPECULATIVE);
                            (useAfterQueue ? toAbortAfter : toAbortBefore).add(spec_ts);
                        } else {
                            toCommit.add(spec_ts);
                        }
                       
                    } // FOR
                   
                    // (1) Process all of the aborting txns that need to come *before*
                    //     we abort the dtxn
                    if (toAbortBefore.isEmpty() == false)
                        this.processClientResponseBatch(toAbortBefore, Status.ABORT_SPECULATIVE);
                   
                    // (2) Now abort the dtxn
                    this.finishTransaction(ts, status);
                   
                    // (3) Then abort all of the txn that need to come *after* we abort the dtxn
                    if (toAbortAfter.isEmpty() == false)
                        this.processClientResponseBatch(toAbortAfter, Status.ABORT_SPECULATIVE);
                   
                    // (4) Then blast out all of the txns that we want to commit
                    if (toCommit.isEmpty() == false)
                        this.processClientResponseBatch(toCommit, Status.OK);
                }
                // -------------------------------
                // DTXN READ-ONLY ABORT or DTXN COMMIT
                // -------------------------------
                else {
                    // **IMPORTANT**
                    // If the dtxn needs to commit, then all we need to do is get the
                    // last undoToken that we've generated (since we know that it had to
                    // have been used either by our distributed txn or for one of our
                    // speculative txns).
                    //
                    // If the read-only dtxn needs to abort, then there's nothing we need to
                    // do, because it didn't make any changes. That means we can just
                    // commit the last speculatively executed transaction
                    //
                    // Once we have this token, we can just make a direct call to the EE
                    // to commit any changes that came before it. Note that we are using our
                    // special 'finishWorkEE' method that does not require us to provide
                    // the transaction that we're committing.
                    long undoToken = this.lastUndoToken;
                    if (debug.val)
                        LOG.debug(String.format("%s - Last undoToken at partition %d => %d",
                                  ts, this.partitionId, undoToken));
                    // Bombs away!
                    if (undoToken != this.lastCommittedUndoToken) {
                        this.finishWorkEE(ts, undoToken, true);
                       
                        // IMPORTANT: Make sure that we remove the dtxn from the lock queue!
                        // This is normally done in finishTransaction() but because we're trying
                        // to be clever and invoke the EE directly, we have to make sure that
                        // we call it ourselves.
                        this.queueManager.lockQueueFinished(ts, status, this.partitionId);
                    }
                   
                    // Make sure that we mark the dtxn as finished so that we don't
                    // try to do anything with it later on.
                    if (hstore_conf.site.exec_readwrite_tracking)
                        this.markTransactionFinished(ts);
                    else
                        ts.markFinished(this.partitionId);
               
                    // Now make sure that all of the speculative txns are processed without
                    // committing (since we just committed any change that they could have made
                    // up above).
                    LocalTransaction spec_ts = null;
                    while ((spec_ts = this.specExecBlocked.pollFirst()) != null) {
                        ClientResponseImpl spec_cr = spec_ts.getClientResponse();
                        assert(spec_cr != null);
                        if (hstore_conf.site.exec_readwrite_tracking)
                            this.markTransactionFinished(spec_ts);
                        else
                            spec_ts.markFinished(this.partitionId);
                           
                        try {
                            if (trace.val)
                                LOG.trace(String.format("%s - Releasing blocked ClientResponse for %s [status=%s]",
                                          ts, spec_ts, spec_cr.getStatus()));
View Full Code Here

     * @param status
     */
    private void processClientResponseBatch(Collection<LocalTransaction> batch, Status status) {
        // Only processs the last txn in the list, since it will have the
        // the greatest undo token value.
        LocalTransaction targetTxn = null;
        if (status == Status.OK) {
            targetTxn = CollectionUtil.last(batch);
        } else {
            targetTxn = CollectionUtil.first(batch);
        }
        assert(targetTxn != null);
        long lastUndoToken = targetTxn.getFirstUndoToken(this.partitionId);
        this.finishWorkEE(targetTxn, lastUndoToken, (status == Status.OK));
       
        for (LocalTransaction ts : batch) {
            // Marking the txn as finished will prevent us from going down
            // into the EE to finish up the transaction.
View Full Code Here

            // } // FOR
        } // FOR


       
        this.ts = new LocalTransaction(this.hstore_sites[LOCAL_SITE]) {
            @Override
            public org.voltdb.ParameterSet getProcedureParameters() {
                return (params);
            }
            @Override
View Full Code Here

        // having to be explicitly told in the code.
        dtxnVoltProc.LOCK_BEFORE.release();
        result = dtxnVoltProc.NOTIFY_AFTER.tryAcquire(HStoreSiteTestUtil.NOTIFY_TIMEOUT, TimeUnit.MILLISECONDS);
        assertTrue(result);
       
        LocalTransaction dtxn = (LocalTransaction)this.baseExecutor.getDebugContext().getCurrentDtxn();
        assertEquals(dtxnVoltProc.getTransactionId(), dtxn.getTransactionId());
//        EstimatorState t_state = dtxn.getEstimatorState();
//        if (t_state instanceof MarkovEstimatorState) {
//            LOG.warn("WROTE MARKOVGRAPH: " + ((MarkovEstimatorState)t_state).dumpMarkovGraph());
//        }
        PartitionSet donePartitions = dtxn.getDonePartitions();
        assertEquals(donePartitions.toString(), 1, donePartitions.size());
        assertEquals(this.remoteExecutor.getPartitionId(), donePartitions.get());
       
        // ThreadUtil.sleep(10000000);
       
View Full Code Here

            }
        }
       
        // Now peek in the queue looking for single-partition txns that do not
        // conflict with the current dtxn
        LocalTransaction next = null;
        int txn_ctr = 0;
        int examined_ctr = 0;
        int matched_ctr = 0;
        boolean was_interrupted = false;
        long bestTime = (this.policyType == SpecExecSchedulerPolicyType.LONGEST ? Long.MIN_VALUE : Long.MAX_VALUE);

        // Check whether we can use our same iterator from the last call
        if (this.policyType != SpecExecSchedulerPolicyType.FIRST ||
                this.lastDtxn != dtxn ||
                this.lastIterator == null ||
                (this.ignore_speculation_type_change == false && this.lastSpecType != specType) ||
                (this.ignore_queue_size_change == false && this.lastSize != this.queue.size())) {
            this.lastIterator = this.queue.iterator();   
        }
        boolean resetIterator = true;
        if (profiler != null) profiler.queue_size.put(this.queue.size());
        boolean lastHasNext;
        if (trace.val) LOG.trace(StringUtil.header("BEGIN QUEUE CHECK :: " + dtxn));
        while ((lastHasNext = this.lastIterator.hasNext()) == true) {
            if (this.interrupted && was_interrupted == false) {
                if (debug.val)
                    LOG.warn(String.format("Search interrupted after %d examinations [%s]",
                             examined_ctr, this.latchMsg.getSimpleName()));
                if (profiler != null) profiler.interrupts++;
                was_interrupted = true;
                if (this.ignore_interrupts == false) break;
            }
           
            AbstractTransaction txn = this.lastIterator.next();
            assert(txn != null) : "Null transaction handle " + txn;
            boolean singlePartition = txn.isPredictSinglePartition();
            txn_ctr++;

            // Skip any distributed or non-local transactions
            if ((txn instanceof LocalTransaction) == false || singlePartition == false) {
                if (trace.val)
                    LOG.trace(String.format("Skipping non-speculative candidate %s", txn));
                continue;
            }
            LocalTransaction localTxn = (LocalTransaction)txn;
           
            // Skip anything already executed
            if (localTxn.isMarkedControlCodeExecuted()) {
                if (trace.val)
                    LOG.trace(String.format("Skipping %s because it was already executed", txn));
                continue;
            }
            // We can only support single-partition txns right now
            else if (singlePartition == false) {
                if (trace.val)
                    LOG.trace(String.format("Skipping %s because it is not single-partitioned", localTxn));
                continue;
            }
           
            // Let's check it out!
            if (profiler != null) profiler.compute_time.start();
            if (debug.val)
                LOG.debug(String.format("Examining whether %s conflicts with current dtxn", localTxn));
            examined_ctr++;
            try {
                switch (specType) {
                    // We can execute anything when we are in SP3 (i.e., 2PC) or IDLE
                    // For SP2, we can execute anything if the txn has not
                    // executed a query at this partition.
                    case IDLE:
                    case SP2_REMOTE_BEFORE:
                    case SP3_LOCAL:
                    case SP3_REMOTE: {
                        break;
                    }
                    // Otherwise we have to use the ConflictChecker to determine whether
                    // it is safe to execute this txn given what the distributed txn
                    // is expected to execute in the future.
                    case SP1_LOCAL:
                    case SP2_REMOTE_AFTER: {
                        if (this.checker.hasConflictBefore(dtxn, localTxn, this.partitionId)) {
                            if (debug.val)
                                LOG.debug(String.format("Skipping %s because it conflicts with current transaction", localTxn));
                            continue;
                        }
                        break;
                    }
                    // BUSTED!
                    default:
                        String msg = String.format("Unexpected %s.%s", specType.getClass().getSimpleName(), specType);
                        throw new RuntimeException(msg);
                } // SWITCH
                // If we get get to this point through the above switch statement, we know
                // that this txn is safe to execute now.
                matched_ctr++;
               
                // Scheduling Policy: FIRST MATCH
                if (this.policyType == SpecExecSchedulerPolicyType.FIRST) {
                    next = localTxn;
                    resetIterator = false;
                    break;
                }
                // Scheduling Policy: LAST MATCH
                else if (this.policyType == SpecExecSchedulerPolicyType.LAST) {
                    next = localTxn;
                }
                // Scheduling Policy: SHORTEST/LONGEST TIME
                else {
                    // Estimate the time that remains.
                    EstimatorState es = localTxn.getEstimatorState();
                    if (es != null) {
                        long remainingTime = es.getLastEstimate().getRemainingExecutionTime();
                        if ((this.policyType == SpecExecSchedulerPolicyType.SHORTEST && remainingTime < bestTime) ||
                            (this.policyType == SpecExecSchedulerPolicyType.LONGEST && remainingTime > bestTime)) {
                            bestTime = remainingTime;
View Full Code Here

                                               WINDOW_SIZE);
        this.schedulerDebug = this.scheduler.getDebugContext();
       
        // Create our current distributed transaction
        Procedure catalog_proc = this.getProcedure(UpdateLocation.class);
        this.dtxn = new LocalTransaction(this.hstore_site);
        this.dtxn.testInit(this.idManager.getNextUniqueTransactionId(),
                           BASE_PARTITION,
                           null,
                           catalogContext.getAllPartitionIds(),
                           catalog_proc);
View Full Code Here

                    break;
            }
        } // FOR
        assertFalse(procList.isEmpty());
       
        LocalTransaction ts = null, tsWithoutEstimatorState = null;
        for (Procedure proc: procList) {
            ts = new LocalTransaction(this.hstore_site);
            ts.testInit(this.idManager.getNextUniqueTransactionId(),
                        BASE_PARTITION,
                        null,
                        catalogContext.getPartitionSetSingleton(BASE_PARTITION),
                        proc);
            if (tsWithoutEstimatorState == null)
                tsWithoutEstimatorState = ts;
            assertTrue(ts.isPredictSinglePartition());
            this.addToQueue(ts);
            txns.add(ts);
        } // FOR
        EstTimeUpdater.update(System.currentTimeMillis());
        return (tsWithoutEstimatorState);
View Full Code Here

        assertNotNull(profiler);
        assertTrue(profiler.num_comparisons.isEmpty());
       
        this.populateQueue(this.addedTxns, 10);
        this.scheduler.setPolicyType(SpecExecSchedulerPolicyType.FIRST);
        LocalTransaction next = this.scheduler.next(this.dtxn, SpeculationType.SP2_REMOTE_BEFORE);
        assertNotNull(next);
        assertEquals(CollectionUtil.first(this.addedTxns), next);
        assertEquals(1, profiler.num_comparisons.get(1));
    }
View Full Code Here

        assertTrue(profiler.num_comparisons.isEmpty());
        this.scheduler.setPolicyType(SpecExecSchedulerPolicyType.LAST);
        this.scheduler.setWindowSize(Integer.MAX_VALUE);
       
        this.populateQueue(this.addedTxns, 10);
        LocalTransaction next = this.scheduler.next(this.dtxn, SpeculationType.SP2_REMOTE_BEFORE);
        assertNotNull(next);
        assertEquals(CollectionUtil.last(this.addedTxns), next);
        assertEquals(this.addedTxns.size(), profiler.num_comparisons.getMaxValue().intValue());
    }
View Full Code Here

TOP

Related Classes of edu.brown.hstore.txns.LocalTransaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.