use of org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl in project ignite by apache.
the class InlineIndexColumnTest method testBytes.
/**
*/
@Test
public void testBytes() throws Exception {
DataRegionConfiguration plcCfg = new DataRegionConfiguration().setInitialSize(1024 * MB).setMaxSize(1024 * MB);
PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, new DataRegionMetricsImpl(plcCfg, new GridTestKernalContext(log())), false);
pageMem.start();
long pageId = 0L;
long page = 0L;
try {
pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
page = pageMem.acquirePage(CACHE_ID, pageId);
long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
int off = 0;
IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().inlineObjHash(false).stringOptimizedCompare(false);
InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(Value.BYTES, keyTypeSettings);
int maxSize = 3 + 3;
int savedBytesCnt = keyType.put(pageAddr, off, idxKey(ValueBytes.get(new byte[] { 1, 2, 3, 4, 5 }), keyTypeSettings), maxSize);
assertTrue(savedBytesCnt > 0);
assertTrue(savedBytesCnt <= maxSize);
maxSize = 3 + 5;
assertTrue(Arrays.equals(new byte[] { 1, 2, 3 }, (byte[]) keyType.get(pageAddr, off, maxSize).key()));
savedBytesCnt = keyType.put(pageAddr, off, idxKey(ValueBytes.get(new byte[] { 1, 2, 3, 4, 5 }), keyTypeSettings), maxSize);
assertTrue(savedBytesCnt > 0);
assertTrue(savedBytesCnt <= maxSize);
assertTrue(Arrays.equals(new byte[] { 1, 2, 3, 4, 5 }, (byte[]) keyType.get(pageAddr, off, maxSize).key()));
} finally {
if (page != 0L)
pageMem.releasePage(CACHE_ID, pageId, page);
pageMem.stop(true);
}
}
use of org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl in project ignite by apache.
the class InlineIndexColumnTest method putAndCompare.
/**
* @param v1 Value 1.
* @param v2 Value 2.
* @param maxSize Max inline size.
* @return Compare result.
* @throws Exception If failed.
*/
private <T> int putAndCompare(T v1, T v2, Class<T> cls, int maxSize) throws Exception {
DataRegionConfiguration plcCfg = new DataRegionConfiguration().setInitialSize(1024 * MB).setMaxSize(1024 * MB);
DataRegionMetricsImpl dataRegionMetrics = new DataRegionMetricsImpl(plcCfg, new GridTestKernalContext(log()));
PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, dataRegionMetrics, false);
pageMem.start();
long pageId = 0L;
long page = 0L;
try {
pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
page = pageMem.acquirePage(CACHE_ID, pageId);
long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
int off = 0;
IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().inlineObjHash(inlineObjHash).stringOptimizedCompare(true);
InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(wrap(v1, cls).getType(), keyTypeSettings);
keyType.put(pageAddr, off, idxKey(wrap(v1, cls)), maxSize);
return keyType.compare(pageAddr, off, maxSize, idxKey(wrap(v2, cls)));
} finally {
if (page != 0L)
pageMem.releasePage(CACHE_ID, pageId, page);
pageMem.stop(true);
}
}
use of org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl in project ignite by apache.
the class InlineIndexColumnTest method testPutGet.
/**
*/
private void testPutGet(Value v1, Value v2, Value v3) throws Exception {
DataRegionConfiguration plcCfg = new DataRegionConfiguration().setInitialSize(1024 * MB).setMaxSize(1024 * MB);
PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, new DataRegionMetricsImpl(plcCfg, new GridTestKernalContext(log())), false);
pageMem.start();
long pageId = 0L;
long page = 0L;
try {
pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
page = pageMem.acquirePage(CACHE_ID, pageId);
long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
int off = 0;
int max = 255;
IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().inlineObjHash(false).stringOptimizedCompare(false);
InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(v1.getType(), keyTypeSettings);
off += keyType.put(pageAddr, off, idxKey(v1), max - off);
off += keyType.put(pageAddr, off, idxKey(v2), max - off);
off += keyType.put(pageAddr, off, idxKey(v3), max - off);
IndexKey v11 = keyType.get(pageAddr, 0, max);
IndexKey v22 = keyType.get(pageAddr, keyType.inlineSize(pageAddr, 0), max);
assertEquals(v1.getObject(), v11.key());
assertEquals(v2.getObject(), v22.key());
assertEquals(0, keyType.compare(pageAddr, 0, max, idxKey(v1)));
} finally {
if (page != 0L)
pageMem.releasePage(CACHE_ID, pageId, page);
pageMem.stop(true);
}
}
use of org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl in project ignite by apache.
the class Loader method apply.
/**
* {@inheritDoc}
*/
@Override
public Integer apply(Integer integer) {
CacheConfiguration<Integer, SampleValue> cc = cache.getConfiguration(CacheConfiguration.class);
String dataRegName = cc.getDataRegionName() == null ? ignite.configuration().getDataStorageConfiguration().getDefaultDataRegionConfiguration().getName() : cc.getDataRegionName();
BenchmarkUtils.println("Data region name = " + dataRegName);
DataStorageConfiguration dataStorCfg = ignite.configuration().getDataStorageConfiguration();
int pageSize = dataStorCfg.getPageSize();
BenchmarkUtils.println("Page size = " + pageSize);
DataRegionConfiguration dataRegCfg = null;
DataRegionConfiguration[] arr = ignite.configuration().getDataStorageConfiguration().getDataRegionConfigurations();
for (DataRegionConfiguration cfg : arr) {
if (cfg.getName().equals(dataRegName))
dataRegCfg = cfg;
}
if (dataRegCfg == null) {
BenchmarkUtils.println(String.format("Failed to get data region configuration for cache %s", cache.getName()));
return null;
}
long maxSize = dataRegCfg.getMaxSize();
BenchmarkUtils.println("Max size = " + maxSize);
long initSize = dataRegCfg.getInitialSize();
if (maxSize != initSize)
BenchmarkUtils.println("Initial data region size must be equal to max size!");
long pageNum = maxSize / pageSize;
BenchmarkUtils.println("Pages in data region: " + pageNum);
int cnt = 0;
final long pagesToLoad = pageNum * args.preloadDataRegionMult();
IgniteEx igniteEx = (IgniteEx) ignite;
try {
final DataRegionMetricsImpl impl = igniteEx.context().cache().context().database().dataRegion(dataRegName).metrics();
impl.enableMetrics();
BenchmarkUtils.println("Initial allocated pages = " + impl.getTotalAllocatedPages());
ExecutorService serv = Executors.newSingleThreadExecutor(new ThreadFactory() {
@Override
public Thread newThread(@NotNull Runnable r) {
return new Thread(r, "Preload checker");
}
});
Future<?> checkFut = serv.submit(new Runnable() {
@Override
public void run() {
while (!loaded.get()) {
if (impl.getTotalAllocatedPages() >= pagesToLoad)
loaded.getAndSet(true);
try {
Thread.sleep(500L);
} catch (InterruptedException e) {
BenchmarkUtils.error("Was interrupted while waiting before next check.", e);
}
}
}
});
try (IgniteDataStreamer<Object, Object> streamer = ignite.dataStreamer(cache.getName())) {
while (!loaded.get()) {
streamer.addData(cnt++, new SampleValue());
if (cnt % 1000_000 == 0) {
long allocPages = impl.getTotalAllocatedPages();
BenchmarkUtils.println("Load count = " + cnt);
BenchmarkUtils.println("Allocated pages = " + allocPages);
}
}
} catch (Exception e) {
BenchmarkUtils.error("Failed to load data.", e);
}
try {
checkFut.get();
} catch (InterruptedException | ExecutionException e) {
BenchmarkUtils.error("Failed to check loading.", e);
} finally {
serv.shutdown();
}
impl.disableMetrics();
BenchmarkUtils.println("Objects loaded = " + cnt);
BenchmarkUtils.println("Total allocated pages = " + impl.getTotalAllocatedPages());
} catch (IgniteCheckedException e) {
BenchmarkUtils.error("Failed to load data.", e);
}
return cnt;
}
use of org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl in project ignite by apache.
the class BPlusTreeReplaceRemoveRaceTest method createPageMemory.
/**
* @return Page memory.
*/
protected PageMemory createPageMemory() {
DataRegionConfiguration plcCfg = new DataRegionConfiguration().setInitialSize(1024 * MB).setMaxSize(1024 * MB);
PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, new DataRegionMetricsImpl(plcCfg, new GridTestKernalContext(log())), true);
pageMem.start();
return pageMem;
}
Aggregations