Search in sources :

Example 11 with StateMap

use of io.prestosql.spi.statestore.StateMap in project hetu-core by openlookeng.

the class InMemoryTransactionManager method removeStateStoreTransaction.

private void removeStateStoreTransaction(TransactionId transactionId) {
    boolean removed = false;
    int attempts = 1;
    final int maxAttempts = 3;
    if (stateStoreProvider != null && stateStoreProvider.getStateStore() != null) {
        while (!removed && attempts <= maxAttempts) {
            try {
                StateMap stateMap = (StateMap<String, String>) stateStoreProvider.getStateStore().getStateCollection(StateStoreConstants.TRANSACTION_STATE_COLLECTION_NAME);
                if (stateMap != null) {
                    stateMap.remove(transactionId.toString());
                    removed = true;
                }
            } catch (RuntimeException e) {
                // Catch the exception so the caller future won't get interrupted
                log.warn(attempts + "attempt failed to remove transaction " + transactionId + " from state store due to: " + e.getMessage());
            } finally {
                attempts++;
            }
        }
    }
}
Also used : StateMap(io.prestosql.spi.statestore.StateMap)

Example 12 with StateMap

use of io.prestosql.spi.statestore.StateMap in project hetu-core by openlookeng.

the class InMemoryTransactionManager method beginTransaction.

@Override
public TransactionId beginTransaction(IsolationLevel isolationLevel, boolean readOnly, boolean autoCommitContext) {
    TransactionId transactionId = TransactionId.create();
    BoundedExecutor executor = new BoundedExecutor(finishingExecutor, maxFinishingConcurrency);
    TransactionMetadata transactionMetadata = new TransactionMetadata(transactionId, isolationLevel, readOnly, autoCommitContext, catalogManager, executor, functionNamespaceManagers);
    synchronized (this) {
        checkState(transactions.put(transactionId, transactionMetadata) == null, "Duplicate transaction ID: %s", transactionId);
        // add transactionId to state store
        if (stateStoreProvider != null && stateStoreProvider.getStateStore() != null) {
            StateMap stateMap = (StateMap<String, String>) stateStoreProvider.getStateStore().getStateCollection(StateStoreConstants.TRANSACTION_STATE_COLLECTION_NAME);
            if (stateMap != null) {
                stateMap.put(transactionId.toString(), transactionId.toString());
            }
        }
    }
    return transactionId;
}
Also used : StateMap(io.prestosql.spi.statestore.StateMap) BoundedExecutor(io.airlift.concurrent.BoundedExecutor)

Example 13 with StateMap

use of io.prestosql.spi.statestore.StateMap in project hetu-core by openlookeng.

the class HazelcastStateStore method createStateMap.

@Override
public <K, V> StateMap<K, V> createStateMap(String name, MapListener... listeners) {
    StateMap<K, V> collection = new HazelcastStateMap<K, V>(hzInstance, name, listeners);
    if (encryptionType != CipherService.Type.NONE) {
        collection = new EncryptedStateMap(collection, createCipherService(encryptionType));
    }
    collections.putIfAbsent(name, collection);
    return (StateMap<K, V>) collections.get(name);
}
Also used : EncryptedStateMap(io.hetu.core.statestore.EncryptedStateMap) StateMap(io.prestosql.spi.statestore.StateMap) EncryptedStateMap(io.hetu.core.statestore.EncryptedStateMap)

Example 14 with StateMap

use of io.prestosql.spi.statestore.StateMap in project hetu-core by openlookeng.

the class TestHazelcastStateMap method testListeners.

