Search in sources :

Example 16 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile in project voltdb by VoltDB.

the class VoltCompiler method debugVerifyCatalog.

/**
     * Internal method that takes the generated DDL from the catalog and builds a new catalog.
     * The generated catalog is diffed with the original catalog to verify compilation and
     * catalog generation consistency.
     */
private void debugVerifyCatalog(InMemoryJarfile origJarFile, Catalog origCatalog) {
    final VoltCompiler autoGenCompiler = new VoltCompiler(m_isXDCR);
    // Make the new compiler use the original jarfile's classloader so it can
    // pull in the class files for procedures and imports
    autoGenCompiler.m_classLoader = origJarFile.getLoader();
    List<VoltCompilerReader> autogenReaderList = new ArrayList<>(1);
    autogenReaderList.add(new VoltCompilerJarFileReader(origJarFile, AUTOGEN_DDL_FILE_NAME));
    InMemoryJarfile autoGenJarOutput = new InMemoryJarfile();
    autoGenCompiler.m_currentFilename = AUTOGEN_DDL_FILE_NAME;
    // This call is purposely replicated in retryFailedCatalogRebuildUnderDebug,
    // where it provides an opportunity to set a breakpoint on a do-over when this
    // mainline call produces a flawed catalog that fails the catalog diff.
    // Keep the two calls in synch to allow debugging under the same exact conditions.
    Catalog autoGenCatalog = autoGenCompiler.compileCatalogInternal(null, null, autogenReaderList, autoGenJarOutput);
    if (autoGenCatalog == null) {
        Log.info("Did not verify catalog because it could not be compiled.");
        return;
    }
    FilteredCatalogDiffEngine diffEng = new FilteredCatalogDiffEngine(origCatalog, autoGenCatalog, false);
    String diffCmds = diffEng.commands();
    if (diffCmds != null && !diffCmds.equals("")) {
        // that is only triggered in hopeless cases.
        if (RETRY_FAILED_CATALOG_REBUILD_UNDER_DEBUG) {
            autoGenCatalog = replayFailedCatalogRebuildUnderDebug(autoGenCompiler, autogenReaderList, autoGenJarOutput);
        }
        // Re-run a failed diff more verbosely as a pre-crash test diagnostic.
        diffEng = new FilteredCatalogDiffEngine(origCatalog, autoGenCatalog, true);
        diffCmds = diffEng.commands();
        String crashAdvice = "Catalog Verification from Generated DDL failed! " + "VoltDB dev: Consider" + (RETRY_FAILED_CATALOG_REBUILD_UNDER_DEBUG ? "" : " setting VoltCompiler.RETRY_FAILED_CATALOG_REBUILD_UNDER_DEBUG = true and") + " setting a breakpoint in VoltCompiler.replayFailedCatalogRebuildUnderDebug" + " to debug a replay of the faulty catalog rebuild roundtrip. ";
        VoltDB.crashLocalVoltDB(crashAdvice + "The offending diffcmds were: " + diffCmds);
    } else {
        Log.info("Catalog verification completed successfuly.");
    }
}
Also used : InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) ArrayList(java.util.ArrayList) FilteredCatalogDiffEngine(org.voltdb.catalog.FilteredCatalogDiffEngine) Catalog(org.voltdb.catalog.Catalog)

Example 17 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile in project voltdb by VoltDB.

the class VoltCompiler method compileEmptyCatalog.

/**
     * Compile empty catalog jar
     * @param jarOutputPath output jar path
     * @return true if successful
     */
public boolean compileEmptyCatalog(final String jarOutputPath) {
    // Use a special DDL reader to provide the contents.
    List<VoltCompilerReader> ddlReaderList = new ArrayList<>(1);
    ddlReaderList.add(new VoltCompilerStringReader("ddl.sql", m_emptyDDLComment));
    // Seed it with the DDL so that a version upgrade hack in compileInternalToFile()
    // doesn't try to get the DDL file from the path.
    InMemoryJarfile jarFile = new InMemoryJarfile();
    try {
        ddlReaderList.get(0).putInJar(jarFile, "ddl.sql");
    } catch (IOException e) {
        compilerLog.error("Failed to add DDL file to empty in-memory jar.");
        return false;
    }
    return compileInternalToFile(jarOutputPath, null, null, ddlReaderList, jarFile);
}
Also used : InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 18 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile in project voltdb by VoltDB.

the class VoltCompilerUtils method getClassAsBytes.

