Search in sources :

Example 26 with Seed

use of io.prestosql.spi.seedstore.Seed in project hetu-core by openlookeng.

the class EmbeddedStateStoreLauncher method launchStateStoreFromSeedStore.

private void launchStateStoreFromSeedStore(Map<String, String> properties) throws IOException {
    URI externalUri = httpServerInfo.getHttpExternalUri() != null ? httpServerInfo.getHttpExternalUri() : httpServerInfo.getHttpsExternalUri();
    // Get all seeds
    Set<String> locations = seedStoreManager.getAllSeeds(SeedStoreSubType.HAZELCAST).stream().map(x -> x.getLocation()).collect(Collectors.toSet());
    String launcherPort = getStateStoreLauncherPort(properties);
    requireNonNull(launcherPort, "The launcher port is null");
    // Detect port conflict and get the next usable one
    launcherPort = checkAndGetAvailablePort(launcherPort);
    properties.put(HAZELCAST_DISCOVERY_PORT_PROPERTY_NAME, launcherPort);
    // Launch state store
    String currentLocation = getNodeUri().getHost() + ":" + launcherPort;
    locations.add(currentLocation);
    if (launchStateStore(locations, properties) != null) {
        // Add seed to seed store if and only if state store launched successfully
        seedStoreManager.addSeed(SeedStoreSubType.HAZELCAST, currentLocation, true);
    }
    // Also add this hazelcast state store uri to the on-yarn seedstore
    if (seedStoreManager.getSeedStore(SeedStoreSubType.ON_YARN) != null) {
        Map<String, String> seedProperties = ImmutableMap.of(Seed.LOCATION_PROPERTY_NAME, externalUri.toString(), Seed.TIMESTAMP_PROPERTY_NAME, String.valueOf(System.currentTimeMillis()), Seed.INTERNAL_STATE_STORE_URI_PROPERTY_NAME, currentLocation);
        seedStoreManager.updateSeed(SeedStoreSubType.ON_YARN, externalUri.toString(), seedProperties);
    }
}
Also used : STATE_STORE_FAILURE(io.prestosql.spi.StandardErrorCode.STATE_STORE_FAILURE) InternalCommunicationConfig(io.prestosql.server.InternalCommunicationConfig) Logger(io.airlift.log.Logger) Inject(com.google.inject.Inject) StateStore(io.prestosql.spi.statestore.StateStore) HAZELCAST_DISCOVERY_PORT_PROPERTY_NAME(io.prestosql.statestore.StateStoreConstants.HAZELCAST_DISCOVERY_PORT_PROPERTY_NAME) SeedStoreSubType(io.prestosql.spi.seedstore.SeedStoreSubType) HashMap(java.util.HashMap) DEFAULT_HAZELCAST_DISCOVERY_PORT(io.prestosql.statestore.StateStoreConstants.DEFAULT_HAZELCAST_DISCOVERY_PORT) FileBasedLock(io.prestosql.spi.filesystem.FileBasedLock) HetuConfig(io.prestosql.utils.HetuConfig) SecureRandom(java.security.SecureRandom) HashSet(java.util.HashSet) SeedStoreManager(io.prestosql.seedstore.SeedStoreManager) ConfigurationLoader.loadPropertiesFrom(io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) URI(java.net.URI) StateStoreBootstrapper(io.prestosql.spi.statestore.StateStoreBootstrapper) HAZELCAST(io.prestosql.statestore.StateStoreConstants.HAZELCAST) PrestoException(io.prestosql.spi.PrestoException) STATE_STORE_CLUSTER_PROPERTY_NAME(io.prestosql.statestore.StateStoreConstants.STATE_STORE_CLUSTER_PROPERTY_NAME) ImmutableMap(com.google.common.collect.ImmutableMap) StateMap(io.prestosql.spi.statestore.StateMap) StateCollection(io.prestosql.spi.statestore.StateCollection) Collection(java.util.Collection) Seed(io.prestosql.spi.seedstore.Seed) Set(java.util.Set) IOException(java.io.IOException) SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) Collectors(java.util.stream.Collectors) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) STATE_STORE_CONFIGURATION_PATH(io.prestosql.statestore.StateStoreConstants.STATE_STORE_CONFIGURATION_PATH) Lock(java.util.concurrent.locks.Lock) HAZELCAST_DISCOVERY_TCPIP_SEEDS(io.prestosql.statestore.StateStoreConstants.HAZELCAST_DISCOVERY_TCPIP_SEEDS) HttpServerInfo(io.airlift.http.server.HttpServerInfo) Paths(java.nio.file.Paths) SSLServerSocket(javax.net.ssl.SSLServerSocket) STATE_STORE_TYPE_PROPERTY_NAME(io.prestosql.statestore.StateStoreConstants.STATE_STORE_TYPE_PROPERTY_NAME) ServerSocketFactory(javax.net.ServerSocketFactory) VisibleForTesting(com.google.common.annotations.VisibleForTesting) URI(java.net.URI)

