Search in sources :

Example 1 with InitializationStatus

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 --");
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) Duration(io.airlift.units.Duration) BlockEncodingSerde(io.prestosql.spi.block.BlockEncodingSerde) InitializationStatus(io.prestosql.execution.SplitCacheStateInitializer.InitializationStatus) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) BlockJsonSerde(io.prestosql.block.BlockJsonSerde) Block(io.prestosql.spi.block.Block) TypeDeserializer(io.prestosql.type.TypeDeserializer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) PostConstruct(javax.annotation.PostConstruct)

Example 2 with InitializationStatus

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();
    }
}
Also used : HashMap(java.util.HashMap) StateStore(io.prestosql.spi.statestore.StateStore) AtomicReference(java.util.concurrent.atomic.AtomicReference) Duration(io.airlift.units.Duration) StateStoreProvider(io.prestosql.statestore.StateStoreProvider) InitializationStatus(io.prestosql.execution.SplitCacheStateInitializer.InitializationStatus) Test(org.testng.annotations.Test)

Example 3 with InitializationStatus

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);
}
Also used : StateStore(io.prestosql.spi.statestore.StateStore) AtomicReference(java.util.concurrent.atomic.AtomicReference) Duration(io.airlift.units.Duration) StateStoreProvider(io.prestosql.statestore.StateStoreProvider) InitializationStatus(io.prestosql.execution.SplitCacheStateInitializer.InitializationStatus) Test(org.testng.annotations.Test)

Aggregations

Duration (io.airlift.units.Duration)3 InitializationStatus (io.prestosql.execution.SplitCacheStateInitializer.InitializationStatus)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 StateStore (io.prestosql.spi.statestore.StateStore)2 StateStoreProvider (io.prestosql.statestore.StateStoreProvider)2 Test (org.testng.annotations.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)1 BlockJsonSerde (io.prestosql.block.BlockJsonSerde)1 Block (io.prestosql.spi.block.Block)1 BlockEncodingSerde (io.prestosql.spi.block.BlockEncodingSerde)1 TypeDeserializer (io.prestosql.type.TypeDeserializer)1 HashMap (java.util.HashMap)1 PostConstruct (javax.annotation.PostConstruct)1