Search in sources :

Example 6 with IndexKeyTypeSettings

use of org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings in project ignite by apache.

the class InlineIndexTree method inlineObjectSupported.

/**
 * Find whether tree supports inlining objects or not.
 *
 * @param def Index definition.
 * @param metaInfo Metapage info.
 * @return {@code true} if inline object is supported by exists tree.
 */
private boolean inlineObjectSupported(SortedIndexDefinition def, MetaPageInfo metaInfo, InlineIndexRowHandlerFactory rowHndFactory) {
    if (metaInfo.flagsSupported())
        return metaInfo.inlineObjectSupported();
    else {
        try {
            if (InlineObjectBytesDetector.objectMayBeInlined(metaInfo.inlineSize(), def.indexKeyDefinitions().values())) {
                try {
                    InlineObjectBytesDetector inlineObjDetector = new InlineObjectBytesDetector(metaInfo.inlineSize(), def.indexKeyDefinitions().values(), def.idxName(), log);
                    // Create a settings for case where java objects inilned as byte array.
                    IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().inlineObjSupported(true).inlineObjHash(false);
                    InlineIndexRowHandler rowHnd = rowHndFactory.create(def, keyTypeSettings);
                    ThreadLocalRowHandlerHolder.rowHandler(rowHnd);
                    findFirst(inlineObjDetector);
                    return inlineObjDetector.inlineObjectSupported();
                } finally {
                    ThreadLocalRowHandlerHolder.clearRowHandler();
                }
            } else
                return false;
        } catch (IgniteCheckedException e) {
            throw new IgniteException("Unexpected exception on detect inline object", e);
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) InlineIndexRowHandler(org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler) IndexKeyTypeSettings(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings)

Example 7 with IndexKeyTypeSettings

use of org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings in project ignite by apache.

the class InlineObjectBytesDetector method objectMayBeInlined.

/**
 * Static analyze inline_size and inline columns set.
 * e.g.: indexed: (long, obj) and inline_size < 12.
 * In this case there is no space for inline object.
 *
 * @param keyDefs Index key definition.
 * @param inlineSize Inline size.
 *
 * @return {@code true} If the object may be inlined.
 */
public static boolean objectMayBeInlined(int inlineSize, Collection<IndexKeyDefinition> keyDefs) {
    int remainSize = inlineSize;
    // The settings does not affect on inline size.
    IndexKeyTypeSettings settings = new IndexKeyTypeSettings();
    for (IndexKeyDefinition def : keyDefs) {
        if (def.idxType() == IndexKeyTypes.JAVA_OBJECT)
            break;
        InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(def.idxType(), settings);
        if (keyType == null)
            return false;
        // Set size to 1 for variable length columns as that value can be set by user.
        remainSize -= keyType.inlineSize() > 0 ? 1 + keyType.inlineSize() : 1;
    }
    // For old versions JO type was inlined as byte array.
    return remainSize >= 4;
}
Also used : IndexKeyDefinition(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition) IndexKeyTypeSettings(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings)

Example 8 with IndexKeyTypeSettings

use of org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings in project ignite by apache.

the class InlineIndexColumnTest method testJavaObjectInlineHash.

/**
 */
@Test
public void testJavaObjectInlineHash() 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().stringOptimizedCompare(false);
        InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(Value.JAVA_OBJECT, keyTypeSettings);
        Value exp = wrap(new TestPojo(4, 3L), TestPojo.class);
        {
            int maxSize = 3;
            int savedBytesCnt = keyType.put(pageAddr, off, idxKey(exp), maxSize);
            Assert.assertEquals(0, savedBytesCnt);
        }
        {
            int maxSize = 7;
            int savedBytesCnt = keyType.put(pageAddr, off, idxKey(exp), maxSize);
            Assert.assertEquals(5, savedBytesCnt);
            Assert.assertEquals(exp.getObject().hashCode(), keyType.get(pageAddr, off, maxSize).key().hashCode());
            Assert.assertEquals(CANT_BE_COMPARE, keyType.compare(pageAddr, off, maxSize, idxKey(exp)));
        }
    } 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) Value(org.h2.value.Value) 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 9 with IndexKeyTypeSettings

use of org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings in project ignite by apache.

the class InlineIndexColumnTest method testStringTruncate.

/**
 */
@Test
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, 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.STRING, keyTypeSettings);
        keyType.put(pageAddr, off, idxKey(ValueString.get("aaaaaaa")), 3 + 5);
        assertEquals("aaaaa", keyType.get(pageAddr, off, 3 + 5).key());
        keyType.put(pageAddr, off, idxKey(ValueString.get("aaa")), 3 + 5);
        assertEquals("aaa", keyType.get(pageAddr, off, 3 + 5).key());
        keyType.put(pageAddr, off, idxKey(ValueString.get("\u20acaaa")), 3 + 2);
        assertNull(keyType.get(pageAddr, off, 3 + 2));
    } 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 10 with IndexKeyTypeSettings

use of org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings in project ignite by apache.

the class InlineIndexColumnTest method testJavaObjectInlineBytes.

/**
 */
@Test
public void testJavaObjectInlineBytes() 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(false).stringOptimizedCompare(false);
        InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(Value.JAVA_OBJECT, keyTypeSettings);
        ValueJavaObject exp = ValueJavaObject.getNoCopy(new TestPojo(4, 3L), null, null);
        int maxSize = 3 + 3;
        int savedBytesCnt = keyType.put(pageAddr, off, idxKey(exp), maxSize);
        assertTrue(savedBytesCnt > 0);
        assertTrue(savedBytesCnt <= maxSize);
        maxSize = 3 + exp.getBytesNoCopy().length;
        assertTrue(Arrays.equals(Arrays.copyOf(exp.getBytesNoCopy(), 3), ((JavaObjectIndexKey) keyType.get(pageAddr, off, maxSize)).bytesNoCopy()));
        savedBytesCnt = keyType.put(pageAddr, off, idxKey(ValueJavaObject.getNoCopy(null, exp.getBytesNoCopy(), null)), maxSize);
        assertTrue(savedBytesCnt > 0);
        assertTrue(savedBytesCnt <= maxSize);
        assertTrue(Arrays.equals(exp.getBytesNoCopy(), ((JavaObjectIndexKey) keyType.get(pageAddr, off, maxSize)).bytesNoCopy()));
    } finally {
        if (page != 0L)
            pageMem.releasePage(CACHE_ID, pageId, page);
        pageMem.stop(true);
    }
}
Also used : 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) JavaObjectIndexKey(org.apache.ignite.internal.cache.query.index.sorted.keys.JavaObjectIndexKey) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) ValueJavaObject(org.h2.value.ValueJavaObject) 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)

Aggregations

IndexKeyTypeSettings (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings)10 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)6 InlineIndexKeyType (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType)6 StringInlineIndexKeyType (org.apache.ignite.internal.cache.query.index.sorted.inline.types.StringInlineIndexKeyType)6 UnsafeMemoryProvider (org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider)6 PageMemory (org.apache.ignite.internal.pagemem.PageMemory)6 PageMemoryNoStoreImpl (org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl)6 DataRegionMetricsImpl (org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl)6 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)6 AbstractIndexingCommonTest (org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest)4 Test (org.junit.Test)4 IndexKeyDefinition (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition)3 IndexKey (org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey)3 JavaObjectIndexKey (org.apache.ignite.internal.cache.query.index.sorted.keys.JavaObjectIndexKey)3 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 IndexQueryCriterion (org.apache.ignite.cache.query.IndexQueryCriterion)1 RangeIndexQueryCriterion (org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion)1