working on memory leak NIHVIVO-2782

This commit is contained in:
briancaruso 2011-06-29 23:53:23 +00:00
parent 025fb1b435
commit 1031455e4c
9 changed files with 98 additions and 37 deletions

View file

@ -13,6 +13,7 @@ import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.rdf.model.Model;
@ -74,9 +75,12 @@ public class ObjectPropertyStatementDaoSDB extends
DatasetWrapper w = dwf.getDatasetWrapper();
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);
QueryExecution qexec = null;
try {
m = QueryExecutionFactory.create(QueryFactory.create(query), dataset).execConstruct();
qexec = QueryExecutionFactory.create(QueryFactory.create(query), dataset);
m = qexec.execConstruct();
} finally {
if(qexec != null) qexec.close();
dataset.getLock().leaveCriticalSection();
w.close();
}

View file

@ -133,6 +133,11 @@ public class VitroRequestPrep implements Filter {
//This will replace the WebappDaoFactory with a different version if menu management parameter is found
wdf = checkForSpecialWDF(vreq, wdf);
// request.setAttribute("aboxModel", setspeicalABoxModel)
// request.setAttribute("tboxModel", speicalTboxModel)
// request.setAttribute("infModel", speicalInfModel) (maybe?)
// request.setAttribute("displayModel", displayModel)
VitroFilters filters = null;
filters = getFiltersFromContextFilterFactory(req, wdf);

View file

@ -146,6 +146,7 @@ public class IndexBuilder extends Thread {
}
}
indexer.abortIndexingAndCleanUp();
if(log != null )//may be null on shutdown
log.info("Stopping IndexBuilder thread");

View file

