From 957296bc5d2f787ba0e2ef57c83357934d6b1345 Mon Sep 17 00:00:00 2001 From: meconlin Date: Thu, 17 Oct 2013 22:27:12 -0400 Subject: [PATCH 1/3] last index and delete time --- .../index/indexing/IndexingStats.java | 36 +++++++++++++++++-- .../index/indexing/ShardIndexingService.java | 15 ++++++-- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java b/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java index 447e260615d31..fa4ac53c581f0 100644 --- a/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java +++ b/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java @@ -40,33 +40,38 @@ public static class Stats implements Streamable, ToXContent { private long indexCount; private long indexTimeInMillis; + private long indexLastTimestamp; private long indexCurrent; private long deleteCount; private long deleteTimeInMillis; + private long deleteLastTimestamp; private long deleteCurrent; Stats() { } - public Stats(long indexCount, long indexTimeInMillis, long indexCurrent, long deleteCount, long deleteTimeInMillis, long deleteCurrent) { + public Stats(long indexCount, long indexTimeInMillis, long indexCurrent, long indexLastTime, long deleteCount, long deleteTimeInMillis, long deleteCurrent, long deleteLastTime) { this.indexCount = indexCount; this.indexTimeInMillis = indexTimeInMillis; this.indexCurrent = indexCurrent; + this.indexLastTimestamp = indexLastTime; this.deleteCount = deleteCount; this.deleteTimeInMillis = deleteTimeInMillis; this.deleteCurrent = deleteCurrent; + this.deleteLastTimestamp = deleteLastTime; } public void add(Stats stats) { indexCount += stats.indexCount; indexTimeInMillis += stats.indexTimeInMillis; indexCurrent += stats.indexCurrent; - + indexLastTimestamp = stats.indexLastTimestamp; deleteCount += stats.deleteCount; deleteTimeInMillis += stats.deleteTimeInMillis; deleteCurrent += stats.deleteCurrent; + deleteLastTimestamp = stats.deleteLastTimestamp; } public long getIndexCount() { @@ -81,6 +86,14 @@ public long getIndexTimeInMillis() { return indexTimeInMillis; } + public TimeValue getLastIndexTime() { + return new TimeValue(indexLastTimestamp); + } + + public long getIndexLastTimestamp() { + return indexLastTimestamp; + } + public long getIndexCurrent() { return indexCurrent; } @@ -89,6 +102,14 @@ public long getDeleteCount() { return deleteCount; } + public TimeValue getDeleteLastTime() { + return new TimeValue(deleteLastTimestamp); + } + + public long getLastDeleteTimestamp() { + return deleteLastTimestamp; + } + public TimeValue getDeleteTime() { return new TimeValue(deleteTimeInMillis); } @@ -112,10 +133,12 @@ public void readFrom(StreamInput in) throws IOException { indexCount = in.readVLong(); indexTimeInMillis = in.readVLong(); indexCurrent = in.readVLong(); - + //indexLastTimestamp = in.readVLong(); + deleteCount = in.readVLong(); deleteTimeInMillis = in.readVLong(); deleteCurrent = in.readVLong(); + //deleteLastTimestamp = in.readVLong(); } @Override @@ -123,10 +146,12 @@ public void writeTo(StreamOutput out) throws IOException { out.writeVLong(indexCount); out.writeVLong(indexTimeInMillis); out.writeVLong(indexCurrent); + //out.writeVLong(indexLastTimestamp); out.writeVLong(deleteCount); out.writeVLong(deleteTimeInMillis); out.writeVLong(deleteCurrent); + //out.writeVLong(deleteLastTimestamp); } @Override @@ -134,10 +159,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.field(Fields.INDEX_TOTAL, indexCount); builder.timeValueField(Fields.INDEX_TIME_IN_MILLIS, Fields.INDEX_TIME, indexTimeInMillis); builder.field(Fields.INDEX_CURRENT, indexCurrent); + builder.field(Fields.INDEX_LAST_TIME_IN_MILLIS, indexLastTimestamp); builder.field(Fields.DELETE_TOTAL, deleteCount); builder.timeValueField(Fields.DELETE_TIME_IN_MILLIS, Fields.DELETE_TIME, deleteTimeInMillis); builder.field(Fields.DELETE_CURRENT, deleteCurrent); + builder.field(Fields.DELETE_LAST_TIME_IN_MILLIS, deleteLastTimestamp); return builder; } @@ -213,11 +240,13 @@ static final class Fields { static final XContentBuilderString INDEX_TOTAL = new XContentBuilderString("index_total"); static final XContentBuilderString INDEX_TIME = new XContentBuilderString("index_time"); static final XContentBuilderString INDEX_TIME_IN_MILLIS = new XContentBuilderString("index_time_in_millis"); + static final XContentBuilderString INDEX_LAST_TIME_IN_MILLIS = new XContentBuilderString("last_index_timestamp"); static final XContentBuilderString INDEX_CURRENT = new XContentBuilderString("index_current"); static final XContentBuilderString DELETE_TOTAL = new XContentBuilderString("delete_total"); static final XContentBuilderString DELETE_TIME = new XContentBuilderString("delete_time"); static final XContentBuilderString DELETE_TIME_IN_MILLIS = new XContentBuilderString("delete_time_in_millis"); static final XContentBuilderString DELETE_CURRENT = new XContentBuilderString("delete_current"); + static final XContentBuilderString DELETE_LAST_TIME_IN_MILLIS = new XContentBuilderString("last_delete_timestamp"); } public static IndexingStats readIndexingStats(StreamInput in) throws IOException { @@ -253,3 +282,4 @@ public void writeTo(StreamOutput out) throws IOException { } } } + diff --git a/src/main/java/org/elasticsearch/index/indexing/ShardIndexingService.java b/src/main/java/org/elasticsearch/index/indexing/ShardIndexingService.java index 45cb268537845..7de116937fcb9 100644 --- a/src/main/java/org/elasticsearch/index/indexing/ShardIndexingService.java +++ b/src/main/java/org/elasticsearch/index/indexing/ShardIndexingService.java @@ -123,11 +123,14 @@ public void postCreateUnderLock(Engine.Create create) { public void postCreate(Engine.Create create) { long took = create.endTime() - create.startTime(); + long now = System.currentTimeMillis(); totalStats.indexMetric.inc(took); totalStats.indexCurrent.dec(); + totalStats.indexLastTimestamp = now; StatsHolder typeStats = typeStats(create.type()); typeStats.indexMetric.inc(took); typeStats.indexCurrent.dec(); + typeStats.indexLastTimestamp = now; slowLog.postCreate(create, took); if (listeners != null) { for (IndexingOperationListener listener : listeners) { @@ -165,11 +168,14 @@ public void postIndexUnderLock(Engine.Index index) { public void postIndex(Engine.Index index) { long took = index.endTime() - index.startTime(); + long now = System.currentTimeMillis(); totalStats.indexMetric.inc(took); totalStats.indexCurrent.dec(); + totalStats.indexLastTimestamp = now; StatsHolder typeStats = typeStats(index.type()); typeStats.indexMetric.inc(took); typeStats.indexCurrent.dec(); + typeStats.indexLastTimestamp = now; slowLog.postIndex(index, took); if (listeners != null) { for (IndexingOperationListener listener : listeners) { @@ -214,9 +220,11 @@ public void postDelete(Engine.Delete delete) { long took = delete.endTime() - delete.startTime(); totalStats.deleteMetric.inc(took); totalStats.deleteCurrent.dec(); + totalStats.deleteLastTimestamp = delete.endTime(); StatsHolder typeStats = typeStats(delete.type()); typeStats.deleteMetric.inc(took); typeStats.deleteCurrent.dec(); + typeStats.deleteLastTimestamp = delete.endTime(); if (listeners != null) { for (IndexingOperationListener listener : listeners) { try { @@ -285,11 +293,13 @@ static class StatsHolder { public final MeanMetric deleteMetric = new MeanMetric(); public final CounterMetric indexCurrent = new CounterMetric(); public final CounterMetric deleteCurrent = new CounterMetric(); + public long indexLastTimestamp = 0; + public long deleteLastTimestamp = 0; public IndexingStats.Stats stats() { return new IndexingStats.Stats( - indexMetric.count(), TimeUnit.NANOSECONDS.toMillis(indexMetric.sum()), indexCurrent.count(), - deleteMetric.count(), TimeUnit.NANOSECONDS.toMillis(deleteMetric.sum()), deleteCurrent.count()); + indexMetric.count(), TimeUnit.NANOSECONDS.toMillis(indexMetric.sum()), indexCurrent.count(), indexLastTimestamp, + deleteMetric.count(), TimeUnit.NANOSECONDS.toMillis(deleteMetric.sum()), deleteCurrent.count(), deleteLastTimestamp); } public long totalCurrent() { @@ -302,3 +312,4 @@ public void clear() { } } } + From cfff3c13a821b521d0ba7100d9a4cce7f705d599 Mon Sep 17 00:00:00 2001 From: meconlin Date: Thu, 17 Oct 2013 22:30:06 -0400 Subject: [PATCH 2/3] last index and delete time --- .../org/elasticsearch/index/indexing/IndexingStats.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java b/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java index fa4ac53c581f0..e7065c679bfbe 100644 --- a/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java +++ b/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java @@ -133,12 +133,12 @@ public void readFrom(StreamInput in) throws IOException { indexCount = in.readVLong(); indexTimeInMillis = in.readVLong(); indexCurrent = in.readVLong(); - //indexLastTimestamp = in.readVLong(); + indexLastTimestamp = in.readVLong(); deleteCount = in.readVLong(); deleteTimeInMillis = in.readVLong(); deleteCurrent = in.readVLong(); - //deleteLastTimestamp = in.readVLong(); + deleteLastTimestamp = in.readVLong(); } @Override @@ -146,12 +146,12 @@ public void writeTo(StreamOutput out) throws IOException { out.writeVLong(indexCount); out.writeVLong(indexTimeInMillis); out.writeVLong(indexCurrent); - //out.writeVLong(indexLastTimestamp); + out.writeVLong(indexLastTimestamp); out.writeVLong(deleteCount); out.writeVLong(deleteTimeInMillis); out.writeVLong(deleteCurrent); - //out.writeVLong(deleteLastTimestamp); + out.writeVLong(deleteLastTimestamp); } @Override From 88ea539d9220932a185e9e3837a88e4ced2d1586 Mon Sep 17 00:00:00 2001 From: meconlin Date: Thu, 17 Oct 2013 23:12:33 -0400 Subject: [PATCH 3/3] max of shards, not clobbered by last --- .../java/org/elasticsearch/index/indexing/IndexingStats.java | 4 ++-- .../elasticsearch/index/indexing/ShardIndexingService.java | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java b/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java index e7065c679bfbe..82d1aea50a986 100644 --- a/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java +++ b/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java @@ -67,11 +67,11 @@ public void add(Stats stats) { indexCount += stats.indexCount; indexTimeInMillis += stats.indexTimeInMillis; indexCurrent += stats.indexCurrent; - indexLastTimestamp = stats.indexLastTimestamp; + indexLastTimestamp = Math.max(indexLastTimestamp, stats.indexLastTimestamp); deleteCount += stats.deleteCount; deleteTimeInMillis += stats.deleteTimeInMillis; deleteCurrent += stats.deleteCurrent; - deleteLastTimestamp = stats.deleteLastTimestamp; + deleteLastTimestamp = Math.max(deleteLastTimestamp, stats.deleteLastTimestamp); } public long getIndexCount() { diff --git a/src/main/java/org/elasticsearch/index/indexing/ShardIndexingService.java b/src/main/java/org/elasticsearch/index/indexing/ShardIndexingService.java index 7de116937fcb9..15ae7eb343daa 100644 --- a/src/main/java/org/elasticsearch/index/indexing/ShardIndexingService.java +++ b/src/main/java/org/elasticsearch/index/indexing/ShardIndexingService.java @@ -218,13 +218,14 @@ public void postDeleteUnderLock(Engine.Delete delete) { public void postDelete(Engine.Delete delete) { long took = delete.endTime() - delete.startTime(); + long now = System.currentTimeMillis(); totalStats.deleteMetric.inc(took); totalStats.deleteCurrent.dec(); - totalStats.deleteLastTimestamp = delete.endTime(); + totalStats.deleteLastTimestamp = now; StatsHolder typeStats = typeStats(delete.type()); typeStats.deleteMetric.inc(took); typeStats.deleteCurrent.dec(); - typeStats.deleteLastTimestamp = delete.endTime(); + typeStats.deleteLastTimestamp = now; if (listeners != null) { for (IndexingOperationListener listener : listeners) { try {