Fixing problem with VClassGroupCache creation NIHVIVO-3453.
Removing log message on IndexBuilder because of slf4j on shutdown problem
This commit is contained in:
parent
c7303bb623
commit
52c3838b44
2 changed files with 75 additions and 48 deletions
|
@ -112,6 +112,11 @@ public class VClassGroupCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized List<VClassGroup> getGroups() {
|
public synchronized List<VClassGroup> getGroups() {
|
||||||
|
//try to build the cache if it doesn't exist
|
||||||
|
if (_groupList == null){
|
||||||
|
doSynchronousRebuild();
|
||||||
|
}
|
||||||
|
|
||||||
if (_groupList == null){
|
if (_groupList == null){
|
||||||
log.error("VClassGroup cache has not been created");
|
log.error("VClassGroup cache has not been created");
|
||||||
requestCacheUpdate();
|
requestCacheUpdate();
|
||||||
|
@ -123,15 +128,21 @@ public class VClassGroupCache {
|
||||||
|
|
||||||
// Get specific VClass corresponding to Map
|
// Get specific VClass corresponding to Map
|
||||||
public synchronized VClass getCachedVClass(String classUri) {
|
public synchronized VClass getCachedVClass(String classUri) {
|
||||||
if( VclassMap != null){
|
//try to build the cache if it doesn't exist
|
||||||
if (VclassMap.containsKey(classUri)) {
|
if ( VclassMap == null ){
|
||||||
return VclassMap.get(classUri);
|
doSynchronousRebuild();
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}else{
|
if( VclassMap == null){
|
||||||
log.error("VClassGroup cache has not been created");
|
log.error("VClassGroup cache has not been created");
|
||||||
requestCacheUpdate();
|
requestCacheUpdate();
|
||||||
return null;
|
return null;
|
||||||
|
}else{
|
||||||
|
if (VclassMap.containsKey(classUri)) {
|
||||||
|
return VclassMap.get(classUri);
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +162,7 @@ public class VClassGroupCache {
|
||||||
try {
|
try {
|
||||||
_cacheRebuildThread.join();
|
_cacheRebuildThread.join();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
log.warn("Waiting for the thread to die, but interrupted.", e);
|
//don't log message since shutting down
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,12 +176,57 @@ public class VClassGroupCache {
|
||||||
return wdf.getVClassGroupDao();
|
return wdf.getVClassGroupDao();
|
||||||
}
|
}
|
||||||
|
|
||||||
// protected void doSynchronousRebuild(){
|
protected void doSynchronousRebuild(){
|
||||||
// _cacheRebuildThread.rebuildCacheUsingSolr(this);
|
//try to rebuild a couple times since the Solr server may not yet be up.
|
||||||
// }
|
|
||||||
|
int attempts = 0;
|
||||||
|
int maxTries = 3;
|
||||||
|
SolrServerException exception = null;
|
||||||
|
|
||||||
|
while( attempts < 2 ){
|
||||||
|
try {
|
||||||
|
rebuildCacheUsingSolr(this);
|
||||||
|
break;
|
||||||
|
} catch (SolrServerException e) {
|
||||||
|
exception = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( exception != null )
|
||||||
|
log.error("could not rebuild cache after " + maxTries + " attempts: " + exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
/* **************** static utility methods ***************** */
|
/* **************** static utility methods ***************** */
|
||||||
|
|
||||||
|
protected static void rebuildCacheUsingSolr( VClassGroupCache cache ) throws SolrServerException{
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
WebappDaoFactory wdFactory = (WebappDaoFactory) cache.context.getAttribute("webappDaoFactory");
|
||||||
|
if (wdFactory == null)
|
||||||
|
log.error("Unable to rebuild cache: could not get 'webappDaoFactory' from Servletcontext");
|
||||||
|
|
||||||
|
SolrServer solrServer = (SolrServer)cache.context.getAttribute(SolrSetup.SOLR_SERVER);
|
||||||
|
if( solrServer == null)
|
||||||
|
log.error("Unable to rebuild cache: could not get solrServer from ServletContext");
|
||||||
|
|
||||||
|
ProhibitedFromSearch pfs = (ProhibitedFromSearch)cache.context.getAttribute(SolrSetup.PROHIBITED_FROM_SEARCH);
|
||||||
|
if(pfs==null)
|
||||||
|
log.error("Unable to rebuild cache: could not get ProhibitedFromSearch from ServletContext");
|
||||||
|
|
||||||
|
VitroFilters vFilters = VitroFilterUtils.getPublicFilter(cache.context);
|
||||||
|
WebappDaoFactory filteringDaoFactory = new WebappDaoFactoryFiltering(wdFactory, vFilters);
|
||||||
|
|
||||||
|
List<VClassGroup> groups = getGroups(
|
||||||
|
filteringDaoFactory.getVClassGroupDao(), !INCLUDE_INDIVIDUAL_COUNT);
|
||||||
|
|
||||||
|
// Remove classes that have been configured to be hidden from search results.
|
||||||
|
removeClassesHiddenFromSearch(groups,pfs);
|
||||||
|
|
||||||
|
addCountsUsingSolr(groups, solrServer);
|
||||||
|
|
||||||
|
cache.setCache(groups, classMapForGroups(groups));
|
||||||
|
log.debug("msec to build cache: " + (System.currentTimeMillis() - start));
|
||||||
|
}
|
||||||
|
|
||||||
protected static List<VClassGroup> getGroups(VClassGroupDao vcgDao,
|
protected static List<VClassGroup> getGroups(VClassGroupDao vcgDao,
|
||||||
boolean includeIndividualCount) {
|
boolean includeIndividualCount) {
|
||||||
// Get all classgroups, each populated with a list of their member vclasses
|
// Get all classgroups, each populated with a list of their member vclasses
|
||||||
|
@ -267,7 +323,7 @@ public class VClassGroupCache {
|
||||||
* Add the Individual count to classes in groups.
|
* Add the Individual count to classes in groups.
|
||||||
* @throws SolrServerException
|
* @throws SolrServerException
|
||||||
*/
|
*/
|
||||||
private void addCountsUsingSolr(List<VClassGroup> groups, SolrServer solrServer) throws SolrServerException {
|
protected static void addCountsUsingSolr(List<VClassGroup> groups, SolrServer solrServer) throws SolrServerException {
|
||||||
|
|
||||||
if( groups == null || solrServer == null )
|
if( groups == null || solrServer == null )
|
||||||
return;
|
return;
|
||||||
|
@ -278,7 +334,7 @@ public class VClassGroupCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addClassCountsToGroup(VClassGroup group, SolrServer solrServer) throws SolrServerException {
|
protected static void addClassCountsToGroup(VClassGroup group, SolrServer solrServer) throws SolrServerException {
|
||||||
if( group == null ) return;
|
if( group == null ) return;
|
||||||
|
|
||||||
String groupUri = group.getURI();
|
String groupUri = group.getURI();
|
||||||
|
@ -309,7 +365,7 @@ public class VClassGroupCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setClassCount(VClassGroup group, String classUri,
|
protected static void setClassCount(VClassGroup group, String classUri,
|
||||||
long individualsInClass) {
|
long individualsInClass) {
|
||||||
for( VClass clz : group){
|
for( VClass clz : group){
|
||||||
if( clz.getURI().equals(classUri)){
|
if( clz.getURI().equals(classUri)){
|
||||||
|
@ -355,7 +411,7 @@ public class VClassGroupCache {
|
||||||
timeToBuildLastCache = System.currentTimeMillis() - start;
|
timeToBuildLastCache = System.currentTimeMillis() - start;
|
||||||
log.debug("rebuildGroupCacheThread.run() -- rebuilt cache in "
|
log.debug("rebuildGroupCacheThread.run() -- rebuilt cache in "
|
||||||
+ timeToBuildLastCache + " msec");
|
+ timeToBuildLastCache + " msec");
|
||||||
delay = 0;
|
delay = 100;
|
||||||
} catch (SolrServerException e) {
|
} catch (SolrServerException e) {
|
||||||
//wait a couple seconds and try again.
|
//wait a couple seconds and try again.
|
||||||
log.error("Will attempt to rebuild cache once solr comes up.");
|
log.error("Will attempt to rebuild cache once solr comes up.");
|
||||||
|
@ -382,34 +438,7 @@ public class VClassGroupCache {
|
||||||
log.debug("rebuildGroupCacheThread.run() -- die()");
|
log.debug("rebuildGroupCacheThread.run() -- die()");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void rebuildCacheUsingSolr(VClassGroupCache cache ) throws SolrServerException{
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
WebappDaoFactory wdFactory = (WebappDaoFactory) cache.context.getAttribute("webappDaoFactory");
|
|
||||||
if (wdFactory == null)
|
|
||||||
log.error("Unable to rebuild cache: could not get 'webappDaoFactory' from Servletcontext");
|
|
||||||
|
|
||||||
SolrServer solrServer = (SolrServer)cache.context.getAttribute(SolrSetup.SOLR_SERVER);
|
|
||||||
if( solrServer == null)
|
|
||||||
log.error("Unable to rebuild cache: could not get solrServer from ServletContext");
|
|
||||||
|
|
||||||
ProhibitedFromSearch pfs = (ProhibitedFromSearch)cache.context.getAttribute(SolrSetup.PROHIBITED_FROM_SEARCH);
|
|
||||||
if(pfs==null)
|
|
||||||
log.error("Unable to rebuild cache: could not get ProhibitedFromSearch from ServletContext");
|
|
||||||
|
|
||||||
VitroFilters vFilters = VitroFilterUtils.getPublicFilter(context);
|
|
||||||
WebappDaoFactory filteringDaoFactory = new WebappDaoFactoryFiltering(wdFactory, vFilters);
|
|
||||||
|
|
||||||
List<VClassGroup> groups = getGroups(
|
|
||||||
filteringDaoFactory.getVClassGroupDao(), !INCLUDE_INDIVIDUAL_COUNT);
|
|
||||||
|
|
||||||
// Remove classes that have been configured to be hidden from search results.
|
|
||||||
removeClassesHiddenFromSearch(groups,pfs);
|
|
||||||
|
|
||||||
addCountsUsingSolr(groups, solrServer);
|
|
||||||
|
|
||||||
cache.setCache(groups, classMapForGroups(groups));
|
|
||||||
log.debug("msec to build cache: " + (System.currentTimeMillis() - start));
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized void informOfQueueChange() {
|
synchronized void informOfQueueChange() {
|
||||||
queueChangeMillis = System.currentTimeMillis();
|
queueChangeMillis = System.currentTimeMillis();
|
||||||
|
|
|
@ -180,8 +180,6 @@ public class IndexBuilder extends VitroBackgroundThread {
|
||||||
|
|
||||||
if( indexer != null)
|
if( indexer != null)
|
||||||
indexer.abortIndexingAndCleanUp();
|
indexer.abortIndexingAndCleanUp();
|
||||||
|
|
||||||
log.info("Stopping IndexBuilder thread");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue