Search in sources :

Example 1 with ImmutableMap

use of com.google_voltpatches.common.collect.ImmutableMap 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 2 with ImmutableMap

use of com.google_voltpatches.common.collect.ImmutableMap in project voltdb by VoltDB.

the class LoadedProcedureSet method loadUserProcedureRunners.

private static ImmutableMap<String, ProcedureRunner> loadUserProcedureRunners(CatalogContext catalogContext, SiteProcedureConnection site, CatalogSpecificPlanner csp) {
    ImmutableMap.Builder<String, ProcedureRunner> builder = ImmutableMap.<String, ProcedureRunner>builder();
    // load up all the stored procedures
    final CatalogMap<Procedure> catalogProcedures = catalogContext.database.getProcedures();
    for (final Procedure proc : catalogProcedures) {
        // sysprocs found in old catalog versions. (PRO-365)
        if (proc.getTypeName().startsWith("@")) {
            continue;
        }
        // skip non-transactional procs. Those will be handled by LoadedNTProcedureSet
        if (proc.getTransactional() == false) {
            continue;
        }
        VoltProcedure procedure = null;
        if (proc.getHasjava()) {
            final String className = proc.getClassname();
            Class<?> procClass = null;
            try {
                procClass = catalogContext.classForProcedure(className);
            } catch (final 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);
                }
            }
            try {
                procedure = (VoltProcedure) procClass.newInstance();
            } catch (final Exception e) {
                // TODO: remove the extra meaningless parameter "0"
                hostLog.l7dlog(Level.WARN, LogKeys.host_ExecutionSite_GenericException.name(), new Object[] { site.getCorrespondingSiteId(), 0 }, e);
            }
        } else {
            procedure = new ProcedureRunner.StmtProcedure();
        }
        assert (procedure != null);
        ProcedureRunner runner = new ProcedureRunner(procedure, site, proc, csp);
        builder.put(proc.getTypeName().intern(), runner);
    }
    return builder.build();
}
Also used : Procedure(org.voltdb.catalog.Procedure) ImmutableMap(com.google_voltpatches.common.collect.ImmutableMap)

Example 3 with ImmutableMap

use of com.google_voltpatches.common.collect.ImmutableMap in project voltdb by VoltDB.

the class ImporterLifeCycleManager method onChange.

/**
     * Callback method used by resource distributer to allocate/deallocate resources.
     * Stop will be called for resources that are removed from assignment list for this node.
     * Accept with be called in its own execution thread for resources that are added for this node.
     */
@Override
public final void onChange(ImporterChannelAssignment assignment) {
    if (m_stopping && !assignment.getAdded().isEmpty()) {
        String msg = "Received an a channel assignment when the importer is stopping: " + assignment;
        s_logger.warn(msg);
        throw new IllegalStateException(msg);
    }
    if (m_stopping) {
        return;
    }
    ImmutableMap<URI, AbstractImporter> oldReference = m_importers.get();
    ImmutableMap.Builder<URI, AbstractImporter> builder = new ImmutableMap.Builder<>();
    builder.putAll(Maps.filterKeys(oldReference, notUriIn(assignment.getRemoved())));
    List<AbstractImporter> toStop = new ArrayList<>();
    List<String> missingRemovedURLs = new ArrayList<>();
    List<String> missingAddedURLs = new ArrayList<>();
    for (URI removed : assignment.getRemoved()) {
        if (m_configs.containsKey(removed)) {
            AbstractImporter importer = oldReference.get(removed);
            if (importer != null) {
                toStop.add(importer);
            }
        } else {
            missingRemovedURLs.add(removed.toString());
        }
    }
    List<AbstractImporter> newImporters = new ArrayList<>();
    for (final URI added : assignment.getAdded()) {
        if (m_configs.containsKey(added)) {
            AbstractImporter importer = m_factory.createImporter(m_configs.get(added));
            newImporters.add(importer);
            builder.put(added, importer);
        } else {
            missingAddedURLs.add(added.toString());
        }
    }
    if (!missingRemovedURLs.isEmpty() || !missingAddedURLs.isEmpty()) {
        s_logger.error("The source for Import has changed its configuration. Removed importer URL(s): (" + Joiner.on(", ").join(missingRemovedURLs) + "), added importer URL(s): (" + Joiner.on(", ").join(missingAddedURLs) + "). Pause and Resume the database to refresh the importer.");
    }
    ImmutableMap<URI, AbstractImporter> newReference = builder.build();
    boolean success = m_importers.compareAndSet(oldReference, newReference);
    if (!m_stopping && success) {
        // Could fail if stop was called after we entered inside this method
        stopImporters(toStop);
        startImporters(newImporters);
    }
}
Also used : FormatterBuilder(org.voltdb.importer.formatter.FormatterBuilder) ArrayList(java.util.ArrayList) URI(java.net.URI) ImmutableMap(com.google_voltpatches.common.collect.ImmutableMap)

Example 4 with ImmutableMap

use of com.google_voltpatches.common.collect.ImmutableMap 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 ImmutableMap

use of com.google_voltpatches.common.collect.ImmutableMap in project voltdb by VoltDB.

the class ImporterLifeCycleManager method readyForData.

/**
     * This method is used by the framework to indicate that the importers must be started now.
     * This implementation starts the required number of threads based on the number of resources
     * configured for this importer type.
     * <p>For importers that must be run on every site, this will also call
     * <code>accept()</code>.
     * For importers that must not be run on every site, this will register itself with the
     * resource distributer.
     */
public final void readyForData() {
    m_starting.compareAndSet(false, true);
    if (m_stopping)
        return;
    if (m_executorService != null) {
        // Should be caused by coding error. Generic RuntimeException is OK
        throw new RuntimeException("Importer has already been started and is running");
    }
    if (m_configs.size() == 0) {
        s_logger.info("No configured importers of " + m_factory.getTypeName() + " are ready to be started at this time");
        return;
    }
    ThreadPoolExecutor tpe = new ThreadPoolExecutor(m_configs.size(), m_configs.size(), 5_000, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), getThreadFactory(m_factory.getTypeName(), MEDIUM_STACK_SIZE));
    tpe.allowCoreThreadTimeOut(true);
    m_executorService = MoreExecutors.listeningDecorator(tpe);
    if (m_factory.isImporterRunEveryWhere()) {
        ImmutableMap.Builder<URI, AbstractImporter> builder = new ImmutableMap.Builder<>();
        for (final ImporterConfig config : m_configs.values()) {
            AbstractImporter importer = m_factory.createImporter(config);
            builder.put(importer.getResourceID(), importer);
        }
        m_importers.set(builder.build());
        startImporters(m_importers.get().values());
    } else {
        m_importers.set(ImmutableMap.<URI, AbstractImporter>of());
        m_distributer.registerCallback(m_distributerDesignation, this);
        m_distributer.registerChannels(m_distributerDesignation, m_configs.keySet());
    }
}
Also used : FormatterBuilder(org.voltdb.importer.formatter.FormatterBuilder) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) URI(java.net.URI) ImmutableMap(com.google_voltpatches.common.collect.ImmutableMap)

Aggregations

ImmutableMap (com.google_voltpatches.common.collect.ImmutableMap)5 URI (java.net.URI)2 Entry (java.util.Map.Entry)2 Config (org.voltdb.SystemProcedureCatalog.Config)2 Procedure (org.voltdb.catalog.Procedure)2 FormatterBuilder (org.voltdb.importer.formatter.FormatterBuilder)2 ArrayList (java.util.ArrayList)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1