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);
}
}
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);
}
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;
}
}
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);
}
}
Aggregations