Package edu.brown.hstore.txns

Examples of edu.brown.hstore.txns.AbstractTransaction


           
            if (debug.val) LOG.debug(String.format("Loading %d tuples for table '%s' in txn #%d",
                                       table.getRowCount(), table_name, txn_id));
            assert(this.isInitialized()) : " The sysproc " + this.getClass().getSimpleName() + " was not initialized properly";
            try {
                AbstractTransaction ts = this.hstore_site.getTransaction(txn_id);
                this.executor.loadTable(ts,
                                        context.getCluster().getName(),
                                        context.getDatabase().getName(),
                                        table_name, table, 0);   
            } catch (VoltAbortException e) {
View Full Code Here


    private boolean checkQueues(PartitionSet partitions) throws InterruptedException {
        boolean ret = true;
        for (int partition : partitions.values()) {
            PartitionLockQueue queue = this.queueManager.getLockQueue(partition);
            assertNotNull(queue);
            AbstractTransaction ts = queue.poll();
            if (ts != null) {
                ts.getInitCallback().run(partition);
                System.err.printf("Partition %d => %s\n", partition, ts);
            }
            ret = (ts != null) || ret;
        }
        return (ret );
View Full Code Here

        // ZOMBIE INFO
        String zombieStatus = Integer.toString(inflight_zombies);
        if (inflight_zombies > 0) {
            zombieStatus += "\n";
           
            AbstractTransaction zombie = null;
            Long txnId = null;
            for (AbstractTransaction ts : this.last_finishedTxns) {
                txnId = ts.getTransactionId();
                if (txnId != null) {
                    zombie = ts;
                    break;
                }
            }
            if (zombie != null) {
                if (zombie.isPredictSinglePartition()) {
                    zombieStatus += zombie.debug();
                } else {
                    Map<Integer, String> zombieDebug = hstore_site.getCoordinator().transactionDebug(txnId);
                    List<String> cols = new ArrayList<String>();
                    for (Integer siteId : zombieDebug.keySet()) {
                        cols.add(String.format("SITE %02d\n%s", siteId, zombieDebug.get(siteId)));
View Full Code Here

                                               lockQueue.getThrottleThreshold(),
                                               lockQueue.getThrottleRelease(),
                                               (lockQueue.isThrottled() ? "*THROTTLED* " : ""));
            txn_id = queueManagerDebug.getCurrentTransaction(partition);
            if (txn_id != null) {
                AbstractTransaction ts = hstore_site.getTransaction(txn_id);
                if (ts != null) {
                    PartitionCountingCallback<AbstractTransaction> callback = ts.getInitCallback();
                    if (callback != null) {
                        queueStatus += String.format("\nReceivedPartitions=%s / AllPartitions=%s",
                                                      callback.getReceivedPartitions(), callback.getPartitions());
                    }
                }
            }
            m.put("Lock Queue", queueStatus);
           
            if (profiler != null) {
                String inner = String.format("%d current / %d processed\n%s",
                                             executorDebug.getWorkQueueSize(),
                                             profiler.numMessages.getSampleCount(),
                                             profiler.numMessages.toString(30, 20));
                m.put("Work Queue", inner);
            } else {
                m.put("Work Queue", String.format("%d current", executorDebug.getWorkQueueSize()));
            }
           
            txn_id = executorDebug.getCurrentTxnId();
            m.put("Current Txn", String.format("%s / %s", (txn_id != null ? "#"+txn_id : "-"), executorDebug.getExecutionMode()));
            AbstractTransaction current_dtxn = executorDebug.getCurrentDtxn();
            m.put("Current DTXN", (current_dtxn == null ? "-" : current_dtxn));
           
            txn_id = executorDebug.getLastExecutedTxnId();
            m.put("Last Executed Txn", (txn_id != null ? "#"+txn_id : "-"));
           
View Full Code Here

     * This is non-blocking. If the txn is not ready, then this will return null.
     * <B>Note:</B> This should only be allowed to be called by one thread.
     */
    @Override
    public AbstractTransaction poll() {
        AbstractTransaction retval = null;
       
        if (trace.val)
            LOG.trace(String.format("Partition %d :: Attempting to acquire lock", this.partitionId));
        this.lock.lock();
        try {
            if (this.state == QueueState.BLOCKED_SAFETY || this.state == QueueState.BLOCKED_ORDERING) {
                this.checkQueueState(false);
            }
            if (this.state == QueueState.UNBLOCKED) {

                if (this.state == QueueState.UNBLOCKED) {
                    // 2012-12-21
                    // So this is allow to be null because there is a race condition
                    // if another thread removes the txn from the queue.
                    retval = super.poll();
                   
                    if (retval != null) {
                        if (debug.val)
                            LOG.debug(String.format("Partition %d :: poll() -> %s",
                                      this.partitionId, retval));
                        this.lastTxnPopped = retval.getTransactionId();
                        this.txnsPopped++;
                    }
                    // call this again to prime the next txn
                    this.checkQueueState(true);
                }
View Full Code Here

     * This method will wait until the transaction's block time has passed.
     * @return
     * @throws InterruptedException
     */
    public AbstractTransaction take() throws InterruptedException {
        AbstractTransaction retval = null;
       
        // Ok now here is the tricky part. We don't have a txn that is
        // ready to run, so we need to block ourselves until we get one.
        // This could be for two reasons:
        //  (1) The queue is empty.
        //  (2) The waiting period for the next txn hasn't passed yet.
        //
        // Note that we can't simply attach ourselves to our inner queue because
        // we don't want to get back the txn right when it gets added.
        // We want to wait until the time period has passed.
        if (trace.val)
            LOG.trace(String.format("Partition %d :: Attempting to acquire lock", this.partitionId));
        this.lock.lockInterruptibly();
        try {
            if (debug.val && this.state != QueueState.UNBLOCKED)
                LOG.debug(String.format("Partition %d :: take() -> " +
                          "Current state is %s. Blocking until ready", this.partitionId, this.state));
            while (this.state != QueueState.UNBLOCKED) {
                if (trace.val)
                    LOG.trace(String.format("Partition %d :: take() -> Calculating how long to block",
                              this.partitionId));
               
                long waitTime = -1;
                boolean isEmpty = (this.state == QueueState.BLOCKED_EMPTY);
                boolean needsUpdateQueue = false;
               
                // If the queue isn't empty, then we need to figure out
                // how long we should sleep for
                if (isEmpty == false) {
                    // If we're blocked because of an ordering issue (i.e., we have a new txn
                    // in the system that is less than our current head of the queue, but we
                    // haven't inserted it yet), then we will want to wait for the full timeout
                    // period. We won't actually have to wait this long because somebody will poke
                    // us after the new txn is added to the queue.
                    if (this.state == QueueState.BLOCKED_ORDERING) {
                        waitTime = this.maxWaitTime;
                    } else {
                        waitTime = this.blockTimestamp - System.currentTimeMillis();
                    }
                }
               
                try {
                    // If we're empty, then we need to block indefinitely until we're poked
                    if (isEmpty) {
                        if (debug.val)
                            LOG.debug(String.format("Partition %d :: take() -> " +
                                  "Blocking because queue is empty", this.partitionId));
                        this.isReady.await();
                    }
                    // Otherwise, we'll sleep until our time out and then
                    // check the queue status for ourselves
                    else if (waitTime > 0) {
                        // We are going to wait for the specified time
                        // The Condition will return true if somebody poked us, which
                        // means that somebody changed the queue state to UNBLOCKED
                        // for us. If we are woken because of a timeout, then the
                        // return status will be false, which means that we need to
                        // queue state ourself.
                        if (debug.val)
                            LOG.debug(String.format("Partition %d :: take() -> " +
                                      "Blocking for %d ms", this.partitionId, waitTime));
                        needsUpdateQueue = (this.isReady.await(waitTime, TimeUnit.MILLISECONDS) == false);
                    }
                    // Our txn is ready to run now, so we don't need to block
                    else {
                        if (debug.val)
                            LOG.debug(String.format("Partition %d :: take() -> " +
                                      "Ready to retrieve next txn immediately [waitTime=%d, isEmpty=%s]",
                                      this.partitionId, waitTime, isEmpty));
                        needsUpdateQueue = true;
                    }
                } catch (InterruptedException ex) {
                    this.isReady.signal();
                    throw ex;
                }
               
                if (needsUpdateQueue) this.checkQueueState(false);
               
            } // WHILE
            // The next txn is ready to run now!
            assert(this.state == QueueState.UNBLOCKED);
            retval = super.poll();
           
            // 2012-01-06
            // This could be null because there is a race condition if all of the
            // txns are removed by another thread right before we try to
            // poll our queue.
            if (retval != null) {
                this.lastTxnPopped = retval.getTransactionId();
                this.txnsPopped++;
               
                // Call this again to prime the next txn
                this.checkQueueState(true);
            }
View Full Code Here

     * Only return transaction state objects that are ready to run.
     * It is safe to call this from any thread if you need to (but you probably don't)
     */
    @Override
    public AbstractTransaction peek() {
        AbstractTransaction retval = null;
        if (this.state == QueueState.UNBLOCKED) {
            // assert(checkQueueState(false) == QueueState.UNBLOCKED);
            retval = super.peek();
            assert(retval != null);
        }
View Full Code Here

    // REMOVE METHODS
    // ----------------------------------------------------------------------------
   
    @Override
    public boolean remove(Object obj) {
        AbstractTransaction txn = (AbstractTransaction)obj;
        boolean retval;
       
        if (trace.val)
            LOG.trace(String.format("Partition %d :: Attempting to acquire lock", this.partitionId));
        this.lock.lock();
        try {
            // We have to check whether we are the first txn in the queue,
            // because we will need to reset the blockTimestamp after
            // delete ourselves so that the next guy can get executed
            // This is not thread-safe...
            boolean reset = txn.equals(super.peek());
            retval = super.remove(txn);
            if (debug.val) {
                LOG.debug(String.format("Partition %d :: remove(%s) -> %s", this.partitionId, txn, retval));
                // Sanity Check
                assert(super.contains(txn) == false) :
View Full Code Here

        if (trace.val && super.isEmpty() == false)
            LOG.trace(String.format("Partition %d :: checkQueueState(afterPoll=%s) [current=%s]",
                      this.partitionId, afterRemoval, this.state));
        QueueState newState = (afterRemoval ? QueueState.BLOCKED_SAFETY : QueueState.UNBLOCKED);
        long currentTimestamp = -1l;
        AbstractTransaction ts = super.peek(); // BLOCKING
        Long txnId = null;
        if (ts == null) {
//            if (trace.val)
//                LOG.trace(String.format("Partition %d :: Queue is empty.", this.partitionId));
            newState = QueueState.BLOCKED_EMPTY;
        }
        // Check whether can unblock now
        else {
            assert(ts.isInitialized()) :
                String.format("Unexpected uninitialized transaction %s [partition=%d]", ts, this.partitionId);
            txnId = ts.getTransactionId();
            // HACK: Ignore null txnIds
            if (txnId == null) {
                LOG.warn(String.format("Partition %d :: Uninitialized transaction handle %s", this.partitionId, ts));
                return (this.state);
            }
View Full Code Here

TOP

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

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.