private <K, V> OffHeapStore<K, V> createStoreInternal(Configuration<K, V> storeConfig, StoreEventDispatcher<K, V> eventDispatcher, ServiceConfiguration<?>... serviceConfigs) { if (serviceProvider == null) { throw new NullPointerException("ServiceProvider is null in OffHeapStore.Provider."); } TimeSource timeSource = serviceProvider.getService(TimeSourceService.class).getTimeSource(); SizedResourcePool offHeapPool = storeConfig.getResourcePools().getPoolForResource(getResourceType()); if (!(offHeapPool.getUnit() instanceof MemoryUnit)) { throw new IllegalArgumentException("OffHeapStore only supports resources with memory unit"); } MemoryUnit unit = (MemoryUnit)offHeapPool.getUnit(); OffHeapStore<K, V> offHeapStore = new OffHeapStore<>(storeConfig, timeSource, eventDispatcher, unit.toBytes(offHeapPool .getSize())); createdStores.add(offHeapStore); return offHeapStore; }
private void flushToLowerTier(OffHeapStore<Object, ?> offheapStore) { StoreAccessException lastFailure = null; int failureCount = 0; for (Object key : offheapStore.backingMap().keySet()) { try { offheapStore.invalidate(key); } catch (StoreAccessException cae) { lastFailure = cae; failureCount++; LOGGER.warn("Error flushing '{}' to lower tier", key, cae); } } if (lastFailure != null) { throw new RuntimeException("Failed to flush some mappings to lower tier, " + failureCount + " could not be flushed. This error represents the last failure.", lastFailure); } }
public OffHeapStore(final Configuration<K, V> config, TimeSource timeSource, StoreEventDispatcher<K, V> eventDispatcher, long sizeInBytes) { super(config, timeSource, eventDispatcher); EvictionAdvisor<? super K, ? super V> evictionAdvisor = config.getEvictionAdvisor(); if (evictionAdvisor != null) { this.evictionAdvisor = wrap(evictionAdvisor); } else { this.evictionAdvisor = wrap(noAdvice()); } this.keySerializer = config.getKeySerializer(); this.valueSerializer = config.getValueSerializer(); this.sizeInBytes = sizeInBytes; }
@Override protected OffHeapStore<String, byte[]> createAndInitStore(TimeSource timeSource, ExpiryPolicy<? super String, ? super byte[]> expiry, EvictionAdvisor<? super String, ? super byte[]> evictionAdvisor) { try { SerializationProvider serializationProvider = new DefaultSerializationProvider(null); serializationProvider.start(providerContaining()); ClassLoader classLoader = getClass().getClassLoader(); Serializer<String> keySerializer = serializationProvider.createValueSerializer(String.class, classLoader); Serializer<byte[]> valueSerializer = serializationProvider.createValueSerializer(byte[].class, classLoader); StoreConfigurationImpl<String, byte[]> storeConfiguration = new StoreConfigurationImpl<>(String.class, byte[].class, evictionAdvisor, getClass().getClassLoader(), expiry, null, 0, keySerializer, valueSerializer); OffHeapStore<String, byte[]> offHeapStore = new OffHeapStore<>(storeConfiguration, timeSource, new TestStoreEventDispatcher<>(), MemoryUnit.MB .toBytes(1)); OffHeapStore.Provider.init(offHeapStore); return offHeapStore; } catch (UnsupportedTypeException e) { throw new AssertionError(e); } }
private void flushToLowerTier(OffHeapStore<Object, ?> offheapStore) { StoreAccessException lastFailure = null; int failureCount = 0; for (Object key : offheapStore.backingMap().keySet()) { try { offheapStore.invalidate(key); } catch (StoreAccessException cae) { lastFailure = cae; failureCount++; LOGGER.warn("Error flushing '{}' to lower tier", key, cae); } } if (lastFailure != null) { throw new RuntimeException("Failed to flush some mappings to lower tier, " + failureCount + " could not be flushed. This error represents the last failure.", lastFailure); } }
public OffHeapStore(final Configuration<K, V> config, TimeSource timeSource, StoreEventDispatcher<K, V> eventDispatcher, long sizeInBytes) { super(config, timeSource, eventDispatcher); EvictionAdvisor<? super K, ? super V> evictionAdvisor = config.getEvictionAdvisor(); if (evictionAdvisor != null) { this.evictionAdvisor = wrap(evictionAdvisor); } else { this.evictionAdvisor = wrap(noAdvice()); } this.keySerializer = config.getKeySerializer(); this.valueSerializer = config.getValueSerializer(); this.sizeInBytes = sizeInBytes; }
private AuthoritativeTier<String, String> newStore(Long capacity, EvictionAdvisor<String, String> evictionAdvisor, ExpiryPolicy<? super String, ? super String> expiry, TimeSource timeSource) { Serializer<String> keySerializer = new JavaSerializer<>(getClass().getClassLoader()); Serializer<String> valueSerializer = new JavaSerializer<>(getClass().getClassLoader()); ResourcePools resourcePools = getOffHeapResourcePool(capacity); SizedResourcePool offheapPool = resourcePools.getPoolForResource(OFFHEAP); MemoryUnit unit = (MemoryUnit)offheapPool.getUnit(); Store.Configuration<String, String> config = new StoreConfigurationImpl<>(getKeyType(), getValueType(), evictionAdvisor, getClass().getClassLoader(), expiry, resourcePools, 0, keySerializer, valueSerializer); OffHeapStore<String, String> store = new OffHeapStore<>(config, timeSource, new TestStoreEventDispatcher<>(), unit .toBytes(offheapPool.getSize())); OffHeapStore.Provider.init(store); return store; }
@Override protected OffHeapStore<String, String> createAndInitStore(TimeSource timeSource, ExpiryPolicy<? super String, ? super String> expiry) { try { SerializationProvider serializationProvider = new DefaultSerializationProvider(null); serializationProvider.start(providerContaining()); ClassLoader classLoader = getClass().getClassLoader(); Serializer<String> keySerializer = serializationProvider.createKeySerializer(String.class, classLoader); Serializer<String> valueSerializer = serializationProvider.createValueSerializer(String.class, classLoader); StoreConfigurationImpl<String, String> storeConfiguration = new StoreConfigurationImpl<>(String.class, String.class, null, classLoader, expiry, null, 0, keySerializer, valueSerializer); OffHeapStore<String, String> offHeapStore = new OffHeapStore<>(storeConfiguration, timeSource, new TestStoreEventDispatcher<>(), MemoryUnit.MB .toBytes(1)); OffHeapStore.Provider.init(offHeapStore); return offHeapStore; } catch (UnsupportedTypeException e) { throw new AssertionError(e); } }
private CachingTier<String, String> newCachingTier(Long capacity) { Store.Configuration<String, String> config = new StoreConfigurationImpl<>(getKeyType(), getValueType(), null, ClassLoader.getSystemClassLoader(), ExpiryPolicyBuilder.noExpiration(), buildResourcePools(capacity), 0, new JavaSerializer<>(getSystemClassLoader()), new JavaSerializer<>(getSystemClassLoader())); StoreEventDispatcher<String, String> eventDispatcher = NullStoreEventDispatcher.nullStoreEventDispatcher(); OffHeapStore<String, String> offHeapStore = new OffHeapStore<>(config, SystemTimeSource.INSTANCE, eventDispatcher, 10 * 1024 * 1024); OffHeapStoreLifecycleHelper.init(offHeapStore); IdentityCopier<String> copier = new IdentityCopier<>(); OnHeapStore<String, String> onHeapStore = new OnHeapStore<>(config, SystemTimeSource.INSTANCE, copier, copier, new NoopSizeOfEngine(), eventDispatcher); CompoundCachingTier<String, String> compoundCachingTier = new CompoundCachingTier<>(onHeapStore, offHeapStore); map.put(compoundCachingTier, offHeapStore); return compoundCachingTier; }
classLoader, expiry, ResourcePoolsBuilder.newResourcePoolsBuilder().offheap(10, MemoryUnit.MB).build(), 0, keySerializer, valueSerializer); OffHeapStore<Long, SoftLock<String>> offHeapStore = new OffHeapStore<>(offHeapConfig, testTimeSource, eventDispatcher, MemorySizeParser .parse("10M")); OffHeapStoreLifecycleHelper.init(offHeapStore);
classLoader, expiry, ResourcePoolsBuilder.newResourcePoolsBuilder().offheap(10, MemoryUnit.MB).build(), 0, keySerializer, valueSerializer); OffHeapStore<Long, SoftLock<String>> offHeapStore = new OffHeapStore<>(offHeapConfig, testTimeSource, eventDispatcher, MemorySizeParser .parse("10M")); OffHeapStoreLifecycleHelper.init(offHeapStore);
.build(), 0, keySerializer, valueSerializer); OffHeapStore<Long, SoftLock<String>> offHeapStore = new OffHeapStore<>(offHeapConfig, testTimeSource, eventDispatcher, MemorySizeParser .parse("10M")); OffHeapStoreLifecycleHelper.init(offHeapStore);
.build(), 0, keySerializer, valueSerializer); OffHeapStore<Long, SoftLock<String>> offHeapStore = new OffHeapStore<>(offHeapConfig, testTimeSource, eventDispatcher, MemorySizeParser .parse("10M")); OffHeapStoreLifecycleHelper.init(offHeapStore);
.build(), 0, keySerializer, valueSerializer); OffHeapStore<Long, SoftLock<String>> offHeapStore = new OffHeapStore<>(offHeapConfig, testTimeSource, eventDispatcher, MemorySizeParser .parse("10M")); OffHeapStoreLifecycleHelper.init(offHeapStore);
long offheapSize = ((MemoryUnit) offheapPool.getUnit()).toBytes(offheapPool.getSize()); final OffHeapStore<String, String> offHeapStore = new OffHeapStore<>(config, timeSource, noOpEventDispatcher, offheapSize);
classLoader, expiry, ResourcePoolsBuilder.newResourcePoolsBuilder().offheap(10, MemoryUnit.MB).build(), 0, keySerializer, valueSerializer); OffHeapStore<Long, SoftLock<String>> offHeapStore = new OffHeapStore<>(offHeapConfig, testTimeSource, eventDispatcher, MemorySizeParser .parse("10M")); OffHeapStoreLifecycleHelper.init(offHeapStore);
classLoader, expiry, ResourcePoolsBuilder.newResourcePoolsBuilder().offheap(10, MemoryUnit.MB).build(), 0, keySerializer, valueSerializer); OffHeapStore<Long, SoftLock<String>> offHeapStore = new OffHeapStore<>(offHeapConfig, testTimeSource, eventDispatcher, MemorySizeParser .parse("10M")); OffHeapStoreLifecycleHelper.init(offHeapStore);
@Test public void testExpiry() throws Exception { Store.Configuration<Long, SoftLock<String>> onHeapConfig = new StoreConfigurationImpl<>(Long.class, valueClass, null, classLoader, expiry, ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES).build(), 0, keySerializer, valueSerializer); onHeapStore = new OnHeapStore<>(onHeapConfig, testTimeSource, keyCopier, valueCopier, new NoopSizeOfEngine(), eventDispatcher); Store.Configuration<Long, SoftLock<String>> offHeapConfig = new StoreConfigurationImpl<>(Long.class, valueClass, null, classLoader, expiry, ResourcePoolsBuilder.newResourcePoolsBuilder().offheap(10, MemoryUnit.MB).build(), 0, keySerializer, valueSerializer); OffHeapStore<Long, SoftLock<String>> offHeapStore = new OffHeapStore<>(offHeapConfig, testTimeSource, eventDispatcher, MemorySizeParser .parse("10M")); OffHeapStoreLifecycleHelper.init(offHeapStore); TieredStore<Long, SoftLock<String>> tieredStore = new TieredStore<>(onHeapStore, offHeapStore); XAStore<Long, String> xaStore = getXAStore(tieredStore); testTransactionManager.begin(); { xaStore.put(1L, "one"); } testTransactionManager.commit(); assertMapping(xaStore, 1L, "one"); testTimeSource.advanceTime(2000); assertMapping(xaStore, 1L, null); OffHeapStoreLifecycleHelper.close(offHeapStore); }
classLoader, expiry, ResourcePoolsBuilder.newResourcePoolsBuilder().offheap(10, MemoryUnit.MB).build(), 0, keySerializer, valueSerializer); OffHeapStore<Long, SoftLock<String>> offHeapStore = new OffHeapStore<>(offHeapConfig, testTimeSource, eventDispatcher, MemorySizeParser .parse("10M")); OffHeapStoreLifecycleHelper.init(offHeapStore);
private <K, V> OffHeapStore<K, V> createStoreInternal(Configuration<K, V> storeConfig, StoreEventDispatcher<K, V> eventDispatcher, ServiceConfiguration<?>... serviceConfigs) { if (serviceProvider == null) { throw new NullPointerException("ServiceProvider is null in OffHeapStore.Provider."); } TimeSource timeSource = serviceProvider.getService(TimeSourceService.class).getTimeSource(); SizedResourcePool offHeapPool = storeConfig.getResourcePools().getPoolForResource(getResourceType()); if (!(offHeapPool.getUnit() instanceof MemoryUnit)) { throw new IllegalArgumentException("OffHeapStore only supports resources with memory unit"); } MemoryUnit unit = (MemoryUnit)offHeapPool.getUnit(); OffHeapStore<K, V> offHeapStore = new OffHeapStore<>(storeConfig, timeSource, eventDispatcher, unit.toBytes(offHeapPool .getSize())); createdStores.add(offHeapStore); return offHeapStore; }