Search in sources :

Example 26 with Procedure

use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.

the class InternalConnectionHandler method callProcedure.

public boolean callProcedure(AuthUser user, boolean isAdmin, int timeout, ProcedureCallback cb, boolean ntPriority, Function<Integer, Boolean> backPressurePredicate, String procName, Object... args) {
    Procedure catProc = InvocationDispatcher.getProcedureFromName(procName, getCatalogContext());
    if (catProc == null) {
        String fmt = "Cannot invoke procedure %s. Procedure not found.";
        m_logger.rateLimitedLog(SUPPRESS_INTERVAL, Level.ERROR, null, fmt, procName);
        m_failedCount.incrementAndGet();
        return false;
    }
    StoredProcedureInvocation task = new StoredProcedureInvocation();
    task.setProcName(procName);
    task.setParams(args);
    try {
        task = MiscUtils.roundTripForCL(task);
    } catch (Exception e) {
        String fmt = "Cannot invoke procedure %s. failed to create task.";
        m_logger.rateLimitedLog(SUPPRESS_INTERVAL, Level.ERROR, null, fmt, procName);
        m_failedCount.incrementAndGet();
        return false;
    }
    if (timeout != BatchTimeoutOverrideType.NO_TIMEOUT) {
        task.setBatchTimeout(timeout);
    }
    int partition = -1;
    try {
        partition = InvocationDispatcher.getPartitionForProcedure(catProc, task);
    } catch (Exception e) {
        String fmt = "Can not invoke procedure %s. Partition not found.";
        m_logger.rateLimitedLog(SUPPRESS_INTERVAL, Level.ERROR, e, fmt, procName);
        m_failedCount.incrementAndGet();
        return false;
    }
    final InternalClientResponseAdapter adapter = m_adapters.get(partition);
    InternalAdapterTaskAttributes kattrs = new InternalAdapterTaskAttributes(DEFAULT_INTERNAL_ADAPTER_NAME, isAdmin, adapter.connectionId());
    if (!adapter.createTransaction(kattrs, procName, catProc, cb, null, task, user, partition, ntPriority, backPressurePredicate)) {
        m_failedCount.incrementAndGet();
        return false;
    }
    m_submitSuccessCount.incrementAndGet();
    return true;
}
Also used : Procedure(org.voltdb.catalog.Procedure)

Example 27 with Procedure

use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.

the class NTProcedureService method update.

/**
     * Refresh the NT procedures when the catalog changes.
     */
@SuppressWarnings("unchecked")
synchronized void update(CatalogContext catalogContext) {
    CatalogMap<Procedure> procedures = catalogContext.database.getProcedures();
    Map<String, ProcedureRunnerNTGenerator> runnerGeneratorMap = new TreeMap<>();
    for (Procedure procedure : procedures) {
        if (procedure.getTransactional()) {
            continue;
        }
        // this code is mostly lifted from transactionally procedures
        String className = procedure.getClassname();
        Class<? extends VoltNonTransactionalProcedure> clz = null;
        try {
            clz = (Class<? extends VoltNonTransactionalProcedure>) catalogContext.classForProcedure(className);
        } catch (ClassNotFoundException e) {
            if (className.startsWith("org.voltdb.")) {
                String msg = String.format(LoadedProcedureSet.ORGVOLTDB_PROCNAME_ERROR_FMT, className);
                VoltDB.crashLocalVoltDB(msg, false, null);
            } else {
                String msg = String.format(LoadedProcedureSet.UNABLETOLOAD_ERROR_FMT, className);
                VoltDB.crashLocalVoltDB(msg, false, null);
            }
        }
        // The ProcedureRunnerNTGenerator has all of the dangerous and slow
        // stuff in it. Like classfinding, instantiation, and reflection.
        ProcedureRunnerNTGenerator prntg = new ProcedureRunnerNTGenerator(clz);
        runnerGeneratorMap.put(procedure.getTypeName(), prntg);
    }
    m_procs = ImmutableMap.<String, ProcedureRunnerNTGenerator>builder().putAll(runnerGeneratorMap).build();
    // reload all sysprocs (I wish we didn't have to do this, but their stats source
    // gets wiped out)
    loadSystemProcedures();
    // Set the system to start accepting work again now that ebertything is updated.
    // We had to stop because stats would be wonky if we called a proc while updating
    // this stuff.
    m_paused = false;
    // release all of the pending invocations into the real queue
    m_pendingInvocations.forEach(pi -> callProcedureNT(pi.ciHandle, pi.user, pi.ccxn, pi.isAdmin, pi.ntPriority, pi.task));
    m_pendingInvocations.clear();
}
Also used : Procedure(org.voltdb.catalog.Procedure) TreeMap(java.util.TreeMap)

