Clarify InternalIndexShard callbacks
This commit changes internal callback to be clear about when they are called and also provide the exception that was potentially thrown as a callback argument. Closes #5945
This commit is contained in:
parent
0b024ad2f3
commit
00275ac1d6
|
@ -132,6 +132,9 @@ public class ShardIndexingService extends AbstractIndexShardComponent {
|
|||
}
|
||||
}
|
||||
|
||||
public void postCreate(Engine.Create create, Throwable ex) {
|
||||
}
|
||||
|
||||
public Engine.Index preIndex(Engine.Index index) {
|
||||
totalStats.indexCurrent.inc();
|
||||
typeStats(index.type()).indexCurrent.inc();
|
||||
|
@ -168,7 +171,7 @@ public class ShardIndexingService extends AbstractIndexShardComponent {
|
|||
}
|
||||
}
|
||||
|
||||
public void failedIndex(Engine.Index index) {
|
||||
public void postIndex(Engine.Index index, Throwable ex) {
|
||||
totalStats.indexCurrent.dec();
|
||||
typeStats(index.type()).indexCurrent.dec();
|
||||
}
|
||||
|
@ -208,7 +211,7 @@ public class ShardIndexingService extends AbstractIndexShardComponent {
|
|||
}
|
||||
}
|
||||
|
||||
public void failedDelete(Engine.Delete delete) {
|
||||
public void postDelete(Engine.Delete delete, Throwable ex) {
|
||||
totalStats.deleteCurrent.dec();
|
||||
typeStats(delete.type()).deleteCurrent.dec();
|
||||
}
|
||||
|
|
|
@ -418,11 +418,16 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
|||
public ParsedDocument create(Engine.Create create) throws ElasticsearchException {
|
||||
writeAllowed(create.origin());
|
||||
create = indexingService.preCreate(create);
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("index [{}][{}]{}", create.type(), create.id(), create.docs());
|
||||
try {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("index [{}][{}]{}", create.type(), create.id(), create.docs());
|
||||
}
|
||||
engine.create(create);
|
||||
create.endTime(System.nanoTime());
|
||||
} catch (Throwable ex) {
|
||||
indexingService.postCreate(create, ex);
|
||||
throw ex;
|
||||
}
|
||||
engine.create(create);
|
||||
create.endTime(System.nanoTime());
|
||||
indexingService.postCreate(create);
|
||||
return create.parsedDoc();
|
||||
}
|
||||
|
@ -445,8 +450,8 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
|||
}
|
||||
engine.index(index);
|
||||
index.endTime(System.nanoTime());
|
||||
} catch (RuntimeException ex) {
|
||||
indexingService.failedIndex(index);
|
||||
} catch (Throwable ex) {
|
||||
indexingService.postIndex(index, ex);
|
||||
throw ex;
|
||||
}
|
||||
indexingService.postIndex(index);
|
||||
|
@ -470,8 +475,8 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
|||
}
|
||||
engine.delete(delete);
|
||||
delete.endTime(System.nanoTime());
|
||||
} catch (RuntimeException ex) {
|
||||
indexingService.failedDelete(delete);
|
||||
} catch (Throwable ex) {
|
||||
indexingService.postDelete(delete, ex);
|
||||
throw ex;
|
||||
}
|
||||
indexingService.postDelete(delete);
|
||||
|
|
Loading…
Reference in New Issue