Search in sources :

Example 6 with SearchMapping

use of org.infinispan.search.mapper.mapping.SearchMapping in project infinispan by infinispan.

the class LifecycleManager method cacheStarted.

@Override
public void cacheStarted(ComponentRegistry cr, String cacheName) {
    Configuration configuration = cr.getComponent(Configuration.class);
    IndexingConfiguration indexingConfiguration = configuration.indexing();
    if (!indexingConfiguration.enabled()) {
        if (verifyChainContainsQueryInterceptor(cr)) {
            throw new IllegalStateException("It was NOT expected to find the Query interceptor registered in the InterceptorChain as indexing was disabled, but it was found");
        }
        return;
    }
    if (!verifyChainContainsQueryInterceptor(cr)) {
        throw new IllegalStateException("It was expected to find the Query interceptor registered in the InterceptorChain but it wasn't found");
    }
    SearchMapping searchMapping = cr.getComponent(SearchMapping.class);
    if (searchMapping != null) {
        checkIndexableClasses(searchMapping, indexingConfiguration.indexedEntities());
    }
    AdvancedCache<?, ?> cache = cr.getComponent(Cache.class).getAdvancedCache();
    Indexer massIndexer = ComponentRegistryUtils.getIndexer(cache);
    InfinispanQueryStatisticsInfo stats = new InfinispanQueryStatisticsInfo(Search.getSearchStatistics(cache), SecurityActions.getCacheComponentRegistry(cache).getComponent(Authorizer.class));
    cr.registerComponent(stats, InfinispanQueryStatisticsInfo.class);
    registerQueryMBeans(cr, massIndexer, stats);
    registerMetrics(cr, stats);
}
Also used : DistributedExecutorMassIndexer(org.infinispan.query.impl.massindex.DistributedExecutorMassIndexer) Indexer(org.infinispan.query.Indexer) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) IndexingConfiguration(org.infinispan.configuration.cache.IndexingConfiguration) SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) Authorizer(org.infinispan.security.impl.Authorizer) IndexingConfiguration(org.infinispan.configuration.cache.IndexingConfiguration) Cache(org.infinispan.Cache) QueryCache(org.infinispan.query.core.impl.QueryCache) AdvancedCache(org.infinispan.AdvancedCache)

Example 7 with SearchMapping

use of org.infinispan.search.mapper.mapping.SearchMapping in project infinispan by infinispan.

the class IndexWorker method apply.

@Override
public Void apply(EmbeddedCacheManager embeddedCacheManager) {
    AdvancedCache<Object, Object> cache = SecurityActions.getUnwrappedCache(embeddedCacheManager.getCache(cacheName)).getAdvancedCache();
    DataConversion valueDataConversion = cache.getValueDataConversion();
    AdvancedCache<Object, Object> reindexCache = cache.withStorageMediaType();
    SearchMapping searchMapping = ComponentRegistryUtils.getSearchMapping(cache);
    TimeService timeService = ComponentRegistryUtils.getTimeService(cache);
    MassIndexerProgressNotifier notifier = new MassIndexerProgressNotifier(searchMapping, timeService);
    IndexUpdater indexUpdater = new IndexUpdater(searchMapping);
    KeyPartitioner keyPartitioner = ComponentRegistryUtils.getKeyPartitioner(cache);
    if (keys == null || keys.size() == 0) {
        preIndex(cache, indexUpdater);
        MassIndexerProgressState progressState = new MassIndexerProgressState(notifier);
        if (!skipIndex) {
            try (Stream<CacheEntry<Object, Object>> stream = reindexCache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).cacheEntrySet().stream()) {
                stream.forEach(entry -> {
                    Object key = entry.getKey();
                    Object value = valueDataConversion.extractIndexable(entry.getValue());
                    int segment = keyPartitioner.getSegment(key);
                    if (value != null && indexedTypes.contains(indexUpdater.toConvertedEntityJavaClass(value))) {
                        progressState.addItem(key, value, indexUpdater.updateIndex(key, value, segment));
                    }
                });
            }
        }
        postIndex(indexUpdater, progressState, notifier);
    } else {
        DataConversion keyDataConversion = cache.getKeyDataConversion();
        Set<Class<?>> classSet = new HashSet<>();
        for (Object key : keys) {
            Object storedKey = keyDataConversion.toStorage(key);
            Object unwrappedKey = keyDataConversion.extractIndexable(storedKey);
            Object value = cache.get(key);
            if (value != null) {
                indexUpdater.updateIndex(unwrappedKey, value, keyPartitioner.getSegment(storedKey));
                classSet.add(value.getClass());
            }
        }
        indexUpdater.flush(classSet);
        indexUpdater.refresh(classSet);
    }
    return null;
}
Also used : SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) TimeService(org.infinispan.commons.time.TimeService) CacheEntry(org.infinispan.container.entries.CacheEntry) DataConversion(org.infinispan.encoding.DataConversion) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) HashSet(java.util.HashSet)