@ -36,6 +36,7 @@ import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames;
public class CalculateParameters implements DocumentModifier {
private boolean shutdown = false;
private Dataset dataset;
public static int totalInd=1;
protected Map<String,Float> betaMap = new Hashtable<String,Float>();
@ -91,10 +92,10 @@ public class CalculateParameters implements DocumentModifier {
Resource uriResource = ResourceFactory.createResource(uri);
initialBinding.add("uri", uriResource);
dataset.getLock().enterCriticalSection(Lock.READ);
QueryExecution qexec=null;
try{
query = QueryFactory.create(betaQuery,Syntax.syntaxARQ);
QueryExecution qexec = QueryExecutionFactory.create(query,dataset,initialBinding);
qexec = QueryExecutionFactory.create(query,dataset,initialBinding);
ResultSet results = qexec.execSelect();
List<String> resultVars = results.getResultVars();
if(resultVars!=null && resultVars.size()!=0){
@ -102,8 +103,11 @@ public class CalculateParameters implements DocumentModifier {
Conn = Integer.parseInt(soln.getLiteral(resultVars.get(0)).getLexicalForm());
}
}catch(Throwable t){
if( ! shutdown )
log.error(t,t);
}finally{
if( qexec != null )
qexec.close();
dataset.getLock().leaveCriticalSection();
}
@ -238,6 +242,7 @@ public class CalculateParameters implements DocumentModifier {
}
}
}catch(Exception e){
if( ! shutdown )
log.error("Error found in getAdjacentNodes method of SearchQueryHandler");
}finally{
qexec.close();
@ -260,6 +265,7 @@ public class CalculateParameters implements DocumentModifier {
}
catch(Throwable t){
if( ! shutdown )
log.error(t,t);
}finally{
dataset.getLock().leaveCriticalSection();
@ -285,16 +291,19 @@ public class CalculateParameters implements DocumentModifier {
for(String term: fieldsToAddBetaTo){
SolrInputField f = doc.getField( term );
f.setBoost( getBeta(uri) + phi + IndividualToSolrDocument.NAME_BOOST);
float orgBoost = f.getBoost();
f.setBoost( getBeta(uri) + phi + orgBoost );
}
for(String term: fieldsToMultiplyBetaBy){
SolrInputField f = doc.getField( term );
f.addValue(info.toString(),getBeta(uri)*phi*IndividualToSolrDocument.ALL_TEXT_BOOST);
//f.addValue(info.toString(),getBeta(uri)*phi*IndividualToSolrDocument.ALL_TEXT_BOOST);
}
SolrInputField f = doc.getField(VitroSearchTermNames.targetInfo);
f.addValue(adjInfo[1],f.getBoost());
//SolrInputField f = doc.getField(VitroSearchTermNames.targetInfo);
//f.addValue(adjInfo[1],f.getBoost());
doc.setDocumentBoost(getBeta(uri)*phi*IndividualToSolrDocument.ALL_TEXT_BOOST);
log.debug("Parameter calculation is done");
@ -304,6 +313,9 @@ public class CalculateParameters implements DocumentModifier {
betaMap.clear();
}
public void shutdown(){
shutdown=true;
}
}
class TotalInd implements Runnable{
@ -321,10 +333,11 @@ class TotalInd implements Runnable{
Query query;
QuerySolution soln = null;
dataset.getLock().enterCriticalSection(Lock.READ);
QueryExecution qexec = null;
try{
query = QueryFactory.create(totalCountQuery,Syntax.syntaxARQ);
QueryExecution qexec = QueryExecutionFactory.create(query,dataset);
qexec = QueryExecutionFactory.create(query,dataset);
ResultSet results = qexec.execSelect();
List<String> resultVars = results.getResultVars();
@ -337,8 +350,12 @@ class TotalInd implements Runnable{
}catch(Throwable t){
log.error(t,t);
}finally{
if( qexec != null )
qexec.close();
dataset.getLock().leaveCriticalSection();
}
}
}

View file

@ -35,6 +35,7 @@ import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames;
public class ContextNodeFields implements DocumentModifier{
private Model model;
private boolean shutdown = false;
private static ExecutorService threadPool = null;
private static final int THREAD_POOL_SIZE = 10;
@ -134,6 +135,7 @@ public class ContextNodeFields implements DocumentModifier{
}
}
}catch(Throwable t){
if( ! shutdown )
log.error(t,t);
} finally{
qExec.close();
@ -437,4 +439,7 @@ public class ContextNodeFields implements DocumentModifier{
}
}
public void shutdown(){
shutdown=true;
}
}

View file

@ -12,4 +12,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual;
public interface DocumentModifier {
public void modifyDocument(Individual individual, SolrInputDocument doc, StringBuffer addUri);
//called to inform the DocumentModifier that the system is shutting down
public void shutdown();
}

View file

@ -315,6 +315,17 @@ public class IndividualToSolrDocument {
return ent;
}
public void shutdown(){
for(DocumentModifier dm: documentModifiers){
try{
dm.shutdown();
}catch(Exception e){
if( log != null)
log.debug(e,e);
}
}
}
private void fillContextNodes(){
IndividualToSolrDocument.contextNodeClassNames.add("Role");
IndividualToSolrDocument.contextNodeClassNames.add("AttendeeRole");

View file

@ -158,8 +158,25 @@ public class SolrIndexer implements IndexerIface {
@Override
public void abortIndexingAndCleanUp() {
endIndexing();
try{
server.commit();
}catch(SolrServerException e){
if( log != null)
log.debug("could not commit to solr server, " +
"this should not be a problem since solr will do autocommit");
} catch (IOException e) {
if( log != null)
log.debug("could not commit to solr server, " +
"this should not be a problem since solr will do autocommit");
}
try{
individualToSolrDoc.shutdown();
}catch(Exception e){
if( log != null)
log.warn(e,e);
}
}
@Override
public synchronized void endIndexing() {
@ -179,11 +196,13 @@ public class SolrIndexer implements IndexerIface {
}
}
}
try {
server.optimize();
} catch (Exception e) {
log.error("Could not optimize solr server", e);
}
indexing = false;
notifyAll();
}
@ -215,8 +234,4 @@ public class SolrIndexer implements IndexerIface {
return false;
}
}

View file

@ -563,7 +563,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
return TYPE;
}
public String getTemplate() {
public String Template() {
return config.templateName;
}