Example 28 with Procedure

use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.

the class LoadedProcedureSet method getProcByName.

public ProcedureRunner getProcByName(String procName) {
    // Check the procs from the catalog
    ProcedureRunner pr = m_userProcs.get(procName);
    if (pr == null) {
        pr = m_sysProcs.get(procName);
    }
    // if not there, check the default proc cache
    if (pr == null) {
        pr = m_defaultProcCache.get(procName);
    }
    // if not in the cache, compile the full default proc and put it in the cache
    if (pr == null) {
        Procedure catProc = m_defaultProcManager.checkForDefaultProcedure(procName);
        if (catProc != null) {
            String sqlText = DefaultProcedureManager.sqlForDefaultProc(catProc);
            Procedure newCatProc = StatementCompiler.compileDefaultProcedure(m_plannerTool, catProc, sqlText);
            VoltProcedure voltProc = new ProcedureRunner.StmtProcedure();
            pr = new ProcedureRunner(voltProc, m_site, newCatProc, m_csp);
            // this will ensure any created fragment tasks know to load the plans
            // for this plan-on-the-fly procedure
            pr.setProcNameToLoadForFragmentTasks(catProc.getTypeName());
            m_defaultProcCache.put(procName, pr);
        }
    }
    // return what we got, hopefully not null
    return pr;
}
Also used : Procedure(org.voltdb.catalog.Procedure)

Example 29 with Procedure

use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.

the class LoadedProcedureSet method loadSystemProcedures.

private ImmutableMap<String, ProcedureRunner> loadSystemProcedures(CatalogContext catalogContext, SiteProcedureConnection site, CatalogSpecificPlanner csp) {
    // clean up all the registered system plan fragments before reloading system procedures
    m_registeredSysProcPlanFragments.clear();
    ImmutableMap.Builder<String, ProcedureRunner> builder = ImmutableMap.<String, ProcedureRunner>builder();
    Set<Entry<String, Config>> entrySet = SystemProcedureCatalog.listing.entrySet();
    for (Entry<String, Config> entry : entrySet) {
        Config sysProc = entry.getValue();
        Procedure proc = sysProc.asCatalogProcedure();
        // NT sysprocs handled by NTProcedureService
        if (!sysProc.transactional) {
            continue;
        }
        VoltSystemProcedure procedure = null;
        final String className = sysProc.getClassname();
        Class<?> procClass = null;
        // this check is for sysprocs that don't have a procedure class
        if (className != null) {
            try {
                procClass = catalogContext.classForProcedure(className);
            } catch (final ClassNotFoundException e) {
                if (sysProc.commercial) {
                    continue;
                }
                hostLog.l7dlog(Level.WARN, LogKeys.host_ExecutionSite_GenericException.name(), // TODO: remove the extra meaningless parameter "0"
                new Object[] { site.getCorrespondingSiteId(), 0 }, e);
                VoltDB.crashLocalVoltDB(e.getMessage(), true, e);
            }
            try {
                procedure = (VoltSystemProcedure) procClass.newInstance();
            } catch (final InstantiationException e) {
                hostLog.l7dlog(Level.WARN, LogKeys.host_ExecutionSite_GenericException.name(), new Object[] { site.getCorrespondingSiteId(), 0 }, e);
            } catch (final IllegalAccessException e) {
                hostLog.l7dlog(Level.WARN, LogKeys.host_ExecutionSite_GenericException.name(), new Object[] { site.getCorrespondingSiteId(), 0 }, e);
            }
            ProcedureRunner runner = new ProcedureRunner(procedure, site, site.getSystemProcedureExecutionContext(), proc, csp);
            procedure.initSysProc(site, catalogContext.cluster, catalogContext.getClusterSettings(), catalogContext.getNodeSettings());
            // register the plan fragments with procedure set
            long[] planFragments = procedure.getPlanFragmentIds();
            assert (planFragments != null);
            for (long pfId : planFragments) {
                registerPlanFragment(pfId, runner);
            }
            builder.put(entry.getKey().intern(), runner);
        }
    }
    return builder.build();
}
Also used : Config(org.voltdb.SystemProcedureCatalog.Config) ImmutableMap(com.google_voltpatches.common.collect.ImmutableMap) Entry(java.util.Map.Entry) Procedure(org.voltdb.catalog.Procedure)

