Package edu.brown.designer

Examples of edu.brown.designer.DesignerVertex


            ptree.setName("PartTree-Round" + round);
            //
            // Make sure we include the replicated tables
            //
            for (String table_name : proc_hints.force_replication) {
                DesignerVertex vertex = agraph.getVertex(info.catalogContext.database.getTables().get(table_name));
                ptree.addVertex(vertex);
                vertex.setAttribute(ptree, PartitionTree.VertexAttributes.METHOD.name(), PartitionMethodType.REPLICATION);
            } // FOR
            try {
                for (DesignerVertex root : candidate_roots) {
                    buildPartitionTree(ptree, root, agraph, proc_hints);
                } // FOR
            } catch (Exception ex) {
                LOG.fatal(ex.getLocalizedMessage());
                ex.printStackTrace();
                System.exit(1);
            }

            //
            // We add the procedure that was used to generate this ptree for
            // debugging
            // Weight the partition trees by how often the procedure is executed
            //
            ptree.getProcedures().add(catalog_proc);
            ptree.setWeight((double) info.workload.getTraces(catalog_proc).size());
            designer.getGraphs(catalog_proc).add(ptree);

            //
            // Now go through and see if there any tables that need to be
            // replicated
            //
            LOG.debug("Invoking replication tree generation...");

            AbstractDirectedGraph<DesignerVertex, DesignerEdge> rtree = new AbstractDirectedGraph<DesignerVertex, DesignerEdge>(info.catalogContext.database) {
                private static final long serialVersionUID = 1L;
            };
            rtree.setName("RepTree-Round" + round);
            ReplicationTreeGenerator replication_check = new ReplicationTreeGenerator(info, agraph, ptree);
            try {
                replication_check.generate(rtree);
            } catch (Exception ex) {
                LOG.fatal(ex.getLocalizedMessage());
                ex.printStackTrace();
                System.exit(1);
            }
            designer.getGraphs(catalog_proc).add(rtree);

            //
            // If there are no tables that are conflicted, then there is nothing
            // else we can do
            //
            if (replication_check.getConflictVertices().isEmpty())
                break;

            //
            // Examine the edges that we created and see if there is a common
            // ancestor that the
            // the destination vertex wants to be partitioned on
            //
            List<Table> candidates = new ArrayList<Table>();
            candidates.addAll(replication_check.getReplicationCandidates());
            boolean forced_dependency = false;
            for (DesignerVertex conflict_vertex : replication_check.getConflictVertices()) {
                Table conflict_tbl = conflict_vertex.getCatalogItem();
                //
                // For each edge in the replication tree that is coming into
                // this conflict vertex,
                // see whether there is an overlapping ancestor
                //
                Map<Column, Integer> ancestors = new HashMap<Column, Integer>();
                int max_count = 0;
                Column max_column = null;
                Column max_conflict_column = null;
                for (DesignerEdge conflict_edge : rtree.getInEdges(conflict_vertex)) {
                    PredicatePairs cset = (PredicatePairs) conflict_edge.getAttribute(AccessGraph.EdgeAttributes.COLUMNSET.name());
                    for (Column conflict_column : cset.findAllForParent(Column.class, conflict_tbl)) {
                        Column ancestor_column = CollectionUtil.last(info.dependencies.getAncestors(conflict_column));
                        Integer count = ancestors.get(ancestor_column);
                        count = (count == null ? 1 : count + 1);
                        ancestors.put(ancestor_column, count);
                        if (count > max_count) {
                            max_count = count;
                            max_column = ancestor_column;
                            max_conflict_column = conflict_column;
                        }
                    } // FOR
                } // FOR
                assert (max_column != null);
                //
                // If we have a column that is used in both trees, then that's
                // the one we'll want to partition
                // our buddy on...
                //
                boolean valid = true;
                for (Column column : ancestors.keySet()) {
                    if (!max_column.equals(column) && max_count == ancestors.get(column)) {
                        valid = false;
                        break;
                    }
                } // FOR
                LOG.debug("CONFLICT - " + conflict_vertex + ": " + ancestors);
                if (valid) {
                    String child_key = CatalogKey.createKey(max_conflict_column.getParent());
                    String parent_key = CatalogKey.createKey(max_column.getParent());
                    String orig_parent_key = proc_hints.force_dependency.put(child_key, parent_key);
                    if (!parent_key.equals(orig_parent_key)) {
                        LOG.debug("Forcing dependency " + child_key + "->" + parent_key);
                        forced_dependency = true;
                    }
                }
            } // FOR
            if (forced_dependency)
                continue;

            //
            // Now for each candidate we need to check whether replicating would
            // actually improve
            // the performance of this procedure. So first we need to get a
            // baseline cost
            // of the procedure on the workload
            // TODO: Support set sizes greater than 2!!
            //
            Set<Set<Table>> candidate_sets = new LinkedHashSet<Set<Table>>();
            assert (candidates.size() <= 2);
            for (int ctr0 = 0, cnt = candidates.size(); ctr0 < cnt; ctr0++) {
                Set<Table> set = new HashSet<Table>();
                set.add(candidates.get(ctr0));
                candidate_sets.add(set);
                for (int ctr1 = ctr0 + 1; ctr1 < cnt; ctr1++) {
                    set = new HashSet<Table>();
                    set.add(candidates.get(ctr0));
                    set.add(candidates.get(ctr1));
                    candidate_sets.add(set);
                } // FOR
            } // FOR

            //
            // Calculate the cost of each replication candidate set
            // If this is the first time we are doing this for this procedure,
            // then add in a blank
            // replication set so that we can get the baseline cost
            //
            Set<Table> best_set = null;
            double best_cost = Double.MAX_VALUE;
            if (best_cost == overall_best_cost)
                candidate_sets.add(new HashSet<Table>());
            for (Set<Table> replication_set : candidate_sets) {
                cost_model.invalidateCache(candidates);

                Catalog new_catalog = CatalogCloner.cloneBaseCatalog(info.catalogContext.database.getCatalog());
                for (Table catalog_tbl : proc_tables) {
                    DesignerVertex vertex = ptree.getVertex(catalog_tbl);
                    assert (vertex != null) : "PartitionTree is missing a vertex for " + catalog_tbl + " " + ptree.getVertices();
                    Table new_catalog_tbl = CatalogCloner.clone(catalog_tbl, new_catalog);

                    //
                    // Mark the table as replicated if it's in the current set
                    //
                    if (replication_set.contains(catalog_tbl) || ptree.isReplicated(vertex)) {
                        new_catalog_tbl.setIsreplicated(true);
                        new_catalog_tbl.setPartitioncolumn(ReplicatedColumn.get(new_catalog_tbl));
                        //
                        // Otherwise partition it according to the current
                        // partition tree
                        //
                    } else {
                        Column catalog_col = (Column) vertex.getAttribute(ptree, PartitionTree.VertexAttributes.ATTRIBUTE.name());
                        assert (catalog_col != null) : "Failed to retrieve partition column for " + catalog_tbl + " " + vertex.getAttributeValues(ptree);
                        Column new_catalog_col = new_catalog_tbl.getColumns().get(catalog_col.getName());
                        assert (new_catalog_col != null);
                        new_catalog_tbl.setIsreplicated(false);
                        new_catalog_tbl.setPartitioncolumn(new_catalog_col);
                    }
View Full Code Here


        LOG.debug("Successors:     " + agraph.getSuccessors(parent));

        // Look through all the vertices that our parent is adjacent to in the
        // AccessGraph
        // and come up with a list of the next vertices to visit
        DesignerVertex parent_root = ptree.getRoot(parent);
        for (DesignerVertex vertex : agraph.getSuccessors(parent)) {
            boolean force = false;
            Table vertex_tbl = vertex.getCatalogItem();

            // Skip any self-references
            if (vertex == parent)
                continue;
            // Skip any vertices that are marked as replicated
            if (ptree.isReplicated(vertex)) {
                LOG.debug("Skipping " + vertex + " because it is already marked for replication");
                continue;
            }

            // Force dependencies
            if (hints.force_dependency.containsKey(CatalogKey.createKey(vertex_tbl))) {
                String force_dependency = hints.force_dependency.get(CatalogKey.createKey(vertex_tbl));
                // We'll force this We're allowed to break this forced
                // dependency if the current parent
                // is a descendant of the table that the child should be forced
                // to
                if (force_dependency != null) {
                    Table force_tbl = CatalogKey.getFromKey(info.catalogContext.database, force_dependency, Table.class);
                    if (parent_table.equals(force_tbl)) {
                        force = true;
                        LOG.debug("Forcing dependency: " + parent_table + "->" + vertex_tbl);
                    } else if (info.dependencies.getDescendants(force_tbl).contains(parent_table) && (ptree.containsVertex(vertex) || hints.force_replication.contains(force_dependency))) {
                        LOG.debug("Allowing take over of dependency: " + parent_table + "->" + vertex_tbl);
                    } else {
                        LOG.debug("Not allowing: " + parent_table + "->" + vertex_tbl);
                        LOG.debug(info.dependencies.getDescendants(force_tbl));
                        LOG.debug("ptree.containsVertex: " + ptree.containsVertex(vertex));
                        continue;
                    }
                }
            }

            // We then need to check whether the current parent table is a
            // descendant of
            // the other vertex in the DependencyGraph. This to check that you
            // don't violate
            // a foreign key dependency that may be several vertices removed
            List<DesignerEdge> path = info.dgraph.getPath(vertex, parent);
            if (!path.isEmpty()) {
                LOG.debug("Skipping " + vertex + " because it is an ancestor of " + parent + " in the DependencyGraph");
                continue;
            }

            // If this vertex is already in the PartitionTree, we need to check
            // whether our
            // current parent has an edge with a greater weight to the vertex
            // than the one it
            // currently has in the tree.
            //
            // What if the other vertex is a direct ascendant of the current
            // parent? That means
            // if we break the edge then the whole path will get messed up and
            // all the vertices
            // will be orphans again. Therefore, I think it should only move the
            // vertex if
            // the edge is greater *AND* it's not an ascendant of the current
            // parent.
            if (ptree.containsVertex(vertex)) {
                if (ptree.getPath(parent).contains(vertex)) {
                    LOG.debug("Skipping " + vertex + " because it is an ancestor of " + parent + " in the PartitionTree");
                    continue;
                }

                // Now look to whether there is a new Edge in the AccessGraph
                // with a greater
                // weight than the one that is currently being used in the
                // PartitionTree
                // We will only move the vertex if it's in the same tree
                DesignerVertex vertex_orig_parent = ptree.getParent(vertex);
                if (vertex_orig_parent != null) {
                    // Check whether these guys have the same root
                    // If they don't, then we won't move the child.
                    DesignerVertex child_root = ptree.getRoot(vertex);
                    if (!child_root.equals(parent_root)) {
                        LOG.debug("Skipping " + vertex + " because it's in a different partition tree (" + child_root + "<->" + parent_root + ")");
                        continue;
                    }

                    DesignerEdge orig_edge = null;
View Full Code Here

                    }

                    @Override
                    protected void callback(DesignerVertex element) {
                        LOG.debug("SimpleCountingMapper.CALLBACK -> " + element.getCatalogItem());
                        DesignerVertex parent = this.getPrevious();

                        PartitionMethodType method = (PartitionMethodType) (element.getAttribute(ptree, PartitionTree.VertexAttributes.METHOD.name()));
                        Column attribute = null;
                        Table parent_table = null;
                        Column parent_attribute = null;

                        if (method == PartitionMethodType.REPLICATION) {
                            // Anything???
                        } else {
                            attribute = (Column) element.getAttribute(ptree, PartitionTree.VertexAttributes.ATTRIBUTE.name());
                            //
                            // If this vertex is a dependent on a parent, then
                            // we also need to get the
                            // mapping of columns
                            //
                            if (parent != null) {
                                DesignerEdge edge = ptree.findEdge(parent, element);
                                if (edge == null) {
                                    LOG.fatal("Failed to find edge between parent '" + parent + "' and child '" + element + "'");
                                    this.stop();
                                    return;
                                }
                                parent_attribute = (Column) element.getAttribute(ptree, PartitionTree.VertexAttributes.PARENT_ATTRIBUTE.name());
                                parent_table = parent.getCatalogItem();
                                method = PartitionMethodType.MAP; // Why do we
                                                                  // have to set
                                                                  // this here?
                                // if (parent_attribute == null) {
                                // PartitionEntry entry = new
View Full Code Here

                    VerticalPartitionColumn vp_col = (VerticalPartitionColumn) catalog_col;
                    catalog_col = vp_col.getHorizontalColumn();
                    assert (catalog_col != null);
                }

                DesignerVertex v0 = this.agraph.getVertex(catalog_tbl);
                if (v0 == null)
                    throw new IllegalArgumentException("Missing vertex for " + catalog_tbl);
                Collection<DesignerEdge> edges = this.agraph.findEdgeSet(v0, catalog_col);
                assert (edges != null);
                Collection<DesignerEdge> all_edges = this.agraph.getIncidentEdges(v0);
View Full Code Here

        // ----------------------------------------------
        // Table
        // ----------------------------------------------
        if (catalog_obj instanceof Table) {
            Table catalog_tbl = (Table) catalog_obj;
            DesignerVertex v = this.agraph.getVertex(catalog_tbl);
            if (v == null)
                throw new IllegalArgumentException("Missing vertex for " + catalog_tbl);
            for (DesignerEdge e : this.agraph.getIncidentEdges(v)) {
                if (this.isMarked(e))
                    this.unmarkEdge(e);
View Full Code Here

        // Table
        // ----------------------------------------------
        if (catalog_obj instanceof Table) {
            Table catalog_tbl = (Table) catalog_obj;
            int total_cols = 0;
            DesignerVertex v = this.agraph.getVertex(catalog_tbl);
            if (v == null) {
                throw new IllegalArgumentException("Missing vertex for " + catalog_tbl);
            }

            Column repcol = this.repcolumns.get(catalog_tbl);
View Full Code Here

            new AccessGraphGenerator(info, catalog_proc).generate(agraph);
        } // FOR

        double ret = 1;
        for (Table catalog_tbl : catalog_db.getTables()) {
            DesignerVertex v = agraph.getVertex(catalog_tbl);
            if (v == null)
                continue;

            Set<Column> used_cols = new HashSet<Column>();
            Collection<DesignerEdge> edges = agraph.getIncidentEdges(v);
View Full Code Here

                Table catalog_tbl = args.catalog_db.getTables().getIgnoreCase(tableName);
                if (catalog_tbl == null) {
                    LOG.warn("Unknown table '" + tableName + "'");
                    continue;
                }
                DesignerVertex v = dgraph.getVertex(catalog_tbl);
                assert(v != null) : "Failed to get vertex for " + catalog_tbl;
                dgraph.removeVertex(v);
            } // FOR
        } // FOR
       
View Full Code Here

     */
    private DependencyGraph generateDependencyGraph() {
        DependencyGraph dgraph = new DependencyGraph(this.catalog_db);

        for (Table catalog_tbl : this.table_profiles.keySet()) {
            dgraph.addVertex(new DesignerVertex(catalog_tbl));
        } // FOR

        for (Entry<Table, TableProfile> e : this.table_profiles.entrySet()) {
            Table catalog_tbl = e.getKey();
            TableProfile profile = e.getValue();
            DesignerVertex v = dgraph.getVertex(catalog_tbl);

            for (Table other_tbl : profile.getDependentTables()) {
                boolean ret = dgraph.addEdge(new DesignerEdge(dgraph), dgraph.getVertex(other_tbl), v, EdgeType.DIRECTED);
                assert (ret) : "Failed to add edge from " + other_tbl + " to " + catalog_tbl;
            } // FOR
View Full Code Here

        List<DesignerVertex> ptree_vertices = new ArrayList<DesignerVertex>();
        ptree_vertices.addAll(this.ptree.getVertices());

        Set<DesignerVertex> modified = new HashSet<DesignerVertex>();
        for (int ctr0 = 0, cnt = ptree_vertices.size(); ctr0 < cnt; ctr0++) {
            DesignerVertex v0 = ptree_vertices.get(ctr0);
            if (this.ptree.isReplicated(v0))
                continue;

            LOG.debug("v0: " + v0 + "\n");
            for (int ctr1 = ctr0 + 1; ctr1 < cnt; ctr1++) {
                DesignerVertex v1 = ptree_vertices.get(ctr1);
                LOG.debug("  |- v1: " + v1 + "\n");
                DesignerEdge ag_edge = this.agraph.findEdge(v0, v1);

                if (((v0.getCatalogItem().getName().equals("WAREHOUSE") && v1.getCatalogItem().getName().equals("STOCK")) || (v1.getCatalogItem().getName().equals("WAREHOUSE") && v0.getCatalogItem()
                        .getName().equals("STOCK")))
                        && ag_edge == null) {
                    LOG.debug("???????????\n");
                }

                //
                // If this other vertex is already replicated, then we don't
                // care
                //
                if (this.ptree.isReplicated(v1))
                    continue;

                //
                // If there is an edge between these two vertices, then check
                // whether
                // there is a path from the "upper" vertex to the "lower" vertex
                //
                if (ag_edge != null && this.ptree.getPath(v0, v1).isEmpty() && this.ptree.getPath(v1, v0).isEmpty() && graph.getPath(v0, v1).isEmpty() && graph.getPath(v1, v0).isEmpty()) {

                    //
                    // There was no edge in the PartitionTree, so that means we
                    // want to add
                    // an edge in our replication tree. Note that although edges
                    // in the AccessGraph
                    // are undirected, we need to make sure that our edge goes
                    // in the right direction.
                    // Well, that's easy then there is a foreign key but what
                    // about when it's just
                    // some random join?
                    //
                    boolean found = false;
                    for (int ctr = 0; ctr < 2; ctr++) {
                        if (ctr == 1) {
                            DesignerVertex temp = v0;
                            v0 = v1;
                            v1 = temp;
                        }
                        // Edge dg_edge = this.info.dgraph.findEdge(v0, v1);
                        // Edge dg_edge = this.agraph.findEdge(v0, v1);
View Full Code Here

TOP

Related Classes of edu.brown.designer.DesignerVertex

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.