Example 27 with Seed

use of io.prestosql.spi.seedstore.Seed in project hetu-core by openlookeng.

the class HazelcastStateStoreFactory method create.

@Override
public StateStore create(String stateStoreName, SeedStore seedStore, Map<String, String> properties) {
    if (properties == null) {
        throw new IllegalArgumentException(format("found no state store config"));
    }
    this.name = stateStoreName;
    requireNonNull(properties, "properties is null");
    log.info("-- Starting new state store client --");
    String clusterId = properties.get(STATE_STORE_CLUSTER_CONFIG_NAME);
    if (clusterId == null) {
        log.info("cluster name not provided, using default cluster name: %s", DEFAULT_CLUSTER_ID);
        clusterId = DEFAULT_CLUSTER_ID;
    }
    ClientConfig clientConfig = new ClientConfig();
    // Add serialization for Slice
    SerializerConfig sc = new SerializerConfig().setImplementation(new HazelCastSliceSerializer()).setTypeClass(Slice.class);
    clientConfig.getSerializationConfig().addSerializerConfig(sc);
    SerializerConfig catalogEntity = new SerializerConfig().setImplementation(new HazelcastCatalogSerializer()).setTypeClass(CatalogEntity.class);
    clientConfig.getSerializationConfig().addSerializerConfig(catalogEntity);
    SerializerConfig dataEntity = new SerializerConfig().setImplementation(new HazelcastDatabaseEntitySerializer()).setTypeClass(DatabaseEntity.class);
    clientConfig.getSerializationConfig().addSerializerConfig(dataEntity);
    SerializerConfig tableEntity = new SerializerConfig().setImplementation(new HazelcastTableEntitySerializer()).setTypeClass(TableEntity.class);
    clientConfig.getSerializationConfig().addSerializerConfig(tableEntity);
    SerializerConfig op = new SerializerConfig().setImplementation(new HazelcastOptionalSerializer()).setTypeClass(Optional.class);
    clientConfig.getSerializationConfig().addSerializerConfig(op);
    clientConfig.setClusterName(clusterId);
    // set security config
    if (Boolean.parseBoolean(properties.get(KERBEROS_ENABLED))) {
        KerberosConfig.setKerberosEnabled(true);
        KerberosConfig.setLoginContextName(properties.get(KERBEROS_LOGIN_CONTEXT_NAME));
        KerberosConfig.setServicePrincipalName(properties.get(KERBEROS_SERVICE_PRINCIPAL));
        System.setProperty("java.security.krb5.conf", properties.get(KRB5_CONFIG_FILE));
        System.setProperty("java.security.auth.login.config", properties.get(JAAS_CONFIG_FILE));
    }
    // Set hazelcast SSL config
    if (Boolean.parseBoolean(properties.get(HAZELCAST_SSL_ENABLED))) {
        SslConfig.setSslEnabled(true);
        SslConfig.setKeyStorePath(properties.get(SSL_KEYSTORE_PATH));
        SslConfig.setKeyStorePassword(properties.get(SSL_KEYSTORE_PASSWORD));
        SslConfig.setTrustStorePath(properties.get(SSL_TRUSTSTORE_PATH));
        SslConfig.setTrustStorePassword(properties.get(SSL_TRUSTSTORE_PASSWORD));
        SslConfig.setCipherSuites(properties.get(SSL_CIPHER_SUITES));
        SslConfig.setProtocols(properties.get(SSL_PROTOCOLS));
    }
    // Set heartbeat config
    final String heartbeatInterval = properties.get(HEARTBEAT_INTERVAL_SECONDS);
    final String heartbeatTimeout = properties.get(HEARTBEAT_TIMEOUT_SECONDS);
    if (heartbeatInterval != null) {
        clientConfig.setProperty(CLIENT_HEARTBEAT_INTERVAL, String.valueOf(Integer.parseInt(heartbeatInterval) * 1000));
    }
    if (heartbeatTimeout != null) {
        clientConfig.setProperty(CLIENT_HEARTBEAT_TIMEOUT, String.valueOf(Integer.parseInt(heartbeatTimeout) * 1000));
    }
    final String discoveryMode = properties.get(DISCOVERY_MODE_CONFIG_NAME);
    if (discoveryMode == null || discoveryMode.equalsIgnoreCase(DISCOVERY_MODE_MULTICAST)) {
        log.info("Using Multicast discovery for Hazelcast");
        clientConfig.setProperty(DISCOVERY_ENABLED, "true");
        DiscoveryStrategyConfig strategy = new DiscoveryStrategyConfig(DISCOVERY_MULTICAST_STRATEGY_CLASS_NAME);
        clientConfig.getNetworkConfig().getDiscoveryConfig().addDiscoveryStrategyConfig(strategy);
    } else if (discoveryMode.equalsIgnoreCase(DISCOVERY_MODE_TCPIP)) {
        String tcpipSeeds = properties.get(DISCOVERY_TCPIP_SEEDS);
        Collection<String> seedLocation = new HashSet<>();
        if (tcpipSeeds != null && !tcpipSeeds.trim().isEmpty()) {
            for (String seed : tcpipSeeds.split(COMMA)) {
                seedLocation.add(seed);
            }
        } else {
            seedStore.setName(clusterId);
            seedLocation = getSeedLocation(seedStore);
        }
        log.info("Using TCP-IP discovery for Hazelcast, seed nodes are: %s", String.join(",", seedLocation));
        seedLocation.stream().forEach(ip -> {
            clientConfig.getNetworkConfig().addAddress(ip);
        });
    } else {
        throw new PrestoException(CONFIGURATION_INVALID, "Discovery mode not supported: " + discoveryMode);
    }
    HazelcastInstance hzClient = HazelcastClient.newHazelcastClient(clientConfig);
    CipherService.Type encryptionType = getEncryptionTypeFromConfig(properties);
    return new HazelcastStateStore(hzClient, stateStoreName, encryptionType);
}
Also used : SSL_KEYSTORE_PASSWORD(io.hetu.core.statestore.hazelcast.HazelcastConstants.SSL_KEYSTORE_PASSWORD) StateStore(io.prestosql.spi.statestore.StateStore) CONFIGURATION_INVALID(io.prestosql.spi.StandardErrorCode.CONFIGURATION_INVALID) DISCOVERY_MULTICAST_STRATEGY_CLASS_NAME(io.hetu.core.statestore.hazelcast.HazelcastConstants.DISCOVERY_MULTICAST_STRATEGY_CLASS_NAME) Map(java.util.Map) KRB5_CONFIG_FILE(io.hetu.core.statestore.hazelcast.HazelcastConstants.KRB5_CONFIG_FILE) SSL_PROTOCOLS(io.hetu.core.statestore.hazelcast.HazelcastConstants.SSL_PROTOCOLS) SSL_TRUSTSTORE_PASSWORD(io.hetu.core.statestore.hazelcast.HazelcastConstants.SSL_TRUSTSTORE_PASSWORD) DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity) DISCOVERY_MODE_MULTICAST(io.hetu.core.statestore.hazelcast.HazelcastConstants.DISCOVERY_MODE_MULTICAST) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) KERBEROS_ENABLED(io.hetu.core.statestore.hazelcast.HazelcastConstants.KERBEROS_ENABLED) PrestoException(io.prestosql.spi.PrestoException) SeedStore(io.prestosql.spi.seedstore.SeedStore) DISCOVERY_MODE_CONFIG_NAME(io.hetu.core.statestore.hazelcast.HazelcastConstants.DISCOVERY_MODE_CONFIG_NAME) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) JAAS_CONFIG_FILE(io.hetu.core.statestore.hazelcast.HazelcastConstants.JAAS_CONFIG_FILE) Optional(java.util.Optional) SslConfig(io.hetu.core.security.networking.ssl.SslConfig) CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) STATE_STORE_FAILURE(io.prestosql.spi.StandardErrorCode.STATE_STORE_FAILURE) Slice(io.airlift.slice.Slice) Logger(io.airlift.log.Logger) HazelcastClient(com.hazelcast.client.HazelcastClient) STATE_STORE_CLUSTER_CONFIG_NAME(io.hetu.core.statestore.Constants.STATE_STORE_CLUSTER_CONFIG_NAME) HAZELCAST_SSL_ENABLED(io.hetu.core.statestore.hazelcast.HazelcastConstants.HAZELCAST_SSL_ENABLED) KerberosConfig(io.hetu.core.security.authentication.kerberos.KerberosConfig) SSL_KEYSTORE_PATH(io.hetu.core.statestore.hazelcast.HazelcastConstants.SSL_KEYSTORE_PATH) HashSet(java.util.HashSet) StateStoreUtils.getEncryptionTypeFromConfig(io.hetu.core.statestore.StateStoreUtils.getEncryptionTypeFromConfig) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) DISCOVERY_TCPIP_SEEDS(io.hetu.core.statestore.hazelcast.HazelcastConstants.DISCOVERY_TCPIP_SEEDS) Objects.requireNonNull(java.util.Objects.requireNonNull) SSL_TRUSTSTORE_PATH(io.hetu.core.statestore.hazelcast.HazelcastConstants.SSL_TRUSTSTORE_PATH) ClientConfig(com.hazelcast.client.config.ClientConfig) SerializerConfig(com.hazelcast.config.SerializerConfig) DISCOVERY_ENABLED(io.hetu.core.statestore.hazelcast.HazelcastConstants.DISCOVERY_ENABLED) DEFAULT_CLUSTER_ID(io.hetu.core.statestore.hazelcast.HazelcastConstants.DEFAULT_CLUSTER_ID) DISCOVERY_MODE_TCPIP(io.hetu.core.statestore.hazelcast.HazelcastConstants.DISCOVERY_MODE_TCPIP) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CipherService(io.prestosql.spi.statestore.CipherService) KERBEROS_SERVICE_PRINCIPAL(io.hetu.core.statestore.hazelcast.HazelcastConstants.KERBEROS_SERVICE_PRINCIPAL) Seed(io.prestosql.spi.seedstore.Seed) KERBEROS_LOGIN_CONTEXT_NAME(io.hetu.core.statestore.hazelcast.HazelcastConstants.KERBEROS_LOGIN_CONTEXT_NAME) IOException(java.io.IOException) ThreadContextClassLoader(io.prestosql.spi.classloader.ThreadContextClassLoader) HEARTBEAT_INTERVAL_SECONDS(io.hetu.core.statestore.hazelcast.HazelcastConstants.HEARTBEAT_INTERVAL_SECONDS) TimeUnit(java.util.concurrent.TimeUnit) TableEntity(io.prestosql.spi.metastore.model.TableEntity) StateStoreFactory(io.prestosql.spi.statestore.StateStoreFactory) HEARTBEAT_TIMEOUT_SECONDS(io.hetu.core.statestore.hazelcast.HazelcastConstants.HEARTBEAT_TIMEOUT_SECONDS) SSL_CIPHER_SUITES(io.hetu.core.statestore.hazelcast.HazelcastConstants.SSL_CIPHER_SUITES) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) CipherService(io.prestosql.spi.statestore.CipherService) PrestoException(io.prestosql.spi.PrestoException) SerializerConfig(com.hazelcast.config.SerializerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Collection(java.util.Collection) ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 28 with Seed

use of io.prestosql.spi.seedstore.Seed in project hetu-core by openlookeng.

the class HazelcastStateStoreFactory method getSeedLocation.

private Collection<String> getSeedLocation(SeedStore seedStore) {
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(seedStore.getClass().getClassLoader())) {
        int retryTimes = 0;
        long retryInterval = 0L;
        Set<String> ips = null;
        do {
            try {
                log.debug("getSeedLocation at retry times: %s, retryInterval: %s", retryTimes, retryInterval);
                TimeUnit.MILLISECONDS.sleep(retryInterval);
                Collection<Seed> seeds = seedStore.get();
                ips = seeds.stream().map(x -> x.getLocation()).collect(Collectors.toSet());
            } catch (IOException e) {
                throw new RuntimeException("Error getSeedLocation: " + e.getMessage());
            } catch (UncheckedExecutionException | IllegalStateException | InterruptedException e) {
                log.warn("getSeedLocation failed with following exception : %s", e.getMessage());
            } finally {
                retryTimes++;
                retryInterval += SEED_IP_FETCHING_INITIAL_RETRY_INTERVAL;
            }
        } while (retryTimes <= SEED_IP_FETCHING_RETRY_TIMES && (ips == null || ips.size() == 0));
        if (ips == null || ips.size() == 0) {
            throw new PrestoException(STATE_STORE_FAILURE, "Using TCP-IP discovery but can not find seeds");
        }
        return ips;
    }
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) PrestoException(io.prestosql.spi.PrestoException) IOException(java.io.IOException) Seed(io.prestosql.spi.seedstore.Seed) ThreadContextClassLoader(io.prestosql.spi.classloader.ThreadContextClassLoader)

