Package org.voltdb.catalog

Examples of org.voltdb.catalog.Database


                expected.add(mpp);
            } // FOR
        } // FOR
        assertFalse(expected.isEmpty());
       
        Database clone_db = CatalogCloner.cloneDatabase(catalog_db);
        assertNotNull(clone_db);

        Cluster catalog_cluster = CatalogUtil.getCluster(catalog_db);
        assertNotNull(catalog_cluster);
        Cluster clone_cluster = CatalogUtil.getCluster(clone_db);
        assertNotNull(clone_cluster);
        for (Host catalog_host : catalog_cluster.getHosts()) {
            Host clone_host = clone_cluster.getHosts().get(catalog_host.getName());
            assertNotNull(clone_host);
            checkFields(Host.class, catalog_host, clone_host);
        } // FOR

        for (Site catalog_site : catalog_cluster.getSites()) {
            Site clone_site = clone_cluster.getSites().get(catalog_site.getName());
            assertNotNull(clone_site);
            checkFields(Site.class, catalog_site, clone_site);
        }

        assertEquals(NUM_PARTITIONS, CatalogUtil.getNumberOfPartitions(clone_db));
        Collection<Integer> clone_partitions = CatalogUtil.getAllPartitionIds(clone_db);
        assertNotNull(clone_partitions);
        assertEquals(all_partitions.size(), clone_partitions.size());
        assert (all_partitions.containsAll(clone_partitions));

        for (Table catalog_tbl : catalog_db.getTables()) {
            Table clone_tbl = clone_db.getTables().get(catalog_tbl.getName());
            assertNotNull(catalog_tbl.toString(), clone_tbl);
            checkFields(Table.class, catalog_tbl, clone_tbl);

            for (Column catalog_col : catalog_tbl.getColumns()) {
                Column clone_col = clone_tbl.getColumns().get(catalog_col.getName());
                assertNotNull(CatalogUtil.getDisplayName(catalog_col), clone_col);
                assertEquals(CatalogUtil.getDisplayName(clone_col), clone_tbl, (Table) clone_col.getParent());
                assertEquals(CatalogUtil.getDisplayName(clone_col), clone_tbl.hashCode(), clone_col.getParent().hashCode());
            } // FOR
            for (MaterializedViewInfo catalog_view : catalog_tbl.getViews()) {
                assert (catalog_view.getGroupbycols().size() > 0);
                MaterializedViewInfo clone_view = clone_tbl.getViews().get(catalog_view.getName());
                checkFields(MaterializedViewInfo.class, catalog_view, clone_view);
            } // FOR

        } // FOR

        for (Procedure catalog_proc : catalog_db.getProcedures()) {
            Procedure clone_proc = clone_db.getProcedures().get(catalog_proc.getName());
            assertNotNull(catalog_proc.toString(), clone_proc);
            assertEquals(clone_proc.getParameters().toString(), catalog_proc.getParameters().size(), clone_proc.getParameters().size());

            // Procedure Conflicts
            this.checkProcedureConflicts(catalog_proc, catalog_proc.getConflicts(), clone_proc.getConflicts());
View Full Code Here


        Column columns[] = new Column[] { this.getColumn(catalog_tbl, "W_NAME"), this.getColumn(catalog_tbl, "W_YTD"), };
        MultiColumn mc = MultiColumn.get(columns);
        assertNotNull(mc);
        catalog_tbl.setPartitioncolumn(mc);

        Database clone_db = CatalogCloner.cloneDatabase(catalog_db);
        assertNotNull(clone_db);

        Table clone_tbl = this.getTable(clone_db, catalog_tbl.getName());
        Column clone_col = clone_tbl.getPartitioncolumn();
        assertNotNull(clone_col);
View Full Code Here

        // update the jar file with the new catalog
        if (m_paramMappingsFile != null || m_paramMappings.isEmpty() == false) {
            File jarFile = new File(jarPath);
            Catalog catalog = CatalogUtil.loadCatalogFromJar(jarFile);
            assert(catalog != null);
            Database catalog_db = CatalogUtil.getDatabase(catalog);
           
            this.applyParameterMappings(catalog_db);
           
            // Construct a List of prefetchable Statements
            this.applyPrefetchableFlags(catalog_db);
View Full Code Here

    @Override
    public void load() {
        if (d) LOG.debug(String.format("Starting TM1Loader [subscriberSize=%d, scaleFactor=%.2f]",
                         this.subscriberSize, this.getScaleFactor()));

        final Database catalog_db = this.getCatalogContext().database;

        final Thread threads[] =
        { new Thread() {
            public void run() {
                if (d) LOG.debug("Start loading " + TM1Constants.TABLENAME_SUBSCRIBER);
                Table catalog_tbl = catalog_db.getTables().get(TM1Constants.TABLENAME_SUBSCRIBER);
                genSubscriber(catalog_tbl);
                if (d) LOG.debug("Finished loading " + TM1Constants.TABLENAME_SUBSCRIBER);
            }
        }, new Thread() {
            public void run() {
                if (d) LOG.debug("Start loading " + TM1Constants.TABLENAME_ACCESS_INFO);
                Table catalog_tbl = catalog_db.getTables().get(TM1Constants.TABLENAME_ACCESS_INFO);
                genAccessInfo(catalog_tbl);
                if (d) LOG.debug("Finished loading " + TM1Constants.TABLENAME_ACCESS_INFO);
            }
        }, new Thread() {
            public void run() {
                if (d) LOG.debug("Start loading " + TM1Constants.TABLENAME_SPECIAL_FACILITY + " and " + TM1Constants.TABLENAME_CALL_FORWARDING);
                Table catalog_spe = catalog_db.getTables().get(TM1Constants.TABLENAME_SPECIAL_FACILITY);
                Table catalog_cal = catalog_db.getTables().get(TM1Constants.TABLENAME_CALL_FORWARDING);
                genSpeAndCal(catalog_spe, catalog_cal);
                if (d) LOG.debug("Finished loading " + TM1Constants.TABLENAME_SPECIAL_FACILITY + " and " + TM1Constants.TABLENAME_CALL_FORWARDING);
            }
        } };
View Full Code Here

            System.exit(28);
        }
        Catalog catalog = new Catalog();
        catalog.execute(serializedCatalog);
        Cluster cluster = catalog.getClusters().get("cluster");
        Database db = cluster.getDatabases().get("database");
        log("catalog loaded");

        //////////////////////
        // LOAD HSQL
        //////////////////////

        log("creating HSQLInterface");
        HSQLInterface hsql = HSQLInterface.loadHsqldb();
        String hexDDL = db.getSchema();
        String ddl = Encoder.hexDecodeToString(hexDDL);
        String[] commands = ddl.split(";");
        for (String command : commands) {
            command = command.trim();
            if (command.length() == 0)
View Full Code Here

            LOG.error("Failed to retrieve already compiled catalog", ex);
            System.exit(1);
        }
//        Database catalog_db = catalog.getClusters().get(0).getDatabases().get(0); // NASTY!
                                                                                  // CatalogUtil.getDatabase(catalog);
        Database catalog_db = catalogContext.database;

        //
        // Fixed-sized Tables
        //
        LOG.info("Generating and loading fixed-sized TPC-E tables");
        try {
            for (String table_name : TPCEConstants.FIXED_TABLES) {
                Table catalog_tbl = catalog_db.getTables().get(table_name);
                assert (catalog_tbl != null);
                this.loadTable(catalog_tbl, 1000);
            } // FOR
        } catch (Exception ex) {
            LOG.error("Failed to generate and load fixed-sized tables", ex);
            System.exit(1);
        }

        //
        // Scaling Tables
        // Load them in batches based on the customer ids
        //
        LOG.info("Generating and loading scaling TPC-E tables");
        try {
            for (long start_idx = 0, cnt = this.generator.getTotalCustomers(); start_idx < cnt; start_idx += TPCEConstants.DEFAULT_LOAD_UNIT) {
                this.generator.changeSessionParams(TPCEConstants.DEFAULT_LOAD_UNIT, start_idx + 1);
                for (String table_name : TPCEConstants.SCALING_TABLES) {
                    Table catalog_tbl = catalog_db.getTables().get(table_name);
                    assert (catalog_tbl != null);
                    this.loadTable(catalog_tbl, 100);
                } // FOR
            } // FOR
        } catch (Exception ex) {
View Full Code Here

            throw new VoltCompilerException(msg);
        }

        // create the database in the catalog
        m_catalog.execute("add /clusters[cluster] databases " + databaseName);
        Database db = m_catalog.getClusters().get("cluster").getDatabases().get(databaseName);
        if (database.getProject() != null && database.getProject().isEmpty() == false) {
            db.setProject(database.getProject());
        } else {
            db.setProject("unknown");
        }

        SnapshotType snapshotSettings = database.getSnapshot();
        if (snapshotSettings != null) {
            SnapshotSchedule schedule = db.getSnapshotschedule().add("default");
            String frequency = snapshotSettings.getFrequency();
            if (!frequency.endsWith("s") &&
                    !frequency.endsWith("m") &&
                    !frequency.endsWith("h")) {
                throw new VoltCompilerException(
                        "Snapshot frequency " + frequency +
                        " needs to end with time unit specified" +
                        " that is one of [s, m, h] (seconds, minutes, hours)");
            }

            int frequencyInt = 0;
            String frequencySubstring = frequency.substring(0, frequency.length() - 1);
            try {
                frequencyInt = Integer.parseInt(frequencySubstring);
            } catch (Exception e) {
                throw new VoltCompilerException("Frequency " + frequencySubstring +
                        " is not an integer ");
            }

            String prefix = snapshotSettings.getPrefix();
            if (prefix == null || prefix.isEmpty()) {
                throw new VoltCompilerException("Snapshot prefix " + prefix +
                " is not a valid prefix ");
            }

            if (prefix.contains("-") || prefix.contains(",")) {
                throw new VoltCompilerException("Snapshot prefix " + prefix +
                " cannot include , or - ");
            }

            String path = snapshotSettings.getPath();
            if (path == null || path.isEmpty()) {
                throw new VoltCompilerException("Snapshot path " + path +
                " is not a valid path ");
            }

            if (snapshotSettings.getRetain() == null) {
                throw new VoltCompilerException("Snapshot retain value not provided");
            }

            int retain = snapshotSettings.getRetain().intValue();
            if (retain < 1) {
                throw new VoltCompilerException("Snapshot retain value " + retain +
                        " is not a valid value. Must be 1 or greater.");
            }

            schedule.setFrequencyunit(
                    frequency.substring(frequency.length() - 1, frequency.length()));
            schedule.setFrequencyvalue(frequencyInt);
            schedule.setPath(path);
            schedule.setPrefix(prefix);
            schedule.setRetain(retain);
        }

        // schemas/schema
        for (SchemasType.Schema schema : database.getSchemas().getSchema()) {
            LOG.l7dlog( Level.DEBUG, LogKeys.compiler_VoltCompiler_CatalogPath.name(),
                                new Object[] {schema.getPath()}, null);
            schemas.add(schema.getPath());
        }

        // groups/group.
        if (database.getGroups() != null) {
            for (GroupsType.Group group : database.getGroups().getGroup()) {
                org.voltdb.catalog.Group catGroup = db.getGroups().add(group.getName());
                catGroup.setAdhoc(group.isAdhoc());
                catGroup.setSysproc(group.isSysproc());
            }
        }

        // users/user
        if (database.getUsers() != null) {
            for (UsersType.User user : database.getUsers().getUser()) {
                org.voltdb.catalog.User catUser = db.getUsers().add(user.getName());
                catUser.setAdhoc(user.isAdhoc());
                catUser.setSysproc(user.isSysproc());
                byte passwordHash[] = extractPassword(user.getPassword());
                catUser.setShadowpassword(Encoder.hexEncode(passwordHash));

                // process the @groups comma separated list
                if (user.getGroups() != null) {
                    String grouplist[] = user.getGroups().split(",");
                    for (final String group : grouplist) {
                        final GroupRef groupRef = catUser.getGroups().add(group);
                        final Group catalogGroup = db.getGroups().get(group);
                        if (catalogGroup != null) {
                            groupRef.setGroup(catalogGroup);
                        }
                    }
                }
            }
        }

        // procedures/procedure
        for (ProceduresType.Procedure proc : database.getProcedures().getProcedure()) {
            procedures.add(getProcedure(proc));
        }

        // classdependencies/classdependency
        if (database.getClassdependencies() != null) {
            for (Classdependency dep : database.getClassdependencies().getClassdependency()) {
                classDependencies.add(getClassDependency(dep));
            }
        }

        // partitions/table
        if (database.getPartitions() != null) {
            for (org.voltdb.compiler.projectfile.PartitionsType.Partition table : database.getPartitions().getPartition()) {
                partitions.add(getPartition(table));
            }
        }

        String msg = "Database \"" + databaseName + "\" ";
        // TODO: schema allows 0 procedures. Testbase relies on this.
        if (procedures.size() == 0) {
            msg += "needs at least one \"procedure\" element " +
                    "(currently has " + String.valueOf(procedures.size()) + ")";
            throw new VoltCompilerException(msg);
        }
        if (procedures.size() < 1) {
            msg += "is missing the \"procedures\" element";
            throw new VoltCompilerException(msg);
        }

        // shutdown and make a new hsqldb
        m_hsql = HSQLInterface.loadHsqldb();

        // Actually parse and handle all the programs
        for (final String programName : programs) {
            m_catalog.execute("add " + db.getPath() + " programs " + programName);
        }

        // Actually parse and handle all the DDL
        final DDLCompiler ddlcompiler = new DDLCompiler(this, m_hsql);

        for (final String schemaPath : schemas) {
            File schemaFile = null;

            if (schemaPath.contains(".jar!")) {
                String ddlText = null;
                try {
                    ddlText = JarReader.readFileFromJarfile(schemaPath);
                } catch (final Exception e) {
                    throw new VoltCompilerException(e);
                }
                schemaFile = VoltProjectBuilder.writeStringToTempFile(ddlText);
            }
            else {
                schemaFile = new File(schemaPath);
            }

            if (!schemaFile.isAbsolute()) {
                // Resolve schemaPath relative to the database definition xml file
                schemaFile = new File(new File(m_projectFileURL).getParent(), schemaPath);
            }

            // add the file object's path to the list of files for the jar
            m_ddlFilePaths.put(schemaFile.getName(), schemaFile.getPath());

            ddlcompiler.loadSchema(schemaFile.getAbsolutePath());
        }
        ddlcompiler.compileToCatalog(m_catalog, db);

        // Actually parse and handle all the partitions
        // this needs to happen before procedures are compiled
        msg = "In database \"" + databaseName + "\", ";
        final CatalogMap<Table> tables = db.getTables();
        for (final String[] partition : partitions) {
            final String tableName = partition[0];
            final String colName = partition[1];
            final Table t = tables.getIgnoreCase(tableName);
            if (t == null) {
                msg += "\"partition\" element has unknown \"table\" attribute '" + tableName + "'";
                throw new VoltCompilerException(msg);
            }
            final Column c = t.getColumns().getIgnoreCase(colName);
            // make sure the column exists
            if (c == null) {
                msg += "\"partition\" element has unknown \"column\" attribute '" + colName + "'";
                throw new VoltCompilerException(msg);
            }
            // make sure the column is marked not-nullable
            if (c.getNullable() == true) {
                msg += "Partition column '" + tableName + "." + colName + "' is nullable. " +
                    "Partition columns must be constrained \"NOT NULL\".";
                throw new VoltCompilerException(msg);
            }
            t.setPartitioncolumn(c);
            t.setIsreplicated(false);

            // Set the destination tables of associated views non-replicated.
            // If a view's source table is replicated, then a full scan of the
            // associated view is singled-sited. If the source is partitioned,
            // a full scan of the view must be distributed.
            final CatalogMap<MaterializedViewInfo> views = t.getViews();
            for (final MaterializedViewInfo mvi : views) {
                mvi.getDest().setIsreplicated(false);
            }
        }

        // Mark tables evictable if needed
        // NOTE: A table can only be evictable if it has a primary key
        if (database.getEvictables() != null) {
            for (Evictable e : database.getEvictables().getEvictable()) {
                String tableName = e.getTable();
                Table catalog_tbl = db.getTables().getIgnoreCase(tableName);
                if (catalog_tbl == null) {
                    throw new VoltCompilerException("Invalid evictable table name '" + tableName + "'");
                }
//                Index pkey = null;
//                try {
//                    pkey = CatalogUtil.getPrimaryKeyIndex(catalog_tbl);
//                } catch (Exception ex) {
//                    // Ignore
//                }
//                if (pkey == null) {
//                    throw new VoltCompilerException("Unable to mark table '" + catalog_tbl.getName() + "' as " +
//                                                "evictable because it does not have a primary key");
//                }
                catalog_tbl.setEvictable(true);
            } // FOR
        }

        if (database.getBatchevictables() != null) {
            for (Evictable e : database.getBatchevictables().getEvictable()) {
                String tableName = e.getTable();
                Table catalog_tbl = db.getTables().getIgnoreCase(tableName);
                if (catalog_tbl == null) {
                    throw new VoltCompilerException("Invalid evictable table name '" + tableName + "'");
                }
//                Index pkey = null;
//                try {
View Full Code Here

    }

    @Override
    public void load() {
        if (d) LOG.debug("Starting ArticlesLoader");
        final Database catalog_db = this.getCatalogContext().database;

        if (d) LOG.debug("Start loading " + ArticlesConstants.TABLENAME_ARTICLES);
        Table catalog_tbl = catalog_db.getTables().get(ArticlesConstants.TABLENAME_ARTICLES);
        genArticles(catalog_tbl);
        if (d) LOG.debug("Finished loading " + ArticlesConstants.TABLENAME_ARTICLES);
               
        if (d) LOG.debug("Start loading " + ArticlesConstants.TABLENAME_USERS);
        catalog_tbl = catalog_db.getTables().get(ArticlesConstants.TABLENAME_USERS);
        genUsers(catalog_tbl);
        if (d) LOG.debug("Finished loading " + ArticlesConstants.TABLENAME_USERS);

        try {
      Thread.sleep(60000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
        if (d) LOG.debug("Start loading " + ArticlesConstants.TABLENAME_COMMENTS);
        Table catalog_spe = catalog_db.getTables().get(ArticlesConstants.TABLENAME_COMMENTS);
        genComments(catalog_spe);
        if (d) LOG.debug("Finished loading " + ArticlesConstants.TABLENAME_COMMENTS);

    }
View Full Code Here

    }

    @Override
    public void load() {
        if (d) LOG.debug("Starting ArticlesLoader");
        final Database catalog_db = this.getCatalogContext().database;

        if (d) LOG.debug("Start loading " + UsersConstants.TABLENAME_USERS);
        Table catalog_tbl = catalog_db.getTables().get(UsersConstants.TABLENAME_USERS);
        genUsers(catalog_tbl);
        if (d) LOG.debug("Finished loading " + UsersConstants.TABLENAME_USERS);

    }
View Full Code Here

    // -----------------------------------------------------------------
    // SERIALIZATION METHODS
    // -----------------------------------------------------------------

    protected final void saveProfile(AuctionMarkLoader baseClient) {
        Database catalog_db = baseClient.getCatalogContext().database;
       
     // CONFIG_PROFILE
        Table catalog_tbl = catalog_db.getTables().get(AuctionMarkConstants.TABLENAME_CONFIG_PROFILE);
        VoltTable vt = CatalogUtil.getVoltTable(catalog_tbl);
        assert(vt != null);
        vt.addRow(
            this.scale_factor,                  // CFP_SCALE_FACTOR
            this.benchmarkStartTime,            // CFP_BENCHMARK_START
View Full Code Here

TOP

Related Classes of org.voltdb.catalog.Database

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.