Verify shard state if prepareCreate/prepareIndex fails
This is pretty much a workaround for the fact that we simply close the downstream resources once the shard is closed. This means the document parser will barf with NPE or something similar while AlreadyClosedException would be approriate.
This commit is contained in:
parent
4db689f05e
commit
00e9654006
|
@ -454,7 +454,12 @@ public class IndexShard extends AbstractIndexShardComponent {
|
|||
}
|
||||
|
||||
public Engine.Create prepareCreate(SourceToParse source, long version, VersionType versionType, Engine.Operation.Origin origin, boolean canHaveDuplicates, boolean autoGeneratedId) {
|
||||
return prepareCreate(docMapper(source.type()), source, version, versionType, origin, state != IndexShardState.STARTED || canHaveDuplicates, autoGeneratedId);
|
||||
try {
|
||||
return prepareCreate(docMapper(source.type()), source, version, versionType, origin, state != IndexShardState.STARTED || canHaveDuplicates, autoGeneratedId);
|
||||
} catch (Throwable t) {
|
||||
verifyNotClosed(t);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
static Engine.Create prepareCreate(Tuple<DocumentMapper, Mapping> docMapper, SourceToParse source, long version, VersionType versionType, Engine.Operation.Origin origin, boolean canHaveDuplicates, boolean autoGeneratedId) {
|
||||
|
@ -484,7 +489,12 @@ public class IndexShard extends AbstractIndexShardComponent {
|
|||
}
|
||||
|
||||
public Engine.Index prepareIndex(SourceToParse source, long version, VersionType versionType, Engine.Operation.Origin origin, boolean canHaveDuplicates) {
|
||||
return prepareIndex(docMapper(source.type()), source, version, versionType, origin, state != IndexShardState.STARTED || canHaveDuplicates);
|
||||
try {
|
||||
return prepareIndex(docMapper(source.type()), source, version, versionType, origin, state != IndexShardState.STARTED || canHaveDuplicates);
|
||||
} catch (Throwable t) {
|
||||
verifyNotClosed(t);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
static Engine.Index prepareIndex(Tuple<DocumentMapper, Mapping> docMapper, SourceToParse source, long version, VersionType versionType, Engine.Operation.Origin origin, boolean canHaveDuplicates) {
|
||||
|
@ -932,9 +942,17 @@ public class IndexShard extends AbstractIndexShardComponent {
|
|||
}
|
||||
|
||||
private void verifyNotClosed() throws IllegalIndexShardStateException {
|
||||
verifyNotClosed(null);
|
||||
}
|
||||
|
||||
private void verifyNotClosed(Throwable suppressed) throws IllegalIndexShardStateException {
|
||||
IndexShardState state = this.state; // one time volatile read
|
||||
if (state == IndexShardState.CLOSED) {
|
||||
throw new IllegalIndexShardStateException(shardId, state, "operation only allowed when not closed");
|
||||
final IllegalIndexShardStateException exc = new IllegalIndexShardStateException(shardId, state, "operation only allowed when not closed");
|
||||
if (suppressed != null) {
|
||||
exc.addSuppressed(suppressed);
|
||||
}
|
||||
throw exc;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue