Search in sources :

Example 16 with DataRegionMetricsImpl

use of org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl in project ignite by apache.

the class InlineIndexHelperTest method testStringTruncate.

/**
 */
public void testStringTruncate() 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), 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;
        InlineIndexHelper ih = new InlineIndexHelper(Value.STRING, 1, 0, CompareMode.getInstance(null, 0));
        ih.put(pageAddr, off, ValueString.get("aaaaaaa"), 3 + 5);
        assertFalse(ih.isValueFull(pageAddr, off));
        assertEquals("aaaaa", ih.get(pageAddr, off, 3 + 5).getString());
        ih.put(pageAddr, off, ValueString.get("aaa"), 3 + 5);
        assertTrue(ih.isValueFull(pageAddr, off));
        assertEquals("aaa", ih.get(pageAddr, off, 3 + 5).getString());
        ih.put(pageAddr, off, ValueString.get("\u20acaaa"), 3 + 2);
        assertNull(ih.get(pageAddr, off, 3 + 2));
    } finally {
        if (page != 0L)
            pageMem.releasePage(CACHE_ID, pageId, page);
        pageMem.stop();
    }
}
Also used : DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) PageMemoryNoStoreImpl(org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider)

Example 17 with DataRegionMetricsImpl

use of org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl in project ignite by apache.

the class InlineIndexHelperTest method testBytes.

/**
 */
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), 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;
        InlineIndexHelper ih = new InlineIndexHelper(Value.BYTES, 1, 0, CompareMode.getInstance(null, 0));
        ih.put(pageAddr, off, ValueBytes.get(new byte[] { 1, 2, 3, 4, 5 }), 3 + 3);
        assertFalse(ih.isValueFull(pageAddr, off));
        assertTrue(Arrays.equals(new byte[] { 1, 2, 3 }, ih.get(pageAddr, off, 3 + 5).getBytes()));
        ih.put(pageAddr, off, ValueBytes.get(new byte[] { 1, 2, 3, 4, 5 }), 3 + 5);
        assertTrue(ih.isValueFull(pageAddr, off));
        assertTrue(Arrays.equals(new byte[] { 1, 2, 3, 4, 5 }, ih.get(pageAddr, off, 3 + 5).getBytes()));
    } finally {
        if (page != 0L)
            pageMem.releasePage(CACHE_ID, pageId, page);
        pageMem.stop();
    }
}
Also used : DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) PageMemoryNoStoreImpl(org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider)

Example 18 with DataRegionMetricsImpl

use of org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl in project ignite by apache.

the class InlineIndexHelperTest 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), 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;
        InlineIndexHelper ih = new InlineIndexHelper(v1.getType(), 1, 0, CompareMode.getInstance(null, 0));
        off += ih.put(pageAddr, off, v1, max - off);
        off += ih.put(pageAddr, off, v2, max - off);
        off += ih.put(pageAddr, off, v3, max - off);
        Value v11 = ih.get(pageAddr, 0, max);
        Value v22 = ih.get(pageAddr, ih.fullSize(pageAddr, 0), max);
        assertEquals(v1.getObject(), v11.getObject());
        assertEquals(v2.getObject(), v22.getObject());
    } finally {
        if (page != 0L)
            pageMem.releasePage(CACHE_ID, pageId, page);
        pageMem.stop();
    }
}
Also used : DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) PageMemoryNoStoreImpl(org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) Value(org.h2.value.Value) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider)

Example 19 with DataRegionMetricsImpl

use of org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl in project ignite by apache.

the class InlineIndexHelperTest method putAndCompare.

/**
 * @param v1 Value 1.
 * @param v2 Value 2.
 * @param maxSize Max inline size.
 * @return Compare result.
 * @throws Exception If failed.
 */
private int putAndCompare(String v1, String v2, int maxSize) 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), 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;
        InlineIndexHelper ih = new InlineIndexHelper(Value.STRING, 1, 0, CompareMode.getInstance(null, 0));
        ih.put(pageAddr, off, v1 == null ? ValueNull.INSTANCE : ValueString.get(v1), maxSize);
        Comparator<Value> comp = new Comparator<Value>() {

            @Override
            public int compare(Value o1, Value o2) {
                throw new AssertionError("Optimized algorithm should be used.");
            }
        };
        return ih.compare(pageAddr, off, maxSize, v2 == null ? ValueNull.INSTANCE : ValueString.get(v2), comp);
    } finally {
        if (page != 0L)
            pageMem.releasePage(CACHE_ID, pageId, page);
        pageMem.stop();
    }
}
Also used : DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) PageMemoryNoStoreImpl(org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) Value(org.h2.value.Value) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) Comparator(java.util.Comparator)

Aggregations

DataRegionMetricsImpl (org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl)19 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)15 UnsafeMemoryProvider (org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider)11 PageMemory (org.apache.ignite.internal.pagemem.PageMemory)9 DirectMemoryProvider (org.apache.ignite.internal.mem.DirectMemoryProvider)8 PageMemoryNoStoreImpl (org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl)8 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)6 IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)6 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)5 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)5 MappedFileMemoryProvider (org.apache.ignite.internal.mem.file.MappedFileMemoryProvider)4 File (java.io.File)2 CheckpointLockStateChecker (org.apache.ignite.internal.processors.cache.persistence.CheckpointLockStateChecker)2 Value (org.h2.value.Value)2 Comparator (java.util.Comparator)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteCache (org.apache.ignite.IgniteCache)1 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 GridKernalContext (org.apache.ignite.internal.GridKernalContext)1