Search in sources :

Example 1 with Config

use of org.voltdb.SystemProcedureCatalog.Config in project voltdb by VoltDB.

the class MpScheduler method handleIv2InitiateTaskMessage.

// MpScheduler expects to see initiations for multipartition procedures and
// system procedures which are "every-partition", meaning that they run as
// single-partition procedures at every partition, and the results are
// aggregated/deduped here at the MPI.
public void handleIv2InitiateTaskMessage(Iv2InitiateTaskMessage message) {
    final String procedureName = message.getStoredProcedureName();
    /*
         * If this is CL replay, use the txnid from the CL and use it to update the current txnid
         */
    long mpTxnId;
    //Timestamp is actually a pre-IV2ish style time based transaction id
    long timestamp = Long.MIN_VALUE;
    // Update UID if it's for replay
    if (message.isForReplay()) {
        timestamp = message.getUniqueId();
        m_uniqueIdGenerator.updateMostRecentlyGeneratedUniqueId(timestamp);
    } else {
        timestamp = m_uniqueIdGenerator.getNextUniqueId();
    }
    TxnEgo ego = advanceTxnEgo();
    mpTxnId = ego.getTxnId();
    // Thread name has to be materialized here
    final String threadName = Thread.currentThread().getName();
    final VoltTrace.TraceEventBatch traceLog = VoltTrace.log(VoltTrace.Category.MPI);
    if (traceLog != null) {
        traceLog.add(() -> VoltTrace.meta("process_name", "name", CoreUtils.getHostnameOrAddress())).add(() -> VoltTrace.meta("thread_name", "name", threadName)).add(() -> VoltTrace.meta("thread_sort_index", "sort_index", Integer.toString(100))).add(() -> VoltTrace.beginAsync("initmp", mpTxnId, "txnId", TxnEgo.txnIdToString(mpTxnId), "ciHandle", message.getClientInterfaceHandle(), "name", procedureName, "read", message.isReadOnly()));
    }
    // Don't have an SP HANDLE at the MPI, so fill in the unused value
    Iv2Trace.logIv2InitiateTaskMessage(message, m_mailbox.getHSId(), mpTxnId, Long.MIN_VALUE);
    // Handle every-site system procedures (at the MPI)
    final Config sysprocConfig = SystemProcedureCatalog.listing.get(procedureName);
    if (sysprocConfig != null && sysprocConfig.getEverysite()) {
        // Send an SP initiate task to all remote sites
        final Long localId = m_mailbox.getHSId();
        Iv2InitiateTaskMessage sp = new Iv2InitiateTaskMessage(// make the MPI the initiator.
        localId, message.getCoordinatorHSId(), m_repairLogTruncationHandle, mpTxnId, timestamp, message.isReadOnly(), // isSinglePartition
        true, message.getStoredProcedureInvocation(), message.getClientInterfaceHandle(), message.getConnectionId(), message.isForReplay());
        DuplicateCounter counter = new DuplicateCounter(message.getInitiatorHSId(), mpTxnId, m_iv2Masters, message);
        safeAddToDuplicateCounterMap(mpTxnId, counter);
        EveryPartitionTask eptask = new EveryPartitionTask(m_mailbox, m_pendingTasks, sp, m_iv2Masters);
        m_pendingTasks.offer(eptask);
        return;
    }
    // Create a copy so we can overwrite the txnID so the InitiateResponse will be
    // correctly tracked.
    Iv2InitiateTaskMessage mp = new Iv2InitiateTaskMessage(message.getInitiatorHSId(), message.getCoordinatorHSId(), m_repairLogTruncationHandle, mpTxnId, timestamp, message.isReadOnly(), message.isSinglePartition(), message.getStoredProcedureInvocation(), message.getClientInterfaceHandle(), message.getConnectionId(), message.isForReplay());
    // Multi-partition initiation (at the MPI)
    MpProcedureTask task = null;
    if (isNpTxn(message) && NpProcedureTaskConstructor != null) {
        Set<Integer> involvedPartitions = getBalancePartitions(message);
        if (involvedPartitions != null) {
            HashMap<Integer, Long> involvedPartitionMasters = Maps.newHashMap(m_partitionMasters);
            involvedPartitionMasters.keySet().retainAll(involvedPartitions);
            task = instantiateNpProcedureTask(m_mailbox, procedureName, m_pendingTasks, mp, involvedPartitionMasters, m_buddyHSIds.get(m_nextBuddy), false);
        }
    // if cannot figure out the involved partitions, run it as an MP txn
    }
    if (task == null) {
        task = new MpProcedureTask(m_mailbox, procedureName, m_pendingTasks, mp, m_iv2Masters, m_partitionMasters, m_buddyHSIds.get(m_nextBuddy), false);
    }
    m_nextBuddy = (m_nextBuddy++) % m_buddyHSIds.size();
    m_outstandingTxns.put(task.m_txnState.txnId, task.m_txnState);
    m_pendingTasks.offer(task);
}
Also used : VoltTrace(org.voltdb.utils.VoltTrace) Config(org.voltdb.SystemProcedureCatalog.Config) Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage)

Example 2 with Config

use of org.voltdb.SystemProcedureCatalog.Config in project voltdb by VoltDB.

the class ClientInterface method initiateSnapshotDaemonWork.

