Package edu.brown.hstore.txns

Examples of edu.brown.hstore.txns.AbstractTransaction


        assert(request.hasTransactionId()) : "Got " + request.getClass().getSimpleName() + " without a txn id!";
        Long txn_id = request.getTransactionId();
        if (debug.val)
            LOG.debug(String.format("Got %s for txn #%d", request.getClass().getSimpleName(), txn_id));
       
        AbstractTransaction ts = this.hstore_site.getTransaction(txn_id);
        assert(ts == null || ts instanceof LocalTransaction) :
            String.format("Got init request for remote txn #%d but we already have one [%s]",
                          txn_id, ts);

        // This allocation is unnecessary if we're on the same site
        PartitionSet partitions = null;
        if (ts instanceof LocalTransaction) {
            partitions = ((LocalTransaction)ts).getPredictTouchedPartitions();
        } else {
           
            // We first need all of the partitions so that we know
            // what it's actually going to touch
            // The init callback obviously only needs to have the
            // partitions that are local at this site.
            partitions = new PartitionSet(request.getPartitionsList());

            ParameterSet procParams = null;
            if (request.hasProcParams()) {
                FastDeserializer fds = new FastDeserializer(request.getProcParams().asReadOnlyByteBuffer());
                try {
                    procParams = fds.readObject(ParameterSet.class);
                } catch (Exception ex) {
                    String msg = String.format("Failed to deserialize procedure ParameterSet for txn #%d from %s",
                                               txn_id, request.getClass().getSimpleName());
                    throw new ServerFaultException(msg, ex, txn_id);
                }
            }
           
            // If we don't have a handle, we need to make one so that we can stick in the
            // things that we need to keep track of at this site. At this point we know that we're on
            // a remote site from the txn's base partition
            ts = this.hstore_site.getTransactionInitializer()
                                 .createRemoteTransaction(txn_id,
                                                          partitions,
                                                          procParams,
                                                          request.getBasePartition(),
                                                          request.getProcedureId());
           
            // Make sure that we initialize the RemoteTransactionInitCallback too!
            RemoteInitQueueCallback initCallback = ts.getInitCallback();
            initCallback.init((RemoteTransaction)ts, partitions, callback);
        }
       
        // If (request.getPrefetchFragmentsCount() > 0), then we need to
        // make a RemoteTransaction handle for ourselves so that we can keep track of
        // our state when prefetching queries.
        if (request.getPrefetchFragmentsCount() > 0) {
            // Stick the prefetch information into the transaction
            if (debug.val) {
                PartitionSet prefetchPartitions = new PartitionSet();
                for (WorkFragment fragment : request.getPrefetchFragmentsList())
                    prefetchPartitions.add(fragment.getPartitionId());
                LOG.debug(String.format("%s - Attaching %d prefetch %s at partitions %s",
                          ts, request.getPrefetchFragmentsCount(),
                          WorkFragment.class.getSimpleName(), prefetchPartitions));
            }
//            for (int i = 0; i < request.getPrefetchParamsCount(); i++) {
//                LOG.info(String.format("%s - XXX INBOUND PREFETCH RAW [%02d]: %s",
//                         ts, i,
//                         StringUtil.md5sum(request.getPrefetchParams(i).asReadOnlyByteBuffer())));
//            }
           
            ts.initializePrefetch();
            ts.attachPrefetchQueries(request.getPrefetchFragmentsList(),
                                     request.getPrefetchParamsList());
        }

        // We don't need to send back a response right here.
        // The init callback will wait until it has results from all of the partitions
View Full Code Here


       
        if (debug.val)
            LOG.debug("__FILE__:__LINE__ " + String.format("Got %s for txn #%d",
                                   request.getClass().getSimpleName(), txn_id));

        AbstractTransaction ts = hstore_site.getTransaction(txn_id);
        assert(ts != null) : "Unexpected transaction #" + txn_id;

        SendDataResponse.Builder builder = SendDataResponse.newBuilder()
                                                             .setTransactionId(txn_id)
                                                             .setStatus(Hstoreservice.Status.OK)
                                                             .setSenderSite(hstore_site.getSiteId());
       
        for (int i = 0, cnt = request.getDataCount(); i < cnt; i++) {
            int partition = request.getDepId(i);
            assert(hstore_site.getLocalPartitionIds().contains(partition));
           
            ByteBuffer data = request.getData(i).asReadOnlyByteBuffer();
            assert(data != null);
               
            // Deserialize the VoltTable object for the given byte array
            VoltTable vt = null;
            try {
                vt = FastDeserializer.deserialize(data, VoltTable.class);
            } catch (Exception ex) {
                LOG.warn("Unexpected error when deserializing VoltTable", ex);
            }
            assert(vt != null);
            if (debug.val) {
                byte bytes[] = request.getData(i).toByteArray();
                LOG.debug(String.format("Inbound data for Partition #%d: RowCount=%d / MD5=%s / Length=%d",
                                        partition, vt.getRowCount(),StringUtil.md5sum(bytes), bytes.length));
            }
               
            if (debug.val)
                LOG.debug(String.format("<StoreTable from Partition %d to Partition:%d>\n %s",hstore_site.getSiteId() ,partition,vt));
            Hstoreservice.Status status = ts.storeData(partition, vt);
            if (status != Hstoreservice.Status.OK) builder.setStatus(status);
            builder.addPartitions(partition);
        } // FOR
       
        callback.run(builder.build());
