elasticsearch/elasticsearch — Issue #1441: deleting CouchDB river can leave some docs behind
Author: erickt
Created: 2011-11-04 22:32:18+00:00
State: open

I'm running into a problem trying to atomically reindex a couchdb river. It seems that deleting the couchdb river can occasionally leave behind the `_seq` document. I believe this is happening because the river shutdown process isn't waiting for the couchdb's river indexer thread to exit before deleting all the couchdb river docs.

Here's the code to close the river:

@Override public void close() {
if (closed) {
return;
}
logger.info("closing couchdb stream river");
slurperThread.interrupt();
indexerThread.interrupt();
closed = true;
}

After this function exits, ES goes off to delete all the river documents. However, because the plugin isn't joining on the subthreads, it's possible for the indexer thread to miss the interrupt until after it's updated the `_seq` doc;

....
} catch (InterruptedException e) {
if (closed) {
return;
}
}

// thread halts here.

if (lastSeq != null) {
try {
if (logger.isTraceEnabled()) {
logger.trace("processing [_seq ]: [{}]/[{}]/[{}], last_seq [{}]", riverIndexName, riverName.name(), "_seq", lastSeq);re
}
bulk.add(indexRequest(riverIndexName).type(riverName.name()).id("_seq")
.source(jsonBuilder().startObject().startObject("couchdb").field("last_seq", lastSeq).endObject().endObject()));
} catch (IOException e) {
logger.warn("failed to add last_seq entry to bulk indexing");
}
}
...

If everything happens just right, ES will delete the plugin subdocuments, and this thread will recreate the `_seq` file.

It looks like the other river plugins use threads, but I haven't checked if they're also susceptible to this bug.