GitHub PullRequestReviewCommentEvent at 2014-02-10 17:08:14
Repository: voltdb
Actor: jhugg
Payload: {"comment":{"url":"https://api.github.com/repos/VoltDB/voltdb/pulls/comments/9592084","id":9592084,"diff_hunk":"@@ -2141,4 +2227,113 @@ static DeprecatedProjectElement valueOf( JAXBException jxbex) {\n             return null;\n         }\n     }\n+\n+    /**\n+     * Check a loaded catalog. If it needs to be upgraded recompile it and save\n+     * an upgraded jar.\n+     *\n+     * @param outputJar  in-memory jar file (updated in place here)\n+     * @throws FileNotFoundException, IOException\n+     */\n+    public void postProcessLoadedCatalog(InMemoryJarfile outputJar)\n+                    throws FileNotFoundException, IOException\n+    {\n+        byte[] buildInfoBytes = outputJar.get(CatalogUtil.CATALOG_BUILDINFO_FILENAME);\n+        if (buildInfoBytes == null) {\n+            throw new IOException(\"Catalog build information not found - please build your application using the current version of VoltDB.\");\n+        }\n+        String buildInfo = new String(buildInfoBytes, \"UTF-8\");\n+        String[] buildInfoLines = buildInfo.split(\"\\n\");\n+        if (buildInfoLines.length != 5) {\n+            throw new IOException(\"Catalog built with an old version of VoltDB - please build your application using the current version of VoltDB.\");\n+        }\n+        String voltVersionString = buildInfoLines[0].trim();\n+\n+        // Check if it's compatible (or the upgrade is being forced).\n+        // getConfig() may return null if it's being mocked for a test.\n+        if (   VoltDB.Configuration.m_forceCatalogUpgrade\n+            || !CatalogUtil.isCatalogCompatible(voltVersionString)) {\n+\n+            // Patch the buildinfo.\n+            String version = VoltDB.instance().getVersionString();\n+            buildInfoLines[0] = version;\n+            buildInfoLines[1] = String.format(\"voltdb-auto-upgrade-to-%s\", version);\n+            buildInfoBytes = StringUtils.join(buildInfoLines, \"\\n\").getBytes();\n+            outputJar.put(CatalogUtil.CATALOG_BUILDINFO_FILENAME, buildInfoBytes);\n+\n+            /*\n+             * Get the schema file names from project.xml, if provided, to avoid\n+             * duplications when discovering .sql files in the jar (below).\n+             * Note that the jar has the ddl files in the root directory, so\n+             * name matching is fine.\n+             */\n+            Set<String> ddlNames = new HashSet<String>();\n+            VoltCompilerReader projectReader =\n+                    (outputJar.containsKey(\"project.xml\")\n+                        ? new VoltCompilerJarFileReader(outputJar, \"project.xml\")\n+                        : null);\n+            if (projectReader != null) {\n+                DatabaseType database = getProjectDatabase(projectReader);\n+                SchemasType schemas = database.getSchemas();\n+                if (schemas != null) {\n+                    for (SchemasType.Schema schema : schemas.getSchema()) {\n+                        ddlNames.add(new File(schema.getPath()).getName());\n+                    }\n+                }\n+            }\n+\n+            // Recompile the DDL.\n+            List<VoltCompilerReader> ddlReaderList = new ArrayList<VoltCompilerReader>();\n+            Entry<String, byte[]> entry = outputJar.firstEntry();\n+            while (entry != null) {\n+                String path = entry.getKey();\n+                //TODO: It would be better to have a manifest that explicitly lists\n+                // ddl files instead of using a brute force *.sql glob.\n+                if (path.toLowerCase().endsWith(\".sql\")) {\n+                    // Don't duplicate project.xml schema names.\n+                    if (!ddlNames.contains(new File(path).getName())) {\n+                        ddlReaderList.add(new VoltCompilerJarFileReader(outputJar, path));\n+                    }\n+                }\n+                entry = outputJar.higherEntry(entry.getKey());\n+            }\n+\n+            // Save the source in-memory jar to a file to add it to the classpath\n+            // so that procedure classes can be found and pulled into the new jar.\n+            File tempfile = File.createTempFile(\"catalog\", \".jar\");","path":"src/frontend/org/voltdb/compiler/VoltCompiler.java","position":874,"original_position":874,"commit_id":"2937a35d8952160a77c939b2c4dca29cf1513cca","original_commit_id":"2937a35d8952160a77c939b2c4dca29cf1513cca","user":{"login":"jhugg","id":634609,"avatar_url":"https://gravatar.com/avatar/4440b1fbd54e5357c779cb09d0aa6f42?d=https%3A%2F%2Fidenticons.github.com%2Fb2788fc2a8d0b4c0c2c8600a321266bf.png&r=x","gravatar_id":"4440b1fbd54e5357c779cb09d0aa6f42","url":"https://api.github.com/users/jhugg","html_url":"https://github.com/jhugg","followers_url":"https://api.github.com/users/jhugg/followers","following_url":"https://api.github.com/users/jhugg/following{/other_user}","gists_url":"https://api.github.com/users/jhugg/gists{/gist_id}","starred_url":"https://api.github.com/users/jhugg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhugg/subscriptions","organizations_url":"https://api.github.com/users/jhugg/orgs","repos_url":"https://api.github.com/users/jhugg/repos","events_url":"https://api.github.com/users/jhugg/events{/privacy}","received_events_url":"https://api.github.com/users/jhugg/received_events","type":"User","site_admin":false},"body":"I'm not sure you need to do this? We already have a class loader that loads classes from a catalog jar in memory.\r\n\r\nThough maybe this is easier...","created_at":"2014-02-10T17:08:14Z","updated_at":"2014-02-10T17:08:14Z","html_url":"https://github.com/VoltDB/voltdb/pull/1125#discussion_r9592084","pull_request_url":"https://api.github.com/repos/VoltDB/voltdb/pulls/1125","_links":{"self":{"href":"https://api.github.com/repos/VoltDB/voltdb/pulls/comments/9592084"},"html":{"href":"https://github.com/VoltDB/voltdb/pull/1125#discussion_r9592084"},"pull_request":{"href":"https://api.github.com/repos/VoltDB/voltdb/pulls/1125"}}}}