use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.
the class JdbcDatabaseMetaDataGenerator method getProcedureColumns.
VoltTable getProcedureColumns() {
VoltTable results = new VoltTable(PROCEDURECOLUMNS_SCHEMA);
// merge catalog and default procedures
SortedSet<Procedure> procedures = new TreeSet<>();
for (Procedure proc : m_database.getProcedures()) {
procedures.add(proc);
}
if (m_defaultProcs != null) {
for (Procedure proc : m_defaultProcs.m_defaultProcMap.values()) {
procedures.add(proc);
}
}
for (Procedure proc : procedures) {
for (ProcParameter param : proc.getParameters()) {
Integer[] paramPrecisionAndRadix = getParamPrecisionAndRadix(param);
results.addRow(// procedure catalog
null, // procedure schema
null, // procedure name
proc.getTypeName(), // param name
param.getTypeName(), // param type, all are IN
java.sql.DatabaseMetaData.procedureColumnIn, // data type
getColumnSqlDataType(VoltType.get((byte) param.getType())), // type name
getColumnSqlTypeName(VoltType.get((byte) param.getType())), // precision
paramPrecisionAndRadix[0], // length
getParamLength(param), getColumnDecimalDigits(VoltType.get((byte) param.getType())), // radix
paramPrecisionAndRadix[1], // nullable
java.sql.DatabaseMetaData.procedureNullableUnknown, // remarks
getProcedureColumnRemarks(param, proc), // column default. always null for us
null, // reserved
null, // reserved
null, // char octet length
getParamCharOctetLength(param), // ordinal position
param.getIndex() + 1, // is_nullable
"", // specific name
proc.getTypeName());
}
}
return results;
}
use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.
the class InternalConnectionHandler method callProcedure.
// Use null backPressurePredicate for no back pressure
public boolean callProcedure(InternalConnectionContext caller, Function<Integer, Boolean> backPressurePredicate, InternalConnectionStatsCollector statsCollector, ProcedureCallback procCallback, String proc, Object... fieldList) {
Procedure catProc = InvocationDispatcher.getProcedureFromName(proc, getCatalogContext());
if (catProc == null) {
String fmt = "Cannot invoke procedure %s from streaming interface %s. Procedure not found.";
m_logger.rateLimitedLog(SUPPRESS_INTERVAL, Level.ERROR, null, fmt, proc, caller);
m_failedCount.incrementAndGet();
return false;
}
StoredProcedureInvocation task = new StoredProcedureInvocation();
task.setProcName(proc);
task.setParams(fieldList);
try {
task = MiscUtils.roundTripForCL(task);
} catch (Exception e) {
String fmt = "Cannot invoke procedure %s from streaming interface %s. failed to create task.";
m_logger.rateLimitedLog(SUPPRESS_INTERVAL, Level.ERROR, null, fmt, proc, caller);
m_failedCount.incrementAndGet();
return false;
}
int partition = -1;
try {
partition = InvocationDispatcher.getPartitionForProcedure(catProc, task);
} catch (Exception e) {
String fmt = "Can not invoke procedure %s from streaming interface %s. Partition not found.";
m_logger.rateLimitedLog(SUPPRESS_INTERVAL, Level.ERROR, e, fmt, proc, caller);
m_failedCount.incrementAndGet();
return false;
}
final InternalClientResponseAdapter adapter = m_adapters.get(partition);
InternalAdapterTaskAttributes kattrs = new InternalAdapterTaskAttributes(caller, adapter.connectionId());
final AuthUser user = getCatalogContext().authSystem.getImporterUser();
if (!adapter.createTransaction(kattrs, proc, catProc, procCallback, statsCollector, task, user, partition, false, backPressurePredicate)) {
m_failedCount.incrementAndGet();
return false;
}
m_submitSuccessCount.incrementAndGet();
return true;
}
use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.
the class ReportMaker method generateSchemaRow.
static String generateSchemaRow(Table table, boolean isExportTable) {
StringBuilder sb = new StringBuilder();
sb.append("<tr class='primaryrow'>");
// column 1: table name
String anchor = table.getTypeName().toLowerCase();
sb.append("<td style='white-space: nowrap;'><i id='s-" + anchor + "--icon' class='icon-chevron-right'></i> <a href='#' id='s-");
sb.append(anchor).append("' class='togglex'>");
sb.append(table.getTypeName());
sb.append("</a></td>");
// column 2: type
sb.append("<td>");
if (table.getMaterializer() != null) {
tag(sb, "info", "Materialized View");
} else {
if (isExportTable) {
tag(sb, "inverse", "Export Streams");
} else {
tag(sb, null, "Table");
}
}
sb.append("</td>");
// column 3: partitioning
sb.append("<td style='whitespace: nowrap;'>");
if (table.getIsreplicated()) {
tag(sb, "warning", "Replicated");
} else {
tag(sb, "success", "Partitioned");
Column partitionCol = table.getPartitioncolumn();
if (partitionCol != null) {
sb.append("<small> on " + partitionCol.getName() + "</small>");
} else {
Table matSrc = table.getMaterializer();
if (matSrc != null) {
sb.append("<small> with " + matSrc.getTypeName() + "</small>");
}
}
}
sb.append("</td>");
// column 4: column count
sb.append("<td>");
sb.append(table.getColumns().size());
sb.append("</td>");
// column 5: index count
sb.append("<td>");
sb.append(table.getIndexes().size());
// computing unused indexes
int unusedIndexes = 0;
for (Index index : table.getIndexes()) {
IndexAnnotation indexAnnotation = (IndexAnnotation) index.getAnnotation();
if (indexAnnotation == null) {
unusedIndexes++;
}
}
if (unusedIndexes != 0) {
sb.append(" (" + unusedIndexes + " unused)");
}
sb.append("</td>");
// column 6: has pkey
sb.append("<td>");
boolean found = false;
for (Constraint constraint : table.getConstraints()) {
if (ConstraintType.get(constraint.getType()) == ConstraintType.PRIMARY_KEY) {
found = true;
break;
}
}
if (found) {
tag(sb, "info", "Has-PKey");
} else {
tag(sb, null, "No-PKey");
}
sb.append("</td>");
// column 6: has tuple limit
sb.append("<td>");
if (table.getTuplelimit() != Integer.MAX_VALUE) {
tag(sb, "info", String.valueOf(table.getTuplelimit()));
if (CatalogUtil.getLimitPartitionRowsDeleteStmt(table) != null) {
sb.append("<small>enforced by DELETE statement</small>");
}
} else {
tag(sb, null, "No-limit");
}
sb.append("</td>");
sb.append("</tr>\n");
// BUILD THE DROPDOWN FOR THE DDL / INDEXES DETAIL
sb.append("<tr class='tablesorter-childRow'><td class='invert' colspan='7' id='s-" + table.getTypeName().toLowerCase() + "--dropdown'>\n");
TableAnnotation annotation = (TableAnnotation) table.getAnnotation();
if (annotation != null) {
// output the DDL
if (annotation.ddl == null) {
sb.append("<p>MISSING DDL</p>\n");
} else {
String ddl = escapeHtml4(annotation.ddl);
sb.append("<p><pre>" + ddl + "</pre></p>\n");
}
// make sure procs appear in only one category
annotation.proceduresThatReadThis.removeAll(annotation.proceduresThatUpdateThis);
if (annotation.proceduresThatReadThis.size() > 0) {
sb.append("<p>Read-only by procedures: ");
List<String> procs = new ArrayList<String>();
for (Procedure proc : annotation.proceduresThatReadThis) {
procs.add("<a href='#p-" + proc.getTypeName() + "'>" + proc.getTypeName() + "</a>");
}
sb.append(StringUtils.join(procs, ", "));
sb.append("</p>");
}
if (annotation.proceduresThatUpdateThis.size() > 0) {
sb.append("<p>Read/Write by procedures: ");
List<String> procs = new ArrayList<String>();
for (Procedure proc : annotation.proceduresThatUpdateThis) {
procs.add("<a href='#p-" + proc.getTypeName() + "'>" + proc.getTypeName() + "</a>");
}
sb.append(StringUtils.join(procs, ", "));
sb.append("</p>");
}
}
// LIMIT PARTITION ROW statement may also use the index in this table, prepare the information for report
if (!table.getTuplelimitdeletestmt().isEmpty()) {
assert (table.getTuplelimitdeletestmt().size() == 1);
Statement stmt = table.getTuplelimitdeletestmt().iterator().next();
for (String tableDotIndexPair : stmt.getIndexesused().split(",")) {
if (tableDotIndexPair.length() == 0) {
continue;
}
String[] parts = tableDotIndexPair.split("\\.", 2);
assert (parts.length == 2);
if (parts.length != 2) {
continue;
}
String tableName = parts[0];
String indexName = parts[1];
if (!table.getTypeName().equals(tableName)) {
continue;
}
Index i = table.getIndexes().get(indexName);
assert (i != null);
IndexAnnotation ia = (IndexAnnotation) i.getAnnotation();
if (ia == null) {
ia = new IndexAnnotation();
i.setAnnotation(ia);
}
ia.statementsThatUseThis.add(stmt);
}
}
if (table.getIndexes().size() > 0) {
sb.append(generateIndexesTable(table));
} else {
sb.append("<p>No indexes defined on table.</p>\n");
}
// Generate explainview report.
if (table.getMaterializer() != null) {
sb.append(generateExplainViewTable(table));
}
sb.append("</td></tr>\n");
return sb.toString();
}
use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.
the class ReportMaker method getStatsHTML.
/**
* Get some embeddable HTML of some generic catalog/application stats
* that is drawn on the first page of the report.
*/
static String getStatsHTML(Database db, long requiredHeap, ArrayList<Feedback> warnings) {
StringBuilder sb = new StringBuilder();
sb.append("<table class='table table-condensed'>\n");
// count things
int indexes = 0, views = 0, statements = 0;
int partitionedTables = 0, replicatedTables = 0;
int partitionedProcs = 0, replicatedProcs = 0;
int readProcs = 0, writeProcs = 0;
for (Table t : db.getTables()) {
if (t.getMaterializer() != null) {
views++;
} else {
if (t.getIsreplicated()) {
replicatedTables++;
} else {
partitionedTables++;
}
}
indexes += t.getIndexes().size();
}
for (Procedure p : db.getProcedures()) {
// skip auto-generated crud procs
if (p.getDefaultproc()) {
continue;
}
if (p.getSinglepartition()) {
partitionedProcs++;
} else {
replicatedProcs++;
}
if (p.getReadonly()) {
readProcs++;
} else {
writeProcs++;
}
statements += p.getStatements().size();
}
// version
sb.append("<tr><td>Generated by VoltDB Version</td><td>");
sb.append(VoltDB.instance().getVersionString()).append("</td></tr>\n");
// timestamp
sb.append("<tr><td>Last Schema Update on</td><td>");
SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z");
sb.append(sdf.format(m_timestamp)).append("</td></tr>\n");
// tables
sb.append("<tr><td>Table Count</td><td>");
sb.append(String.format("%d (%d partitioned / %d replicated)", partitionedTables + replicatedTables, partitionedTables, replicatedTables));
sb.append("</td></tr>\n");
// views
sb.append("<tr><td>Materialized View Count</td><td>").append(views).append("</td></tr>\n");
// indexes
sb.append("<tr><td>Index Count</td><td>").append(indexes).append("</td></tr>\n");
// procedures
sb.append("<tr><td>Procedure Count</td><td>");
sb.append(String.format("%d (%d partitioned / %d replicated) (%d read-only / %d read-write)", partitionedProcs + replicatedProcs, partitionedProcs, replicatedProcs, readProcs, writeProcs));
sb.append("</td></tr>\n");
// statements
sb.append("<tr><td>SQL Statement Count</td><td>").append(statements).append("</td></tr>\n");
//heap
sb.append("<tr><td>Required Java Heap</td><td>").append(requiredHeap).append(" Megabytes").append("</td></tr>\n");
long megabytes = 1024 * 1024;
long configuredHeap = Runtime.getRuntime().maxMemory() / megabytes;
if (configuredHeap > requiredHeap) {
sb.append("<tr><td>Configured Java Heap</td><td>").append(configuredHeap).append(" Megabytes").append("</td></tr>\n");
} else {
sb.append("<tr><td>Configured Java Heap</td><td><font color=\"red\">").append(configuredHeap).append("<font color=\"black\">").append(" Megabytes").append("</td></tr>\n");
}
sb.append("</table>\n\n");
// warnings, add warning section if any
if (warnings.size() > 0) {
sb.append("<h4>Warnings</h4>");
sb.append("<table class='table table-condensed'>\n");
for (Feedback warning : warnings) {
String procName = warning.getFileName().replace(".class", "");
String nameLink = "";
// not a warning during compiling procedures, must from the schema
if (procName.compareToIgnoreCase("null") == 0) {
String schemaName = "";
String warningMsg = warning.getMessage().toLowerCase();
if (warningMsg.contains("table ")) {
int begin = warningMsg.indexOf("table ") + 6;
int end = (warningMsg.substring(begin)).indexOf(" ");
schemaName = warningMsg.substring(begin, begin + end);
}
nameLink = "<a href='#s-" + schemaName + "'>" + schemaName.toUpperCase() + "</a>";
} else {
nameLink = "<a href='#p-" + procName.toLowerCase() + "'>" + procName + "</a>";
}
sb.append("<tr><td>").append(nameLink).append("</td><td>").append(escapeHtml4(warning.getMessage())).append("</td></tr>\n");
}
sb.append("").append("</table>\n").append("</td></tr>\n");
}
return sb.toString();
}
use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.
the class ReportMaker method genrateIndexRow.
static String genrateIndexRow(Table table, Index index) {
StringBuilder sb = new StringBuilder();
sb.append(" <tr class='primaryrow2'>");
// name column
String anchor = (table.getTypeName() + "-" + index.getTypeName()).toLowerCase();
sb.append("<td style='white-space: nowrap'><i id='s-" + anchor + "--icon' class='icon-chevron-right'></i> <a href='#' id='s-");
sb.append(anchor).append("' class='togglex'>");
sb.append(index.getTypeName());
sb.append("</a></td>");
// type column
sb.append("<td>");
sb.append(IndexType.get(index.getType()).toString());
sb.append("</td>");
// columns column
sb.append("<td>");
List<ColumnRef> cols = CatalogUtil.getSortedCatalogItems(index.getColumns(), "index");
List<String> columnNames = new ArrayList<String>();
for (ColumnRef colRef : cols) {
columnNames.add(colRef.getColumn().getTypeName());
}
sb.append(StringUtils.join(columnNames, ", "));
sb.append("</td>");
// attribute column
sb.append("<td>");
if (index.getAssumeunique()) {
tag(sb, "success", "AssumeUnique");
} else if (index.getUnique()) {
tag(sb, "success", "Unique");
} else {
tag(sb, "info", "Nonunique");
}
IndexAnnotation annotation = (IndexAnnotation) index.getAnnotation();
if (annotation == null) {
sb.append(" ");
tag(sb, "important", "Unused");
}
sb.append("</td>");
sb.append("</tr>\n");
// BUILD THE DROPDOWN FOR THE PLAN/DETAIL TABLE
sb.append("<tr class='dropdown2'><td colspan='5' id='s-" + table.getTypeName().toLowerCase() + "-" + index.getTypeName().toLowerCase() + "--dropdown'>\n");
if (annotation != null) {
if (annotation.proceduresThatUseThis.size() > 0) {
sb.append("<p>Used by procedures: ");
List<String> procs = new ArrayList<String>();
for (Procedure proc : annotation.proceduresThatUseThis) {
procs.add("<a href='#p-" + proc.getTypeName() + "'>" + proc.getTypeName() + "</a>");
}
sb.append(StringUtils.join(procs, ", "));
sb.append("</p>");
}
if (annotation.statementsThatUseThis.size() > 0) {
assert (annotation.statementsThatUseThis.size() == 1);
sb.append("<p>Used by the LIMIT PARTITION ROWS Statement</p>");
}
}
sb.append("</td></tr>\n");
return sb.toString();
}
Aggregations