Example 30 with Procedure

use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.

the class JdbcDatabaseMetaDataGenerator method getProcedures.

VoltTable getProcedures() {
    VoltTable results = new VoltTable(PROCEDURES_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) {
        String remark = null;
        try {
            JSONObject jsObj = new JSONObject();
            jsObj.put(JSON_READ_ONLY, proc.getReadonly());
            jsObj.put(JSON_SINGLE_PARTITION, proc.getSinglepartition());
            if (proc.getSinglepartition()) {
                jsObj.put(JSON_PARTITION_PARAMETER, proc.getPartitionparameter());
                jsObj.put(JSON_PARTITION_PARAMETER_TYPE, proc.getPartitioncolumn().getType());
            }
            remark = jsObj.toString();
        } catch (JSONException e) {
            hostLog.warn("You have encountered an unexpected error while generating results for the " + "@SystemCatalog procedure call. This error will not affect your database's " + "operation. Please contact VoltDB support with your log files and a " + "description of what you were doing when this error occured.", e);
            remark = "{\"" + JSON_ERROR + "\",\"" + e.getMessage() + "\"}";
        }
        results.addRow(null, // procedure schema
        null, // procedure name
        proc.getTypeName(), // reserved
        null, // reserved
        null, // reserved
        null, // REMARKS
        remark, // procedure time
        java.sql.DatabaseMetaData.procedureResultUnknown, // specific name
        proc.getTypeName());
    }
    return results;
}
Also used : JSONObject(org.json_voltpatches.JSONObject) TreeSet(java.util.TreeSet) Procedure(org.voltdb.catalog.Procedure) JSONException(org.json_voltpatches.JSONException)

Aggregations

Procedure (org.voltdb.catalog.Procedure)42 Statement (org.voltdb.catalog.Statement)12 Database (org.voltdb.catalog.Database)9 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Table (org.voltdb.catalog.Table)6 VoltTable (org.voltdb.VoltTable)5 Catalog (org.voltdb.catalog.Catalog)5 Constraint (org.voltdb.catalog.Constraint)5 ProcParameter (org.voltdb.catalog.ProcParameter)5 Config (org.voltdb.SystemProcedureCatalog.Config)4 ImmutableMap (com.google_voltpatches.common.collect.ImmutableMap)3 JSONException (org.json_voltpatches.JSONException)3 ProcInfoData (org.voltdb.ProcInfoData)3 SQLStmt (org.voltdb.SQLStmt)3 GroupRef (org.voltdb.catalog.GroupRef)3 PlanFragment (org.voltdb.catalog.PlanFragment)3 File (java.io.File)2 IOException (java.io.IOException)2 SimpleDateFormat (java.text.SimpleDateFormat)2