public static byte[] getClassAsBytes(final Class<?> c) throws IOException {
    ClassLoader cl = c.getClassLoader();
    if (cl == null) {
        cl = Thread.currentThread().getContextClassLoader();
    }
    String classAsPath = classNameToPackagePath(c.getName());
    if (cl instanceof JarLoader) {
        InMemoryJarfile memJar = ((JarLoader) cl).getInMemoryJarfile();
        return memJar.get(classAsPath);
    } else {
        BufferedInputStream cis = null;
        ByteArrayOutputStream baos = null;
        try {
            cis = new BufferedInputStream(cl.getResourceAsStream(classAsPath));
            baos = new ByteArrayOutputStream();
            byte[] buf = new byte[1024];
            int rsize = 0;
            while ((rsize = cis.read(buf)) != -1) {
                baos.write(buf, 0, rsize);
            }
        } finally {
            try {
                if (cis != null)
                    cis.close();
            } catch (Exception ignoreIt) {
            }
            try {
                if (baos != null)
                    baos.close();
            } catch (Exception ignoreIt) {
            }
        }
        return baos.toByteArray();
    }
}
Also used : JarLoader(org.voltdb.utils.InMemoryJarfile.JarLoader) BufferedInputStream(java.io.BufferedInputStream) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 19 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile in project voltdb by VoltDB.

the class TestInitStartLocalClusterAllOutOfProcess method loadAndAddProcs.

void loadAndAddProcs() throws IOException, NoConnectionsException {
    ClientResponse resp = null;
    long numberOfClasses = 0;
    try {
        resp = client.callProcedure("@SystemCatalog", "CLASSES");
    } catch (ProcCallException excp) {
        assert false : "@SystemCatalogClasses failed";
    }
    numberOfClasses = resp.getResults()[0].getRowCount();
    InMemoryJarfile jarfile = new InMemoryJarfile();
    VoltCompiler comp = new VoltCompiler(false);
    try {
        comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.testImportProc.class);
        comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.testCreateProcFromClassProc.class);
        comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.InnerClassesTestProc.class);
    } catch (Exception e) {
        assert false : "Failed add class to jar: " + e.getMessage();
    }
    try {
        client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
    } catch (ProcCallException excp) {
        assert false : "Failed updating the class";
    }
    try {
        resp = client.callProcedure("@SystemCatalog", "CLASSES");
    } catch (ProcCallException excp) {
        assert false : "@SystemCatalogClasses failed";
    }
    assertTrue((numberOfClasses + jarfile.getLoader().getClassNames().size()) == resp.getResults()[0].getRowCount());
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) VoltCompiler(org.voltdb.compiler.VoltCompiler) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) ProcCallException(org.voltdb.client.ProcCallException) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException)

Example 20 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile in project voltdb by VoltDB.

the class TestInitStartLocalClusterAllOutOfProcess method testGetClasses.

public void testGetClasses() throws IOException {
    InMemoryJarfile jarFile = null;
    org.voltdb.client.ClientResponse resp = null;
    // fetch the java procs classes currently in catalog
    try {
        resp = client.callProcedure("@SystemCatalog", "CLASSES");
    } catch (ProcCallException excp) {
        assert false : "@SystemCatalogClasses failed";
    }
    jarFile = getProcJarFromCatalog();
    assertTrue(!TestInitStartLocalClusterInProcess.anyCatalogDefaultArtifactsExists(jarFile));
    assertTrue(jarFile.getLoader().getClassNames().size() == resp.getResults()[0].getRowCount());
    // load some additional java stored proc classes and verify the retrieved classes count
    loadAndAddProcs();
    jarFile = getProcJarFromCatalog();
    assertTrue(!TestInitStartLocalClusterInProcess.anyCatalogDefaultArtifactsExists(jarFile));
    try {
        resp = client.callProcedure("@SystemCatalog", "CLASSES");
    } catch (ProcCallException excp) {
        assert false : "@SystemCatalogClasses failed";
    }
    assertTrue(jarFile.getLoader().getClassNames().size() == resp.getResults()[0].getRowCount());
}
Also used : InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) ClientResponse(org.voltdb.client.ClientResponse) ProcCallException(org.voltdb.client.ProcCallException)

Aggregations

InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)52 VoltCompiler (org.voltdb.compiler.VoltCompiler)26 File (java.io.File)20 ProcCallException (org.voltdb.client.ProcCallException)19 ClientResponse (org.voltdb.client.ClientResponse)18 Test (org.junit.Test)15 Configuration (org.voltdb.VoltDB.Configuration)15 IOException (java.io.IOException)14 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)12 VoltDB (org.voltdb.VoltDB)9 Catalog (org.voltdb.catalog.Catalog)6 VoltTable (org.voltdb.VoltTable)5 VoltFile (org.voltdb.utils.VoltFile)5 ArrayList (java.util.ArrayList)4 JSONObject (org.json_voltpatches.JSONObject)3 CatalogContext (org.voltdb.CatalogContext)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JAXBException (javax.xml.bind.JAXBException)2