use of io.prestosql.execution.SplitCacheStateInitializer.InitializationStatus in project hetu-core by openlookeng.
the class SplitCacheStateManager method startStateServices.
@PostConstruct
public void startStateServices() {
if (!PropertyService.getBooleanProperty(HetuConstant.SPLIT_CACHE_MAP_ENABLED)) {
log.info("Split cache map feature is disabled.");
return;
}
if (!PropertyService.getBooleanProperty(HetuConstant.MULTI_COORDINATOR_ENABLED)) {
return;
}
BlockEncodingSerde blockEncodingSerde = metadata.getFunctionAndTypeManager().getBlockEncodingSerde();
ObjectMapper mapper = new ObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TypeDeserializer(metadata)).addSerializer(Block.class, new BlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new BlockJsonSerde.Deserializer(blockEncodingSerde)).addKeyDeserializer(SplitKey.class, new SplitKey.KeyDeserializer()));
AtomicReference<InitializationStatus> status = new AtomicReference<>(InitializationStatus.INITIALIZING);
// Async: One-shot action. Fetch split cache map info from state store if available
if (initializer == null) {
final Duration delay = new Duration(2, TimeUnit.SECONDS);
final Duration timeout = new Duration(60, TimeUnit.SECONDS);
initializer = new SplitCacheStateInitializer(provider, splitCacheMap, delay, timeout, mapper, status);
initializer.start();
}
if (updater == null) {
Duration updateInterval = PropertyService.getDurationProperty(HetuConstant.SPLIT_CACHE_STATE_UPDATE_INTERVAL);
// Async Task - Periodically update state store with local split cache map changes
updater = new SplitCacheStateUpdater(provider, splitCacheMap, updateInterval, mapper, status);
updater.start();
}
log.info("-- Initialized split cache map state store and started state services --");
}
use of io.prestosql.execution.SplitCacheStateInitializer.InitializationStatus in project hetu-core by openlookeng.
the class TestSplitCacheStateUpdater method testStateUpdates.
@Test
public void testStateUpdates() throws InterruptedException, IOException {
StateStoreProvider provider = mock(StateStoreProvider.class);
StateStore stateStore = mock(StateStore.class);
when(stateStore.getName()).thenReturn("mock");
Map<String, String> testStateMap = new HashMap<>();
when(stateStore.getStateCollection(StateStoreConstants.SPLIT_CACHE_METADATA_NAME)).thenReturn(new MockStateMap<>(StateStoreConstants.SPLIT_CACHE_METADATA_NAME, testStateMap));
// simulate behaviour wait until state store is ready
when(provider.getStateStore()).thenReturn(null).thenReturn(stateStore);
SplitCacheMap splitCacheMap = createNew();
assertTrue(testStateMap.isEmpty());
AtomicReference<InitializationStatus> status = new AtomicReference<>(InitializationStatus.COMPLETED);
SplitCacheStateUpdater updater = new SplitCacheStateUpdater(provider, splitCacheMap, new Duration(500, TimeUnit.MILLISECONDS), objectMapper, status);
try {
updater.start();
splitCacheMap.addCache(table1QN, tupleDomainA, tupleDomainAPredicateString);
splitCacheMap.addCachedNode(table1SplitKey1, workerNode.getNodeIdentifier());
Thread.sleep(2000);
assertTrue(testStateMap.containsKey(table1QN.toString()));
assertEquals(testStateMap.size(), 1);
TableCacheInfo deserTable1Cache = objectMapper.readerFor(TableCacheInfo.class).readValue(testStateMap.get(table1QN.toString()));
assertEquals(deserTable1Cache, splitCacheMap.tableCacheInfoMap().get(table1QN.toString()));
splitCacheMap.addCache(table1QN, tupleDomainB, tupleDomainBPredicateString);
splitCacheMap.addCachedNode(table1SplitKey2, workerNode2.getNodeIdentifier());
splitCacheMap.addCache(table2QN, tupleDomainA, tupleDomainAPredicateString);
splitCacheMap.addCachedNode(table2SplitKey1, workerNode2.getNodeIdentifier());
Thread.sleep(2000);
assertEquals(testStateMap.size(), 2);
deserTable1Cache = objectMapper.readerFor(TableCacheInfo.class).readValue(testStateMap.get(table1QN.toString()));
assertEquals(deserTable1Cache, splitCacheMap.tableCacheInfoMap().get(table1QN.toString()));
TableCacheInfo deserTable2Cache = objectMapper.readerFor(TableCacheInfo.class).readValue(testStateMap.get(table2QN.toString()));
assertEquals(deserTable2Cache, splitCacheMap.tableCacheInfoMap().get(table2QN.toString()));
splitCacheMap.dropCache(table1QN, Optional.empty());
assertFalse(splitCacheMap.cacheExists(table1QN));
Thread.sleep(2000);
assertEquals(testStateMap.size(), 1);
assertTrue(testStateMap.containsKey(table2QN.toString()));
} finally {
updater.stop();
}
}
use of io.prestosql.execution.SplitCacheStateInitializer.InitializationStatus in project hetu-core by openlookeng.
the class TestSplitCacheStateUpdater method testUpdateWhenStateStillInitializing.
@Test
public void testUpdateWhenStateStillInitializing() throws InterruptedException {
StateStoreProvider provider = mock(StateStoreProvider.class);
StateStore stateStore = mock(StateStore.class);
when(stateStore.getName()).thenReturn("mock");
when(provider.getStateStore()).thenReturn(stateStore);
AtomicReference<InitializationStatus> status = new AtomicReference<>(InitializationStatus.INITIALIZING);
SplitCacheMap splitCacheMap = createNew();
SplitCacheStateUpdater updater = new SplitCacheStateUpdater(provider, splitCacheMap, new Duration(300, TimeUnit.MILLISECONDS), objectMapper, status);
try {
updater.start();
Thread.sleep(1000);
} finally {
updater.stop();
}
verify(provider, atLeast(1)).getStateStore();
verify(stateStore, never()).getStateCollection(StateStoreConstants.SPLIT_CACHE_METADATA_NAME);
}
Aggregations