View Full Code Here

        if (debug.val)
            LOG.debug(String.format("Got %s for txn #%d [status=%s]",
                      request.getClass().getSimpleName(), txn_id, request.getStatus()));

        // Cancel the InitCallback if it hasn't been invoked yet
        AbstractTransaction ts = this.hstore_site.getTransaction(txn_id);
        if (ts != null) {
            PartitionCountingCallback<AbstractTransaction> initCallback = ts.getInitCallback();
            if (initCallback.isUnblocked() == false && initCallback.isAborted() == false) {
                initCallback.cancel();
            }
        }
       
View Full Code Here

    // UTILITY METHODS
    // --------------------------------------------------------------------------------------------
   
    private void checkCurrentDtxn() {
        // Make sure that this txn is the current dtxn at each of the partitions
        AbstractTransaction dtxn = null;
        for (PartitionExecutor executor : this.executors) {
            AbstractTransaction ts = null;
            int tries = 3;
            while (tries-- > 0) {
                ts = executor.getDebugContext().getCurrentDtxn();
                if (ts != null) break;
                ThreadUtil.sleep(HStoreSiteTestUtil.NOTIFY_TIMEOUT);
View Full Code Here

                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)
View Full Code Here

        assertNotNull(profiler);
        assertTrue(profiler.num_comparisons.isEmpty());
       
        // Add a bunch and then set the last one to have the shortest time
        this.populateQueue(this.addedTxns, 20);
        AbstractTransaction shortest = CollectionUtil.last(this.work_queue);
        for (AbstractTransaction ts : this.work_queue) {
            final long remaining = (ts == shortest ? 10 : 1000);
            EstimatorState state = new EstimatorState(catalogContext) {
                {
                    MockEstimate est = new MockEstimate(remaining);
View Full Code Here

        }
        // *********************************** DEBUG ***********************************

        // Things that we will need in the loop below
        InternalMessage nextWork = null;
        AbstractTransaction nextTxn = null;
        if (debug.val)
            LOG.debug("Starting PartitionExecutor run loop...");
        try {
            while (this.shutdown_state == ShutdownState.STARTED) {
                this.currentTxnId = null;
                nextTxn = null;
                nextWork = null;
               
                // This is the starting state of the PartitionExecutor.
                // At this point here we currently don't have a txn to execute nor
                // are we involved in a distributed txn running at another partition.
                // So we need to go our PartitionLockQueue and get back the next
                // txn that will have our lock.
                if (this.currentDtxn == null) {
                    this.tick();
                   
                    if (hstore_conf.site.exec_profiling) profiler.poll_time.start();
                    try {
                        nextTxn = this.queueManager.checkLockQueue(this.partitionId); // NON-BLOCKING
                    } finally {
                        if (hstore_conf.site.exec_profiling) profiler.poll_time.stopIfStarted();
                    }
                   
                    // If we get something back here, then it should become our current transaction.
                    if (nextTxn != null) {
                        // If it's a single-partition txn, then we can return the StartTxnMessage
                        // so that we can fire it off right away.
                        if (nextTxn.isPredictSinglePartition()) {
                            LocalTransaction localTxn = (LocalTransaction)nextTxn;
                            nextWork = localTxn.getStartTxnMessage();
                            if (hstore_conf.site.txn_profiling && localTxn.profiler != null)
                                localTxn.profiler.startQueueExec();
                        }
View Full Code Here

     * Process an InternalTxnMessage
     * @param work
     */
    private void processInternalTxnMessage(InternalTxnMessage work) {
        //LOG.info("process a txn msg");
        AbstractTransaction ts = work.getTransaction();
        this.currentTxn = ts;
        this.currentTxnId = ts.getTransactionId();

        // If this transaction has already been aborted and they are trying to give us
        // something that isn't a FinishTaskMessage, then we won't bother processing it
        if (ts.isAborted() && (work instanceof FinishTxnMessage) == false) {
            if (debug.val)
                LOG.debug(String.format("%s - Cannot process %s on partition %d because txn was marked as aborted",
                          ts, work.getClass().getSimpleName(), this.partitionId));
            return;
        }
                   
        if (debug.val)
            LOG.debug(String.format("Processing %s at partition %d", work, this.partitionId));
       
        // -------------------------------
        // Start Transaction
        // -------------------------------
        if (work instanceof StartTxnMessage) {
            if (hstore_conf.site.specexec_enable && ts.isPredictSinglePartition()) this.specExecScheduler.reset();
            if (hstore_conf.site.exec_profiling) profiler.txn_time.start();
            try {
                this.executeTransaction((LocalTransaction)ts);
            } finally {
                if (hstore_conf.site.exec_profiling) profiler.txn_time.stopIfStarted();
            }
        }
        // -------------------------------
        // Execute Query Plan Fragments
        // -------------------------------
        else if (work instanceof WorkFragmentMessage) {
            WorkFragment fragment = ((WorkFragmentMessage)work).getFragment();
            assert(fragment != null);
           
            // HACK HACK HACK
            if (ts.isInitialized() == false) {
                LOG.warn(String.format("Skipping %s at partition %d for unitialized txn",
                         work.getClass().getSimpleName(), this.partitionId));
                return;
            }

            // Get the ParameterSet array for this WorkFragment
            // It can either be attached to the AbstractTransaction handle if it came
            // over the wire directly from the txn's base partition, or it can be attached
            // as for prefetch WorkFragments
            ParameterSet parameters[] = null;
            if (fragment.getPrefetch()) {
                parameters = ts.getPrefetchParameterSets();
                ts.markExecPrefetchQuery(this.partitionId);
                if (trace.val && ts.isSysProc() == false)
                    LOG.trace(ts + " - Prefetch Parameters:\n" + StringUtil.join("\n", parameters));
            } else {
                parameters = ts.getAttachedParameterSets();
                if (trace.val && ts.isSysProc() == false)
                    LOG.trace(ts + " - Attached Parameters:\n" + StringUtil.join("\n", parameters));
            }
           
            // At this point we know that we are either the current dtxn or the current dtxn is null
            // We will allow any read-only transaction to commit if
            // (1) The WorkFragment for the remote txn is read-only
            // (2) This txn has always been read-only up to this point at this partition
            ExecutionMode newMode = null;
            if (hstore_conf.site.specexec_enable) {
                if (fragment.getReadOnly() && ts.isExecReadOnly(this.partitionId)) {
                    newMode = ExecutionMode.COMMIT_READONLY ;
                } else {
                    newMode = ExecutionMode.COMMIT_NONE;
                }
            } else {
View Full Code Here

        }
        else {
            assert(plan != null);
           
            ExecutionEngine ee = context.getExecutionEngine();
            AbstractTransaction ts = this.hstore_site.getTransaction(txn_id);
           
            // Enable read/write set tracking
            if (hstore_conf.site.exec_readwrite_tracking && ts.hasExecutedWork(this.partitionId) == false) {
                if (debug.val)
                    LOG.trace(String.format("%s - Enabling read/write set tracking in EE at partition %d",
                              ts, this.partitionId));
                ee.trackingEnable(txn_id);
            }
           
            // Always mark this information for the txn so that we can
            // rollback anything that it may do
            ts.markExecNotReadOnly(this.partitionId);
            ts.markExecutedWork(this.partitionId);
           
            table = ee.executeCustomPlanFragment(plan, outputDepId, inputDepId, txn_id,
                                          context.getLastCommittedTxnId(),
                                          ts.getLastUndoToken(this.partitionId));
        }

        return new DependencySet(new int[]{ outputDepId }, new VoltTable[]{ table });
    }
View Full Code Here

        m_hostId = ((Site) executor.getPartition().getParent()).getHost().getId();
    }

    @Override
    public DependencySet executePlanFragment(Long txn_id, Map<Integer, List<VoltTable>> dependencies, int fragmentId, ParameterSet params, final SystemProcedureExecutionContext context) {
        AbstractTransaction ts = hstore_site.getTransaction(txn_id);
        String hostname = ConnectionUtil.getHostnameOrAddress();
        if (fragmentId == SysProcFragmentId.PF_restoreScan) {
            assert (params.toArray()[0] != null);
            assert (params.toArray()[1] != null);
            VoltTable result = ClusterSaveFileState.constructEmptySaveFileStateVoltTable();
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.