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.");
}
}
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);
}
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();
}
}
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());
}
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());
}
Aggregations