@Override
public void initiateSnapshotDaemonWork(final String procedureName, long clientData, final Object[] params) {
    final Config sysProc = SystemProcedureCatalog.listing.get(procedureName);
    if (sysProc == null) {
        throw new RuntimeException("SnapshotDaemon attempted to invoke " + procedureName + " which is not a known procedure");
    }
    Procedure catProc = sysProc.asCatalogProcedure();
    StoredProcedureInvocation spi = new StoredProcedureInvocation();
    spi.setProcName(procedureName);
    spi.params = new FutureTask<ParameterSet>(new Callable<ParameterSet>() {

        @Override
        public ParameterSet call() {
            ParameterSet paramSet = ParameterSet.fromArrayWithCopy(params);
            return paramSet;
        }
    });
    spi.clientHandle = clientData;
    // Ugh, need to consolidate this with handleRead() somehow but not feeling it at the moment
    if (procedureName.equals("@SnapshotScan")) {
        InvocationDispatcher.dispatchStatistics(OpsSelector.SNAPSHOTSCAN, spi, m_snapshotDaemonAdapter);
        return;
    } else if (procedureName.equals("@SnapshotDelete")) {
        InvocationDispatcher.dispatchStatistics(OpsSelector.SNAPSHOTDELETE, spi, m_snapshotDaemonAdapter);
        return;
    }
    // initiate the transaction
    createTransaction(m_snapshotDaemonAdapter.connectionId(), spi, catProc.getReadonly(), catProc.getSinglepartition(), catProc.getEverysite(), 0, 0, System.nanoTime());
}
Also used : Config(org.voltdb.SystemProcedureCatalog.Config) Procedure(org.voltdb.catalog.Procedure) Callable(java.util.concurrent.Callable)

Example 3 with Config

use of org.voltdb.SystemProcedureCatalog.Config in project voltdb by VoltDB.

the class NTProcedureService method loadSystemProcedures.

/**
     * Load the system procedures.
     * Optionally don't load UAC but use parameter instead.
     */
@SuppressWarnings("unchecked")
private ImmutableMap<String, ProcedureRunnerNTGenerator> loadSystemProcedures() {
    // todo need to skip UAC creation
    // but can wait until UAC is an NT proc
    ImmutableMap.Builder<String, ProcedureRunnerNTGenerator> builder = ImmutableMap.<String, ProcedureRunnerNTGenerator>builder();
    Set<Entry<String, Config>> entrySet = SystemProcedureCatalog.listing.entrySet();
    for (Entry<String, Config> entry : entrySet) {
        String procName = entry.getKey();
        Config sysProc = entry.getValue();
        // transactional sysprocs handled by LoadedProcedureSet
        if (sysProc.transactional) {
            continue;
        }
        final String className = sysProc.getClassname();
        Class<? extends VoltNonTransactionalProcedure> procClass = null;
        // this check is for sysprocs that don't have a procedure class
        if (className != null) {
            try {
                procClass = (Class<? extends VoltNonTransactionalProcedure>) Class.forName(className);
            } catch (final ClassNotFoundException e) {
                if (sysProc.commercial) {
                    continue;
                }
                VoltDB.crashLocalVoltDB("Missing Java class for NT System Procedure: " + procName);
            }
            // This is a startup-time check to make sure we can instantiate
            try {
                if ((procClass.newInstance() instanceof VoltNTSystemProcedure) == false) {
                    VoltDB.crashLocalVoltDB("NT System Procedure is incorrect class type: " + procName);
                }
            } catch (InstantiationException | IllegalAccessException e) {
                VoltDB.crashLocalVoltDB("Unable to instantiate NT System Procedure: " + procName);
            }
            ProcedureRunnerNTGenerator prntg = new ProcedureRunnerNTGenerator(procClass);
            builder.put(procName, prntg);
        }
    }
    return builder.build();
}
Also used : Config(org.voltdb.SystemProcedureCatalog.Config) ImmutableMap(com.google_voltpatches.common.collect.ImmutableMap) Entry(java.util.Map.Entry)

Example 4 with Config

use of org.voltdb.SystemProcedureCatalog.Config 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 5 with Config

use of org.voltdb.SystemProcedureCatalog.Config in project voltdb by VoltDB.

the class ClientInterface method callExecuteTaskAsync.

/**
     * Asynchronous version, call @ExecuteTask to generate a MP transaction.
     *
     * @param cb  maximum timeout in milliseconds
     * @param params  actual parameter(s) for sub task to run
     * @return
     * @throws IOException
     * @throws InterruptedException
     */
public void callExecuteTaskAsync(SimpleClientResponseAdapter.Callback cb, byte[] params) throws IOException {
    final String procedureName = "@ExecuteTask";
    Config procedureConfig = SystemProcedureCatalog.listing.get(procedureName);
    Procedure proc = procedureConfig.asCatalogProcedure();
    StoredProcedureInvocation spi = new StoredProcedureInvocation();
    spi.setProcName(procedureName);
    spi.setParams(params);
    spi.setClientHandle(m_executeTaskAdpater.registerCallback(cb));
    if (spi.getSerializedParams() == null) {
        spi = MiscUtils.roundTripForCL(spi);
    }
    synchronized (m_executeTaskAdpater) {
        createTransaction(m_executeTaskAdpater.connectionId(), spi, proc.getReadonly(), proc.getSinglepartition(), proc.getEverysite(), 0, /* Can provide anything for multi-part */
        spi.getSerializedSize(), System.nanoTime());
    }
}
Also used : Config(org.voltdb.SystemProcedureCatalog.Config) Procedure(org.voltdb.catalog.Procedure)

Aggregations

Config (org.voltdb.SystemProcedureCatalog.Config)5 Procedure (org.voltdb.catalog.Procedure)3 ImmutableMap (com.google_voltpatches.common.collect.ImmutableMap)2 Entry (java.util.Map.Entry)2 Callable (java.util.concurrent.Callable)1 Iv2InitiateTaskMessage (org.voltdb.messaging.Iv2InitiateTaskMessage)1 VoltTrace (org.voltdb.utils.VoltTrace)1