Skip to content

Commit

Permalink
112307: Solr hard commit after removing index
Browse files Browse the repository at this point in the history
  • Loading branch information
Atmire-Kristof committed Feb 21, 2024
1 parent 2685fbd commit 14007e4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private void performStatusUpdate(Context context) throws SearchServiceException,
}
}

indexingService.commit();
indexingService.commit(true);
}

private void updateItem(Context context, IndexableObject indexableObject) throws SolrServerException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ void reIndexContent(Context context, IndexableObject dso)

void commit() throws SearchServiceException;

void commit(boolean hard) throws SearchServiceException;

void optimize() throws SearchServiceException;

void buildSpellCheck() throws SearchServiceException, IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void unIndexContent(Context context, IndexableObject indexableObject, boo
log.info("Try to delete uniqueID:" + uniqueID);
indexObjectServiceFactory.getIndexableObjectFactory(indexableObject).delete(indexableObject);
if (commit) {
solrSearchCore.getSolr().commit(false, false);
solrSearchCore.getSolr().commit(true, true);
}
} catch (IOException | SolrServerException exception) {
log.error(exception.getMessage(), exception);
Expand Down Expand Up @@ -263,7 +263,7 @@ public void unIndexContent(Context context, String searchUniqueID, boolean commi
log.warn("Object not found in Solr index: " + searchUniqueID);
}
if (commit) {
solrSearchCore.getSolr().commit(false, false);
solrSearchCore.getSolr().commit(true, true);
}
}
} catch (SolrServerException e) {
Expand Down Expand Up @@ -1065,7 +1065,7 @@ protected DiscoverResult retrieveResult(Context context, DiscoverQuery query)
log.info("ZombieDocs ");
zombieDocs.forEach(log::info);
solrSearchCore.getSolr().deleteById(zombieDocs);
solrSearchCore.getSolr().commit(false, false);
solrSearchCore.getSolr().commit(true, true);
} else {
valid = true;
}
Expand Down Expand Up @@ -1546,9 +1546,14 @@ public void indexContent(Context context, IndexableObject indexableObject, boole

@Override
public void commit() throws SearchServiceException {
commit(false);
}

@Override
public void commit(boolean hard) throws SearchServiceException {
try {
if (solrSearchCore.getSolr() != null) {
solrSearchCore.getSolr().commit(false, false);
solrSearchCore.getSolr().commit(hard, hard);
}
} catch (IOException | SolrServerException e) {
throw new SearchServiceException(e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ public boolean isUseProxies() {
public void removeIndex(String query) throws IOException,
SolrServerException {
solr.deleteByQuery(query);
solr.commit(false, false);
solr.commit(true, true);
}

@Override
Expand Down Expand Up @@ -1345,7 +1345,7 @@ public void shardSolrIndex() throws IOException, SolrServerException {

//Delete contents of this year from our year query !
solr.deleteByQuery(filterQuery.toString());
solr.commit(false, false);
solr.commit(true, true);

log.info("Moved {} records into core: {}", totalRecords, coreName);
}
Expand Down Expand Up @@ -1530,7 +1530,7 @@ public void reindexBitstreamHits(boolean removeDeletedBitstreams) throws Excepti
//Now that all our new bitstream stats are in place, delete all the old ones !
solr.deleteByQuery("-bundleName:[* TO *] AND type:" + Constants.BITSTREAM);
//Commit everything to wrap up
solr.commit(false, false);
solr.commit(true, true);
//Clean up our directory !
FileUtils.deleteDirectory(tempDirectory);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ private void deleteItem(Item item) throws SQLException, AuthorizeException, IOEx
item = context.reloadEntity(item);
itemService.delete(context, item);
context.commit();
indexer.commit();
indexer.commit(true);
context.restoreAuthSystemState();
}

Expand All @@ -839,7 +839,7 @@ private void deleteSubmission(WorkspaceItem anotherWorkspaceItem)
anotherWorkspaceItem = context.reloadEntity(anotherWorkspaceItem);
workspaceItemService.deleteAll(context, anotherWorkspaceItem);
context.commit();
indexer.commit();
indexer.commit(true);
context.restoreAuthSystemState();
}

Expand All @@ -849,7 +849,7 @@ private void deleteWorkflowItem(XmlWorkflowItem workflowItem)
workflowItem = context.reloadEntity(workflowItem);
workflowService.deleteWorkflowByWorkflowItem(context, workflowItem, admin);
context.commit();
indexer.commit();
indexer.commit(true);
context.restoreAuthSystemState();
}

Expand Down
2 changes: 1 addition & 1 deletion dspace-oai/src/main/java/org/dspace/xoai/app/XOAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ private void clearIndex() throws DSpaceSolrIndexerException {
try {
System.out.println("Clearing index");
solrServerResolver.getServer().deleteByQuery("*:*");
solrServerResolver.getServer().commit(false, false);
solrServerResolver.getServer().commit(true, true);
System.out.println("Index cleared");
} catch (SolrServerException | IOException ex) {
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
Expand Down

0 comments on commit 14007e4

Please sign in to comment.