Package org.voltdb.catalog

Examples of org.voltdb.catalog.ProcParameter


        // Set procedure parameter types from its run method parameters
        if (isMapReduce == false) {
            paramTypes = procMethod.getParameterTypes();// run method parameters
            for (int i = 0; i < paramTypes.length; i++) {
                Class<?> cls = paramTypes[i];
                ProcParameter param = params.add(String.valueOf(i));
                param.setIndex(i);

                // handle the case where the param is an array
                if (cls.isArray()) {
                    param.setIsarray(true);
                    cls = cls.getComponentType();
                } else
                    param.setIsarray(false);

                VoltType type;
                try {
                    type = VoltType.typeFromClass(cls);
                } catch (RuntimeException e) {
                    // handle the case where the type is invalid
                    String msg = "Procedure: " + shortName + " has a parameter with invalid type: ";
                    msg += cls.getSimpleName();
                    throw compiler.new VoltCompilerException(msg);
                }
                param.setType(type.getValue());
            } // FOR
        }
        // The input parameters to the MapInputQuery are the input parameters
        // for the Procedure
        else {
            paramTypes = new Class<?>[mapStatement.getParameters().size()];
            for (int i = 0; i < paramTypes.length; i++) {
                StmtParameter catalog_stmt_param = mapStatement.getParameters().get(i);
                assert (catalog_stmt_param != null);
                VoltType vtype = VoltType.get(catalog_stmt_param.getJavatype());
                paramTypes[i] = vtype.classFromType();

                ProcParameter catalog_proc_param = procedure.getParameters().add(catalog_stmt_param.getName());
                catalog_proc_param.setIndex(i);
                catalog_proc_param.setIsarray(false); // One day...
                catalog_proc_param.setType(vtype.getValue());
            } // FOR
        }
        return (paramTypes);
    }
View Full Code Here


        // set the procedure parameter types from the statement parameter types
        int i = 0;
        for (StmtParameter stmtParam : CatalogUtil.getSortedCatalogItems(stmtParams, "index")) {
            // name each parameter "param1", "param2", etc...
            ProcParameter procParam = params.add("param" + String.valueOf(i));
            procParam.setIndex(stmtParam.getIndex());
            procParam.setIsarray(false);
            procParam.setType(stmtParam.getJavatype());
            i++;
        }

        // parse the procinfo
        procedure.setSinglepartition(info.singlePartition);
