use of org.apache.ignite.internal.processors.cache.persistence.freelist.FreeList in project ignite by apache.
the class CacheFreeListSelfTest method checkInsertDeleteMultiThreaded.
/**
* @param pageSize Page size.
* @param batched Batch mode flag.
* @throws Exception If failed.
*/
protected void checkInsertDeleteMultiThreaded(final int pageSize, final boolean batched) throws Exception {
final FreeList<CacheDataRow> list = createFreeList(pageSize);
Random rnd = new Random();
final ConcurrentMap<Long, CacheDataRow> stored = new ConcurrentHashMap<>();
for (int i = 0; i < 100; i++) {
int keySize = rnd.nextInt(pageSize * 3 / 2) + 10;
int valSize = rnd.nextInt(pageSize * 5 / 2) + 10;
TestDataRow row = new TestDataRow(keySize, valSize);
list.insertDataRow(row, IoStatisticsHolderNoOp.INSTANCE);
assertTrue(row.link() != 0L);
CacheDataRow old = stored.put(row.link(), row);
assertNull(old);
}
final AtomicBoolean grow = new AtomicBoolean(true);
GridTestUtils.runMultiThreaded(new Callable<Object>() {
@Override
public Object call() throws Exception {
List<CacheDataRow> rows = new ArrayList<>(BATCH_SIZE);
Random rnd = ThreadLocalRandom.current();
for (int i = 0; i < 200_000; i++) {
boolean grow0 = grow.get();
if (grow0) {
if (stored.size() > 20_000) {
if (grow.compareAndSet(true, false))
info("Shrink... [" + stored.size() + ']');
grow0 = false;
}
} else {
if (stored.size() < 1_000) {
if (grow.compareAndSet(false, true))
info("Grow... [" + stored.size() + ']');
grow0 = true;
}
}
boolean insert = rnd.nextInt(100) < 70 == grow0;
if (insert) {
int keySize = rnd.nextInt(pageSize * 3 / 2) + 10;
int valSize = rnd.nextInt(pageSize * 3 / 2) + 10;
TestDataRow row = new TestDataRow(keySize, valSize);
if (batched) {
rows.add(row);
if (rows.size() == BATCH_SIZE) {
list.insertDataRows(rows, IoStatisticsHolderNoOp.INSTANCE);
for (CacheDataRow row0 : rows) {
assertTrue(row0.link() != 0L);
CacheDataRow old = stored.put(row0.link(), row0);
assertNull(old);
}
rows.clear();
}
continue;
}
list.insertDataRow(row, IoStatisticsHolderNoOp.INSTANCE);
assertTrue(row.link() != 0L);
CacheDataRow old = stored.put(row.link(), row);
assertNull(old);
} else {
while (!stored.isEmpty()) {
Iterator<CacheDataRow> it = stored.values().iterator();
if (it.hasNext()) {
CacheDataRow row = it.next();
CacheDataRow rmvd = stored.remove(row.link());
if (rmvd != null) {
list.removeDataRowByLink(row.link(), IoStatisticsHolderNoOp.INSTANCE);
break;
}
}
}
}
}
return null;
}
}, 8, "runner");
}
use of org.apache.ignite.internal.processors.cache.persistence.freelist.FreeList in project ignite by apache.
the class CacheFreeListImplSelfTest method checkInsertDeleteSingleThreaded.
/**
* @throws Exception if failed.
*/
protected void checkInsertDeleteSingleThreaded(int pageSize) throws Exception {
FreeList list = createFreeList(pageSize);
Random rnd = new Random();
Map<Long, TestDataRow> stored = new HashMap<>();
for (int i = 0; i < 100; i++) {
int keySize = rnd.nextInt(pageSize * 3 / 2) + 10;
int valSize = rnd.nextInt(pageSize * 5 / 2) + 10;
TestDataRow row = new TestDataRow(keySize, valSize);
list.insertDataRow(row);
assertTrue(row.link() != 0L);
TestDataRow old = stored.put(row.link(), row);
assertNull(old);
}
boolean grow = true;
for (int i = 0; i < 1_000_000; i++) {
if (grow) {
if (stored.size() > 20_000) {
grow = false;
info("Shrink... [" + stored.size() + ']');
}
} else {
if (stored.size() < 1_000) {
grow = true;
info("Grow... [" + stored.size() + ']');
}
}
boolean insert = rnd.nextInt(100) < 70 == grow;
if (insert) {
int keySize = rnd.nextInt(pageSize * 3 / 2) + 10;
int valSize = rnd.nextInt(pageSize * 3 / 2) + 10;
TestDataRow row = new TestDataRow(keySize, valSize);
list.insertDataRow(row);
assertTrue(row.link() != 0L);
TestDataRow old = stored.put(row.link(), row);
assertNull(old);
} else {
Iterator<TestDataRow> it = stored.values().iterator();
if (it.hasNext()) {
TestDataRow row = it.next();
TestDataRow rmvd = stored.remove(row.link);
assertTrue(rmvd == row);
list.removeDataRowByLink(row.link);
}
}
}
}
use of org.apache.ignite.internal.processors.cache.persistence.freelist.FreeList in project ignite by apache.
the class CacheFreeListImplSelfTest method checkInsertDeleteMultiThreaded.
/**
* @param pageSize Page size.
* @throws Exception If failed.
*/
protected void checkInsertDeleteMultiThreaded(final int pageSize) throws Exception {
final FreeList list = createFreeList(pageSize);
Random rnd = new Random();
final ConcurrentMap<Long, TestDataRow> stored = new ConcurrentHashMap<>();
for (int i = 0; i < 100; i++) {
int keySize = rnd.nextInt(pageSize * 3 / 2) + 10;
int valSize = rnd.nextInt(pageSize * 5 / 2) + 10;
TestDataRow row = new TestDataRow(keySize, valSize);
list.insertDataRow(row);
assertTrue(row.link() != 0L);
TestDataRow old = stored.put(row.link(), row);
assertNull(old);
}
final AtomicBoolean grow = new AtomicBoolean(true);
GridTestUtils.runMultiThreaded(new Callable<Object>() {
@Override
public Object call() throws Exception {
Random rnd = ThreadLocalRandom.current();
for (int i = 0; i < 200_000; i++) {
boolean grow0 = grow.get();
if (grow0) {
if (stored.size() > 20_000) {
if (grow.compareAndSet(true, false))
info("Shrink... [" + stored.size() + ']');
grow0 = false;
}
} else {
if (stored.size() < 1_000) {
if (grow.compareAndSet(false, true))
info("Grow... [" + stored.size() + ']');
grow0 = true;
}
}
boolean insert = rnd.nextInt(100) < 70 == grow0;
if (insert) {
int keySize = rnd.nextInt(pageSize * 3 / 2) + 10;
int valSize = rnd.nextInt(pageSize * 3 / 2) + 10;
TestDataRow row = new TestDataRow(keySize, valSize);
list.insertDataRow(row);
assertTrue(row.link() != 0L);
TestDataRow old = stored.put(row.link(), row);
assertNull(old);
} else {
while (true) {
Iterator<TestDataRow> it = stored.values().iterator();
if (it.hasNext()) {
TestDataRow row = it.next();
TestDataRow rmvd = stored.remove(row.link);
if (rmvd != null) {
list.removeDataRowByLink(row.link);
break;
}
}
}
}
}
return null;
}
}, 8, "runner");
}
use of org.apache.ignite.internal.processors.cache.persistence.freelist.FreeList in project ignite by apache.
the class GridCacheProcessor method startCacheGroup.
/**
* @param desc Group descriptor.
* @param cacheType Cache type.
* @param affNode Affinity node flag.
* @param cacheObjCtx Cache object context.
* @param exchTopVer Current topology version.
* @return Started cache group.
* @throws IgniteCheckedException If failed.
*/
private CacheGroupContext startCacheGroup(CacheGroupDescriptor desc, CacheType cacheType, boolean affNode, CacheObjectContext cacheObjCtx, AffinityTopologyVersion exchTopVer, boolean recoveryMode) throws IgniteCheckedException {
desc = enricher().enrich(desc, affNode);
CacheConfiguration cfg = new CacheConfiguration(desc.config());
String memPlcName = cfg.getDataRegionName();
DataRegion dataRegion = affNode ? sharedCtx.database().dataRegion(memPlcName) : null;
boolean needToStart = (dataRegion != null) && (cacheType != CacheType.USER || (sharedCtx.isLazyMemoryAllocation(dataRegion) && (!cacheObjCtx.kernalContext().clientNode() || cfg.getCacheMode() == LOCAL)));
if (needToStart)
dataRegion.pageMemory().start();
FreeList freeList = sharedCtx.database().freeList(memPlcName);
ReuseList reuseList = sharedCtx.database().reuseList(memPlcName);
boolean persistenceEnabled = recoveryMode || sharedCtx.localNode().isClient() ? desc.persistenceEnabled() : dataRegion != null && dataRegion.config().isPersistenceEnabled();
CacheGroupContext grp = new CacheGroupContext(sharedCtx, desc.groupId(), desc.receivedFrom(), cacheType, cfg, affNode, dataRegion, cacheObjCtx, freeList, reuseList, exchTopVer, persistenceEnabled, desc.walEnabled(), recoveryMode);
for (Object obj : grp.configuredUserObjects()) prepare(cfg, obj, false);
U.startLifecycleAware(grp.configuredUserObjects());
grp.start();
CacheGroupContext old = cacheGrps.put(desc.groupId(), grp);
if (!grp.systemCache() && !U.IGNITE_MBEANS_DISABLED) {
try {
U.registerMBean(ctx.config().getMBeanServer(), ctx.igniteInstanceName(), CACHE_GRP_METRICS_MBEAN_GRP, grp.cacheOrGroupName(), new CacheGroupMetricsMXBeanImpl(grp), CacheGroupMetricsMXBean.class);
} catch (Throwable e) {
U.error(log, "Failed to register MBean for cache group: " + grp.name(), e);
}
}
assert old == null : old.name();
return grp;
}
Aggregations