Add created flag to IndexingOperationListener#postIndex

fixes #17333
This commit is contained in:
Dan Jasek 2016-03-24 16:47:31 -06:00
parent 7f0134e725
commit e366a45203
7 changed files with 40 additions and 22 deletions

View File

@ -136,7 +136,7 @@ public final class IndexingSlowLog implements IndexingOperationListener {
}
public void postIndex(Engine.Index index) {
public void postIndex(Engine.Index index, boolean created) {
final long took = index.endTime() - index.startTime();
postIndexing(index.parsedDoc(), took);
}

View File

@ -468,7 +468,7 @@ public class IndexShard extends AbstractIndexShardComponent {
throw ex;
}
indexingOperationListeners.postIndex(index);
indexingOperationListeners.postIndex(index, created);
return created;
}

View File

@ -38,7 +38,7 @@ public interface IndexingOperationListener {
/**
* Called after the indexing operation occurred.
*/
default void postIndex(Engine.Index index) {}
default void postIndex(Engine.Index index, boolean created) {}
/**
* Called after the indexing operation occurred with exception.
@ -89,11 +89,11 @@ public interface IndexingOperationListener {
}
@Override
public void postIndex(Engine.Index index) {
public void postIndex(Engine.Index index, boolean created) {
assert index != null;
for (IndexingOperationListener listener : listeners) {
try {
listener.postIndex(index);
listener.postIndex(index, created);
} catch (Throwable t) {
logger.warn("postIndex listener [{}] failed", t, listener);
}

View File

@ -72,7 +72,7 @@ final class InternalIndexingStats implements IndexingOperationListener {
}
@Override
public void postIndex(Engine.Index index) {
public void postIndex(Engine.Index index, boolean created) {
long took = index.endTime() - index.startTime();
totalStats.indexMetric.inc(took);
totalStats.indexCurrent.dec();

View File

@ -210,13 +210,13 @@ public class IndexingMemoryController extends AbstractComponent implements Index
}
@Override
public void postIndex(Engine.Index index) {
bytesWritten(index.getTranslogLocation().size);
public void postIndex(Engine.Index index, boolean created) {
bytesWritten(index.getTranslogLocation().size);
}
@Override
public void postDelete(Engine.Delete delete) {
bytesWritten(delete.getTranslogLocation().size);
bytesWritten(delete.getTranslogLocation().size);
}
private static final class ShardAndBytesUsed implements Comparable<ShardAndBytesUsed> {

View File

@ -576,7 +576,8 @@ public class IndexShardTests extends ESSingleNodeTestCase {
IndexService test = indicesService.indexService(resolveIndex("test_iol"));
IndexShard shard = test.getShardOrNull(0);
AtomicInteger preIndex = new AtomicInteger();
AtomicInteger postIndex = new AtomicInteger();
AtomicInteger postIndexCreate = new AtomicInteger();
AtomicInteger postIndexUpdate = new AtomicInteger();
AtomicInteger postIndexException = new AtomicInteger();
AtomicInteger preDelete = new AtomicInteger();
AtomicInteger postDelete = new AtomicInteger();
@ -589,8 +590,12 @@ public class IndexShardTests extends ESSingleNodeTestCase {
}
@Override
public void postIndex(Engine.Index index) {
postIndex.incrementAndGet();
public void postIndex(Engine.Index index, boolean created) {
if(created) {
postIndexCreate.incrementAndGet();
} else {
postIndexUpdate.incrementAndGet();
}
}
@Override
@ -620,7 +625,17 @@ public class IndexShardTests extends ESSingleNodeTestCase {
Engine.Index index = new Engine.Index(new Term("_uid", "1"), doc);
shard.index(index);
assertEquals(1, preIndex.get());
assertEquals(1, postIndex.get());
assertEquals(1, postIndexCreate.get());
assertEquals(0, postIndexUpdate.get());
assertEquals(0, postIndexException.get());
assertEquals(0, preDelete.get());
assertEquals(0, postDelete.get());
assertEquals(0, postDeleteException.get());
shard.index(index);
assertEquals(1, preIndex.get());
assertEquals(1, postIndexCreate.get());
assertEquals(1, postIndexUpdate.get());
assertEquals(0, postIndexException.get());
assertEquals(0, preDelete.get());
assertEquals(0, postDelete.get());
@ -629,8 +644,9 @@ public class IndexShardTests extends ESSingleNodeTestCase {
Engine.Delete delete = new Engine.Delete("test", "1", new Term("_uid", "1"));
shard.delete(delete);
assertEquals(1, preIndex.get());
assertEquals(1, postIndex.get());
assertEquals(2, preIndex.get());
assertEquals(1, postIndexCreate.get());
assertEquals(1, postIndexUpdate.get());
assertEquals(0, postIndexException.get());
assertEquals(1, preDelete.get());
assertEquals(1, postDelete.get());
@ -646,8 +662,9 @@ public class IndexShardTests extends ESSingleNodeTestCase {
}
assertEquals(2, preIndex.get());
assertEquals(1, postIndex.get());
assertEquals(3, preIndex.get());
assertEquals(1, postIndexCreate.get());
assertEquals(1, postIndexUpdate.get());
assertEquals(1, postIndexException.get());
assertEquals(1, preDelete.get());
assertEquals(1, postDelete.get());
@ -659,8 +676,9 @@ public class IndexShardTests extends ESSingleNodeTestCase {
}
assertEquals(2, preIndex.get());
assertEquals(1, postIndex.get());
assertEquals(3, preIndex.get());
assertEquals(1, postIndexCreate.get());
assertEquals(1, postIndexUpdate.get());
assertEquals(1, postIndexException.get());
assertEquals(2, preDelete.get());
assertEquals(1, postDelete.get());

View File

@ -46,7 +46,7 @@ public class IndexingOperationListenerTests extends ESTestCase{
}
@Override
public void postIndex(Engine.Index index) {
public void postIndex(Engine.Index index, boolean created) {
postIndex.incrementAndGet();
}
@ -79,7 +79,7 @@ public class IndexingOperationListenerTests extends ESTestCase{
}
@Override
public void postIndex(Engine.Index index) {
public void postIndex(Engine.Index index, boolean created) {
throw new RuntimeException(); }
@Override
@ -135,7 +135,7 @@ public class IndexingOperationListenerTests extends ESTestCase{
assertEquals(2, postDelete.get());
assertEquals(2, postDeleteException.get());
compositeListener.postIndex(index);
compositeListener.postIndex(index, false);
assertEquals(0, preIndex.get());
assertEquals(2, postIndex.get());
assertEquals(0, postIndexException.get());