View Full Code Here

    }

    private synchronized void buildCatalogCache() {
        for (Procedure catalog_proc : this.catalogContext.database.getProcedures()) {
            if (catalog_proc.getParameters().size() > 0) {
                ProcParameter catalog_param = null;
                int param_idx = catalog_proc.getPartitionparameter();
                if (param_idx == NullProcParameter.PARAM_IDX || catalog_proc.getParameters().isEmpty()) {
                    catalog_param = NullProcParameter.singleton(catalog_proc);
                } else if (param_idx == RandomProcParameter.PARAM_IDX) {
                    catalog_param = RandomProcParameter.singleton(catalog_proc);
                } else {
                    catalog_param = catalog_proc.getParameters().get(param_idx);
                }
                this.cache_procPartitionParameters.put(catalog_proc, catalog_param);
                if (debug.val)
                    LOG.debug(catalog_proc + " ProcParameter Cache: " + (catalog_param != null ? catalog_param.fullName() : catalog_param));
            }
        } // FOR

        for (Table catalog_tbl : this.catalogContext.database.getTables()) {
            if (catalog_tbl.getSystable())
View Full Code Here

        assert(catalog_proc != null);
        assert(params != null);
//        assert(catalog_proc.getParameters().size() == params.length) :
//            String.format("Invalid number of ProcParameters for %s: %d != %d",
//                          catalog_proc, catalog_proc.getParameters().size(), params.length);
        ProcParameter catalog_param = this.cache_procPartitionParameters.get(catalog_proc);

        if (catalog_param == null && force) {
            if (force) {
                int idx = catalog_proc.getPartitionparameter();
                if (idx == NullProcParameter.PARAM_IDX || catalog_proc.getParameters().isEmpty()) {
                    catalog_param = NullProcParameter.singleton(catalog_proc);
                } else if (idx == RandomProcParameter.PARAM_IDX) {
                    catalog_param = RandomProcParameter.singleton(catalog_proc);
                } else {
                    catalog_param = catalog_proc.getParameters().get(idx);
                }
                this.cache_procPartitionParameters.put(catalog_proc, catalog_param);
                if (debug.val)
                    LOG.debug("Added cached " + catalog_param + " for " + catalog_proc);
            } else {
                if (debug.val)
                    LOG.debug(catalog_proc + " has no parameters. No base partition for you!");
                return (HStoreConstants.NULL_PARTITION_ID);
            }
        }

        if (force == false && (catalog_param == null || catalog_param instanceof NullProcParameter)) {
            if (debug.val)
                LOG.debug(catalog_proc + " does not have a pre-defined partition parameter. No base partition!");
            return (HStoreConstants.NULL_PARTITION_ID);
            // } else if (!force && !catalog_proc.getSinglepartition()) {
            // if (debug.val) LOG.debug(catalog_proc +
            // " is not marked as single-partitioned. Executing as multi-partition");
            // return (null);
        }
        int partition = HStoreConstants.NULL_PARTITION_ID;
        boolean is_array = catalog_param.getIsarray();

        // Special Case: RandomProcParameter
        if (catalog_param instanceof RandomProcParameter) {
            partition = RandomProcParameter.rand.nextInt(this.num_partitions);
        }
        // Special Case: MultiProcParameter
        else if (catalog_param instanceof MultiProcParameter) {
            MultiProcParameter mpp = (MultiProcParameter) catalog_param;
            if (debug.val)
                LOG.debug(catalog_proc.getName() + " MultiProcParameter: " + mpp);
            int hashes[] = new int[mpp.size()];
            for (int i = 0; i < hashes.length; i++) {
                int mpp_param_idx = mpp.get(i).getIndex();
                assert (mpp_param_idx >= 0) : "Invalid Partitioning MultiProcParameter #" + mpp_param_idx;
                assert (mpp_param_idx < params.length) : CatalogUtil.getDisplayName(mpp) + " < " + params.length;
                int hash = this.calculatePartition(catalog_proc, params[mpp_param_idx], is_array);
                hashes[i] = (hash == HStoreConstants.NULL_PARTITION_ID ? 0 : hash);
                if (debug.val)
                    LOG.debug(mpp.get(i) + " value[" + params[mpp_param_idx] + "] => hash[" + hashes[i] + "]");
            } // FOR
            partition = this.hasher.multiValueHash(hashes);
            if (debug.val)
                LOG.debug(Arrays.toString(hashes) + " => " + partition);
        }
        // Single ProcParameter
        else {
            if (debug.val)
                LOG.debug("Calculating base partition using " + catalog_param.fullName() + ": " + params[catalog_param.getIndex()]);
            assert(catalog_param.getIndex() >= 0) : "Invalid parameter offset " + catalog_param.fullName();
            partition = this.calculatePartition(catalog_proc, params[catalog_param.getIndex()], is_array);
        }
        return (partition);
    }
View Full Code Here

                if (PartitionerUtil.shouldIgnoreProcedure(hints, catalog_proc))
                    continue;
                String proc_key = CatalogKey.createKey(catalog_proc);
                String param_key = catalogkey_map.get(proc_key);
                if (param_key != null) {
                    ProcParameter catalog_proc_param = CatalogKey.getFromKey(info.catalogContext.database, param_key, ProcParameter.class);
                    pplan_map.put(catalog_proc, catalog_proc_param);
                } else if (useCatalog) {
                    pplan_map.put(catalog_proc, CatalogUtil.getPartitioningProcParameter(catalog_proc));
                }
            } // FOR
View Full Code Here

            if (catalog_proc.getSystemproc() || pentry == null || catalog_proc.getParameters().size() == 0)
                continue;
            if (debug)
                LOG.debug("Applying PartitionEntry to " + catalog_proc.getName() + ": " + pentry);

            ProcParameter catalog_proc_param = null;
            switch (pentry.getMethod()) {
                case NONE:
                    catalog_proc_param = NullProcParameter.singleton(catalog_proc);
                    break;
                case RANDOM:
                    catalog_proc_param = RandomProcParameter.singleton(catalog_proc);
                    break;
                case HASH:
                    catalog_proc_param = pentry.getAttribute();
                    break;
                default:
                    assert (false) : "Unexpected PartitionMethodType for " + catalog_proc + ": " + pentry.getMethod();
            } // SWITCH

            assert (catalog_proc_param != null) : "Null ProcParameter for " + catalog_proc;
            catalog_proc.setPartitionparameter(catalog_proc_param.getIndex());

            Boolean single_partition = pentry.isSinglePartition();
            if (single_partition != null)
                catalog_proc.setSinglepartition(single_partition);
        } // FOR
