SOLR-728 -- Add synchronization to avoid race condition of multiple imports working concurrently

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@707295 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2008-10-23 06:54:56 +00:00
parent ca6e3f100f
commit 1e5562a910
3 changed files with 32 additions and 16 deletions

View File

@ -37,6 +37,9 @@ Bug Fixes
2. SOLR-823: Request parameter variables ${dataimporter.request.xxx} are not resolved
(Mck SembWever, Noble Paul, shalin)
3. SOLR-728: Add synchronization to avoid race condition of multiple imports working concurrently
(Walter Ferrara, shalin)
Documentation
----------------------

View File

@ -141,7 +141,7 @@ public class DataImportHandler extends RequestHandlerBase implements
if (command != null)
rsp.add("command", command);
if (requestParams.debug) {
if (requestParams.debug && (importer == null || !importer.isBusy())) {
// Reload the data-config.xml
importer = null;
if (requestParams.dataConfig != null) {
@ -168,7 +168,7 @@ public class DataImportHandler extends RequestHandlerBase implements
if (command != null && DataImporter.ABORT_CMD.equals(command)) {
importer.runCmd(requestParams, null, null);
} else if (importer.getStatus() != DataImporter.Status.IDLE) {
} else if (importer.isBusy()) {
message = DataImporter.MSG.CMD_RUNNING;
} else if (command != null) {
if (DataImporter.FULL_IMPORT_CMD.equals(command)
@ -202,8 +202,7 @@ public class DataImportHandler extends RequestHandlerBase implements
message = DataImporter.MSG.CONFIG_RELOADED;
}
}
rsp.add("status", importer.getStatus() == DataImporter.Status.IDLE ? "idle"
: "busy");
rsp.add("status", importer.isBusy() ? "busy" : "idle");
rsp.add("importResponse", message);
rsp.add("statusMessages", importer.getStatusMessages());

View File

@ -32,6 +32,8 @@ import java.io.StringReader;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReentrantLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -75,6 +77,8 @@ public class DataImporter {
private SolrCore core;
private ReentrantLock importLock = new ReentrantLock();
/**
* Only for testing purposes
*/
@ -318,6 +322,10 @@ public class DataImporter {
this.status = status;
}
public boolean isBusy() {
return importLock.isLocked();
}
public void doFullImport(SolrWriter writer, RequestParams requestParams,
Map<String, String> variables) {
LOG.info("Starting Full Import");
@ -376,18 +384,24 @@ public class DataImporter {
}.start();
}
void runCmd(RequestParams reqParams, SolrWriter sw,
Map<String, String> variables) {
String command = reqParams.command;
Date lastModified = sw.loadIndexStartTime();
setLastIndexTime(lastModified);
if (command.equals("full-import")) {
doFullImport(sw, reqParams, variables);
} else if (command.equals(DELTA_IMPORT_CMD)) {
doDeltaImport(sw, reqParams, variables);
} else if (command.equals(ABORT_CMD)) {
if (docBuilder != null)
docBuilder.abort();
void runCmd(RequestParams reqParams, SolrWriter sw, Map<String, String> variables) {
if (importLock.isLocked())
return;
importLock.lock();
try {
String command = reqParams.command;
Date lastModified = sw.loadIndexStartTime();
setLastIndexTime(lastModified);
if (command.equals("full-import")) {
doFullImport(sw, reqParams, variables);
} else if (command.equals(DELTA_IMPORT_CMD)) {
doDeltaImport(sw, reqParams, variables);
} else if (command.equals(ABORT_CMD)) {
if (docBuilder != null)
docBuilder.abort();
}
} finally {
importLock.unlock();
}
}