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);
}
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;
}
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;
}
}
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;
}
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();
}
}
}
Aggregations