use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.
the class TestStateStoreLauncherAndProvider method setUp.
// setup for test provider
@BeforeTest
private void setUp() throws IOException {
Set<Seed> seeds = new HashSet<>();
SeedStore mockSeedStore = mock(SeedStore.class);
Seed mockSeed = mock(Seed.class);
seeds.add(mockSeed);
SeedStoreManager mockSeedStoreManager = mock(SeedStoreManager.class);
when(mockSeedStoreManager.getSeedStore(SeedStoreSubType.HAZELCAST)).thenReturn(mockSeedStore);
when(mockSeed.getLocation()).thenReturn(LOCALHOST + ":" + PORT3);
when(mockSeedStore.get()).thenReturn(seeds);
factory = new HazelcastStateStoreFactory();
stateStoreProvider = new LocalStateStoreProvider(mockSeedStoreManager);
stateStoreProvider.addStateStoreFactory(factory);
}
use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.
the class SeedStoreManager method refreshSeeds.
private void refreshSeeds(SeedStoreSubType subType) {
SeedStore seedStore = getSeedStore(subType);
if (seedStore == null) {
throw new PrestoException(SEED_STORE_FAILURE, "Seed store is null");
}
for (Map.Entry<String, Seed> entry : refreshableSeedsMap.entrySet()) {
long newTime = System.currentTimeMillis();
LOG.debug("seed=%s refresh with oldTimestamp=%s and newTimestamp=%s", entry.getKey(), entry.getValue().getTimestamp(), newTime);
Seed newSeed = seedStore.create(ImmutableMap.of(Seed.LOCATION_PROPERTY_NAME, entry.getKey(), Seed.TIMESTAMP_PROPERTY_NAME, String.valueOf(newTime)));
try {
seedStore.add(Lists.newArrayList(newSeed));
entry.setValue(newSeed);
} catch (IOException | RuntimeException e) {
LOG.warn("Error refresh seed=%s with error message: %s, will refresh in next %s milliseconds", entry.getKey(), e.getMessage(), seedHeartBeat);
continue;
}
}
}
use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.
the class SeedStoreManager method addSeed.
/**
* Add seed to seed store. If refreshable is enabled, seed will be refreshed periodically
*
* @param refreshable
* @return a collection of seeds in the seed store
* @throws IOException
*/
public Collection<Seed> addSeed(SeedStoreSubType subType, String seedLocation, boolean refreshable) throws IOException {
Collection<Seed> seeds = new HashSet<>();
SeedStore seedStore = getSeedStore(subType);
if (seedStore == null) {
throw new PrestoException(SEED_STORE_FAILURE, "Seed store is null");
}
Seed seed = seedStore.create(ImmutableMap.of(Seed.LOCATION_PROPERTY_NAME, seedLocation, Seed.TIMESTAMP_PROPERTY_NAME, String.valueOf(System.currentTimeMillis())));
seeds = addSeed(subType, seed);
if (refreshable) {
refreshableSeedsMap.put(seedLocation, seed);
}
LOG.debug("Seed=%s added to seed store", seedLocation);
return seeds;
}
use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.
the class SeedStoreManager method updateSeed.
/**
* Update the existing seed at seedLocation with new properties
* @param subType
* @param seedLocation
* @param updatedProperties
*/
public void updateSeed(SeedStoreSubType subType, String seedLocation, Map<String, String> updatedProperties) {
SeedStore seedStore = getSeedStore(subType);
if (seedStore == null) {
throw new PrestoException(SEED_STORE_FAILURE, "Seed store is null");
}
try {
Collection<Seed> existingSeeds = seedStore.get();
List<Seed> toUpdate = existingSeeds.stream().filter(s -> {
return s.getLocation().equals(seedLocation);
}).collect(Collectors.toList());
LOG.debug("SeedStoreManager::updateSeed toUpdate.size() is %s", Integer.toString(toUpdate.size()));
for (Seed s : toUpdate) {
seedStore.remove(ImmutableList.of(s));
Seed newSeed = seedStore.create(updatedProperties);
addSeed(subType, newSeed);
}
} catch (IOException e) {
LOG.warn("Update seed %s failed with error: %s", seedLocation, e.getMessage());
}
}
use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.
the class SeedStoreManager method getAllSeeds.
/**
* Get all seeds from seed store
*
* @return a collection of seeds in the seed store
* @throws IOException
*/
public Collection<Seed> getAllSeeds(SeedStoreSubType subType) throws IOException {
SeedStore seedStore = getSeedStore(subType);
if (seedStore == null) {
throw new PrestoException(SEED_STORE_FAILURE, "Seed store is null");
}
Collection<Seed> seeds = seedStore.get();
return seeds;
}
Aggregations