use of org.apache.ignite.cache.eviction.lru.LruEvictionPolicy in project ignite by apache.
the class PlatformConfigurationUtils method writeEvictionPolicy.
/**
* Writes the eviction policy.
* @param out Stream.
* @param p Policy.
*/
@SuppressWarnings("TypeMayBeWeakened")
private static void writeEvictionPolicy(BinaryRawWriter out, EvictionPolicy p) {
if (p instanceof FifoEvictionPolicy) {
out.writeByte((byte) 1);
FifoEvictionPolicy p0 = (FifoEvictionPolicy) p;
out.writeInt(p0.getBatchSize());
out.writeInt(p0.getMaxSize());
out.writeLong(p0.getMaxMemorySize());
} else if (p instanceof LruEvictionPolicy) {
out.writeByte((byte) 2);
LruEvictionPolicy p0 = (LruEvictionPolicy) p;
out.writeInt(p0.getBatchSize());
out.writeInt(p0.getMaxSize());
out.writeLong(p0.getMaxMemorySize());
} else {
out.writeByte((byte) 0);
}
}
use of org.apache.ignite.cache.eviction.lru.LruEvictionPolicy in project ignite by apache.
the class GridCacheReloadSelfTest method getConfiguration.
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setLocalHost("127.0.0.1");
TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
ipFinder.setAddresses(Collections.singleton("127.0.0.1:47500"));
discoSpi.setIpFinder(ipFinder);
cfg.setDiscoverySpi(discoSpi);
CacheConfiguration cacheCfg = defaultCacheConfiguration();
cacheCfg.setName(CACHE_NAME);
cacheCfg.setCacheMode(cacheMode);
LruEvictionPolicy plc = new LruEvictionPolicy();
plc.setMaxSize(MAX_CACHE_ENTRIES);
cacheCfg.setEvictionPolicy(plc);
cacheCfg.setOnheapCacheEnabled(true);
cacheCfg.setNearConfiguration(nearEnabled ? new NearCacheConfiguration() : null);
final CacheStore store = new CacheStoreAdapter<Integer, Integer>() {
@Override
public Integer load(Integer key) {
return key;
}
@Override
public void write(javax.cache.Cache.Entry<? extends Integer, ? extends Integer> e) {
//No-op.
}
@Override
public void delete(Object key) {
//No-op.
}
};
cacheCfg.setCacheStoreFactory(singletonFactory(store));
cacheCfg.setReadThrough(true);
cacheCfg.setWriteThrough(true);
cacheCfg.setLoadPreviousValue(true);
if (cacheMode == PARTITIONED)
cacheCfg.setBackups(1);
cfg.setCacheConfiguration(cacheCfg);
return cfg;
}
use of org.apache.ignite.cache.eviction.lru.LruEvictionPolicy in project ignite by apache.
the class IgniteCacheMultiTxLockSelfTest method getConfiguration.
/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
TcpDiscoverySpi disco = new TcpDiscoverySpi();
disco.setIpFinder(ipFinder);
c.setDiscoverySpi(disco);
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setName(CACHE_NAME);
ccfg.setAtomicityMode(TRANSACTIONAL);
ccfg.setWriteSynchronizationMode(PRIMARY_SYNC);
ccfg.setBackups(2);
ccfg.setCacheMode(PARTITIONED);
LruEvictionPolicy plc = new LruEvictionPolicy();
plc.setMaxSize(100000);
ccfg.setEvictionPolicy(plc);
ccfg.setOnheapCacheEnabled(true);
c.setCacheConfiguration(ccfg);
c.setClientMode(client);
return c;
}
use of org.apache.ignite.cache.eviction.lru.LruEvictionPolicy in project ignite by apache.
the class IgniteCacheQueryMultiThreadedSelfTest method cacheConfiguration.
/**
* @return Cache configuration.
*/
protected CacheConfiguration cacheConfiguration() {
CacheConfiguration<?, ?> cacheCfg = defaultCacheConfiguration();
cacheCfg.setCacheMode(PARTITIONED);
cacheCfg.setAtomicityMode(TRANSACTIONAL);
cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
cacheCfg.setBackups(1);
LruEvictionPolicy plc = null;
if (evictsEnabled()) {
plc = new LruEvictionPolicy();
plc.setMaxSize(100);
}
cacheCfg.setEvictionPolicy(plc);
cacheCfg.setOnheapCacheEnabled(plc != null);
return cacheCfg;
}
use of org.apache.ignite.cache.eviction.lru.LruEvictionPolicy in project ignite by apache.
the class CacheSerializableTransactionsTest method testNoOptimisticExceptionOnChangingTopology.
/**
* @throws Exception If failed.
*/
public void testNoOptimisticExceptionOnChangingTopology() throws Exception {
if (FAST)
return;
final AtomicBoolean finished = new AtomicBoolean();
final List<String> cacheNames = new ArrayList<>();
Ignite srv = ignite(1);
try {
{
CacheConfiguration<Integer, Integer> ccfg = cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false);
ccfg.setName("cache1");
ccfg.setRebalanceMode(SYNC);
srv.createCache(ccfg);
cacheNames.add(ccfg.getName());
}
{
// Store enabled.
CacheConfiguration<Integer, Integer> ccfg = cacheConfiguration(PARTITIONED, FULL_SYNC, 1, true, false);
ccfg.setName("cache2");
ccfg.setRebalanceMode(SYNC);
srv.createCache(ccfg);
cacheNames.add(ccfg.getName());
}
{
// Eviction.
CacheConfiguration<Integer, Integer> ccfg = cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false);
ccfg.setName("cache3");
ccfg.setRebalanceMode(SYNC);
LruEvictionPolicy plc = new LruEvictionPolicy();
plc.setMaxSize(100);
ccfg.setEvictionPolicy(plc);
ccfg.setOnheapCacheEnabled(true);
srv.createCache(ccfg);
cacheNames.add(ccfg.getName());
}
IgniteInternalFuture<?> restartFut = restartFuture(finished, null);
List<IgniteInternalFuture<?>> futs = new ArrayList<>();
final int KEYS_PER_THREAD = 100;
for (int i = 1; i < SRVS + CLIENTS; i++) {
final Ignite node = ignite(i);
final int minKey = i * KEYS_PER_THREAD;
final int maxKey = minKey + KEYS_PER_THREAD;
// Threads update non-intersecting keys, optimistic exception should not be thrown.
futs.add(GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
log.info("Started update thread [node=" + node.name() + ", minKey=" + minKey + ", maxKey=" + maxKey + ']');
final ThreadLocalRandom rnd = ThreadLocalRandom.current();
List<IgniteCache<Integer, Integer>> caches = new ArrayList<>();
for (String cacheName : cacheNames) caches.add(node.<Integer, Integer>cache(cacheName));
assertEquals(3, caches.size());
int iter = 0;
while (!finished.get()) {
int keyCnt = rnd.nextInt(1, 10);
final Set<Integer> keys = new LinkedHashSet<>();
while (keys.size() < keyCnt) keys.add(rnd.nextInt(minKey, maxKey));
for (final IgniteCache<Integer, Integer> cache : caches) {
doInTransaction(node, OPTIMISTIC, SERIALIZABLE, new Callable<Void>() {
@Override
public Void call() throws Exception {
for (Integer key : keys) randomOperation(rnd, cache, key);
return null;
}
});
}
if (iter % 100 == 0)
log.info("Iteration: " + iter);
iter++;
}
return null;
} catch (Throwable e) {
log.error("Unexpected error: " + e, e);
throw e;
}
}
}, "update-thread-" + i));
}
U.sleep(60_000);
finished.set(true);
restartFut.get();
for (IgniteInternalFuture<?> fut : futs) fut.get();
} finally {
finished.set(true);
for (String cacheName : cacheNames) destroyCache(cacheName);
}
}
Aggregations