Package edu.brown.utils

Examples of edu.brown.utils.PartitionSet$Itr


        return (base_partition.intValue());
    }
   
    private PartitionSet getAllPartitions(TransactionTrace txn_trace) {
        Long txn_id = Long.valueOf(txn_trace.getTransactionId());
        PartitionSet all_partitions = this.cache_all_partitions.get(txn_id);
        if (all_partitions == null) {
            all_partitions = new PartitionSet();
            try {
                this.p_estimator.getAllPartitions(all_partitions, txn_trace);
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
View Full Code Here


            // Skip any txn that executes on a partition that we're not evaluating
            if (this.all_partitions.contains(base_partition) == false) continue;

            // Ok so now let's figure out what this mofo is going to do...
            PartitionSet partitions = this.getAllPartitions(txn_trace);
            boolean singlepartitioned = (partitions.size() == 1);
           
            // Estimate Global MarkovGraph Cost
            double g_cost = this.global_costmodel.estimateTransactionCost(catalogContext, txn_trace);
            if (g_cost > 0) {
                this.total_g_cost += g_cost;
View Full Code Here

//            cluster_to_key.get(c).put(key);
//            if (debug.val) LOG.debug(String.format("[%s, %s] => %d", , c));
           

            // Ok so now let's figure out what this mofo is going to do...
            PartitionSet partitions = this.getAllPartitions(txn_trace);
            boolean singlepartitioned = (partitions.size() == 1);
            t_counters[singlepartitioned ? 0 : 1]++;
            t_counters[2]++; // Total # of Txns
           
            // Estimate Clusterer MarkovGraphCost
            MarkovCostModel c_costmodel = state.costmodels_per_partition[base_partition.intValue()];
View Full Code Here

            data = fset.export(catalog_proc.getName());
        }
        assert(data != null);
        assert(args.workload.getTransactionCount() == data.numInstances());
       
        PartitionSet partitions = null;
        if (args.hasParam(ArgumentsParser.PARAM_WORKLOAD_RANDOM_PARTITIONS)) {
            PartitionEstimator p_estimator = new PartitionEstimator(args.catalogContext);
            final ObjectHistogram<Integer> h = new ObjectHistogram<Integer>();
            for (TransactionTrace txn_trace : args.workload.getTransactions()) {
                int base_partition = p_estimator.getBasePartition(txn_trace);
                h.put(base_partition);
            } // FOR
//            System.err.println("# OF PARTITIONS: " + h.getValueCount());
//            h.setKeepZeroEntries(true);
//            for (Integer p : CatalogUtil.getAllPartitionIds(args.catalog_db)) {
//                if (h.contains(p) == false) h.put(p, 0);
//            }
//            System.err.println(h);
//            System.exit(1);
//           
            partitions = new PartitionSet(h.values());
        } else {
            partitions = args.catalogContext.getAllPartitionIds();   
        }
        FeatureClusterer fclusterer = new FeatureClusterer(args.catalogContext,
                                                           catalog_proc,
View Full Code Here

    public boolean isWritePartition(EstimationThresholds t, int partition) {
        return (this.getSpecificProbability(Probability.WRITE, partition) >= t.write);
    }
    @Override
    public PartitionSet getWritePartitions(EstimationThresholds t) {
        PartitionSet partitions = new PartitionSet();
        for (int p = 0, cnt = this.probabilities[Probability.WRITE.ordinal()].length; p < cnt; p++) {
            if (this.isWritePartition(t, p)) {
                partitions.add(p);
            }
        } // FOR
        return (partitions);
    }
View Full Code Here

    public boolean isDonePartition(EstimationThresholds t, int partition) {
        return (this.getSpecificProbability(Probability.DONE, partition) >= t.done);
    }
    @Override
    public PartitionSet getDonePartitions(EstimationThresholds t) {
        PartitionSet partitions = new PartitionSet();
        for (int p = 0, cnt = this.probabilities[Probability.DONE.ordinal()].length; p < cnt; p++) {
            if (this.isDonePartition(t, p)) {
                partitions.add(p);
            }
        } // FOR
        return (partitions);
    }
View Full Code Here

                // TransactionCacheEntry
                // or any histograms because they will have been updated when
                // the QueryCacheEntry is created
                for (String table_key : query_entry.getTableKeys()) {
                    if (!temp_stmtPartitions.containsKey(table_key)) {
                        temp_stmtPartitions.put(table_key, new PartitionSet());
                    }
                    temp_stmtPartitions.get(table_key).addAll(query_entry.getPartitions(table_key));
                } // FOR
                txn_entry.examined_queries += query_weight;
                query_partitions += query_entry.getAllPartitions().size();

                // Create a new QueryCacheEntry
            } else {
                if (trace.val)
                    LOG.trace(String.format("Calculating new cost information for %s - Weight:%d", query_trace, query_weight));
                if (this.use_caching == false || query_entry == null) {
                    query_entry = new QueryCacheEntry(txn_trace, query_trace, query_weight);
                }
                this.query_ctr.addAndGet(query_weight);
                query_entry.invalid = false;

                // QUERY XREF
                if (this.use_caching) {
                    txn_entry.query_entries[query_idx] = query_entry;
                    String stmt_key = CatalogKey.createKey(catalog_stmt);
                    Set<QueryCacheEntry> cache = this.cache_stmtXref.get(stmt_key);
                    if (cache == null) {
                        cache = new HashSet<QueryCacheEntry>();
                        this.cache_stmtXref.put(stmt_key, cache);
                    }
                    cache.add(query_entry);
                }

                // Give the QueryTrace to the PartitionEstimator to get back a
                // mapping from TableKeys
                // to sets of partitions that were touched by the query.
                // XXX: What should we do if the TransactionCacheEntry's base
                // partition hasn't been calculated yet?
                // Let's just throw it at the PartitionEstimator and let it figure out what to do...
                Map<String, PartitionSet> table_partitions = this.p_estimator.getTablePartitions(query_trace, txn_entry.base_partition);
                StringBuilder sb = null;
                if (trace.val) {
                    sb = new StringBuilder();
                    sb.append("\n" + StringUtil.SINGLE_LINE + query_trace + " Table Partitions:");
                }
                assert (!table_partitions.isEmpty()) : "Failed to get back table partitions for " + query_trace;
                for (Entry<String, PartitionSet> e : table_partitions.entrySet()) {
                    assert (e.getValue() != null) : "Null table partitions for '" + e.getKey() + "'";

                    // If we didn't get anything back, then that means that we
                    // know we need to touch this
                    // table but the PartitionEstimator doesn't have enough
                    // information yet
                    if (e.getValue().isEmpty())
                        continue;
                    if (trace.val)
                        sb.append("\n  " + e.getKey() + ": " + e.getValue());

                    // Update the cache xref mapping so that we know this Table
                    // is referenced by this QueryTrace
                    // This will allow us to quickly find the QueryCacheEntry in
                    // invalidate()
                    if (this.use_caching) {
                        Set<QueryCacheEntry> cache = this.cache_tableXref.get(e.getKey());
                        if (cache == null) {
                            cache = new HashSet<QueryCacheEntry>();
                            this.cache_tableXref.put(e.getKey(), cache);
                        }
                        cache.add(query_entry);
                    }

                    // Ok, so now update the variables in our QueryCacheEntry
                    query_entry.singlesited = (query_entry.singlesited && e.getValue().size() == 1);
                    query_entry.addAllPartitions(e.getKey(), e.getValue());

                    // And then update the Statement partitions map to include
                    // all of the partitions
                    // that this query touched
                    if (!temp_stmtPartitions.containsKey(e.getKey())) {
                        temp_stmtPartitions.put(e.getKey(), e.getValue());
                    } else {
                        temp_stmtPartitions.get(e.getKey()).addAll(e.getValue());
                    }
                } // FOR (Entry<TableKey, Set<Partitions>>
                if (trace.val)
                    LOG.trace(sb.toString() + "\n" + query_trace.debug(catalogContext.database) + "\n" + StringUtil.SINGLE_LINE.trim());

                // Lastly, update the various histogram that keep track of which
                // partitions are accessed:
                //  (1) The global histogram for the cost model of partitions touched by all queries
                //  (2) The TransactionCacheEntry histogram of which partitions are touched by all queries
                //
                // Note that we do not want to update the global histogram for the cost model on the
                // partitions touched by txns, because we don't want to count the same partition multiple times
                // Note also that we want to do this *outside* of the loop above, otherwise we will count
                // the same partition multiple times if the query references more than one table!
                this.histogram_query_partitions.put(query_entry.getAllPartitions(), query_weight * txn_weight);
                txn_entry.touched_partitions.put(query_entry.getAllPartitions(), query_weight);
                int query_num_partitions = query_entry.getAllPartitions().size();
                query_partitions += query_num_partitions;

                // If the number of partitions is zero, then we will classify
                // this query as currently
                // being unknown. This can happen if the query needs does a
                // single look-up on a replicated
                // table but we don't know the base partition yet
                if (query_num_partitions == 0) {
                    if (trace.val)
                        LOG.trace("# of Partitions for " + query_trace + " is zero. Marking as unknown for now");
                    txn_entry.unknown_queries += query_weight;
                    query_entry.unknown = true;
                    query_entry.invalid = true;
                } else {
                    txn_entry.examined_queries += query_weight;
                    query_entry.unknown = false;
                }
            } // if (new cache entry)

            // If we're not single-sited, well then that ruins it for everyone
            // else now doesn't it??
            if (query_entry.getAllPartitions().size() > 1) {
                if (debug.val)
                    LOG.debug(query_trace + " is being marked as multi-partition: " + query_entry.getAllPartitions());
                query_entry.singlesited = false;
                txn_entry.singlesited = false;
                txn_entry.multisite_queries += query_weight;
            } else {
                if (debug.val)
                    LOG.debug(query_trace + " is marked as single-partition");
                query_entry.singlesited = true;
                txn_entry.singlesite_queries += query_weight;
            }

            if (debug_txn)
                LOG.info(query_entry);
        } // FOR (QueryTrace)

        // Now just check whether this sucker has queries that touch more than one partition
        // We do this one first because it's the fastest and will pick up enough of them
        if (txn_entry.touched_partitions.getValueCount() > 1) {
            if (trace.val)
                LOG.trace(txn_trace + " touches " + txn_entry.touched_partitions.getValueCount() + " different partitions");
            txn_entry.singlesited = false;

            // Otherwise, now that we have processed all of queries that we
            // could, we need to check whether the values of the StmtParameters used on the partitioning
            // column of each table all hash to the same value. If they don't, then we know we can't
            // be single-partition
        } else {
            for (Entry<String, PartitionSet> e : temp_stmtPartitions.entrySet()) {
                String table_key = e.getKey();
                Table catalog_tbl = CatalogKey.getFromKey(catalogContext.database, table_key, Table.class);
                if (catalog_tbl.getIsreplicated()) {
                    continue;
                }

                Column table_partition_col = catalog_tbl.getPartitioncolumn();
                PartitionSet partitions = e.getValue();

                // If there is more than one partition, then we'll never be multi-partition
                // so we can stop our search right here.
                if (partitions.size() > 1) {
                    if (trace.val)
                        LOG.trace(String.format("%s references %s's partitioning attribute %s on %d different partitions -- VALUES %s", catalog_proc.getName(), catalog_tbl.getName(),
                                table_partition_col.fullName(), partitions.size(), partitions));
                    txn_entry.singlesited = false;
                    break;

                // Make sure that the partitioning ProcParameter hashes to the same
                // site as the value used on the partitioning column for this table
                } else if (!partitions.isEmpty() && txn_entry.base_partition != HStoreConstants.NULL_PARTITION_ID) {
                    int tbl_partition = CollectionUtil.first(partitions);
                    if (txn_entry.base_partition != tbl_partition) {
                        if (trace.val)
                            LOG.trace(txn_trace + " executes on Partition #" + txn_entry.base_partition + " " + "but partitioning column " + CatalogUtil.getDisplayName(table_partition_col) + " "
                                    + "references Partition #" + tbl_partition);
View Full Code Here

        long singlepartition = 0;
        long multipartition = 0;
        long total = 0;
        SingleSitedCostModel costmodel = new SingleSitedCostModel(args.catalogContext);
        PartitionSet all_partitions = args.catalogContext.getAllPartitionIds();
        // costmodel.setEntropyWeight(4.0);
        // costmodel.setJavaExecutionWeightEnabled(true);
        // costmodel.setJavaExecutionWeight(100);

        // XXX: 2011-10-28
        costmodel.setCachingEnabled(true);
        ObjectHistogram<String> hist = new ObjectHistogram<String>();
        for (int i = 0; i < 2; i++) {
            ProfileMeasurement time = new ProfileMeasurement("costmodel").start();
            hist.clear();
            for (AbstractTraceElement<? extends CatalogType> element : args.workload) {
                if (element instanceof TransactionTrace) {
                    total++;
                    TransactionTrace xact = (TransactionTrace) element;
                    boolean is_singlesited = costmodel.processTransaction(args.catalogContext, xact, null).singlesited;
                    if (is_singlesited) {
                        singlepartition++;
                        hist.put(xact.getCatalogItemName());
                    } else {
                        multipartition++;
                        if (!hist.contains(xact.getCatalogItemName()))
                            hist.put(xact.getCatalogItemName(), 0);
                    }
                }
            } // FOR
            System.err.println("ESTIMATE TIME: " + time.stop().getTotalThinkTimeSeconds());
            break; // XXX
        } // FOR
        // long total_partitions_touched_txns =
        // costmodel.getTxnPartitionAccessHistogram().getSampleCount();
        // long total_partitions_touched_queries =
        // costmodel.getQueryPartitionAccessHistogram().getSampleCount();

        Histogram<Integer> h = null;
        if (!table_output) {
            System.out.println("Workload Procedure Histogram:");
            System.out.println(StringUtil.addSpacers(args.workload.getProcedureHistogram().toString()));
            System.out.print(StringUtil.DOUBLE_LINE);

            System.out.println("SinglePartition Procedure Histogram:");
            System.out.println(StringUtil.addSpacers(hist.toString()));
            System.out.print(StringUtil.DOUBLE_LINE);

            System.out.println("Java Execution Histogram:");
            h = costmodel.getJavaExecutionHistogram();
            h.setKeepZeroEntries(true);
            h.put(all_partitions, 0);
            System.out.println(StringUtil.addSpacers(h.toString()));
            System.out.print(StringUtil.DOUBLE_LINE);

            System.out.println("Transaction Partition Histogram:");
            h = costmodel.getTxnPartitionAccessHistogram();
            h.setKeepZeroEntries(true);
            h.put(all_partitions, 0);
            System.out.println(StringUtil.addSpacers(h.toString()));
            System.out.print(StringUtil.DOUBLE_LINE);

            System.out.println("Query Partition Touch Histogram:");
            h = costmodel.getQueryPartitionAccessHistogram();
            h.setKeepZeroEntries(true);
            h.put(all_partitions, 0);
            System.out.println(StringUtil.addSpacers(h.toString()));
            System.out.print(StringUtil.DOUBLE_LINE);
        }

        Map<String, Object> maps[] = new Map[2];
        int idx = 0;
        LinkedHashMap<String, Object> m = null;

        // Execution Cost
        m = new LinkedHashMap<String, Object>();
        m.put("SINGLE-PARTITION", singlepartition);
        m.put("MULTI-PARTITION", multipartition);
        m.put("TOTAL", total + " [" + singlepartition / (double) total + "]");
        m.put("PARTITIONS TOUCHED (TXNS)", costmodel.getTxnPartitionAccessHistogram().getSampleCount());
        m.put("PARTITIONS TOUCHED (QUERIES)", costmodel.getQueryPartitionAccessHistogram().getSampleCount());
        maps[idx++] = m;

        // Utilization
        m = new LinkedHashMap<String, Object>();
        costmodel.getJavaExecutionHistogram().setKeepZeroEntries(false);
        int active_partitions = costmodel.getJavaExecutionHistogram().getValueCount();
        m.put("ACTIVE PARTITIONS", active_partitions);
        m.put("IDLE PARTITIONS", (all_partitions.size() - active_partitions));
        // System.out.println("Partitions Touched By Queries: " +
        // total_partitions_touched_queries);

        Histogram<Integer> entropy_h = costmodel.getJavaExecutionHistogram();
        m.put("JAVA SKEW", SkewFactorUtil.calculateSkew(all_partitions.size(), entropy_h.getSampleCount(), entropy_h));

        entropy_h = costmodel.getTxnPartitionAccessHistogram();
        m.put("TRANSACTION SKEW", SkewFactorUtil.calculateSkew(all_partitions.size(), entropy_h.getSampleCount(), entropy_h));

        // TimeIntervalCostModel<SingleSitedCostModel> timecostmodel = new
        // TimeIntervalCostModel<SingleSitedCostModel>(args.catalog_db,
        // SingleSitedCostModel.class, 1);
        // timecostmodel.estimateCost(args.catalog_db, args.workload);
        // double entropy = timecostmodel.getLastEntropyCost()
        m.put("UTILIZATION", (costmodel.getJavaExecutionHistogram().getValueCount() / (double) all_partitions.size()));
        maps[idx++] = m;

        System.out.println(StringUtil.formatMaps(maps));
    }
View Full Code Here

            this.getPartitions(table_key).addAll(partitions);
            this.all_partitions.addAll(partitions);
        }

        private PartitionSet getPartitions(String table_key) {
            PartitionSet p = this.partitions.get(table_key);
            if (p == null) {
                p = new PartitionSet();
                this.partitions.put(table_key, p);
            }
            return (p);
        }
View Full Code Here

        }

        @Override
        public Object clone() throws CloneNotSupportedException {
            QueryCacheEntry clone = (QueryCacheEntry) super.clone();
            clone.all_partitions = new PartitionSet(this.all_partitions);
            clone.partitions = new HashMap<String, PartitionSet>();
            for (String key : this.partitions.keySet()) {
                clone.partitions.put(key, new PartitionSet(this.partitions.get(key)));
            } // FOR
            return (clone);
        }
View Full Code Here

TOP

Related Classes of edu.brown.utils.PartitionSet$Itr

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.