SOLR-886 -- DataImportHandler should rollback when an import fails or it is aborted

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@725616 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2008-12-11 08:25:38 +00:00
parent b6fbd20943
commit 71c18d5b3c
4 changed files with 25 additions and 5 deletions

View File

@ -106,7 +106,9 @@ New Features
22. SOLR-781: Distributed search ability to sort field.facet values
lexicographically. facet.sort values "true" and "false" are
also deprecated and replaced with "count" and "lex".
(Lars Kotthoff via yonik
(Lars Kotthoff via yonik)
23. SOLR-886: DataImportHandler should rollback when an import fails or it is aborted (shalin)
Optimizations
----------------------

View File

@ -319,6 +319,7 @@ public class DataImporter {
cumulativeStatistics.add(docBuilder.importStatistics);
} catch (Throwable t) {
LOG.error("Full Import failed", t);
docBuilder.rollback();
} finally {
setStatus(Status.IDLE);
config.clearCaches();
@ -342,6 +343,7 @@ public class DataImporter {
cumulativeStatistics.add(docBuilder.importStatistics);
} catch (Throwable t) {
LOG.error("Delta Import Failed", t);
docBuilder.rollback();
} finally {
setStatus(Status.IDLE);
config.clearCaches();

View File

@ -139,8 +139,8 @@ public class DocBuilder {
if (stop.get()) {
if (DataImporter.ABORT_CMD.equals(requestParameters.command)) {
// Dont commit if aborted using command=abort
statusMessages.put("Aborted", DataImporter.DATE_TIME_FORMAT
.format(new Date()));
statusMessages.put("Aborted", DataImporter.DATE_TIME_FORMAT.format(new Date()));
rollback();
} else if (requestParameters.commit) {
// Debug mode, commit if commit=true was specified
commit();
@ -170,6 +170,12 @@ public class DocBuilder {
}
void rollback() {
writer.rollback();
statusMessages.put("", "Indexing failed. Rolled back all changes.");
addStatusMessage("Rolledback");
}
@SuppressWarnings("unchecked")
private void doFullDump() {
addStatusMessage("Full Dump Started");

View File

@ -20,6 +20,7 @@ import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.update.AddUpdateCommand;
import org.apache.solr.update.CommitUpdateCommand;
import org.apache.solr.update.DeleteUpdateCommand;
import org.apache.solr.update.RollbackUpdateCommand;
import org.apache.solr.update.processor.UpdateRequestProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -177,8 +178,17 @@ public class SolrWriter {
try {
CommitUpdateCommand commit = new CommitUpdateCommand(optimize);
processor.processCommit(commit);
} catch (Exception e) {
log.error("Exception while solr commit.", e);
} catch (Throwable t) {
log.error("Exception while solr commit.", t);
}
}
public void rollback() {
try {
RollbackUpdateCommand rollback = new RollbackUpdateCommand();
processor.processRollback(rollback);
} catch (Throwable t) {
log.error("Exception while solr rollback.", t);
}
}