26
26
import com .carrotsearch .randomizedtesting .generators .RandomStrings ;
27
27
import org .apache .logging .log4j .Logger ;
28
28
import org .apache .lucene .store .AlreadyClosedException ;
29
- import org .elasticsearch .common .collect .Tuple ;
30
- import org .elasticsearch .common .lucene .Lucene ;
31
29
import org .elasticsearch .core .internal .io .IOUtils ;
32
30
import org .elasticsearch .ElasticsearchException ;
33
31
import org .elasticsearch .action .admin .cluster .node .stats .NodeStats ;
77
75
import org .elasticsearch .index .IndexService ;
78
76
import org .elasticsearch .index .engine .CommitStats ;
79
77
import org .elasticsearch .index .engine .Engine ;
80
- import org .elasticsearch .index .engine .EngineTestCase ;
81
- import org .elasticsearch .index .shard .IllegalIndexShardStateException ;
82
78
import org .elasticsearch .index .shard .IndexShard ;
83
- import org .elasticsearch .index .shard .IndexShardState ;
84
79
import org .elasticsearch .index .shard .IndexShardTestCase ;
85
80
import org .elasticsearch .index .shard .ShardId ;
86
81
import org .elasticsearch .indices .IndicesService ;
@@ -1108,7 +1103,7 @@ public void beforeIndexDeletion() throws Exception {
1108
1103
// ElasticsearchIntegrationTest must override beforeIndexDeletion() to avoid failures.
1109
1104
assertNoPendingIndexOperations ();
1110
1105
//check that shards that have same sync id also contain same number of documents
1111
- assertSameSyncIdSameDocs ();
1106
+ assertSameSyncIdSameDocs ();
1112
1107
assertOpenTranslogReferences ();
1113
1108
}
1114
1109
@@ -1119,39 +1114,23 @@ private void assertSameSyncIdSameDocs() {
1119
1114
IndicesService indexServices = getInstance (IndicesService .class , nodeAndClient .name );
1120
1115
for (IndexService indexService : indexServices ) {
1121
1116
for (IndexShard indexShard : indexService ) {
1122
- Tuple < String , Integer > commitStats = commitStats (indexShard );
1123
- if (commitStats != null ) {
1124
- String syncId = commitStats .v1 ( );
1125
- long liveDocsOnShard = commitStats . v2 ();
1126
- if ( docsOnShards . get ( syncId ) != null ) {
1127
- assertThat ( "sync id is equal but number of docs does not match on node " + nodeAndClient . name +
1128
- ". expected " + docsOnShards .get (syncId ) + " but got " + liveDocsOnShard , docsOnShards .get (syncId ),
1129
- equalTo ( liveDocsOnShard ));
1130
- } else {
1131
- docsOnShards . put ( syncId , liveDocsOnShard );
1117
+ CommitStats commitStats = indexShard . commitStats ();
1118
+ if (commitStats != null ) { // null if the engine is closed or if the shard is recovering
1119
+ String syncId = commitStats .getUserData (). get ( Engine . SYNC_COMMIT_ID );
1120
+ if ( syncId != null ) {
1121
+ long liveDocsOnShard = commitStats . getNumDocs ();
1122
+ if ( docsOnShards . get ( syncId ) != null ) {
1123
+ assertThat ( "sync id is equal but number of docs does not match on node " + nodeAndClient . name + ". expected " + docsOnShards .get (syncId ) + " but got " + liveDocsOnShard , docsOnShards .get (syncId ), equalTo ( liveDocsOnShard ));
1124
+ } else {
1125
+ docsOnShards . put ( syncId , liveDocsOnShard );
1126
+ }
1132
1127
}
1133
1128
}
1134
1129
}
1135
1130
}
1136
1131
}
1137
1132
}
1138
1133
1139
- private Tuple <String , Integer > commitStats (IndexShard indexShard ) {
1140
- try (Engine .IndexCommitRef commitRef = indexShard .acquireLastIndexCommit (false )) {
1141
- final String syncId = commitRef .getIndexCommit ().getUserData ().get (Engine .SYNC_COMMIT_ID );
1142
- // Only read if sync_id exists
1143
- if (Strings .hasText (syncId )) {
1144
- return Tuple .tuple (syncId , Lucene .getExactNumDocs (commitRef .getIndexCommit ()));
1145
- } else {
1146
- return null ;
1147
- }
1148
- } catch (IllegalIndexShardStateException ex ) {
1149
- return null ; // Shard is closed or not started yet.
1150
- } catch (IOException ex ) {
1151
- throw new AssertionError (ex );
1152
- }
1153
- }
1154
-
1155
1134
private void assertNoPendingIndexOperations () throws Exception {
1156
1135
assertBusy (() -> {
1157
1136
final Collection <NodeAndClient > nodesAndClients = nodes .values ();
0 commit comments