Example 8 with SearchMapping

use of org.infinispan.search.mapper.mapping.SearchMapping in project infinispan by infinispan.

the class ObjectRemoteQueryManager method createEntityNamesResolver.

private EntityNameResolver<Class<?>> createEntityNamesResolver(MediaType mediaType) {
    if (mediaType.match(APPLICATION_PROTOSTREAM)) {
        return new ProtobufEntityNameResolver(serCtx);
    } else {
        ClassLoader classLoader = cr.getGlobalComponentRegistry().getComponent(ClassLoader.class);
        ReflectionEntityNamesResolver reflectionEntityNamesResolver = new ReflectionEntityNamesResolver(classLoader);
        if (searchMapping != null) {
            // If indexing is enabled then use the declared set of indexed classes for lookup but fallback to global classloader.
            QueryInterceptor queryInterceptor = cr.getComponent(QueryInterceptor.class);
            Map<String, Class<?>> indexedEntities = queryInterceptor.indexedEntities();
            return name -> {
                Class<?> c = indexedEntities.get(name);
                if (c == null) {
                    c = reflectionEntityNamesResolver.resolve(name);
                }
                return c;
            };
        }
        return reflectionEntityNamesResolver;
    }
}
Also used : ReflectionEntityNamesResolver(org.infinispan.objectfilter.impl.syntax.parser.ReflectionEntityNamesResolver) QueryInterceptor(org.infinispan.query.backend.QueryInterceptor) SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) APPLICATION_PROTOSTREAM(org.infinispan.commons.dataconversion.MediaType.APPLICATION_PROTOSTREAM) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ReflectionMatcher(org.infinispan.objectfilter.impl.ReflectionMatcher) ComponentRegistry(org.infinispan.factories.ComponentRegistry) EntityNameResolver(org.infinispan.objectfilter.impl.syntax.parser.EntityNameResolver) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) MediaType(org.infinispan.commons.dataconversion.MediaType) AdvancedCache(org.infinispan.AdvancedCache) Matcher(org.infinispan.objectfilter.Matcher) APPLICATION_OBJECT(org.infinispan.commons.dataconversion.MediaType.APPLICATION_OBJECT) Map(java.util.Map) ReflectionEntityNamesResolver(org.infinispan.objectfilter.impl.syntax.parser.ReflectionEntityNamesResolver) ObjectReflectionMatcher(org.infinispan.query.dsl.embedded.impl.ObjectReflectionMatcher) SerializationContext(org.infinispan.protostream.SerializationContext) QueryInterceptor(org.infinispan.query.backend.QueryInterceptor)

Example 9 with SearchMapping

use of org.infinispan.search.mapper.mapping.SearchMapping in project infinispan by infinispan.

the class LazySearchMapping method createMapping.

private SearchMapping createMapping() {
    IndexingConfiguration indexingConfiguration = cache.getCacheConfiguration().indexing();
    Set<String> indexedEntityTypes = indexingConfiguration.indexedEntityTypes();
    DataConversion valueDataConversion = cache.getAdvancedCache().getValueDataConversion();
    SearchMapping searchMapping = null;
    if (commonBuilding != null) {
        SearchMappingBuilder builder = SerializationContextSearchMapping.createBuilder(commonBuilding, entityLoader, indexedEntityTypes, serCtx);
        searchMapping = builder != null ? builder.build() : null;
    }
    if (indexingConfiguration.enabled()) {
        if (valueDataConversion.getStorageMediaType().match(APPLICATION_PROTOSTREAM)) {
            // Try to resolve the indexed type names to protobuf type names.
            Set<String> knownTypes = protobufMetadataManager.getSerializationContext().getGenericDescriptors().keySet();
            for (String typeName : indexedEntityTypes) {
                if (!knownTypes.contains(typeName)) {
                    if (searchMapping != null)
                        searchMapping.close();
                    throw log.unknownType(typeName);
                }
                if (searchMapping == null || searchMapping.indexedEntity(typeName) == null) {
                    if (searchMapping != null)
                        searchMapping.close();
                    throw log.typeNotIndexed(typeName);
                }
            }
        }
    }
    return searchMapping;
}
Also used : DataConversion(org.infinispan.encoding.DataConversion) SearchMappingBuilder(org.infinispan.search.mapper.mapping.SearchMappingBuilder) SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) SerializationContextSearchMapping(org.infinispan.query.remote.impl.mapping.SerializationContextSearchMapping) IndexingConfiguration(org.infinispan.configuration.cache.IndexingConfiguration)

Example 10 with SearchMapping

use of org.infinispan.search.mapper.mapping.SearchMapping in project infinispan by infinispan.