Example 29 with Seed

use of io.prestosql.spi.seedstore.Seed in project hetu-core by openlookeng.

the class DistributedQueryRunnerWithStateStore method setupStateStore.

public void setupStateStore() throws Exception {
    int port = SslSocketUtil.getAvailablePort();
    for (TestingPrestoServer server : servers) {
        server.installPlugin(new StateStoreManagerPlugin());
        // State Store
        StateStoreLauncher launcher = server.getInstance(Key.get(StateStoreLauncher.class));
        if (launcher instanceof EmbeddedStateStoreLauncher) {
            Set<String> ips = Sets.newHashSet(Arrays.asList("127.0.0.1"));
            Map<String, String> stateStoreProperties = new HashMap<>();
            stateStoreProperties.put(DISCOVERY_PORT_CONFIG_NAME, port + "");
            stateStoreProperties.putIfAbsent(HazelcastConstants.DISCOVERY_MODE_CONFIG_NAME, HazelcastConstants.DISCOVERY_MODE_TCPIP);
            this.stateStores.add(((EmbeddedStateStoreLauncher) launcher).launchStateStore(ips, stateStoreProperties));
        }
        launcher.launchStateStore();
        StateStoreProvider provider = server.getInstance(Key.get(StateStoreProvider.class));
        Seed seed = new FileBasedSeed("127.0.0.1:" + port, 0);
        SeedStore seedStore = new SeedStore() {

            @Override
            public Collection<Seed> add(Collection<Seed> seeds) throws IOException {
                return null;
            }

            @Override
            public Collection<Seed> get() throws IOException {
                return new ArrayList<>((Arrays.asList(seed)));
            }

            @Override
            public Collection<Seed> remove(Collection<Seed> seeds) throws IOException {
                return null;
            }

            @Override
            public Seed create(Map<String, String> properties) {
                return null;
            }

            @Override
            public String getName() {
                return null;
            }

            @Override
            public void setName(String name) {
            }
        };
        server.getInstance(Key.get(SeedStoreManager.class)).setSeedStore(SeedStoreSubType.HAZELCAST, seedStore);
        if (provider instanceof LocalStateStoreProvider) {
            Map<String, String> stateStoreProperties = new HashMap<>();
            stateStoreProperties.putIfAbsent(HazelcastConstants.DISCOVERY_MODE_CONFIG_NAME, HazelcastConstants.DISCOVERY_MODE_TCPIP);
            stateStoreProperties.put(DISCOVERY_PORT_CONFIG_NAME, port + "");
            ((LocalStateStoreProvider) provider).setStateStore("hazelcast", stateStoreProperties);
            ((LocalStateStoreProvider) provider).createStateCollections();
        }
        provider.loadStateStore();
        this.providers.add(provider);
    }
}
Also used : EmbeddedStateStoreLauncher(io.prestosql.statestore.EmbeddedStateStoreLauncher) FileBasedSeed(io.hetu.core.seedstore.filebased.FileBasedSeed) HashMap(java.util.HashMap) TestingPrestoServer(io.prestosql.server.testing.TestingPrestoServer) ArrayList(java.util.ArrayList) LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) StateStoreProvider(io.prestosql.statestore.StateStoreProvider) LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) FileBasedSeed(io.hetu.core.seedstore.filebased.FileBasedSeed) Seed(io.prestosql.spi.seedstore.Seed) StateStoreLauncher(io.prestosql.statestore.StateStoreLauncher) EmbeddedStateStoreLauncher(io.prestosql.statestore.EmbeddedStateStoreLauncher) SeedStore(io.prestosql.spi.seedstore.SeedStore) Collection(java.util.Collection) StateStoreManagerPlugin(io.hetu.core.statestore.StateStoreManagerPlugin) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Seed (io.prestosql.spi.seedstore.Seed)29 SeedStore (io.prestosql.spi.seedstore.SeedStore)21 HashSet (java.util.HashSet)20 IOException (java.io.IOException)15 Map (java.util.Map)12 PrestoException (io.prestosql.spi.PrestoException)11 Collection (java.util.Collection)11 HashMap (java.util.HashMap)10 HetuFileSystemClient (io.prestosql.spi.filesystem.HetuFileSystemClient)8 Set (java.util.Set)8 Test (org.testng.annotations.Test)8 Logger (io.airlift.log.Logger)7 SeedStoreSubType (io.prestosql.spi.seedstore.SeedStoreSubType)7 File (java.io.File)7 Collectors (java.util.stream.Collectors)7 BeforeTest (org.testng.annotations.BeforeTest)7 FileBasedLock (io.prestosql.spi.filesystem.FileBasedLock)6 SeedStoreFactory (io.prestosql.spi.seedstore.SeedStoreFactory)6 Paths (java.nio.file.Paths)6 Lock (java.util.concurrent.locks.Lock)6