Search in sources :

Example 36 with DataRegionMetricsImpl

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);
    }
}
Also used : DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) PageMemoryNoStoreImpl(org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl) StringInlineIndexKeyType(org.apache.ignite.internal.cache.query.index.sorted.inline.types.StringInlineIndexKeyType) InlineIndexKeyType(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) IndexKeyTypeSettings(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 37 with DataRegionMetricsImpl

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);
    }
}
Also used : DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) PageMemoryNoStoreImpl(org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl) StringInlineIndexKeyType(org.apache.ignite.internal.cache.query.index.sorted.inline.types.StringInlineIndexKeyType) InlineIndexKeyType(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) IndexKeyTypeSettings(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings)

Example 38 with DataRegionMetricsImpl

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);
    }
}
Also used : DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) PageMemoryNoStoreImpl(org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl) IndexKey(org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey) JavaObjectIndexKey(org.apache.ignite.internal.cache.query.index.sorted.keys.JavaObjectIndexKey) StringInlineIndexKeyType(org.apache.ignite.internal.cache.query.index.sorted.inline.types.StringInlineIndexKeyType) InlineIndexKeyType(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) IndexKeyTypeSettings(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings)

Example 39 with DataRegionMetricsImpl

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;
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) SampleValue(org.apache.ignite.yardstick.cache.model.SampleValue) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ExecutionException(java.util.concurrent.ExecutionException) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteEx(org.apache.ignite.internal.IgniteEx) ExecutorService(java.util.concurrent.ExecutorService) ExecutionException(java.util.concurrent.ExecutionException)

Example 40 with DataRegionMetricsImpl

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;
}
Also used : DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) PageMemoryNoStoreImpl(org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider)

Aggregations

DataRegionMetricsImpl (org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl)68 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)50 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)40 UnsafeMemoryProvider (org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider)38 PageMemory (org.apache.ignite.internal.pagemem.PageMemory)34 PageMemoryNoStoreImpl (org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl)30 DirectMemoryProvider (org.apache.ignite.internal.mem.DirectMemoryProvider)20 Test (org.junit.Test)18 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)15 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)14 IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)14 GridMetricManager (org.apache.ignite.internal.processors.metric.GridMetricManager)14 NoopMetricExporterSpi (org.apache.ignite.spi.metric.noop.NoopMetricExporterSpi)14 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)12 GridEncryptionManager (org.apache.ignite.internal.managers.encryption.GridEncryptionManager)12 CheckpointProgress (org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgress)12 GridInternalSubscriptionProcessor (org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor)12 IgniteEx (org.apache.ignite.internal.IgniteEx)11 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)11 IgnitePluginProcessor (org.apache.ignite.internal.processors.plugin.IgnitePluginProcessor)11