Package edu.brown.utils

Examples of edu.brown.utils.PartitionSet


        if (host.startsWith("#"))
            return;
        int site = Integer.parseInt(data[1]);

        // Partition Ranges
        PartitionSet partitions = PartitionSet.parse(data[2]);
        for (int partition : partitions) {
            this.addPartition(host, site, partition);
        } // FOR
    }
View Full Code Here


       
        if (type == MarkovVertex.Type.ABORT) {
            v.setAbortProbability(1.0f);
        }
        if (type != MarkovVertex.Type.START) {
            @SuppressWarnings("deprecation")
            PartitionSet partitions = CatalogUtil.getAllPartitionIds(catalog_db);
            for (int partition : partitions.values()) {
                v.setDoneProbability(partition, 1.0f);
            } // FOR
        }
        assert(v != null);
        return (v);
View Full Code Here

     * Get the set of all partitions touched (either read or write) by the list of vertices
     * @param path
     * @return
     */
    public static PartitionSet getTouchedPartitions(List<MarkovVertex> path) {
        PartitionSet partitions = new PartitionSet();
        for (MarkovVertex v : path) {
            partitions.addAll(v.getPartitions());
        } // FOR
        return (partitions);
    }
View Full Code Here

     * Get the read/write partition counts for the given path
     * @param path
     * @return Set<ReadPartitions>, Set<WritePartitions>
     */
    public static Pair<PartitionSet, PartitionSet> getReadWritePartitions(List<MarkovVertex> path) {
        PartitionSet read_p = new PartitionSet();
        PartitionSet write_p = new PartitionSet();
        MarkovUtil.getReadWritePartitions(path, read_p, write_p);
        return (Pair.of(read_p, write_p));
    }
View Full Code Here

            seen_ids.put(e.getElementId(), e);
        } // FOR
       
        // Validate Vertices
        Set<MarkovVertex> seen_vertices = new HashSet<MarkovVertex>();
        PartitionSet all_partitions = new PartitionSet();
        for (MarkovVertex v0 : this.getVertices()) {
            float total_prob = 0.0f;
            long total_edgehits = 0;
           
            // Make sure the vertex thinks it's valid
            v0.validate(this);
           
            Collection<MarkovEdge> outbound = this.getOutEdges(v0);
            Collection<MarkovEdge> inbound = this.getInEdges(v0);
           
            // Make sure that nobody else has the same element id
            if (seen_ids.containsKey(v0.getElementId())) {
                throw new InvalidGraphElementException(this, v0, String.format("Duplicate element id #%d: Vertex[%s] <-> %s",
                                                                 v0.getElementId(), v0, seen_ids.get(v0.getElementId())));
            }
            seen_ids.put(v0.getElementId(), v0);
           
            all_partitions.addAll(v0.partitions);
            all_partitions.addAll(v0.past_partitions);
           
            for (MarkovEdge e : outbound) {
                MarkovVertex v1 = this.getOpposite(v0, e);
               
                // Make sure that each vertex only has one edge to another vertex
                if (seen_vertices.contains(v1)) {
                    throw new InvalidGraphElementException(this, v0, "Vertex has more than one edge to vertex " + v1);
                }
                seen_vertices.add(v1);
               
                // The totalhits for this vertex should always be greater than or equal to the total hints for
                // all of its edges and equal to the sum
                if (v0.getTotalHits() < e.getTotalHits()) {
                    throw new InvalidGraphElementException(this, v0, String.format("Vertex has %d totalHits but edge from %s to %s has %d",
                                                                                   v0.getTotalHits(), v0, v1, e.getTotalHits()));
                }
               
                // Make sure that this the destination vertex has the same partitions as the past+current partitions
                // for the destination vertex
                if (v0.isQueryVertex() && v1.isQueryVertex() && v1.past_partitions.equals(all_partitions) == false) {
                    v1.past_partitions.equals(all_partitions);
                    throw new InvalidGraphElementException(this, e, "Destination vertex in edge does not have the correct past partitions");
                }
               
                // Make sure that if the two vertices are for the same Statement, that
                // the source vertex's instance counter is one less than the destination
                if (v0.getCatalogKey().equals(v1.getCatalogKey())) {
                    if (v0.counter+1 != v1.counter) {
                        throw new InvalidGraphElementException(this, e, String.format("Invalid edge in from multiple invocations of %s: %d+1 != %d",
                                                                                       this.catalog_proc.getName(), v0.counter, v1.counter));
                    }
                }
               
                // Calculate total edge probabilities and hits
                total_prob += e.getProbability();
                total_edgehits += e.getTotalHits();
            } // FOR
            if (v0.isQueryVertex()) {
                if (MathUtil.equals(total_prob, 1.0f, MarkovGraph.PROBABILITY_EPSILON) == false && outbound.size() > 0) {
                    throw new InvalidGraphElementException(this, v0, "Total outbound edge probability is not equal to one: " + total_prob);
                }
                if (total_edgehits != v0.getTotalHits()) {
                    throw new InvalidGraphElementException(this, v0, String.format("Vertex has %d totalHits but the sum of all its edges has %d",
                                                                                   v0.getTotalHits(), total_edgehits));
                }
            }
           
            total_prob = 0.0f;
            total_edgehits = 0;
            for (MarkovEdge e : inbound) {
                total_prob += e.getProbability();
                total_edgehits += e.getTotalHits();
            } // FOR
            if (MathUtil.greaterThan(total_prob, 0.0f, MarkovGraph.PROBABILITY_EPSILON) == false && inbound.size() > 0 && total_edgehits > 0) {
                throw new InvalidGraphElementException(this, v0, "Total inbound edge probability is not greater than zero: " + total_prob);
            }
           
            seen_vertices.clear();
            all_partitions.clear();
        } // FOR
    }
