Class CatalogSolrIndexUpdateCommandHandlerImpl
java.lang.Object
org.broadleafcommerce.core.search.service.solr.indexer.AbstractSolrIndexUpdateCommandHandlerImpl
org.broadleafcommerce.core.search.service.solr.indexer.CatalogSolrIndexUpdateCommandHandlerImpl
- All Implemented Interfaces:
CatalogSolrIndexCommandHandler,SolrIndexUpdateCommandHandler,org.springframework.beans.factory.DisposableBean
@Service("blCatalogSolrUpdateCommandHandler")
public class CatalogSolrIndexUpdateCommandHandlerImpl
extends AbstractSolrIndexUpdateCommandHandlerImpl
implements CatalogSolrIndexCommandHandler, org.springframework.beans.factory.DisposableBean
Default command handler to handle Catalog Solr index commands. This is multi-threaded. SKU browsing is not supported with this implementation.
- Author:
- Kelly Tisdell
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CatalogDocumentBuilderprotected SolrIndexServiceExtensionManagerprotected IndexFieldDaoprotected org.broadleafcommerce.common.locale.service.LocaleServiceprotected intprotected ProductDaoprotected SolrIndexQueueProviderprotected longprotected org.broadleafcommerce.common.sandbox.SandBoxHelperprotected SolrHelperServiceprotected org.broadleafcommerce.common.site.service.SiteServiceprotected SolrConfigurationprotected SolrIndexDaoprotected org.springframework.transaction.PlatformTransactionManagerprotected int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterBackgroundThread(ReindexStateHolder holder, org.broadleafcommerce.common.site.domain.Catalog catalog, org.broadleafcommerce.common.site.domain.Site site, org.broadleafcommerce.common.sandbox.domain.SandBox sandBox) This executes after to the main execution of the background (page) thread(s).protected voidafterPage(List<Long> productIds, List<Product> products, List<org.broadleafcommerce.common.locale.domain.Locale> locales, List<IndexField> fields, ReindexStateHolder holder) This executes immediately after a page is processed.protected voidafterProcess(ReindexStateHolder holder) Hook point at that is executed at the end of the reindex process.protected voidafterReadIdBatch(ReindexStateHolder holder, Long catalogId, int batchSize, Long lastId) This executes immediately after reading a batch of product IDs for processing in a background thread.protected voidafterReadProducts(ReindexStateHolder holder, List<Long> productIds) This executes immediately after reading a batch of products.protected voidbeforeBackgroundThread(ReindexStateHolder holder, org.broadleafcommerce.common.site.domain.Catalog catalog, org.broadleafcommerce.common.site.domain.Site site, org.broadleafcommerce.common.sandbox.domain.SandBox sandBox) The reindex process, specifically page processing, is executed in background threads.protected voidbeforePage(List<Long> productIds, List<Product> products, List<org.broadleafcommerce.common.locale.domain.Locale> locales, List<IndexField> fields, ReindexStateHolder holder) This is executed immediately before a page is processed.protected voidbeforeProcess(ReindexStateHolder holder) Hook point that is executed at the beginning of the reindex process.protected voidbeforeReadIdBatch(ReindexStateHolder holder, Long catalogId, int batchSize, Long lastId) This executes immediately prior to reading a batch of product IDs for processing in a background thread.protected voidbeforeReadProducts(ReindexStateHolder holder, List<Long> productIds) This executes immediately prior to reading a batch of products.org.apache.solr.common.SolrInputDocumentbuildDocument(Indexable indexable) Provides an interface for a caller to convert anIndexableinto aSolrInputDocument.org.apache.solr.common.SolrInputDocumentbuildDocument(Indexable indexable, List<IndexField> fields, List<org.broadleafcommerce.common.locale.domain.Locale> locales) Provides an interface for a caller to convert anIndexableinto aSolrInputDocument.protected voidbuildIncrementalIndex(List<Long> productIds, List<Product> products, ReindexStateHolder holder, org.broadleafcommerce.common.site.domain.Catalog catalog, org.broadleafcommerce.common.site.domain.Site site) Builds an incremental or batch portion of the index.protected List<org.apache.solr.common.SolrInputDocument>buildPage(List<Long> productIds, List<Product> products, List<org.broadleafcommerce.common.locale.domain.Locale> locales, List<IndexField> fields, ReindexStateHolder holder) Given the arguments, this builds a list ofSolrInputDocuments.protected org.springframework.scheduling.concurrent.ThreadPoolTaskExecutorprotected org.broadleafcommerce.common.util.EntityManagerAwareRunnablecreateBackgroundRunnable(ReindexStateHolder holder, List<Long> ids, Semaphore sem, Long catalogId, Long siteId, org.broadleafcommerce.common.sandbox.domain.SandBox sandBox) This is where most of the heavy lifting happens.protected voiddeleteAllDocuments(String collection, boolean commit) By default this deletes all items in the collection, since there is a good chance that the collection will be re-aliased or swapped into the foreground after reindexing is complete.voiddestroy()protected void<C extends SolrUpdateCommand>
voidexecuteCommand(C command) Entry point from which this component can delegate action based on the type ofSolrUpdateCommand.protected voidprotected voidprotected voidfinalizeChanges(String collection, boolean error, boolean swap) Composite method that issues a commit or rollback (if there is an error), and optionally swaps (if there is no error).protected org.broadleafcommerce.common.site.domain.CatalogfindCatalog(Long catalogId) This reads aCatalogby ID.protected org.broadleafcommerce.common.site.domain.SiteThis reads aSiteby ID.protected List<org.broadleafcommerce.common.locale.domain.Locale>protected org.springframework.scheduling.concurrent.ThreadPoolTaskExecutorprotected longThe amount of time between commits during a full reindex.getIncrementalIndexOperation(ReindexStateHolder holder, org.broadleafcommerce.common.site.domain.Catalog catalog, org.broadleafcommerce.common.site.domain.Site site, List<Long> ids) Returns anIdentityOperationwho may be executed in the context of aCatalogand/orSiteto read products by IDs, and then build the index incrementally.protected List<IndexField>getReadIdsOperation(ReindexStateHolder holder, Long catalogId, Long siteId, Integer batchSize, Long lastId) Provides anIdentityOperation(function that runs in the context of a Site and/or Catalog) to read batches of IDs.protected SolrConfigurationprotected intNumber of worker threads (page processing threads) in the thread pool.protected voidincrementalCommit(ReindexStateHolder holder) Issues incremental commits.protected booleanMethod to determine whether a full reindex was successful.protected voidperformCachedOperation(SolrIndexCachedOperation.CacheOperation cacheOperation) protected voidpopulateIndex(ReindexStateHolder holder, Long catalogId, Long siteId, org.broadleafcommerce.common.sandbox.domain.SandBox sandbox) This method populates the index.readIdBatch(ReindexStateHolder holder, Long catalogId, int batchSize, Long lastId) Reads a batch ofProductIDs from the DB.readProductsByIds(ReindexStateHolder holder, List<Long> productIds) Reads a batch of products by IDs.protected voidMethods inherited from class org.broadleafcommerce.core.search.service.solr.indexer.AbstractSolrIndexUpdateCommandHandlerImpl
addDocument, addDocuments, commit, deleteByIds, deleteByQueries, deleteByQuery, executeCommandInternal, executeCommandInternal, executeCommandInternalNoDefaultCommandType, getBackgroundCollectionName, getCommandGroup, getForegroundCollectionName, rollbackMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.broadleafcommerce.core.search.service.solr.indexer.SolrIndexUpdateCommandHandler
getBackgroundCollectionName, getCommandGroup, getForegroundCollectionName
-
Field Details
-
solrConfiguration
@Qualifier("blCatalogSolrConfiguration") @Autowired(required=false) protected SolrConfiguration solrConfiguration -
localeService
protected org.broadleafcommerce.common.locale.service.LocaleService localeService -
shs
-
siteService
protected org.broadleafcommerce.common.site.service.SiteService siteService -
extensionManager
-
transactionManager
protected org.springframework.transaction.PlatformTransactionManager transactionManager -
solrIndexDao
-
sandBoxHelper
protected org.broadleafcommerce.common.sandbox.SandBoxHelper sandBoxHelper -
indexFieldDao
-
productDao
-
queueProvider
-
documentBuilder
-
pageSize
@Value("${solr.index.product.pageSize:100}") protected int pageSize -
workerThreads
@Value("${solr.index.product.workerThreads:10}") protected int workerThreads -
reindexCommitInterval
@Value("${solr.index.product.reindexCommitInterval:30000}") protected long reindexCommitInterval
-
-
Constructor Details
-
CatalogSolrIndexUpdateCommandHandlerImpl
public CatalogSolrIndexUpdateCommandHandlerImpl()
-
-
Method Details
-
executeCommand
public <C extends SolrUpdateCommand> void executeCommand(C command) throws org.broadleafcommerce.common.exception.ServiceException Description copied from interface:SolrIndexUpdateCommandHandlerEntry point from which this component can delegate action based on the type ofSolrUpdateCommand.This should never be called directly. Rather it will be called from inside the
AbstractSolrIndexUpdateServiceImpl.- Specified by:
executeCommandin interfaceSolrIndexUpdateCommandHandler- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
buildDocument
public org.apache.solr.common.SolrInputDocument buildDocument(Indexable indexable, List<IndexField> fields, List<org.broadleafcommerce.common.locale.domain.Locale> locales) Description copied from interface:SolrIndexUpdateCommandHandlerProvides an interface for a caller to convert anIndexableinto aSolrInputDocument. This may return null if the implementor does not want the specifiedIndexableindexed.- Specified by:
buildDocumentin interfaceSolrIndexUpdateCommandHandler- Returns:
-
buildDocument
Description copied from interface:SolrIndexUpdateCommandHandlerProvides an interface for a caller to convert anIndexableinto aSolrInputDocument. This may return null if the implementor does not want the specifiedIndexableindexed.- Specified by:
buildDocumentin interfaceSolrIndexUpdateCommandHandler- Returns:
-
executeFullReindexCommand
protected void executeFullReindexCommand(FullReindexCommand command) throws org.broadleafcommerce.common.exception.ServiceException - Throws:
org.broadleafcommerce.common.exception.ServiceException
-
executeCatalogReindexCommand
protected void executeCatalogReindexCommand(CatalogReindexCommand command) throws org.broadleafcommerce.common.exception.ServiceException - Throws:
org.broadleafcommerce.common.exception.ServiceException
-
executeSiteReindexCommand
protected void executeSiteReindexCommand(SiteReindexCommand command) throws org.broadleafcommerce.common.exception.ServiceException - Throws:
org.broadleafcommerce.common.exception.ServiceException
-
getSolrConfiguration
- Specified by:
getSolrConfigurationin classAbstractSolrIndexUpdateCommandHandlerImpl
-
getAllLocales
-
performCachedOperation
protected void performCachedOperation(SolrIndexCachedOperation.CacheOperation cacheOperation) throws org.broadleafcommerce.common.exception.ServiceException - Throws:
org.broadleafcommerce.common.exception.ServiceException
-
populateIndex
protected void populateIndex(ReindexStateHolder holder, Long catalogId, Long siteId, org.broadleafcommerce.common.sandbox.domain.SandBox sandbox) throws org.broadleafcommerce.common.exception.ServiceException This method populates the index.It is not recommended that you override this method. Rather, consider overriding one of the other methods as this one generally coordinates and delegates to others.
- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
getReadIdsOperation
protected org.broadleafcommerce.common.util.tenant.IdentityOperation<List<Long>,Exception> getReadIdsOperation(ReindexStateHolder holder, Long catalogId, Long siteId, Integer batchSize, Long lastId) Provides anIdentityOperation(function that runs in the context of a Site and/or Catalog) to read batches of IDs.- Parameters:
holder-catalogId-siteId-batchSize-lastId-- Returns:
-
deleteAllDocuments
protected void deleteAllDocuments(String collection, boolean commit) throws org.broadleafcommerce.common.exception.ServiceException By default this deletes all items in the collection, since there is a good chance that the collection will be re-aliased or swapped into the foreground after reindexing is complete.- Parameters:
collection-commit-- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
finalizeChanges
protected void finalizeChanges(String collection, boolean error, boolean swap) throws org.broadleafcommerce.common.exception.ServiceException Composite method that issues a commit or rollback (if there is an error), and optionally swaps (if there is no error).- Parameters:
collection-error-swap-- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
swapCollections
protected void swapCollections() throws org.broadleafcommerce.common.exception.ServiceException- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
destroy
- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Throws:
Exception
-
getBackgroundOperationExecutor
protected org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor getBackgroundOperationExecutor() -
getThreadsForBackgroundExecution
protected int getThreadsForBackgroundExecution()Number of worker threads (page processing threads) in the thread pool.Default is 10.
- Returns:
-
createBackgroundOperationExecutor
protected org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor createBackgroundOperationExecutor() -
createBackgroundRunnable
protected org.broadleafcommerce.common.util.EntityManagerAwareRunnable createBackgroundRunnable(ReindexStateHolder holder, List<Long> ids, Semaphore sem, Long catalogId, Long siteId, org.broadleafcommerce.common.sandbox.domain.SandBox sandBox) This is where most of the heavy lifting happens.- Parameters:
holder-ids-sem-catalogId-siteId-sandBox-- Returns:
-
getIncrementalIndexOperation
protected org.broadleafcommerce.common.util.tenant.IdentityOperation<Void,Exception> getIncrementalIndexOperation(ReindexStateHolder holder, org.broadleafcommerce.common.site.domain.Catalog catalog, org.broadleafcommerce.common.site.domain.Site site, List<Long> ids) Returns anIdentityOperationwho may be executed in the context of aCatalogand/orSiteto read products by IDs, and then build the index incrementally.- Parameters:
holder-catalog-site-ids-- Returns:
-
buildPage
protected List<org.apache.solr.common.SolrInputDocument> buildPage(List<Long> productIds, List<Product> products, List<org.broadleafcommerce.common.locale.domain.Locale> locales, List<IndexField> fields, ReindexStateHolder holder) throws Exception Given the arguments, this builds a list ofSolrInputDocuments. This does not write them to Solr.- Parameters:
productIds-products-locales-fields-holder-- Returns:
- Throws:
Exception
-
readProductsByIds
protected List<Product> readProductsByIds(ReindexStateHolder holder, List<Long> productIds) throws Exception Reads a batch of products by IDs.- Parameters:
holder-productIds-- Returns:
- Throws:
Exception
-
getIndexFields
-
buildIncrementalIndex
protected void buildIncrementalIndex(List<Long> productIds, List<Product> products, ReindexStateHolder holder, org.broadleafcommerce.common.site.domain.Catalog catalog, org.broadleafcommerce.common.site.domain.Site site) throws Exception Builds an incremental or batch portion of the index. Activities include readingLocales andIndexFields, building a page, adding the documents to the index, and incrementally committing. It is not recommended that you override this method. Rather, consider overriding one of the other methods as this is largely responsible for orchestrating and delegating.- Parameters:
productIds-products-holder-catalog-site-- Throws:
Exception
-
readIdBatch
protected List<Long> readIdBatch(ReindexStateHolder holder, Long catalogId, int batchSize, Long lastId) throws Exception Reads a batch ofProductIDs from the DB.- Parameters:
holder-catalogId-batchSize-lastId-- Returns:
- Throws:
Exception
-
beforeProcess
protected void beforeProcess(ReindexStateHolder holder) throws org.broadleafcommerce.common.exception.ServiceException Hook point that is executed at the beginning of the reindex process. If you extend this class and implement this method, consider calling the super method.- Parameters:
holder-- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
afterProcess
protected void afterProcess(ReindexStateHolder holder) throws org.broadleafcommerce.common.exception.ServiceException Hook point at that is executed at the end of the reindex process. If you extend this class and implement this method, consider calling the super method. Note that you can query theReindexStateHolderto determine if an error has occured during the process.- Parameters:
holder-- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
beforeBackgroundThread
protected void beforeBackgroundThread(ReindexStateHolder holder, org.broadleafcommerce.common.site.domain.Catalog catalog, org.broadleafcommerce.common.site.domain.Site site, org.broadleafcommerce.common.sandbox.domain.SandBox sandBox) throws org.broadleafcommerce.common.exception.ServiceException The reindex process, specifically page processing, is executed in background threads. This executes prior to the main execution of the thread. If you extend this class and implement this method, consider calling the super method. Note that you can query theReindexStateHolderto determine if an error has occurred during the process.- Parameters:
holder-catalog-site-sandBox-- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
afterBackgroundThread
protected void afterBackgroundThread(ReindexStateHolder holder, org.broadleafcommerce.common.site.domain.Catalog catalog, org.broadleafcommerce.common.site.domain.Site site, org.broadleafcommerce.common.sandbox.domain.SandBox sandBox) throws org.broadleafcommerce.common.exception.ServiceException This executes after to the main execution of the background (page) thread(s). If you extend this class and implement this method, consider calling the super method. Note that you can query theReindexStateHolderto determine if an error has occurred during the process.- Parameters:
holder-catalog-site-sandBox-- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
beforePage
protected void beforePage(List<Long> productIds, List<Product> products, List<org.broadleafcommerce.common.locale.domain.Locale> locales, List<IndexField> fields, ReindexStateHolder holder) throws org.broadleafcommerce.common.exception.ServiceException This is executed immediately before a page is processed. If you extend this class and implement this method, consider calling the super method. Note that you can query theReindexStateHolderto determine if an error has occurred during the process.- Parameters:
productIds-products-locales-fields-holder-- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
afterPage
protected void afterPage(List<Long> productIds, List<Product> products, List<org.broadleafcommerce.common.locale.domain.Locale> locales, List<IndexField> fields, ReindexStateHolder holder) throws org.broadleafcommerce.common.exception.ServiceException This executes immediately after a page is processed. If you extend this class and implement this method, consider calling the super method. Note that you can query theReindexStateHolderto determine if an error has occurred during the process.- Parameters:
productIds-products-locales-fields-holder-- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
beforeReadProducts
protected void beforeReadProducts(ReindexStateHolder holder, List<Long> productIds) throws org.broadleafcommerce.common.exception.ServiceException This executes immediately prior to reading a batch of products. If you extend this class and implement this method, consider calling the super method. Note that you can query theReindexStateHolderto determine if an error has occurred during the process.- Parameters:
holder-productIds-- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
afterReadProducts
protected void afterReadProducts(ReindexStateHolder holder, List<Long> productIds) throws org.broadleafcommerce.common.exception.ServiceException This executes immediately after reading a batch of products. If you extend this class and implement this method, consider calling the super method. Note that you can query theReindexStateHolderto determine if an error has occurred during the process.- Parameters:
holder-productIds-- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
beforeReadIdBatch
protected void beforeReadIdBatch(ReindexStateHolder holder, Long catalogId, int batchSize, Long lastId) throws org.broadleafcommerce.common.exception.ServiceException This executes immediately prior to reading a batch of product IDs for processing in a background thread. If you extend this class and implement this method, consider calling the super method. Note that you can query theReindexStateHolderto determine if an error has occurred during the process.- Parameters:
holder-catalogId-batchSize-lastId-- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
afterReadIdBatch
protected void afterReadIdBatch(ReindexStateHolder holder, Long catalogId, int batchSize, Long lastId) throws org.broadleafcommerce.common.exception.ServiceException This executes immediately after reading a batch of product IDs for processing in a background thread. If you extend this class and implement this method, consider calling the super method. Note that you can query theReindexStateHolderto determine if an error has occurred during the process.- Parameters:
holder-catalogId-batchSize-lastId-- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
findCatalog
This reads aCatalogby ID. If the ID is null (default, unless in Multi-Tenant mode), this returns null.- Parameters:
catalogId-- Returns:
-
findSite
This reads aSiteby ID. If the ID is null (default, unless in Multi-Tenant mode), this returns null.- Parameters:
siteId-- Returns:
-
getIncrementalCommitInterval
protected long getIncrementalCommitInterval()The amount of time between commits during a full reindex. Commits are global, so there's no need to have every thread committing every page.Default is 30 seconds.
- Returns:
-
incrementalCommit
Issues incremental commits. Commits in Sorl are global, so we don't need multiple threads issuing commits at the same time, or even back-to-back. This uses a commit interval to determine if a commit should be issued.- Parameters:
holder-- Throws:
Exception
-
isReindexSuccessful
Method to determine whether a full reindex was successful. By default, this simply returns whether theReindexStateHolder.isFailed()returns false and that at least 1 document was indexed. Implementors may wish to override this to determine whether theReindexStateHolder.getIndexableCount()is a certain number, or ifReindexStateHolder.getUnindexedItemCount()is at least a percentage of total items or of the items that were indexed, given that the failure to build a single document / product does not stop the reindex process.- Parameters:
holder-- Returns:
-