Examples of CatalogType


Examples of org.voltdb.catalog.CatalogType

         * @param idx
         * @throws Exception
         */
        protected void traverse(final StateVertex parent, final int idx) throws Exception {
            assert (idx < this.num_elements && idx >= 0);
            final CatalogType current = this.all_search_elements.get(idx);
            assert (current != null);
            final String current_key = this.all_search_keys.get(idx);

            this.traverse_ctr++;
            final boolean is_table = (idx < this.num_tables);
            // Are we the last element in the list, thereby creating a complete
            // solution
            final boolean complete_solution = (idx + 1 == this.num_elements);
            if (is_table)
                assert (current instanceof Table);
            final String spacer = BranchAndBoundPartitioner.TRAVERSAL_SPACERS.get(idx);

            if (this.halt_search == false) {
                assert (this.halt_reason == null);
                if (hints.limit_back_tracks != null && hints.limit_back_tracks >= 0 && this.backtrack_ctr > hints.limit_back_tracks) {
                    LOG.info("Hit back track limit. Halting search [" + this.backtrack_ctr + "]");
                    this.halt_search = true;
                    this.halt_reason = HaltReason.BACKTRACK_LIMIT;
                    return;
                } else if (this.halt_time != null && System.currentTimeMillis() >= this.halt_time) {
                    LOG.info("Hit time limit. Halting search [" + this.backtrack_ctr + "]");
                    this.halt_search = true;
                    this.halt_reason = (this.halt_time_local ? HaltReason.LOCAL_TIME_LIMIT : HaltReason.GLOBAL_TIME_LIMIT);
                    return;
                }
            } else
                return;

            // Get the list of possible attributes that we could use for this
            // current element
            Collection<CatalogType> current_attributes = null;
            try {
                current_attributes = this.cp.getCandidateValues(current, CatalogType.class);
            } catch (IllegalArgumentException ex) {
                throw new RuntimeException("Failed to get candidate attributes for " + current, ex);
            }
            final int num_attributes = current_attributes.size();
            assert (current_attributes != null);
            if (trace.val) {
                Map<String, Object> m = new LinkedHashMap<String, Object>();
                m.put("Traversal Level", traverse_ctr);
                m.put("Item Index", idx);
                m.put("Current", current);
                m.put("Attributes", String.format("COUNT=%d\n%s", num_attributes, StringUtil.join("\n", CatalogUtil.getDisplayNames(current_attributes))));
                LOG.trace(StringUtil.formatMaps(m));
            }

            // Keep track of whether we have a VerticalPartitionColumn that
            // needs to be
            // reset after each round
            VerticalPartitionColumn vp_col = null;

            // Get our workload filter for this level of the traversal
            Filter filter = BranchAndBoundPartitioner.this.traversal_filters.get(current);

            // Descendant tables used for memory calculations
            // It's ok for it to be empty. That means we're searching against
            // all of tables
            Set<Table> current_previousTables = this.previous_tables[idx];
            assert (current_previousTables != null) : String.format("No previous tables at index %d? [current=%s, num_tables=%d]", idx, current, num_tables);

            // The local best vertex is the best vertex for this level in the
            // traversal
            StateVertex local_best_vertex = null;

            // Just make sure that if we have a VerticalPartitionColumn in our
            // list of
            // current attributes that it's optimizations are not applied
            // If they are, then we can disable them
            for (CatalogType attribute : current_attributes) {
                if (attribute instanceof VerticalPartitionColumn && ((VerticalPartitionColumn) attribute).isUpdateApplied()) {
                    ((VerticalPartitionColumn) attribute).revertUpdate();
                }
            } // FOR

            // Iterate through the columns and find the one with the best cost
            int attribute_ctr = 0;
            for (CatalogType attribute : current_attributes) {
                assert (attribute != null) : "Null attribute key for " + current + ": " + current_attributes;
                String attribute_key = CatalogKey.createKey(attribute);
                if (trace.val)
                    LOG.trace("Evaluating " + attribute.fullName());
                boolean memory_exceeded = false;
                Long memory = null;
                CatalogType current_attribute = null;

                // Is this the last element we have to look at
                boolean last_attribute = (++attribute_ctr == num_attributes);

                // Dynamic Debugging
                this.cost_model.setDebuggingEnabled(this.hints.isDebuggingEnabled(attribute_key));

                // IMPORTANT: We have to invalidate the cache for the current
                // element *AND* all those levels
                // below us in the search tree!
                if (this.cost_model.isCachingEnabled()) {
                    for (int i = idx; i < this.num_elements; i++) {
                        if (trace.val)
                            LOG.trace("Invalidating " + this.all_search_keys.get(i));
                        this.cost_model.invalidateCache(this.all_search_keys.get(i));
                    } // FOR
                    // If we're not using caching, then just clear out the cost
                    // model completely
                } else {
                    this.cost_model.clear();
                }

                // ----------------------------------------------
                // TABLE PARTITIONING KEY
                // ----------------------------------------------
                if (is_table) {
                    Table current_tbl = (Table) current;
                    Column search_col = (Column) attribute;
                    Column current_col = null;

                    // Check whether this is our replication marker column
                    if (search_col instanceof ReplicatedColumn) {
                        current_tbl.setIsreplicated(true);
                        current_col = ReplicatedColumn.get(current_tbl);
                    }
                    // VerticalPartitionColumn
                    else if (search_col instanceof VerticalPartitionColumn) {
                        // We need to update the statements that can use them
                        // using the pre-compiled query plans
                        current_tbl.setIsreplicated(false);
                        current_col = search_col;
                        vp_col = (VerticalPartitionColumn) search_col;
                        assert (CatalogUtil.getDatabase(vp_col).equals(info.catalogContext.database)) : String.format("VP_COL[%d] != INFO[%d]", CatalogUtil.getDatabase(vp_col).hashCode(),
                                info.catalogContext.database.hashCode());

                        MaterializedViewInfo catalog_view = vp_col.applyUpdate();
                        assert (catalog_view != null) : "Unexpected null MaterializedViewInfo for " + current_tbl + " vertical partition:\n" + vp_col;
                        if (this.cost_model.isCachingEnabled()) {
                            if (trace.val)
                                LOG.trace("Invalidating VerticalPartition Statements in cost model: " + vp_col.getOptimizedQueries());
                            this.cost_model.invalidateCache(vp_col.getOptimizedQueries());
                        }
                        TableStatistics tstats = VerticalPartitionerUtil.computeTableStatistics(vp_col, info.stats);
                        assert (tstats != null);
                        // Add the vp's sys table to the list of tables that we
                        // need to estimate the memory
                        assert (catalog_view.getDest() != null) : "Missing parent table for " + catalog_view.fullName();
                        assert (this.current_vertical_partitions.contains(catalog_view.getDest()) == false) : vp_col;
                        this.current_vertical_partitions.add(catalog_view.getDest());
                    }
                    // MultiColumn
                    else if (search_col instanceof MultiColumn) {
                        // Nothing special?
                        current_tbl.setIsreplicated(false);
                        current_col = search_col;
                    }
                    // Otherwise partition on this particular column
                    else {
                        current_tbl.setIsreplicated(false);
                        current_col = current_tbl.getColumns().get(search_col.getName());
                    }

                    // We should always have a horizontal partition column
                    assert (current_col != null);
                    current_tbl.setPartitioncolumn(current_col);
                    assert (current_col.getName().equals(current_tbl.getPartitioncolumn().getName())) : "Unexpected " + current_col.fullName() + " != " + current_tbl.getPartitioncolumn().fullName();

                    // Estimate memory size
                    Collection<Table> tablesToEstimate = null;
                    if (hints.enable_vertical_partitioning && this.current_vertical_partitions.isEmpty() == false) {
                        tablesToEstimate = CollectionUtils.union(current_previousTables, this.current_vertical_partitions);
                    } else {
                        tablesToEstimate = current_previousTables;
                    }
                    if (trace.val)
                        LOG.trace(String.format("Calculating memory size of current solution [%s]:\n%s", current_col.fullName(), StringUtil.join("\n", current_previousTables)));
                    try {
                        memory = this.memory_estimator.estimate(info.catalogContext.database, info.getNumPartitions(), tablesToEstimate);
                    } catch (Throwable ex) {
                        throw new RuntimeException("Failed to estimate memory using new attribute " + current_col.fullName(), ex);
                    }
                    memory_exceeded = (memory > this.hints.max_memory_per_partition);
                    if (trace.val)
                        LOG.trace(String.format("%s Memory: %s [ratio=%.2f, exceeded=%s]", current_col.fullName(), StringUtil.formatSize(memory), memory / (double) hints.max_memory_per_partition,
                                memory_exceeded));
                    current_attribute = current_col;

                    // ----------------------------------------------
                    // PROCEDURE PARTITIONING PARAMETER
                    // ----------------------------------------------
                } else {
                    Procedure current_proc = (Procedure) current;
                    ProcParameter current_proc_param = (ProcParameter) attribute;
                    assert (current_proc_param != null);
                    current_proc.setPartitionparameter(current_proc_param.getIndex());
                    memory = parent.memory;
                    current_attribute = current_proc_param;
                }

                // ----------------------------------------------
                // COST ESTIMATION
                // ----------------------------------------------
                Double cost = null;
                Double singlep_txns = null;
                // Don't estimate the cost if it doesn't fit
                if (!memory_exceeded) {
                    cost = this.cost_model.estimateWorkloadCost(info.catalogContext, info.workload, filter, best_vertex.cost);
                    singlep_txns = this.cost_model.getSinglePartitionProcedureHistogram().getSampleCount() / (double) this.cost_model.getProcedureHistogram().getSampleCount();
                } else {
                    cost = Double.MAX_VALUE;
                }

                StateVertex state = new StateVertex(parent, current_key, attribute_key, is_table, cost, singlep_txns, memory);
                if (debug.val)
                    state.debug = cost_model.debugHistograms(info.catalogContext);
                // if (!this.graph.containsVertex(parent))
                // this.graph.addVertex(parent);
                // this.graph.addEdge(new StateEdge(), parent, state,
                // EdgeType.DIRECTED);

                if (local_best_vertex == null || local_best_vertex.cost > state.cost)
                    local_best_vertex = state;
                assert (local_best_vertex != null);

                // ----------------------------------------------
                // DEBUG OUTPUT
                // ----------------------------------------------
                // state.debug = this.cost_model.getLastDebugMessage();
                LOG.info(this.createLevelOutput(state, CatalogUtil.getDisplayName(current_attribute, false), spacer, memory_exceeded));

                // ----------------------------------------------
                // ANALYSIS
                // ----------------------------------------------
                if (memory_exceeded) {
                    if (debug.val)
                        LOG.debug("Memory exceeeded! Skipping solution!");
                    if (vp_col != null) {
                        this.revertVerticalPartitionColumn(vp_col);
                        vp_col = null;
                    }
                    continue;
                }

                // The cost of our parent can never be greater than our cost
                if (!parent.isStartVertex()) {
                    boolean is_valid = MathUtil.greaterThanEquals(cost.floatValue(), parent.cost.floatValue(), 0.001f);

                    if (!is_valid) { // && debug.get()) {
                        Map<String, Object> m0 = new LinkedHashMap<String, Object>();
                        m0.put("Parent State", parent.toString());
                        m0.put("Parent CostModel", parent.debug);
                        m0.put("Parent Catalog", createPartitionPlan(hints, parent, false, false));

                        Map<String, Object> m1 = new LinkedHashMap<String, Object>();
                        m1.put("Current Attribute", current_attribute.fullName());
                        m1.put("Current State", state.toString());
                        m1.put("Current CostModel", cost_model.debugHistograms(info.catalogContext));
                        m1.put("Current Catalog", createPartitionPlan(hints, state, false, false));

                        LOG.error("CURRENT COST IS GREATER THAN CURRENT COST! THIS CANNOT HAPPEN!\n" + StringUtil.formatMaps(m0, m1));
View Full Code Here

Examples of org.voltdb.catalog.CatalogType

    @SuppressWarnings("unchecked")
    private static <T extends CatalogType> void createKey(T catalog_item, JSONStringer stringer) throws JSONException {
        assert (catalog_item.getParent() != null) : catalog_item + " has null parent";

        stringer.object();
        CatalogType parent = catalog_item.getParent();
        String key = null;

        // SPECIAL CASE: StmtParameter
        // Since there may be Statement's with the same name but in different
        // Procedures,
        // we also want to include the Procedure name
        if (catalog_item instanceof StmtParameter) {
            assert (parent.getParent() != null);
            key = parent.getParent().getName() + PARENT_DELIMITER + parent.getName();

            // SPECIAL CASE: MultiAttributeCatalogType
        } else if (catalog_item instanceof MultiAttributeCatalogType) {
            MultiAttributeCatalogType multicatalog = (MultiAttributeCatalogType) catalog_item;
            key = parent.getName() + MULTIATTRIBUTE_DELIMITER + multicatalog.getPrefix();
        } else {
            key = parent.getName();
        }
        assert (key.isEmpty() == false);
        stringer.key(key);

        // SPECIAL CASE: MultiAttributeCatalogType
View Full Code Here

Examples of org.voltdb.catalog.CatalogType

    @SuppressWarnings("unchecked")
    private static <T extends CatalogType> T getFromKey(Database catalog_db, JSONObject jsonObject, Class<T> catalog_class) throws JSONException {
        if (debug.val)
            LOG.debug("Retrieving catalog key for " + jsonObject);
        T catalog_child = null;
        CatalogType catalog_parent = null;

        String parent_key = CollectionUtil.first(jsonObject.keys());
        String orig_parent_key = parent_key;
        String multiattribute_key = null;
        String child_key = jsonObject.getString(parent_key);
View Full Code Here

Examples of org.voltdb.catalog.CatalogType

            super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
            if (value instanceof DefaultMutableTreeNode) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
                Object obj = node.getUserObject();
                if (obj instanceof WrapperNode) {
                    CatalogType catalog_obj = ((WrapperNode)node.getUserObject()).getCatalogType();
                    this.setFont(this.getFont().deriveFont(Font.BOLD));
                   
                    //
                    // Cluster
                    //
View Full Code Here

Examples of org.voltdb.catalog.CatalogType

            Object user_obj = node.getUserObject();
            String new_header = null;
            String new_text = null;
            boolean text_mode = true;
            if (user_obj instanceof WrapperNode) {
                CatalogType catalog_obj  = ((WrapperNode)user_obj).getCatalogType();
                new_text = CatalogViewer.this.attributeText.getAttributesText(catalog_obj);
            }
            else if (user_obj instanceof AttributesNode) {
                AttributesNode wrapper = (AttributesNode)user_obj;
                new_text = wrapper.getAttributes();
View Full Code Here

Examples of org.voltdb.catalog.CatalogType

    }

    public static CatalogPair factory(CatalogType element0, CatalogType element1, ExpressionType comparison_exp, QueryType... query_types) {
        // Sort them!
        if (element0.compareTo(element1) > 0) {
            CatalogType temp = element0;
            element0 = element1;
            element1 = temp;
        }
        return (new CatalogPair(element0, element1, comparison_exp, query_types));
    }
View Full Code Here

Examples of org.voltdb.catalog.CatalogType

            return (ret);
        if (catalog_item == null)
            return (null);
        assert (catalog_item.getParent() != null) : catalog_item + " has null parent";

        CatalogType parent = catalog_item.getParent();
        ret = parent.getName() + PARENT_DELIMITER;

        // Special Case: MultiAttributeCatalogType
        if (catalog_item instanceof MultiAttributeCatalogType) {
            MultiAttributeCatalogType multicatalog = (MultiAttributeCatalogType) catalog_item;
            ret += multicatalog.getPrefix();
            for (Object sub_item : multicatalog) {
                ret += MULTIATTRIBUTE_DELIMITER + ((CatalogType) sub_item).getName();
            } // FOR
        } else {
            ret += catalog_item.getName();

            // Special Case: StmtParameter
            // Since there may be Statement's with the same name but in
            // different Procedures,
            // we also want to include the Procedure name
            if (catalog_item instanceof StmtParameter) {
                assert (parent.getParent() != null);
                ret = parent.getParent().getName() + PARENT_DELIMITER + ret;
            }
        }
        CACHE_CREATEKEY.put(catalog_item, ret);
        return (ret);
    }
View Full Code Here

Examples of org.voltdb.catalog.CatalogType

            cache = new HashMap<String, CatalogType>();
            CatalogKeyOldVersion.CACHE_GETFROMKEY.put(catalog_db, cache);
        }

        T catalog_child = null;
        CatalogType catalog_parent = null;
        int idx = key.indexOf(PARENT_DELIMITER);
        assert (idx != -1) : "Invalid CatalogKeyOldVersion format '" + key + "'";
        String parent_key = key.substring(0, idx);
        String child_key = key.substring(idx + 1);
View Full Code Here

Examples of org.voltdb.catalog.CatalogType

        for (CatalogPair cp : cset) {
            if (cp.getComparisonExp() != ExpressionType.COMPARE_EQUAL) {
                return (false);
            }
           
            CatalogType ctypes[] = { cp.getFirst(), cp.getSecond() };
            for (int i = 0; i < ctypes.length; i++) {
                if (ctypes[i] instanceof Column) {
                    Column target_col = (Column)ctypes[i];
                    Table target_tbl = target_col.getParent();
View Full Code Here

Examples of org.voltdb.catalog.CatalogType

                        new ExpressionTreeWalker() {
                            @Override
                            protected void callback(AbstractExpression exp) {
                                if (!(exp instanceof AbstractValueExpression))
                                    return;
                                CatalogType element = null;
                                switch (exp.getExpressionType()) {
                                    case VALUE_PARAMETER: {
                                        int param_idx = ((ParameterValueExpression) exp).getParameterId();
                                        element = catalog_stmt.getParameters().get(param_idx);
                                        if (element == null) {
                                            LOG.warn("ERROR: Unable to find Parameter object in catalog [" + ((ParameterValueExpression) exp).getParameterId() + "]");
                                            this.stop();
                                        }
                                        // We want to use the ProcParameter instead of the StmtParameter
                                        // It's not an error if the StmtParameter is not mapped to a
                                        // ProcParameter
                                        if (convert_params && ((StmtParameter) element).getProcparameter() != null) {
                                            LOG.debug(element + "(" + element + ") --> ProcParameter[" + element.getField("procparameter") + "]");
                                            element = ((StmtParameter) element).getProcparameter();
                                        }
                                        break;
                                    }
                                    case VALUE_TUPLE_ADDRESS:
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.