View Full Code Here

       
        final int base_partition = pest.getBasePartition(txn_trace);
       
        // The past partitions is all of the partitions that this txn has touched,
        // included the base partition where the java executes
        PartitionSet past_partitions = new PartitionSet();
        // XXX past_partitions.add(this.getBasePartition());
       
        // -----------QUERY TRACE-VERTEX CREATION--------------
        for (QueryTrace query_trace : txn_trace.getQueries()) {
            PartitionSet partitions = new PartitionSet();
            pest.getAllPartitions(partitions, query_trace, base_partition);
            assert(partitions != null);
            assert(!partitions.isEmpty());
            Statement catalog_stmnt = query_trace.getCatalogItem(this.getDatabase());

            int queryInstanceIndex = query_instance_counters.get(catalog_stmnt).getAndIncrement();
            MarkovVertex v = null;
            synchronized (previous) {
                v = this.getVertex(catalog_stmnt, partitions, past_partitions, queryInstanceIndex);
                if (v == null) {
                    // If no such vertex exists we simply create one
                    v = new MarkovVertex(catalog_stmnt, MarkovVertex.Type.QUERY, queryInstanceIndex, partitions, new PartitionSet(past_partitions));
                    this.addVertex(v);
                }
                assert(v.isQueryVertex());
                // Add to the edge between the previous vertex and the current one
                MarkovEdge e = this.addToEdge(previous, v);
View Full Code Here

        }

        // ----------------------------------------------------------------------------
        // BASE PARTITION
        // ----------------------------------------------------------------------------
        PartitionSet most_touched = initial_est.getMostTouchedPartitions(this.thresholds);
        Integer e_base_partition = null;
        if (most_touched.size() > 1) {
            e_base_partition = CollectionUtil.random(most_touched);
        } else {
            e_base_partition = CollectionUtil.first(most_touched);
        }
        if (e_base_partition == null || e_base_partition != base_partition) {
            if (trace.val) {
                LOG.trace(String.format("Estimated base partition for txn #%d was %d but PartitionEstimator says it should be %d", s.getTransactionId(), e_base_partition, base_partition));
            }
            this.penalties.add(Penalty.WRONG_BASE_PARTITION);
            // assert(false) : e_base_partition + " != " + base_partition + "  "
            // + most_touched;
        }

        // ----------------------------------------------------------------------------
        // ABORTS
        // If the transaction was predicted to be single-partitioned and we
        // don't predict that it's going to
        // abort when it actually did, then that's bad! Really bad!
        // ----------------------------------------------------------------------------
        first_penalty = true;
        if (initial_est.isAbortable(this.thresholds) == false && a_last.isAbortVertex()) {
            if (trace.val) {
                if (first_penalty) {
                    LOG.trace("PENALTY: " + MarkovOptimization.OP3_ABORTS);
                    first_penalty = false;
                }
                LOG.trace(String.format("Txn #%d aborts but we predicted that it would never!", s.getTransactionId()));
            }
            this.penalties.add(a_singlepartitioned ? Penalty.MISSED_ABORT_SINGLE : Penalty.MISSED_ABORT_MULTI);
        }

        // For each MarkovEstimate, check whether there is a path in the graph
        // for the current vertex
        // to the abort state. If there isn't, then we need to check whether
        // This should match ExecutionSite.executeLocalPlan()
        MarkovVertex abort_v = markov.getAbortVertex();
        boolean last_hadAbortPath = true;
        first_penalty = true;
        for (Estimate e : estimates) {
            MarkovEstimate est = (MarkovEstimate)e;
            assert(est.isInitialized()) : "Uninitialized MarkovEstimate from " + s;
            MarkovVertex v = est.getVertex();
            assert (v != null) : "No vertex?\n" + est;
            boolean isAbortable = est.isAbortable(this.thresholds);
            boolean isReadOnly = est.isReadOnlyPartition(this.thresholds, base_partition);
            boolean hasAbortPath;
            synchronized (markov) {
                hasAbortPath = (markov.getPath(v, abort_v).isEmpty() == false);
            } // SYNCH

            // Make sure that we didn't have a path for the last MarkovEstimate
            // but
            // we somehow have one now
            if (hasAbortPath && last_hadAbortPath == false) {
                LOG.info("MARKOV: " + MarkovUtil.exportGraphviz(markov, false, markov.getPath(v, abort_v)).writeToTempFile());
                assert (last_hadAbortPath);
            }

            // If the path is not empty, then this txn could still abort
            if (hasAbortPath)
                continue;

            // Otherwise check whether our estimate still says to go with undo
            // buffers when
            // we're going to be read-only for the rest of the transaction
            // This is would be considered wasted work
            if (isAbortable && isReadOnly) {
                if (trace.val) {
                    if (first_penalty) {
                        LOG.trace("PENALTY: " + MarkovOptimization.OP3_ABORTS);
                        first_penalty = false;
                    }
                    LOG.trace(String.format("Txn #%d will never abort but we failed to disable undo buffers!", s.getTransactionId()));
                }
                this.penalties.add(Penalty.MISSED_NO_UNDO_BUFFER);
            }
            last_hadAbortPath = false;
        } // FOR

        // ----------------------------------------------------------------------------
        // MISSED PARTITIONS
        // The transaction actually reads/writes at more partitions than it originally predicted
        // This is expensive because it means that we have to abort+restart the txn
        // ----------------------------------------------------------------------------
        first_penalty = true;
        for (Integer p : this.a_read_partitions) {
            if (this.e_read_partitions.contains(p) == false) {
                if (trace.val) {
                    if (first_penalty) {
                        LOG.trace("PENALTY: " + MarkovOptimization.OP2_PARTITIONS);
                        first_penalty = false;
                    }
                    LOG.trace(String.format("Txn #%d failed to predict that it was READING at partition %d", s.getTransactionId(), p));
                }
                this.penalties.add(Penalty.MISSED_READ_PARTITION);
            }
        } // FOR
        for (Integer p : this.a_write_partitions) {
            if (this.e_write_partitions.contains(p) == false) {
                if (trace.val) {
                    if (first_penalty) {
                        LOG.trace("PENALTY: " + MarkovOptimization.OP2_PARTITIONS);
                        first_penalty = false;
                    }
                    LOG.trace(String.format("Txn #%d failed to predict that it was WRITING at partition %d", s.getTransactionId(), p));
                }
                this.penalties.add(Penalty.MISSED_WRITE_PARTITION);
            }
        } // FOR
        // if (this.penalties.size() > 0) {
        // LOG.info("Estimated Read Partitions:  " + this.e_read_partitions);
        // LOG.info("Estimated Write Partitions: " + this.e_write_partitions);
        // LOG.info("Actual Read Partitions:     " + this.a_read_partitions);
        // LOG.info("Actual Write Partitions:    " + this.a_write_partitions);
        //
        // LOG.info("IS ABORTABLE:    " +
        // initial_est.isAbortable(this.thresholds));
        // LOG.info("ABORT THRESHOLD: " + this.thresholds.getAbortThreshold());
        // LOG.info("Current State\n" + actual.get(1).debug());
        // LOG.info("MarkovEstimate\n" + initial_est.toString());
        // // LOG.info("GRAPH: " + MarkovUtil.exportGraphviz(s.getMarkovGraph(),
        // false, true, false, null).writeToTempFile());
        // System.exit(1);
        // }

        // ----------------------------------------------------------------------------
        // RETURN TO PARTITIONS
        // We declared that we were done at a partition but then later we
        // actually needed it. This can happen if there is a path that a has
        // very low probability of us taking it, but then ended up taking it anyway
        //
        // LATE FINISHED PARTITIONS
        // We keep track of the last batch round that we finished with a partition.
        // We then count how long it takes before we realize that we are finished.
        // We declare that the MarkovEstimate was late if we don't mark it as finished
        // immediately in the next batch
        // ----------------------------------------------------------------------------
        first_penalty = true;
        boolean first_penalty5 = true;

        this.done_partitions.clear();
        int last_est_idx = 0;
        PartitionSet touched_partitions = new PartitionSet();
        PartitionSet new_touched_partitions = new PartitionSet();

        // Reset the idle counters
        this.idle_partition_ctrs.clear();

        for (int i = 0; i < num_estimates; i++) {
            MarkovEstimate est = (MarkovEstimate)estimates.get(i);
            MarkovVertex est_v = est.getVertex();

            // Get the path of vertices
            int start = last_est_idx;
            int stop = actual.indexOf(est_v);
           
            // So this is just a hack so that our test cases still work
            if (stop == -1) {
                LOG.warn("Failed to find MarkovVertex " + est_v + " in path!");
                continue;
            }
            assert(stop != -1);

            new_touched_partitions.clear();
            for (; start <= stop; start++) {
                MarkovVertex v = actual.get(start);
                assert (v != null);

                Statement catalog_stmt = v.getCatalogItem();
                QueryType qtype = QueryType.get(catalog_stmt.getQuerytype());
                Penalty ptype = (qtype == QueryType.SELECT ? Penalty.RETURN_READ_PARTITION : Penalty.RETURN_WRITE_PARTITION);
                for (Integer p : v.getPartitions()) {
                    // Check if we read/write at any partition that was
                    // previously declared as done
                    if (this.done_partitions.contains(p)) {
                        if (trace.val) {
                            if (first_penalty) {
                                LOG.trace("PENALTY: " + MarkovOptimization.OP4_FINISHED);
                                first_penalty = false;
                            }
                            LOG.trace(String.format("Txn #%d said that it was done at partition %d but it executed a %s", s.getTransactionId(), p, qtype.name()));
                        }
                        this.penalties.add(ptype);
                        this.done_partitions.remove(p);
                    }
                } // FOR
                new_touched_partitions.addAll(v.getPartitions());

                // For each partition that we don't touch here, we want to
                // increase their idle counter
                this.idle_partition_ctrs.put(this.catalogContext.getAllPartitionIds());
            } // FOR
View Full Code Here

        // Only load the MarkovGraphs that we actually need
        final int num_transactions = args.workload.getTransactionCount();
        assert (num_transactions > 0) : "No TransactionTraces";
        final int marker = Math.max(1, (int) (num_transactions * 0.10));
        final Set<Procedure> procedures = args.workload.getProcedures(args.catalog_db);
        PartitionSet partitions = null;
        if (base_partition != HStoreConstants.NULL_PARTITION_ID) {
            partitions = new PartitionSet(base_partition);
        } else {
            partitions = args.catalogContext.getAllPartitionIds();
        }

        final File input_path = args.getFileParam(ArgumentsParser.PARAM_MARKOV);
View Full Code Here

            }
            txn_partitions = new TxnPartition(base_partition);
            // int batch = 0;
            for (Integer batch_id : trace.getBatchIds()) {
                // list of query traces
                PartitionSet query_partitions = new PartitionSet();
                for (QueryTrace qt : trace.getBatches().get(batch_id)) {
                    try {
                        est.getAllPartitions(query_partitions, qt, base_partition);
                    } catch (Exception e) {
                        e.printStackTrace();
View Full Code Here

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

TOP

Related Classes of edu.brown.utils.PartitionSet

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.