Package edu.brown.costmodel.SingleSitedCostModel

Examples of edu.brown.costmodel.SingleSitedCostModel.TransactionCacheEntry


        for (TransactionCacheEntry txn_entry : costModel.getTransactionCacheEntries()) {
            // There should be no unknown queries and all transactions should be multi-sited
            assertEquals(txn_entry.toString(), 0, txn_entry.getUnknownQueryCount());
            assertFalse(txn_entry.isSinglePartitioned());
           
            TransactionCacheEntry clone = (TransactionCacheEntry)txn_entry.clone();
            assertNotSame(txn_entry, clone);
            expected_entries.put(txn_entry.getTransactionId(), clone);
            // System.err.println(StringUtil.columns(txn_entry.debug(), clone.debug()));
            // System.err.println(StringUtil.SINGLE_LINE);
        } // FOR
        assertFalse(expected_entries.isEmpty());
        for (Statement catalog_stmt : vpc.getOptimizedQueries()) {
            Collection<QueryCacheEntry> entries = costModel.getQueryCacheEntries(catalog_stmt);
            assertNotNull(entries);
            assertFalse(entries.isEmpty());
        } // FOR
       
        // Now apply the update and get the new cost. We don't care what the cost
        // is because SingleSitedCostModel only looks to see whether a txn is single-partition
        // and not how many partition it actually touches
        // We have to clear the cache for these queries first though
        vpc.applyUpdate();
        costModel.invalidateCache(vpc.getOptimizedQueries());
        double new_cost = costModel.estimateWorkloadCost(clone_catalogContext, workload, filter, null);
        System.err.println("NEW COST: " + new_cost);
        Collection<TransactionCacheEntry> new_entries = costModel.getTransactionCacheEntries();
        assertNotNull(new_entries);
        assertEquals(expected_entries.size(), new_entries.size());
        for (TransactionCacheEntry txn_entry : costModel.getTransactionCacheEntries()) {
            TransactionCacheEntry expected = expected_entries.get(txn_entry.getTransactionId());
            assertNotNull(expected);
           
            assertEquals(expected.getUnknownQueryCount(), txn_entry.getUnknownQueryCount());
            assertEquals(expected.getExaminedQueryCount(), txn_entry.getExaminedQueryCount());
            assertEquals(expected.getTotalQueryCount(), txn_entry.getTotalQueryCount());
            assertEquals(expected.getExecutionPartition(), txn_entry.getExecutionPartition());
           
            assertThat(expected.getMultiSiteQueryCount(), not(equalTo(txn_entry.getMultiSiteQueryCount())));
            assertThat(expected.getSingleSiteQueryCount(), not(equalTo(txn_entry.getSingleSiteQueryCount())));
           
            // None of the queries should touch all of the partitions
            for (QueryCacheEntry query_entry : costModel.getQueryCacheEntries(txn_entry.getTransactionId())) {
                assertNotNull(query_entry);
                assertFalse(query_entry.isInvalid());
View Full Code Here


            total_interval_queries[i] += (txn_trace.getQueryCount() * txn_weight);
            histogram_procs.put(proc_key, txn_weight);

            try {
                singlesited_cost_model.estimateTransactionCost(catalogContext, workload, filter, txn_trace);
                TransactionCacheEntry txn_entry = singlesited_cost_model.getTransactionCacheEntry(txn_trace);
                assert (txn_entry != null) : "No txn entry for " + txn_trace;
                Collection<Integer> partitions = txn_entry.getTouchedPartitions();

                // If the txn runs on only one partition, then the cost is
                // nothing
                if (txn_entry.isSinglePartitioned()) {
                    singlepartition_ctrs[i] += txn_weight;
                    if (!partitions.isEmpty()) {
                        assert (txn_entry.getAllTouchedPartitionsHistogram().getValueCount() == 1) : txn_entry + " says it was single-partitioned but the partition count says otherwise:\n"
                                + txn_entry.debug();
                        singlepartition_with_partitions_ctrs[i] += txn_weight;
                    }
                    histogram_sp_procs.put(proc_key, txn_weight);

                    // If the txn runs on multiple partitions, then the cost
                    // is...
                    // XXX 2010-06-28: The number of partitions that the txn
                    // touches divided by the total number of partitions
                    // XXX 2010-07-02: The histogram for the total number of
                    // partitions touched by all of the queries
                    // in the transaction. This ensures that txns with just one
                    // multi-partition query
                    // isn't weighted the same as a txn with many
                    // multi-partition queries
                } else {
                    assert (!partitions.isEmpty()) : "No touched partitions for " + txn_trace;
                    if (partitions.size() == 1 && txn_entry.getExecutionPartition() != HStoreConstants.NULL_PARTITION_ID) {
                        assert (CollectionUtil.first(partitions) != txn_entry.getExecutionPartition()) : txn_entry.debug();
                        exec_mismatch_ctrs[i] += txn_weight;
                        partitions_touched[i] += txn_weight;
                    } else {
                        assert (partitions.size() > 1) : String.format("%s is not marked as single-partition but it only touches one partition\n%s", txn_trace, txn_entry.debug());
                    }
                    partitions_touched[i] += (partitions.size() * txn_weight); // Txns
                    multipartition_ctrs[i] += txn_weight;
                    histogram_mp_procs.put(proc_key, txn_weight);
                }
                Integer base_partition = txn_entry.getExecutionPartition();
                if (base_partition != null) {
                    exec_histogram[i].put(base_partition, txn_weight);
                } else {
                    exec_histogram[i].put(all_partitions, txn_weight);
                }
                if (debug.val) { // &&
                                   // txn_trace.getCatalogItemName().equalsIgnoreCase("DeleteCallForwarding"))
                                   // {
                    Procedure catalog_proc = txn_trace.getCatalogItem(catalogContext.database);
                    Map<String, Object> inner = new LinkedHashMap<String, Object>();
                    for (Statement catalog_stmt : catalog_proc.getStatements()) {
                        inner.put(catalog_stmt.fullName(), CatalogUtil.getReferencedTables(catalog_stmt));
                    }

                    Map<String, Object> m = new LinkedHashMap<String, Object>();
                    m.put(txn_trace.toString(), null);
                    m.put("Interval", i);
                    m.put("Single-Partition", txn_entry.isSinglePartitioned());
                    m.put("Base Partition", base_partition);
                    m.put("Touched Partitions", partitions);
                    m.put(catalog_proc.fullName(), inner);
                    LOG.debug(StringUtil.formatMaps(m));
                }

                // We need to keep a count of the number txns that didn't have
                // all of its queries estimated
                // completely so that we can update the access histograms down
                // below for entropy calculations
                // Note that this is at the txn level, not the query level.
                if (!txn_entry.isComplete()) {
                    incomplete_txn_ctrs[i] += txn_weight;
                    tmp_missingPartitions.clear();
                    tmp_missingPartitions.addAll(all_partitions);
                    tmp_missingPartitions.removeAll(txn_entry.getTouchedPartitions());
                    // Update the histogram for this interval to keep track of
                    // how many times we need to
                    // increase the partition access histogram
                    incomplete_txn_histogram[i].put(tmp_missingPartitions, txn_weight);
                    if (trace.val) {
                        Map<String, Object> m = new LinkedHashMap<String, Object>();
                        m.put(String.format("Marking %s as incomplete in interval #%d", txn_trace, i), null);
                        m.put("Examined Queries", txn_entry.getExaminedQueryCount());
                        m.put("Total Queries", txn_entry.getTotalQueryCount());
                        m.put("Touched Partitions", txn_entry.getTouchedPartitions());
                        m.put("Missing Partitions", tmp_missingPartitions);
                        LOG.trace(StringUtil.formatMaps(m));
                    }
                }
            } catch (Exception ex) {
View Full Code Here

       
        // We now want to calculate the cost of this new workload
        final SingleSitedCostModel orig_costModel = new SingleSitedCostModel(catalogContext);
        final double orig_cost = orig_costModel.estimateWorkloadCost(catalogContext, new_workload);
        assert(orig_cost > 0);
        TransactionCacheEntry orig_txnEntry = orig_costModel.getTransactionCacheEntry(orig_txn);
        assertNotNull(orig_txnEntry);
        assertEquals(orig_txn.getQueryCount(), orig_txnEntry.getExaminedQueryCount());
//        System.err.println(orig_txnEntry.debug());
//        System.err.println("=========================================");
       
        // Now change make a new workload that has the same multi-partition transaction
        // but this time it only has one but with a transaction weight
        // We should get back the exact same cost
        new_workload = new Workload(catalogContext.catalog);
        final TransactionTrace new_txn = (TransactionTrace)multip_txn.clone();
        clone_queries = new ArrayList<QueryTrace>();
        for (QueryTrace query_trace : multip_txn.getQueries()) {
            QueryTrace clone_query = (QueryTrace)query_trace.clone();
            clone_query.setWeight(num_dupes);
            clone_queries.add(clone_query);
        } // FOR
        new_txn.setQueries(clone_queries);
        new_workload.addTransaction(catalog_proc, new_txn);
        assertEquals(1, new_workload.getTransactionCount());
        assertEquals(multip_txn.getQueryCount(), new_txn.getQueryCount());
        assertEquals(multip_txn.getQueryCount() * num_dupes, new_txn.getWeightedQueryCount());
       
        final SingleSitedCostModel new_costModel = new SingleSitedCostModel(catalogContext);
        final double new_cost = new_costModel.estimateWorkloadCost(catalogContext, new_workload);
        assert(new_cost > 0);
        assertEquals(orig_cost, new_cost, 0.001);
       
       
        // Now make sure the histograms match up
        Map<Field, Histogram<?>> orig_histograms = getHistograms(orig_costModel);
        Map<Field, Histogram<?>> new_histograms = getHistograms(new_costModel);
        for (Field f : orig_histograms.keySet()) {
            Histogram<?> orig_h = orig_histograms.get(f);
            assertNotNull(orig_h);
            Histogram<?> new_h = new_histograms.get(f);
            assert(orig_h != new_h);
            assertNotNull(new_h);
            assertEquals(orig_h, new_h);
        } // FOR
       
        // Compare the TransactionCacheEntries
       
        TransactionCacheEntry new_txnEntry = new_costModel.getTransactionCacheEntry(new_txn);
        assertNotNull(new_txnEntry);
//        System.err.println(new_txnEntry.debug());
       
        assertEquals(orig_txnEntry.getExaminedQueryCount(), new_txnEntry.getExaminedQueryCount());
        assertEquals(orig_txnEntry.getSingleSiteQueryCount(), new_txnEntry.getSingleSiteQueryCount());
        assertEquals(orig_txnEntry.getMultiSiteQueryCount(), new_txnEntry.getMultiSiteQueryCount());
        assertEquals(orig_txnEntry.getUnknownQueryCount(), new_txnEntry.getUnknownQueryCount());
        assertEquals(orig_txnEntry.getTotalQueryCount(), new_txnEntry.getTotalQueryCount());
        assertEquals(orig_txnEntry.getAllTouchedPartitionsHistogram(), new_txnEntry.getAllTouchedPartitionsHistogram());
    }
View Full Code Here

       
        // Throw the TransactionTrace at the costmodel and make sure that there is a TransactionCacheEntry
        SingleSitedCostModel cost_model = new SingleSitedCostModel(clone_catalogContext);
        cost_model.estimateTransactionCost(clone_catalogContext, xact_trace);
        cost_model.setCachingEnabled(true);
        TransactionCacheEntry entry = cost_model.getTransactionCacheEntry(xact_trace);
        assertNotNull(entry);
//        System.err.println(entry.toString());

        // --------------------------
        // Query Counters
        // --------------------------
        assertEquals(xact_trace.getQueries().size(), entry.getTotalQueryCount());
        assertEquals(xact_trace.getQueries().size(), entry.getExaminedQueryCount());
        assertEquals(0, entry.getSingleSiteQueryCount());
        assertEquals(1, entry.getMultiSiteQueryCount());
       
        // ---------------------------------------------
        // Partitions Touched by Txns
        // This should be all partitions because the query is trying to do a
        // range look-up on the partitioning column
View Full Code Here

        assertNotNull(xact_trace);
       
        // System.err.println(xact_trace.debug(catalogContext.database));
        SingleSitedCostModel cost_model = new SingleSitedCostModel(catalogContext);
        cost_model.estimateTransactionCost(catalogContext, xact_trace);
        TransactionCacheEntry entry = cost_model.getTransactionCacheEntry(xact_trace);
        assertNotNull(entry);
       
        assertEquals(xact_trace.getQueries().size(), entry.getTotalQueryCount());
        assertEquals(xact_trace.getQueries().size(), entry.getExaminedQueryCount());
        assertEquals(1, entry.getSingleSiteQueryCount());
        assertEquals(1, entry.getMultiSiteQueryCount());
       
        // Check Partition Access Histogram
        Histogram<Integer> hist_access = cost_model.getQueryPartitionAccessHistogram();
        assertNotNull(hist_access);
        assertEquals(NUM_PARTITIONS, hist_access.getValueCount());
View Full Code Here

        cost_model.invalidateCache(this.getTable(TM1Constants.TABLENAME_SUBSCRIBER));
        cost_model.invalidateCache(this.getTable(TM1Constants.TABLENAME_CALL_FORWARDING));
       
        TransactionTrace xact_trace = xacts.get(0);
        assertNotNull(xact_trace);
        TransactionCacheEntry entry = cost_model.getTransactionCacheEntry(xact_trace);
        assertNull(entry);
       
        // Make sure that we updated the Execution Histogram
        Histogram<Integer> hist = cost_model.getJavaExecutionHistogram();
        assert(hist.isEmpty());
View Full Code Here

        // Invalidate that mofo!
        cost_model.invalidateCache(this.getTable(TM1Constants.TABLENAME_SUBSCRIBER));
       
        Histogram<Integer> expected_touched = new ObjectHistogram<Integer>();
        for (TransactionTrace txn_trace : xacts) {
            TransactionCacheEntry txn_entry = cost_model.getTransactionCacheEntry(txn_trace);
            assertNotNull(txn_entry);
//            expected_touched.put(txn_entry.getExecutionPartition());
           
            for (QueryCacheEntry query_entry : cost_model.getQueryCacheEntries(txn_trace)) {
                QueryTrace query_trace = txn_trace.getQueries().get(query_entry.getQueryIdx());
                assertNotNull(query_trace);
                assertNotNull(query_trace.getCatalogItemName());
                Boolean should_be_invalid = (query_trace.getCatalogItemName().equals(invalid_stmt.getName()) ? true :
                                            (query_trace.getCatalogItemName().equals(valid_stmt.getName()) ? false : null));
                assertNotNull(should_be_invalid);
                assertEquals(should_be_invalid.booleanValue(), query_entry.isInvalid());
               
                if (should_be_invalid) {
                    assert(query_entry.getAllPartitions().isEmpty());
                } else {
                    assertFalse(query_entry.getAllPartitions().isEmpty());
                    expected_touched.put(query_entry.getAllPartitions());
                }
            } // FOR
           
            assertEquals(catalog_proc.getStatements().size(), txn_entry.getTotalQueryCount());
            assert(txn_entry.isSinglePartitioned());
            assertFalse(txn_entry.isComplete());
            assertEquals(1, txn_entry.getExaminedQueryCount());
            assertEquals(0, txn_entry.getMultiSiteQueryCount());
            assertEquals(1, txn_entry.getSingleSiteQueryCount());
        } // FOR
       
        // Grab the histograms about what partitions got touched and make sure that they are updated properly
        Histogram<Integer> txn_partitions = cost_model.getTxnPartitionAccessHistogram();
        Histogram<Integer> query_partitions = cost_model.getQueryPartitionAccessHistogram();
View Full Code Here

                target_txn = txn;
                break;
            }
        } // FOR
        assertNotNull(target_txn);
        TransactionCacheEntry entry = null;
        int orig_partition_parameter = catalog_proc.getPartitionparameter();
       
        // Ok, now let's disable the ProcParameter
        SingleSitedCostModel cost_model = new SingleSitedCostModel(clone_catalogContext);
        catalog_proc.setPartitionparameter(NullProcParameter.PARAM_IDX);
        cost_model.setCachingEnabled(true);
        cost_model.estimateTransactionCost(clone_catalogContext, target_txn);
        entry = cost_model.getTransactionCacheEntry(target_txn);
        assertNotNull(entry);
        assertEquals(HStoreConstants.NULL_PARTITION_ID, entry.getExecutionPartition());
        assert(entry.isSinglePartitioned());
       
        // Make something else the ProcParameter
        cost_model.invalidateCache(catalog_proc);
        catalog_proc.setPartitionparameter(orig_partition_parameter + 1);
        cost_model.getPartitionEstimator().initCatalog(clone_catalogContext);
        cost_model.estimateTransactionCost(clone_catalogContext, target_txn);
        entry = cost_model.getTransactionCacheEntry(target_txn);
        assertNotNull(entry);
        assert(entry.getExecutionPartition() != HStoreConstants.NULL_PARTITION_ID);
        // assertFalse(entry.isSingleSited());
       
        // Now let's put S_ID back in as the ProcParameter
        cost_model.invalidateCache(catalog_proc);
        catalog_proc.setPartitionparameter(orig_partition_parameter);
        cost_model.getPartitionEstimator().initCatalog(clone_catalogContext);
        cost_model.estimateTransactionCost(clone_catalogContext, target_txn);
        entry = cost_model.getTransactionCacheEntry(target_txn);
        assertNotNull(entry);
        assert(entry.getExecutionPartition() != HStoreConstants.NULL_PARTITION_ID);
        if (!entry.isSinglePartitioned()) System.err.println(entry.debug());
        assert(entry.isSinglePartitioned());
    }
View Full Code Here

//        System.err.println(catalog_tbl + ": " + catalog_col);

        SingleSitedCostModel cost_model = new SingleSitedCostModel(clone_catalogContext);
        cost_model.setCachingEnabled(true);
        cost_model.estimateTransactionCost(clone_catalogContext, target_txn);
        TransactionCacheEntry txn_entry = cost_model.getTransactionCacheEntry(target_txn);
        assertNotNull(txn_entry);
        assertNotNull(txn_entry.getExecutionPartition());
        assert(txn_entry.isSinglePartitioned());
//        System.err.println(txn_entry.debug());
    }
View Full Code Here

TOP

Related Classes of edu.brown.costmodel.SingleSitedCostModel.TransactionCacheEntry

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.