the class LifecycleManager method cacheStarting.

/**
 * Registers the interceptor in the ___protobuf_metadata cache before it gets started. Also creates query components
 * for user caches.
 */
@Override
public void cacheStarting(ComponentRegistry cr, Configuration cfg, String cacheName) {
    BasicComponentRegistry gcr = cr.getGlobalComponentRegistry().getComponent(BasicComponentRegistry.class);
    LocalQueryStatistics queryStatistics = cr.getComponent(LocalQueryStatistics.class);
    if (PROTOBUF_METADATA_CACHE_NAME.equals(cacheName)) {
        // a protobuf metadata cache is starting, need to register the interceptor
        ProtobufMetadataManagerImpl protobufMetadataManager = (ProtobufMetadataManagerImpl) gcr.getComponent(ProtobufMetadataManager.class).running();
        protobufMetadataManager.addProtobufMetadataManagerInterceptor(cr.getComponent(BasicComponentRegistry.class));
    }
    InternalCacheRegistry icr = gcr.getComponent(InternalCacheRegistry.class).running();
    if (!icr.isInternalCache(cacheName)) {
        // a stop dependency must be added for each non-internal cache
        ProtobufMetadataManagerImpl protobufMetadataManager = (ProtobufMetadataManagerImpl) gcr.getComponent(ProtobufMetadataManager.class).running();
        protobufMetadataManager.addCacheDependency(cacheName);
        // a remote query manager must be added for each non-internal cache
        SerializationContext serCtx = protobufMetadataManager.getSerializationContext();
        RemoteQueryManager remoteQueryManager = buildQueryManager(cfg, serCtx, cr);
        cr.registerComponent(remoteQueryManager, RemoteQueryManager.class);
        SearchMappingCommonBuilding commonBuilding = cr.getComponent(SearchMappingCommonBuilding.class);
        SearchMapping searchMapping = cr.getComponent(SearchMapping.class);
        if (commonBuilding != null && searchMapping == null) {
            AdvancedCache<?, ?> cache = cr.getComponent(Cache.class).getAdvancedCache().withStorageMediaType().withWrapping(ByteArrayWrapper.class, ProtobufWrapper.class);
            KeyTransformationHandler keyTransformationHandler = ComponentRegistryUtils.getKeyTransformationHandler(cache);
            EntityLoader<?> entityLoader = new EntityLoader<>(queryStatistics, cache, keyTransformationHandler);
            searchMapping = new LazySearchMapping(commonBuilding, entityLoader, serCtx, cache, protobufMetadataManager);
            cr.registerComponent(searchMapping, SearchMapping.class);
            BasicComponentRegistry bcr = cr.getComponent(BasicComponentRegistry.class);
            bcr.replaceComponent(IndexStatistics.class.getName(), new LocalIndexStatistics(), true);
            bcr.rewire();
        }
    }
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) EntityLoader(org.infinispan.query.impl.EntityLoader) SearchMappingCommonBuilding(org.infinispan.search.mapper.mapping.SearchMappingCommonBuilding) LocalIndexStatistics(org.infinispan.query.stats.impl.LocalIndexStatistics) InternalCacheRegistry(org.infinispan.registry.InternalCacheRegistry) LocalIndexStatistics(org.infinispan.query.stats.impl.LocalIndexStatistics) IndexStatistics(org.infinispan.query.core.stats.IndexStatistics) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) KeyTransformationHandler(org.infinispan.query.backend.KeyTransformationHandler) LocalQueryStatistics(org.infinispan.query.core.stats.impl.LocalQueryStatistics) Cache(org.infinispan.Cache) AdvancedCache(org.infinispan.AdvancedCache)

Aggregations

SearchMapping (org.infinispan.search.mapper.mapping.SearchMapping)20 AdvancedCache (org.infinispan.AdvancedCache)4 Cache (org.infinispan.Cache)3 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)3 QueryInterceptor (org.infinispan.query.backend.QueryInterceptor)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 MediaType (org.infinispan.commons.dataconversion.MediaType)2 IndexingConfiguration (org.infinispan.configuration.cache.IndexingConfiguration)2 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)2 DataConversion (org.infinispan.encoding.DataConversion)2 ComponentRegistry (org.infinispan.factories.ComponentRegistry)2 ReflectionEntityNamesResolver (org.infinispan.objectfilter.impl.syntax.parser.ReflectionEntityNamesResolver)2 SerializationContext (org.infinispan.protostream.SerializationContext)2 Indexer (org.infinispan.query.Indexer)2 KeyTransformationHandler (org.infinispan.query.backend.KeyTransformationHandler)2 QueryCache (org.infinispan.query.core.impl.QueryCache)2 IndexStatistics (org.infinispan.query.core.stats.IndexStatistics)2