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