Ignore EngineClosedException on IndexShard#sync

This method syncs the translog unless it's already synced. If the engine
is alreayd closed we are guaranteed to be synced already such that we can just
ignore this exception.

Closes #12603
This commit is contained in:
Simon Willnauer 2015-08-04 15:43:17 +02:00
parent 96ad1911fd
commit 8f6e75b158
2 changed files with 4 additions and 7 deletions

View File

@ -211,12 +211,7 @@ public class TransportIndexAction extends TransportReplicationAction<IndexReques
}
if (indexShard.getTranslogDurability() == Translog.Durabilty.REQUEST && location != null) {
try {
indexShard.sync(location);
} catch (EngineClosedException e) {
// ignore, the engine is already closed and we do not want the
// operation to be retried, because it has been modified
}
}
}
}

View File

@ -1403,9 +1403,11 @@ public class IndexShard extends AbstractIndexShardComponent {
* Syncs the given location with the underlying storage unless already synced.
*/
public void sync(Translog.Location location) {
final Engine engine = engine();
try {
final Engine engine = engine();
engine.getTranslog().ensureSynced(location);
} catch (EngineClosedException ex) {
// that's fine since we already synced everything on engine close - this also is conform with the methods documentation
} catch (IOException ex) { // if this fails we are in deep shit - fail the request
logger.debug("failed to sync translog", ex);
throw new ElasticsearchException("failed to sync translog", ex);