@Test
public void testListeners() throws InterruptedException {
    final CountDownLatch listenersCount = new CountDownLatch(3);
    EntryAddedListener<String, String> addedListener = event -> {
        if (event.getKey().equals("Key") && event.getValue().equals("Created")) {
            listenersCount.countDown();
        }
    };
    EntryUpdatedListener<String, String> updated = event -> {
        if (event.getKey().equals("Key") && event.getOldValue().equals("Created") && event.getValue().equals("Updated")) {
            listenersCount.countDown();
        }
    };
    EntryRemovedListener<String, String> removedListener = event -> {
        if (event.getKey().equals("Key") && event.getOldValue().equals("Updated")) {
            listenersCount.countDown();
        }
    };
    StateMap<String, String> testMap = stateStore.createStateMap("Test_Listeners_Map", addedListener, removedListener, updated);
    testMap.put("Key", "Created");
    testMap.put("Key", "Updated");
    testMap.remove("Key");
    assertTrue(listenersCount.await(500, TimeUnit.MILLISECONDS), "Events were not triggered or values did not match");
}
Also used : BeforeSuite(org.testng.annotations.BeforeSuite) Slice(io.airlift.slice.Slice) Assert.assertNull(org.testng.Assert.assertNull) StateStore(io.prestosql.spi.statestore.StateStore) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) Type(io.prestosql.spi.statestore.StateCollection.Type) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) EntryRemovedListener(io.prestosql.spi.statestore.listener.EntryRemovedListener) SerializerConfig(com.hazelcast.config.SerializerConfig) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ImmutableSet(com.google.common.collect.ImmutableSet) StateMap(io.prestosql.spi.statestore.StateMap) EntryUpdatedListener(io.prestosql.spi.statestore.listener.EntryUpdatedListener) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) NetworkConfig(com.hazelcast.config.NetworkConfig) CountDownLatch(java.util.concurrent.CountDownLatch) Hazelcast(com.hazelcast.core.Hazelcast) EntryAddedListener(io.prestosql.spi.statestore.listener.EntryAddedListener) Assert.assertTrue(org.testng.Assert.assertTrue) AfterSuite(org.testng.annotations.AfterSuite) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Example 15 with StateMap

use of io.prestosql.spi.statestore.StateMap in project hetu-core by openlookeng.

the class TestHazelcastStateStoreFactory method testTcpipCreate.

/**
 * Test state store creation with tcp-ip mode
 *
 * @throws IOException IOException thrown if seedStore read write errors happen
 */
@Test
public void testTcpipCreate() throws IOException {
    HazelcastStateStoreFactory factory = new HazelcastStateStoreFactory();
    assertEquals(factory.getName(), HAZELCAST);
    SeedStoreFactory seedStoreFactory = new FileBasedSeedStoreFactory();
    assertEquals(seedStoreFactory.getName(), "filebased");
    Map<String, String> properties = new HashMap<>(0);
    properties.put(STATE_STORE_CLUSTER_CONFIG_NAME, TEST_CLUSTER_NAME);
    properties.put(DISCOVERY_MODE_CONFIG_NAME, DISCOVERY_MODE_TCPIP);
    SeedStore seedStore = mock(SeedStore.class);
    Seed seed = new FileBasedSeed(MEMBER_ADDRESS, 0);
    when(seedStore.get()).thenReturn(ImmutableList.of(seed));
    setupHazelcastInstance();
    StateStore stateStore = factory.create(TEST_STATE_STORE_NAME, seedStore, properties);
    assertEquals(stateStore.getName(), TEST_STATE_STORE_NAME);
    StateCollection collection = stateStore.createStateCollection("test", StateCollection.Type.MAP);
    ((StateMap<String, String>) collection).put(TEST_KEY, TEST_VALUE);
    assertEquals(collection.size(), 1);
    assertEquals(((StateMap<String, String>) collection).get(TEST_KEY), TEST_VALUE);
    ((HazelcastStateStore) stateStore).shutdown();
}
Also used : FileBasedSeed(io.hetu.core.seedstore.filebased.FileBasedSeed) HashMap(java.util.HashMap) StateCollection(io.prestosql.spi.statestore.StateCollection) StateMap(io.prestosql.spi.statestore.StateMap) StateStore(io.prestosql.spi.statestore.StateStore) SeedStoreFactory(io.prestosql.spi.seedstore.SeedStoreFactory) FileBasedSeedStoreFactory(io.hetu.core.seedstore.filebased.FileBasedSeedStoreFactory) Seed(io.prestosql.spi.seedstore.Seed) FileBasedSeed(io.hetu.core.seedstore.filebased.FileBasedSeed) SeedStore(io.prestosql.spi.seedstore.SeedStore) FileBasedSeedStoreFactory(io.hetu.core.seedstore.filebased.FileBasedSeedStoreFactory) Test(org.testng.annotations.Test)

Aggregations

StateMap (io.prestosql.spi.statestore.StateMap)27 StateStore (io.prestosql.spi.statestore.StateStore)16 HashMap (java.util.HashMap)11 Map (java.util.Map)10 StateCollection (io.prestosql.spi.statestore.StateCollection)8 Test (org.testng.annotations.Test)8 ImmutableSet (com.google.common.collect.ImmutableSet)5 Symbol (io.prestosql.spi.plan.Symbol)5 IOException (java.io.IOException)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 PrestoException (io.prestosql.spi.PrestoException)3 DynamicFilter (io.prestosql.spi.dynamicfilter.DynamicFilter)3 StateSet (io.prestosql.spi.statestore.StateSet)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 TimeUnit (java.util.concurrent.TimeUnit)3 Collectors (java.util.stream.Collectors)3