@@ -136,6 +136,11 @@ public class InternalEngine extends Engine {
136
136
private final AtomicLong maxSeqNoOfNonAppendOnlyOperations = new AtomicLong (SequenceNumbers .NO_OPS_PERFORMED );
137
137
private final CounterMetric numVersionLookups = new CounterMetric ();
138
138
private final CounterMetric numIndexVersionsLookups = new CounterMetric ();
139
+ // Lucene operations since this engine was opened - not include operations from existing segments.
140
+ private final CounterMetric numDocDeletes = new CounterMetric ();
141
+ private final CounterMetric numDocAppends = new CounterMetric ();
142
+ private final CounterMetric numDocUpdates = new CounterMetric ();
143
+
139
144
/**
140
145
* How many bytes we are currently moving to disk, via either IndexWriter.flush or refresh. IndexingMemoryController polls this
141
146
* across all shards to decide if throttling is necessary because moving bytes to disk is falling behind vs incoming documents
@@ -907,11 +912,11 @@ private IndexResult indexIntoLucene(Index index, IndexingStrategy plan)
907
912
index .parsedDoc ().version ().setLongValue (plan .versionForIndexing );
908
913
try {
909
914
if (plan .useLuceneUpdateDocument ) {
910
- update (index .uid (), index .docs (), indexWriter );
915
+ updateDocs (index .uid (), index .docs (), indexWriter );
911
916
} else {
912
917
// document does not exists, we can optimize for create, but double check if assertions are running
913
918
assert assertDocDoesNotExist (index , canOptimizeAddDocument (index ) == false );
914
- index (index .docs (), indexWriter );
919
+ addDocs (index .docs (), indexWriter );
915
920
}
916
921
return new IndexResult (plan .versionForIndexing , plan .seqNoForIndexing , plan .currentNotFoundOrDeleted );
917
922
} catch (Exception ex ) {
@@ -968,12 +973,13 @@ long getMaxSeqNoOfNonAppendOnlyOperations() {
968
973
return maxSeqNoOfNonAppendOnlyOperations .get ();
969
974
}
970
975
971
- private static void index (final List <ParseContext .Document > docs , final IndexWriter indexWriter ) throws IOException {
976
+ private void addDocs (final List <ParseContext .Document > docs , final IndexWriter indexWriter ) throws IOException {
972
977
if (docs .size () > 1 ) {
973
978
indexWriter .addDocuments (docs );
974
979
} else {
975
980
indexWriter .addDocument (docs .get (0 ));
976
981
}
982
+ numDocAppends .inc (docs .size ());
977
983
}
978
984
979
985
private static final class IndexingStrategy {
@@ -1054,12 +1060,13 @@ private boolean assertDocDoesNotExist(final Index index, final boolean allowDele
1054
1060
return true ;
1055
1061
}
1056
1062
1057
- private static void update (final Term uid , final List <ParseContext .Document > docs , final IndexWriter indexWriter ) throws IOException {
1063
+ private void updateDocs (final Term uid , final List <ParseContext .Document > docs , final IndexWriter indexWriter ) throws IOException {
1058
1064
if (docs .size () > 1 ) {
1059
1065
indexWriter .updateDocuments (uid , docs );
1060
1066
} else {
1061
1067
indexWriter .updateDocument (uid , docs .get (0 ));
1062
1068
}
1069
+ numDocUpdates .inc (docs .size ());
1063
1070
}
1064
1071
1065
1072
@ Override
@@ -1188,6 +1195,7 @@ private DeleteResult deleteInLucene(Delete delete, DeletionStrategy plan)
1188
1195
// any exception that comes from this is a either an ACE or a fatal exception there
1189
1196
// can't be any document failures coming from this
1190
1197
indexWriter .deleteDocuments (delete .uid ());
1198
+ numDocDeletes .inc ();
1191
1199
}
1192
1200
versionMap .putUnderLock (delete .uid ().bytes (),
1193
1201
new DeleteVersionValue (plan .versionOfDeletion , plan .seqNoOfDeletion , delete .primaryTerm (),
@@ -2205,13 +2213,28 @@ boolean isSafeAccessRequired() {
2205
2213
return versionMap .isSafeAccessRequired ();
2206
2214
}
2207
2215
2216
+ /**
2217
+ * Returns the number of documents have been deleted since this engine was opened.
2218
+ * This count does not include the deletions from the existing segments before opening engine.
2219
+ */
2220
+ long getNumDocDeletes () {
2221
+ return numDocDeletes .count ();
2222
+ }
2223
+
2224
+ /**
2225
+ * Returns the number of documents have been appended since this engine was opened.
2226
+ * This count does not include the appends from the existing segments before opening engine.
2227
+ */
2228
+ long getNumDocAppends () {
2229
+ return numDocAppends .count ();
2230
+ }
2208
2231
2209
2232
/**
2210
- * Returns <code>true</code> iff the index writer has any deletions either buffered in memory or
2211
- * in the index .
2233
+ * Returns the number of documents have been updated since this engine was opened.
2234
+ * This count does not include the updates from the existing segments before opening engine .
2212
2235
*/
2213
- boolean indexWriterHasDeletions () {
2214
- return indexWriter . hasDeletions ();
2236
+ long getNumDocUpdates () {
2237
+ return numDocUpdates . count ();
2215
2238
}
2216
2239
2217
2240
@ Override
0 commit comments