Search in sources :

Example 1 with Supplier

use of com.google_voltpatches.common.base.Supplier in project voltdb by VoltDB.

the class TheHashinator method getSupplierForType.

private Supplier<VoltTable> getSupplierForType(final VoltType type) {
    return new Supplier<VoltTable>() {

        @Override
        public VoltTable get() {
            VoltTable vt = new VoltTable(new VoltTable.ColumnInfo[] { new VoltTable.ColumnInfo(VoltSystemProcedure.CNAME_PARTITION_ID, VoltSystemProcedure.CTYPE_ID), new VoltTable.ColumnInfo(CNAME_PARTITION_KEY, type) });
            Set<Integer> partitions = TheHashinator.this.pGetPartitions();
            for (int ii = 0; ii < 500000; ii++) {
                if (partitions.isEmpty())
                    break;
                Object value = null;
                if (type == VoltType.INTEGER)
                    value = ii;
                if (type == VoltType.STRING)
                    value = String.valueOf(ii);
                if (type == VoltType.VARBINARY) {
                    ByteBuffer buf = ByteBuffer.allocate(4);
                    buf.putInt(ii);
                    value = buf.array();
                }
                int partition = TheHashinator.this.getHashedPartitionForParameter(type.getValue(), value);
                if (partitions.remove(partition)) {
                    vt.addRow(partition, value);
                }
            }
            return vt;
        }
    };
}
Also used : Supplier(com.google_voltpatches.common.base.Supplier) ByteBuffer(java.nio.ByteBuffer)

Example 2 with Supplier

use of com.google_voltpatches.common.base.Supplier in project voltdb by VoltDB.

the class RealVoltDB method buildClusterMesh.

/**
     * Start the voltcore HostMessenger. This joins the node
     * to the existing cluster. In the non rejoin case, this
     * function will return when the mesh is complete. If
     * rejoining, it will return when the node and agreement
     * site are synched to the existing cluster.
     */
MeshProber.Determination buildClusterMesh(ReadDeploymentResults readDepl) {
    final boolean bareAtStartup = m_config.m_forceVoltdbCreate || pathsWithRecoverableArtifacts(readDepl.deployment).isEmpty();
    setBare(bareAtStartup);
    final Supplier<Integer> hostCountSupplier = new Supplier<Integer>() {

        @Override
        public Integer get() {
            return m_clusterSettings.get().hostcount();
        }
    };
    ClusterType clusterType = readDepl.deployment.getCluster();
    MeshProber criteria = MeshProber.builder().coordinators(m_config.m_coordinators).versionChecker(m_versionChecker).enterprise(m_config.m_isEnterprise).startAction(m_config.m_startAction).bare(bareAtStartup).configHash(CatalogUtil.makeDeploymentHashForConfig(readDepl.deploymentBytes)).hostCountSupplier(hostCountSupplier).kfactor(clusterType.getKfactor()).paused(m_config.m_isPaused).nodeStateSupplier(m_statusTracker.getNodeStateSupplier()).addAllowed(m_config.m_enableAdd).safeMode(m_config.m_safeMode).terminusNonce(getTerminusNonce()).missingHostCount(m_config.m_missingHostCount).build();
    HostAndPort hostAndPort = criteria.getLeader();
    String hostname = hostAndPort.getHostText();
    int port = hostAndPort.getPort();
    org.voltcore.messaging.HostMessenger.Config hmconfig;
    hmconfig = new org.voltcore.messaging.HostMessenger.Config(hostname, port);
    if (m_config.m_placementGroup != null) {
        hmconfig.group = m_config.m_placementGroup;
    }
    hmconfig.internalPort = m_config.m_internalPort;
    hmconfig.internalInterface = m_config.m_internalInterface;
    hmconfig.zkInterface = m_config.m_zkInterface;
    hmconfig.deadHostTimeout = m_config.m_deadHostTimeoutMS;
    hmconfig.factory = new VoltDbMessageFactory();
    hmconfig.coreBindIds = m_config.m_networkCoreBindings;
    hmconfig.acceptor = criteria;
    hmconfig.localSitesCount = m_config.m_sitesperhost;
    m_messenger = new org.voltcore.messaging.HostMessenger(hmconfig, this);
    hostLog.info(String.format("Beginning inter-node communication on port %d.", m_config.m_internalPort));
    try {
        m_messenger.start();
    } catch (Exception e) {
        VoltDB.crashLocalVoltDB(e.getMessage(), true, e);
    }
    VoltZK.createPersistentZKNodes(m_messenger.getZK());
    // Use the host messenger's hostId.
    m_myHostId = m_messenger.getHostId();
    hostLog.info(String.format("Host id of this node is: %d", m_myHostId));
    consoleLog.info(String.format("Host id of this node is: %d", m_myHostId));
    MeshProber.Determination determination = criteria.waitForDetermination();
    // paused is determined in the mesh formation exchanged
    if (determination.paused) {
        m_messenger.pause();
    } else {
        m_messenger.unpause();
    }
    // leader and we're rejoining, this is clearly bad.
    if (m_myHostId == 0 && determination.startAction.doesJoin()) {
        VoltDB.crashLocalVoltDB("Unable to rejoin a node to itself.  " + "Please check your command line and start action and try again.", false, null);
    }
    // load or store settings form/to zookeeper
    if (determination.startAction.doesJoin()) {
        m_clusterSettings.load(m_messenger.getZK());
        m_clusterSettings.get().store();
    } else if (m_myHostId == 0) {
        m_clusterSettings.store(m_messenger.getZK());
    }
    m_clusterCreateTime = m_messenger.getInstanceId().getTimestamp();
    return determination;
}
Also used : VoltDbMessageFactory(org.voltdb.messaging.VoltDbMessageFactory) ClusterType(org.voltdb.compiler.deploymentfile.ClusterType) MeshProber(org.voltdb.probe.MeshProber) SocketException(java.net.SocketException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JSONException(org.json_voltpatches.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) SettingsException(org.voltdb.settings.SettingsException) HostAndPort(com.google_voltpatches.common.net.HostAndPort) HostMessenger(org.voltcore.messaging.HostMessenger) HostMessenger(org.voltcore.messaging.HostMessenger) Supplier(com.google_voltpatches.common.base.Supplier)

Aggregations

Supplier (com.google_voltpatches.common.base.Supplier)2 HostAndPort (com.google_voltpatches.common.net.HostAndPort)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SocketException (java.net.SocketException)1 ByteBuffer (java.nio.ByteBuffer)1 ExecutionException (java.util.concurrent.ExecutionException)1 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)1 JSONException (org.json_voltpatches.JSONException)1 HostMessenger (org.voltcore.messaging.HostMessenger)1 ClusterType (org.voltdb.compiler.deploymentfile.ClusterType)1 VoltDbMessageFactory (org.voltdb.messaging.VoltDbMessageFactory)1 MeshProber (org.voltdb.probe.MeshProber)1 SettingsException (org.voltdb.settings.SettingsException)1