NIHVIVO-3209 Simplify logic in IndexBuilder; don't expose intermediate results as instance variables, where they could be subject to concurrency issues.
This commit is contained in:
parent
9f95c3fbc7
commit
be06b68871
1 changed files with 32 additions and 44 deletions
|
@ -58,17 +58,6 @@ public class IndexBuilder extends Thread {
|
||||||
* updated in the search index when a statement changes. */
|
* updated in the search index when a statement changes. */
|
||||||
protected List<StatementToURIsToUpdate> stmtToURIsToIndexFunctions;
|
protected List<StatementToURIsToUpdate> stmtToURIsToIndexFunctions;
|
||||||
|
|
||||||
/**
|
|
||||||
* updatedUris will only be accessed from the IndexBuilder thread
|
|
||||||
* so it doesn't need to be synchronized.
|
|
||||||
*/
|
|
||||||
private List<String> updatedUris = null;
|
|
||||||
/**
|
|
||||||
* deletedUris will only be accessed from the IndexBuilder thread
|
|
||||||
* so it doesn't need to be synchronized.
|
|
||||||
*/
|
|
||||||
private List<String> deletedUris = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that a full index re-build has been requested.
|
* Indicates that a full index re-build has been requested.
|
||||||
*/
|
*/
|
||||||
|
@ -101,8 +90,8 @@ public class IndexBuilder extends Thread {
|
||||||
super("IndexBuilder");
|
super("IndexBuilder");
|
||||||
|
|
||||||
this.indexer = indexer;
|
this.indexer = indexer;
|
||||||
this.wdf = wdf;
|
|
||||||
|
|
||||||
|
this.wdf = wdf;
|
||||||
if( stmtToURIsToIndexFunctions != null )
|
if( stmtToURIsToIndexFunctions != null )
|
||||||
this.stmtToURIsToIndexFunctions = stmtToURIsToIndexFunctions;
|
this.stmtToURIsToIndexFunctions = stmtToURIsToIndexFunctions;
|
||||||
else
|
else
|
||||||
|
@ -248,32 +237,29 @@ public class IndexBuilder extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets updatedUris and deletedUris lists from the changedStmtQueue.
|
* Take the URIs that we got from the changedStmtQueue, and create the lists
|
||||||
* updatedUris and deletedUris will only be accessed from the IndexBuilder thread
|
* of updated URIs and deleted URIs.
|
||||||
* so they don't need to be synchronized.
|
|
||||||
*/
|
*/
|
||||||
private void makeAddAndDeleteLists( Collection<String> uris){
|
private UriLists makeAddAndDeleteLists(Collection<String> uris) {
|
||||||
IndividualDao indDao = wdf.getIndividualDao();
|
IndividualDao indDao = wdf.getIndividualDao();
|
||||||
|
|
||||||
/* clear updateInds and deletedUris. This is the only method that should set these. */
|
UriLists uriLists = new UriLists();
|
||||||
this.updatedUris = new LinkedList<String>();
|
for (String uri : uris) {
|
||||||
this.deletedUris = new LinkedList<String>();
|
if (uri != null) {
|
||||||
|
try {
|
||||||
for( String uri: uris){
|
Individual ind = indDao.getIndividualByURI(uri);
|
||||||
if( uri != null ){
|
if (ind != null) {
|
||||||
try{
|
uriLists.updatedUris.add(uri);
|
||||||
Individual ind = indDao.getIndividualByURI(uri);
|
} else {
|
||||||
if( ind != null)
|
log.debug("found delete in changed uris");
|
||||||
this.updatedUris.add(uri);
|
uriLists.deletedUris.add(uri);
|
||||||
else{
|
}
|
||||||
log.debug("found delete in changed uris");
|
} catch (QueryParseException ex) {
|
||||||
this.deletedUris.add(uri);
|
log.error("could not get Individual " + uri, ex);
|
||||||
}
|
}
|
||||||
} catch(QueryParseException ex){
|
}
|
||||||
log.error("could not get Individual "+ uri,ex);
|
}
|
||||||
}
|
return uriLists;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -298,13 +284,10 @@ public class IndexBuilder extends Thread {
|
||||||
protected void updatedIndex() {
|
protected void updatedIndex() {
|
||||||
log.debug("Starting updateIndex()");
|
log.debug("Starting updateIndex()");
|
||||||
|
|
||||||
makeAddAndDeleteLists( statementsToUris(getAndEmptyChangedStatements()) );
|
UriLists uriLists = makeAddAndDeleteLists( statementsToUris(getAndEmptyChangedStatements()) );
|
||||||
|
|
||||||
this.numberOfThreads = Math.max( MAX_UPDATE_THREADS, updatedUris.size() / 20);
|
this.numberOfThreads = Math.max( MAX_UPDATE_THREADS, uriLists.updatedUris.size() / 20);
|
||||||
doBuild( updatedUris.iterator(), deletedUris );
|
doBuild( uriLists.updatedUris.iterator(), uriLists.deletedUris );
|
||||||
|
|
||||||
this.updatedUris = null;
|
|
||||||
this.deletedUris = null;
|
|
||||||
|
|
||||||
log.debug("Ending updateIndex()");
|
log.debug("Ending updateIndex()");
|
||||||
}
|
}
|
||||||
|
@ -453,6 +436,11 @@ public class IndexBuilder extends Thread {
|
||||||
synchronized( changedStmtQueue ){
|
synchronized( changedStmtQueue ){
|
||||||
return reindexRequested || ! changedStmtQueue.isEmpty() ;
|
return reindexRequested || ! changedStmtQueue.isEmpty() ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class UriLists {
|
||||||
|
private final List<String> updatedUris = new ArrayList<String>();
|
||||||
|
private final List<String> deletedUris = new ArrayList<String>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue