use of org.broadleafcommerce.common.util.StopWatch in project BroadleafCommerce by BroadleafCommerce.
the class SolrIndexServiceImpl method executeSolrIndexOperation.
@Override
public void executeSolrIndexOperation(final SolrIndexOperation operation) throws ServiceException, IOException {
operation.obtainLock();
try {
LOG.info("Executing Indexing operation");
StopWatch s = new StopWatch();
Object[] pack = saveState();
try {
final Long numItemsToIndex;
try {
operation.beforeCountIndexables();
numItemsToIndex = operation.countIndexables();
} finally {
operation.afterCountIndexables();
}
if (LOG.isDebugEnabled()) {
LOG.debug("There are at most " + numItemsToIndex + " items to index");
}
performCachedOperation(new SolrIndexCachedOperation.CacheOperation() {
@Override
public void execute() throws ServiceException {
int page = 1;
Long lastId = null;
Long remainingNumItemsToIndex = numItemsToIndex;
Long totalPages = getTotalPageCount(numItemsToIndex);
while (remainingNumItemsToIndex > 0) {
String pageNumberMessage = buildPageNumberMessage(page, totalPages);
LOG.info(pageNumberMessage);
lastId = buildIncrementalIndex(pageSize, lastId, operation);
remainingNumItemsToIndex -= pageSize;
page++;
}
}
});
} finally {
restoreState(pack);
}
LOG.info(String.format("Indexing operation completed in %s", s.toLapString()));
} finally {
operation.releaseLock();
}
}
use of org.broadleafcommerce.common.util.StopWatch in project BroadleafCommerce by BroadleafCommerce.
the class SolrIndexServiceImpl method buildIncrementalIndex.
@Override
public Collection<SolrInputDocument> buildIncrementalIndex(List<? extends Indexable> indexables, SolrClient solrServer) throws ServiceException {
TransactionStatus status = TransactionUtils.createTransaction("executeIncrementalIndex", TransactionDefinition.PROPAGATION_REQUIRED, transactionManager, true);
if (SolrIndexCachedOperation.getCache() == null) {
LOG.warn("Consider using SolrIndexService.performCachedOperation() in combination with " + "SolrIndexService.buildIncrementalIndex() for better caching performance during solr indexing");
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Building incremental product index - pageSize: [%s]...", indexables.size()));
}
StopWatch s = new StopWatch();
try {
sandBoxHelper.ignoreCloneCache(true);
extensionManager.getProxy().startBatchEvent(indexables);
Collection<SolrInputDocument> documents = new ArrayList<>();
List<Locale> locales = getAllLocales();
List<Long> productIds = BLCCollectionUtils.collectList(indexables, new TypedTransformer<Long>() {
@Override
public Long transform(Object input) {
return shs.getCurrentProductId((Indexable) input);
}
});
solrIndexDao.populateProductCatalogStructure(productIds, SolrIndexCachedOperation.getCache());
List<IndexField> fields = null;
FieldEntity currentFieldType = null;
for (Indexable indexable : indexables) {
if (fields == null || ObjectUtils.notEqual(currentFieldType, indexable.getFieldEntityType())) {
fields = indexFieldDao.readFieldsByEntityType(indexable.getFieldEntityType());
}
SolrInputDocument doc = buildDocument(indexable, fields, locales);
// to the index.
if (doc != null) {
documents.add(doc);
}
}
extensionManager.getProxy().modifyBuiltDocuments(documents, indexables, fields, locales);
logDocuments(documents);
if (!CollectionUtils.isEmpty(documents) && solrServer != null) {
solrServer.add(documents);
commit(solrServer);
}
TransactionUtils.finalizeTransaction(status, transactionManager, false);
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Built incremental product index - pageSize: [%s] in [%s]", indexables.size(), s.toLapString()));
}
return documents;
} catch (SolrServerException e) {
TransactionUtils.finalizeTransaction(status, transactionManager, true);
throw new ServiceException("Could not rebuild index", e);
} catch (IOException e) {
TransactionUtils.finalizeTransaction(status, transactionManager, true);
throw new ServiceException("Could not rebuild index", e);
} catch (RuntimeException e) {
TransactionUtils.finalizeTransaction(status, transactionManager, true);
throw e;
} finally {
extensionManager.getProxy().endBatchEvent(indexables);
sandBoxHelper.ignoreCloneCache(false);
}
}
use of org.broadleafcommerce.common.util.StopWatch in project BroadleafCommerce by BroadleafCommerce.
the class SolrIndexServiceImpl method rebuildIndex.
@Override
public void rebuildIndex() throws ServiceException, IOException {
LOG.info("Rebuilding the entire Solr index...");
StopWatch s = new StopWatch();
preBuildIndex();
buildIndex();
postBuildIndex();
LOG.info(String.format("Finished building entire Solr index in %s", s.toLapString()));
}
Aggregations