View Full Code Here

                }

                // Procedure Partitioning
            } else if (e.getKey() instanceof Procedure) {
                Procedure catalog_proc = (Procedure) e.getKey();
                ProcParameter catalog_proc_param = (ProcParameter) e.getValue();
                boolean single_partition = true;
                ProcParameter attribute = null;

                if (catalog_proc.getSystemproc()) {
                    continue;
                } else if (catalog_proc_param instanceof NullProcParameter || catalog_proc_param == null || catalog_proc.getParameters().size() == 0) {
                    method = PartitionMethodType.NONE;
View Full Code Here

            } else if (catalog_proc.getPartitionparameter() == NullProcParameter.PARAM_IDX) {
                pplan_map.put(catalog_proc, NullProcParameter.singleton(catalog_proc));
            } else {
                int param_idx = catalog_proc.getPartitionparameter();
                assert (param_idx >= 0);
                ProcParameter catalog_proc_param = catalog_proc.getParameters().get(param_idx);
                assert (catalog_proc_param != null) : "Null ProcParameter for " + catalog_proc.getName() + ": Idx #" + param_idx;
                pplan_map.put(catalog_proc, catalog_proc_param);
            }
        }
        return (PartitionPlan.createFromMap(pplan_map));
View Full Code Here

                    // ----------------------------------------------
                    // 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));

                        cost_model.clear();
                        double cost2 = this.cost_model.estimateWorkloadCost(info.catalogContext, info.workload, filter, best_vertex.cost);
                        LOG.error("Second Time: " + cost2);

                    }
                    assert (is_valid) : attribute_key + ": Parent[" + parent.cost + "] <= Current[" + cost + "]" + "\n" + "Rounded: Parent[" + MathUtil.roundToDecimals(parent.cost, 2)
                            + "] <= Current[" + MathUtil.roundToDecimals(cost, 2) + "]";
                }

                // If this is a complete solution, then check whether if it is
                // the best one that we have seen thus far
                // Allow the current solution to be the best solution if the
                // following criteria are met:
                // (1) It's a complete solution
                // (2) It has not exhausted our per-partition memory limit
                // (4) It is less than the upper bounds limit
                // (3) And one of the following is true:
                // (a) The current best solution is the start vertex
                // (b) Or the current solution has a cost less than the current
                // best solution
                if (complete_solution && memory_exceeded == false && cost < BranchAndBoundPartitioner.this.upper_bounds_vertex.cost
                        && (BranchAndBoundPartitioner.this.best_vertex.isStartVertex() || cost < BranchAndBoundPartitioner.this.best_vertex.cost)) {
                    assert (best_vertex.cost > state.cost) : "Best=" + best_vertex.cost + ", Current=" + state.cost;
                    assert (upper_bounds_vertex.cost > state.cost) : "Upper=" + upper_bounds_vertex.cost + ", Current=" + state.cost;

                    if (debug.val) {
                        LOG.debug("Old Solution:\n" + StringBoxUtil.box(best_vertex.toString()));
                    }
                    BranchAndBoundPartitioner.this.best_vertex = state;
                    if (debug.val) {
                        LOG.debug("New Best Solution:\n" + StringBoxUtil.box(best_vertex.toString()));
                        if (this.cost_model.hasDebugMessages())
                            LOG.debug("Last Cost Model Info:\n " + this.cost_model.getLastDebugMessage());
                    }

                    // Log new solution cost
                    if (hints.shouldLogSolutionCosts())
                        hints.logSolutionCost(state.cost, state.singlep_txns);

                    // Check whether we found our target solution and need to
                    // stop
                    // Note that we only need to compare Tables, because the
                    // Procedure's could have
                    // different parameters for those ones where the parameter
                    // actually doesn't make a difference
                    if (hints.target_plan != null) {
                        if (debug.val)
                            LOG.info("Comparing new best solution with target PartitionPlan");
                        PartitionPlan new_plan = createPartitionPlan(hints, best_vertex, false, false);
                        if (hints.target_plan.getTableEntries().equals(new_plan.getTableEntries())) {
                            this.halt_search = true;
                            this.halt_reason = HaltReason.FOUND_TARGET;
                        }
                    }

                    // for (int i = 0; i <
                    // ((TimeIntervalCostModel)this.cost_model).getIntevalCount();
                    // i++) {
                    // System.err.println("Interval #" + i);
                    // System.err.println(((TimeIntervalCostModel)this.cost_model).getCostModel(i).getTxnPartitionAccessHistogram());
                    // System.err.println("================================================");
                    // }
                    //
                    // System.exit(1);
                }

                // ----------------------------------------------
                // CONTINUE SEARCH TRAVERSAL
                // ----------------------------------------------

                // We now need to look to see whether we should continue down
                // this path. Much like
                // selecting a new best solution, the following criteria must be
                // met in order for
                // the partitioner to be allowed to continue down a search path:
                // (1) If this is last attribute at this level in the tree
                // AND we're looking at a TABLE
                // AND we're doing a greedy search
                // Then we'll always want to keep traversing here.
                // Otherwise, the following the criteria must be met:
                // (1) It must not be a complete solution
                // (2) The current catalog item must be a table (no procedures!)
                // (3) The cost must be less than the current best solution cost
                // (4) The cost must be less than the upper bounds limit
                // Or we can just say screw all that and keep going if the
                // exhaustive flag is enabled
                if (this.halt_search == false
                        && ((last_attribute && is_table && this.hints.greedy_search) || (this.hints.exhaustive_search == true) || (complete_solution == false && is_table
                                && cost < BranchAndBoundPartitioner.this.best_vertex.cost && cost < BranchAndBoundPartitioner.this.upper_bounds_vertex.cost))) {

                    // IMPORTANT: If this is the last table in our traversal,
                    // then we need to switch over
                    // to working Procedures->ProcParameters. We have to now
                    // calculate the list of attributes
                    // that we want to consider
                    // if (is_last_table &&
                    // this.hints.enable_procparameter_search) {
                    // for (int i = idx + 1; i < this.num_elements; i++) {
                    // Procedure catalog_proc =
                    // (Procedure)this.all_search_elements.get(i);
                    // LinkedList<String> attributes =
                    // AbstractPartitioner.generateProcParameterOrder(info,
                    // this.info.catalogContext.database, catalog_proc, hints);
                    //
                    // // We should have ProcParameter candidates!
                    // assert(attributes.isEmpty() == false) :
                    // "No ProcParameter candidates: " + catalog_proc + "\n" +
                    // state;
                    // this.traversal_attributes.get(proc_key).clear();
                    // this.traversal_attributes.get(proc_key).addAll(attributes);
                    // } // FOR
                    // }

                    // We only traverse if this is a table. The ProcParameter
                    // selection is a simple greedy algorithm
                    if (this.hints.greedy_search == false || (this.hints.greedy_search == true && last_attribute)) {
                        if (debug.val && this.hints.greedy_search)
                            LOG.debug(this.createLevelOutput(local_best_vertex, "GREEDY->" + local_best_vertex.getPartitionKey(), spacer, false));
                        this.cp.update(current);
                        this.traverse((this.hints.greedy_search ? local_best_vertex : state), idx + 1);
                        this.cp.reset(current);
                    }
                }
                if (vp_col != null) {
                    this.revertVerticalPartitionColumn(vp_col);
                    vp_col = null;
                }
                if (this.halt_search)
                    break;
            } // FOR

            // ProcParameter Traversal
            if (!is_table && !this.halt_search) {
                assert (local_best_vertex != null) : "Missing local best vertex for " + current_key;

                // Set the partitioning ProcParameter in this Procedure to be
                // the one that
                // had the lowest cost in our search up above.
                Procedure current_proc = (Procedure) current;
                String best_key = local_best_vertex.getPartitionKey();
                ProcParameter current_param = CatalogKey.getFromKey(info.catalogContext.database, best_key, ProcParameter.class);
                assert (current_param != null);
                current_proc.setPartitionparameter(current_param.getIndex());

                // Is this necessary?
                this.cost_model.invalidateCache(current_proc);

                // if (debug.val)
View Full Code Here

        for (Procedure catalog_proc : info.catalogContext.database.getProcedures()) {
            if (catalog_proc.getSystemproc())
                continue;
            int size = catalog_proc.getParameters().size();

            ProcParameter catalog_param = NullProcParameter.singleton(catalog_proc);
            if (size > 0) {
                int idx = this.rand.nextInt(size);
                catalog_param = catalog_proc.getParameters().get(idx);
            }
            pplan_map.put(catalog_proc, catalog_param);
View Full Code Here

TOP

Related Classes of org.voltdb.catalog.ProcParameter

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.