Package edu.brown.hstore.estimators.markov

Examples of edu.brown.hstore.estimators.markov.MarkovEstimatorState


        assertNotSame(w_id, remote_w_id);
        Arrays.fill(s_w_ids, remote_w_id);
//        System.err.println("S_W_ID: " + Arrays.toString(s_w_ids));
        txn_trace.setParam(5, s_w_ids);
       
        MarkovEstimatorState state = t_estimator.startTransaction(XACT_ID.getAndIncrement(),
                                                                  this.catalog_proc,
                                                                  txn_trace.getParams());
        assertNotNull(state);
           
        // Even though it won't correctly identify the exact path that we're going to
        // take (i.e., what partitions the getStockInfo queries will need), the path
        // should be complete (i.e., we should see each Statement in NewOrder executed
        // at least once)
        MarkovEstimate initialEst = state.getInitialEstimate();
//        System.err.println("FIRST ESTIMATE:\n" + initialEst);
        List<MarkovVertex> initialPath = initialEst.getMarkovPath();
        assertFalse(initialPath.isEmpty());
        Set<Statement> seenStmts = new HashSet<Statement>();
        for (MarkovVertex v : initialPath) {
View Full Code Here


    public void testMultipleStartTransaction() throws Exception {
        Set<MarkovEstimatorState> all_states = new HashSet<MarkovEstimatorState>();
        int expected = 20;
        MarkovEstimate initialEst = null;
        for (int i = 0; i < expected; i++) {
            MarkovEstimatorState state = t_estimator.startTransaction(XACT_ID.getAndIncrement(),
                                                                      this.catalog_proc,
                                                                      multip_trace.getParams());
            assertNotNull(state);
            assertFalse(all_states.contains(state));
            all_states.add(state);
           
            if (initialEst == null) {
                initialEst = state.getInitialEstimate();
                // System.err.println("FIRST ESTIMATE:\n" + initialEst);
            } else {
                MarkovEstimate est = state.getInitialEstimate();
                // System.err.printf("ESTIMATE #%02d:\n%s", i, est);
                assertEquals(initialEst.getTouchedPartitions(thresholds), est.getTouchedPartitions(thresholds));
            }
           
        } // FOR
View Full Code Here

     * testStartTransaction
     */
    @Test
    public void testStartTransaction() throws Exception {
        long txn_id = XACT_ID.getAndIncrement();
        MarkovEstimatorState state = t_estimator.startTransaction(txn_id, this.catalog_proc, singlep_trace.getParams());
        assertNotNull(state);
        assertNotNull(state.getLastEstimate());
       
        MarkovEstimate est = state.getInitialEstimate();
        System.err.println(est);
        assertNotNull(est);
        assertTrue(est.toString(), est.isInitialized());
//        assertTrue(est.toString(), est.isSinglePartitionProbabilitySet());
        assertTrue(est.toString(), est.isAbortProbabilitySet());
        assertTrue(est.toString(), est.isConfidenceCoefficientSet());
        // assertTrue(est.toString(), est.getConfidenceCoefficient() >= 0f);
//        assertEquals(est.toString(), 1.0f, est.getSinglePartitionProbability());
        assertEquals(est.toString(), 1.0f, est.getConfidenceCoefficient());

        //        System.err.println(est.toString());
       
        MarkovGraph markov = state.getMarkovGraph();
        List<MarkovVertex> initial_path = est.getMarkovPath();
        assertNotNull(initial_path);
        assertFalse(initial_path.isEmpty());
       
        System.err.println("# of Vertices: " + markov.getVertexCount());
View Full Code Here

     */
    @Test
    public void testStartTransactionDtxn() throws Exception {
        TransactionTrace txn_trace = multip_trace;
        long txn_id = XACT_ID.getAndIncrement();
        MarkovEstimatorState state = t_estimator.startTransaction(txn_id, this.catalog_proc, txn_trace.getParams());
        assertNotNull(state);
        assertNotNull(state.getLastEstimate());
       
        MarkovEstimate initialEst = state.getInitialEstimate();
        assertNotNull(initialEst);
        assertTrue(initialEst.toString(), initialEst.isInitialized());
//        assertTrue(initialEst.toString(), initialEst.isSinglePartitionProbabilitySet());
        assertTrue(initialEst.toString(), initialEst.isAbortProbabilitySet());
//        assertTrue(initialEst.toString(), initialEst.getSinglePartitionProbability() < 1.0f);
        assertTrue(initialEst.toString(), initialEst.isConfidenceCoefficientSet());
        assertTrue(initialEst.toString(), initialEst.getConfidenceCoefficient() >= 0f);
        assertTrue(initialEst.toString(), initialEst.getConfidenceCoefficient() <= 1f);
        assertFalse(initialEst.toString(), initialEst.isSinglePartitioned(this.thresholds));
        assertTrue(initialEst.toString(), initialEst.isAbortable(this.thresholds));
       
        MarkovGraph markov = state.getMarkovGraph();
        List<MarkovVertex> initial_path = initialEst.getMarkovPath();
        assertNotNull(initial_path);
        assertFalse(initial_path.isEmpty());
       
        System.err.println("# of Vertices: " + markov.getVertexCount());
View Full Code Here

     */
    @Test
    public void testExecuteQueries() throws Exception {
        TransactionTrace txn_trace = multip_trace;
        long txn_id = XACT_ID.getAndIncrement();
        MarkovEstimatorState state = t_estimator.startTransaction(txn_id, this.catalog_proc, txn_trace.getParams());
        assertNotNull(state);
        assertNotNull(state.getLastEstimate());
       
        MarkovEstimate initialEst = state.getInitialEstimate();
        assertNotNull(initialEst);
        assertTrue(initialEst.toString(), initialEst.isInitialized());
//        assertTrue(initialEst.toString(), initialEst.isSinglePartitionProbabilitySet());
        assertTrue(initialEst.toString(), initialEst.isAbortProbabilitySet());
//        assertTrue(initialEst.toString(), initialEst.getSinglePartitionProbability() < 1.0f);
        assertTrue(initialEst.toString(), initialEst.isConfidenceCoefficientSet());
        assertTrue(initialEst.toString(), initialEst.getConfidenceCoefficient() >= 0f);
        assertTrue(initialEst.toString(), initialEst.getConfidenceCoefficient() <= 1f);

        // Get the list of partitions that we're going to touch in the beginning
        // We should never mark these as finished in subsequent estimates
        PartitionSet touched = initialEst.getTouchedPartitions(thresholds);
        assertFalse(touched.isEmpty());
        assertFalse(touched.contains(HStoreConstants.NULL_PARTITION_ID));
        System.err.println("TOUCHED: " + touched);
        assertFalse(touched.toString(), touched.size() == 1);
       
        // Execute a bunch of batches
        // All should say that the txn is not finished with the partitions until we
        // get to the one that contains the updateStock queries, which should be the last.
        Statement lastBatchStmt = this.getStatement(this.catalog_proc, "updateStock");
        for (int i = 0, cnt = txn_trace.getBatchCount(); i < cnt; i++) {
            List<QueryTrace> queries = txn_trace.getBatchQueries(i);
            assertFalse(queries.isEmpty());
            boolean is_last = (i+1 == cnt);
            Statement stmts[] = new Statement[queries.size()];
            PartitionSet partitions[] = new PartitionSet[queries.size()];
           
            boolean found = false;
            int idx = 0;
            for (QueryTrace q : queries) {
                stmts[idx] = q.getCatalogItem(catalogContext.database);
                assertNotNull(stmts[idx]);
                partitions[idx] = new PartitionSet();
                p_estimator.getAllPartitions(partitions[idx], q, state.getBasePartition());
                assertFalse(partitions[idx].isEmpty());
                assertFalse(partitions[idx].contains(HStoreConstants.NULL_PARTITION_ID));
               
                found = found || stmts[idx].equals(lastBatchStmt);
                idx++;
View Full Code Here

            partitions[idx] = new PartitionSet();
            p_estimator.getAllPartitions(partitions[idx], q, base_partition);
            idx++;
        } // FOR
       
        MarkovEstimatorState states[] = new MarkovEstimatorState[2];
        MarkovEstimate ests[] = new MarkovEstimate[states.length];
        for (int i = 0; i < states.length; i++) {
            HStoreConf.singleton().site.markov_fast_path = (i != 0);
            states[i] = t_estimator.startTransaction(XACT_ID.getAndIncrement(), this.catalog_proc, txn_trace.getParams());
            assertNotNull(states[i]);
View Full Code Here

     */
    @Test
    public void testProcessTransactionTrace() throws Exception {
        TransactionTrace txn_trace = singlep_trace;
        assertNotNull(txn_trace);
        MarkovEstimatorState s = this.t_estimator.processTransactionTrace(txn_trace);
        assertNotNull(s);
       
        MarkovEstimate initialEst = s.getInitialEstimate();
        assertNotNull(initialEst);
        assertTrue(initialEst.toString(), initialEst.isInitialized());
//        assertTrue(initialEst.toString(), initialEst.isSinglePartitionProbabilitySet());
        assertTrue(initialEst.toString(), initialEst.isAbortProbabilitySet());
//        assertTrue(initialEst.toString(), initialEst.getSinglePartitionProbability() < 1.0f);
        assertTrue(initialEst.toString(), initialEst.isConfidenceCoefficientSet());
        assertTrue(initialEst.toString(), initialEst.getConfidenceCoefficient() >= 0f);
        assertTrue(initialEst.toString(), initialEst.getConfidenceCoefficient() <= 1f);
        assertTrue(initialEst.toString(), initialEst.getMarkovPath().isEmpty() == false);
       
        // We should have an MarkovEstimate for each batch
        assertEquals(txn_trace.getBatchCount(), s.getEstimateCount());
        List<Estimate> estimates = s.getEstimates();
        for (int i = 0, cnt = txn_trace.getBatchCount(); i < cnt; i++) {
            List<QueryTrace> queries = txn_trace.getBatchQueries(i);
            assertFalse(queries.isEmpty());
           
            MarkovEstimate est = (MarkovEstimate)estimates.get(i);
View Full Code Here

        // probably doesn't hurt
        // to do it right in case we need it later
        // At this point we know what the transaction actually would do using
        // the TransactionEstimator's
        // internal Markov models.
        MarkovEstimatorState s = this.t_estimator.processTransactionTrace(txn_trace);
        assert (s != null);
        Procedure catalog_proc = txn_trace.getCatalogItem(catalogContext.database);

        if (debug.val) {
            LOG.debug("Measuring MarkovEstimate Accuracy: " + txn_trace);
            if (trace.val) {
                LOG.trace("Estimated: " + ((MarkovEstimate)s.getInitialEstimate()).getMarkovPath());
                LOG.trace("Actual:    " + s.getActualPath());
            }
        }

        double cost = 0.0d;

        this.e_read_partitions.clear();
        this.e_write_partitions.clear();
        MarkovEstimate initialEst = s.getInitialEstimate();
        assert(initialEst != null);
        assert(initialEst.isInitialized());
        for (Integer partition : initialEst.getTouchedPartitions(this.thresholds)) {
            if (initialEst.isDonePartition(this.thresholds, partition.intValue()) == false) {
                for (MarkovVertex v : initialEst.getMarkovPath()) {
                    if (v.getPartitions().contains(partition) == false)
                        continue;
                    if (((Statement) v.getCatalogItem()).getReadonly()) {
                        this.e_read_partitions.add(partition);
                    } else {
                        this.e_write_partitions.add(partition);
                    }
                } // FOR
            }
        } // FOR

        List<MarkovVertex> initialPath = initialEst.getMarkovPath();
        List<MarkovVertex> actualPath = s.getActualPath();
        this.a_read_partitions.clear();
        this.a_write_partitions.clear();
        MarkovUtil.getReadWritePartitions(actualPath, this.a_read_partitions, this.a_write_partitions);

        // Try fast version
        try {
            if (this.force_full_comparison || !this.comparePathsFast(CollectionUtil.last(initialPath), actualPath)) {
                // Otherwise we have to do the full path comparison to figure
                // out just how wrong we are
                cost = this.comparePathsFull(s);
                this.full_path_counter.put(catalog_proc);
            } else {
                this.fast_path_counter.put(catalog_proc);
            }
        } catch (Throwable ex) {
            System.err.println(txn_trace.debug(catalogContext.database));
            System.err.println("COST = " + cost);
            System.err.println("BASE PARTITION = " + s.getBasePartition());
            System.err.println("PENALTIES = " + this.penalties);
            System.err.println("ESTIMATED PARTITIONS: " + this.e_all_partitions);
            System.err.println("ACTUAL PARTITIONS: " + this.a_all_partitions);
            System.err.println("MARKOV GRAPH: " + MarkovUtil.exportGraphviz(s.getMarkovGraph(), true, null).writeToTempFile(catalog_proc));
            System.err.println();

            String e_path = "ESTIMATED PATH:\n" + StringUtil.join("\n", initialEst.getMarkovPath());
            String a_path = "ACTUAL PATH:\n" + StringUtil.join("\n", s.getActualPath());
            System.err.println(StringUtil.columns(e_path, a_path));
            System.err.println("MARKOV ESTIMATE:\n" + s.getInitialEstimate());

            throw new RuntimeException(ex);
        }

        this.t_estimator.destroyEstimatorState(s);
View Full Code Here

TOP

Related Classes of edu.brown.hstore.estimators.markov.MarkovEstimatorState

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.