77
77
import org .elasticsearch .cluster .routing .ShardRouting ;
78
78
import org .elasticsearch .cluster .routing .ShardRoutingState ;
79
79
import org .elasticsearch .cluster .routing .TestShardRouting ;
80
+ import org .elasticsearch .common .CheckedBiConsumer ;
80
81
import org .elasticsearch .common .CheckedRunnable ;
81
82
import org .elasticsearch .common .Randomness ;
82
83
import org .elasticsearch .common .Strings ;
@@ -3318,8 +3319,8 @@ public void testHandleDocumentFailure() throws Exception {
3318
3319
AtomicReference <ThrowingIndexWriter > throwingIndexWriter = new AtomicReference <>();
3319
3320
try (InternalEngine engine = createEngine (defaultSettings , store , createTempDir (), NoMergePolicy .INSTANCE ,
3320
3321
(directory , iwc ) -> {
3321
- throwingIndexWriter .set (new ThrowingIndexWriter (directory , iwc ));
3322
- return throwingIndexWriter .get ();
3322
+ throwingIndexWriter .set (new ThrowingIndexWriter (directory , iwc ));
3323
+ return throwingIndexWriter .get ();
3323
3324
})
3324
3325
) {
3325
3326
// test document failure while indexing
@@ -3343,22 +3344,6 @@ public void testHandleDocumentFailure() throws Exception {
3343
3344
assertNotNull (indexResult .getTranslogLocation ());
3344
3345
engine .index (indexForDoc (doc2 ));
3345
3346
3346
- // test failure while deleting
3347
- // all these simulated exceptions are not fatal to the IW so we treat them as document failures
3348
- final Engine .DeleteResult deleteResult ;
3349
- if (randomBoolean ()) {
3350
- throwingIndexWriter .get ().setThrowFailure (() -> new IOException ("simulated" ));
3351
- deleteResult = engine .delete (new Engine .Delete ("test" , "1" , newUid (doc1 ), primaryTerm .get ()));
3352
- assertThat (deleteResult .getFailure (), instanceOf (IOException .class ));
3353
- } else {
3354
- throwingIndexWriter .get ().setThrowFailure (() -> new IllegalArgumentException ("simulated max token length" ));
3355
- deleteResult = engine .delete (new Engine .Delete ("test" , "1" , newUid (doc1 ), primaryTerm .get ()));
3356
- assertThat (deleteResult .getFailure (),
3357
- instanceOf (IllegalArgumentException .class ));
3358
- }
3359
- assertThat (deleteResult .getVersion (), equalTo (2L ));
3360
- assertThat (deleteResult .getSeqNo (), equalTo (3L ));
3361
-
3362
3347
// test non document level failure is thrown
3363
3348
if (randomBoolean ()) {
3364
3349
// simulate close by corruption
@@ -5815,4 +5800,48 @@ public long addDocument(Iterable<? extends IndexableField> doc) throws IOExcepti
5815
5800
}
5816
5801
}
5817
5802
5803
+ public void testDeleteFailureSoftDeletesEnabledDocAlreadyDeleted () throws IOException {
5804
+ runTestDeleteFailure (true , InternalEngine ::delete );
5805
+ }
5806
+
5807
+ public void testDeleteFailureSoftDeletesEnabled () throws IOException {
5808
+ runTestDeleteFailure (true , (engine , op ) -> {});
5809
+ }
5810
+
5811
+ public void testDeleteFailureSoftDeletesDisabled () throws IOException {
5812
+ runTestDeleteFailure (false , (engine , op ) -> {});
5813
+ }
5814
+
5815
+ private void runTestDeleteFailure (
5816
+ final boolean softDeletesEnabled ,
5817
+ final CheckedBiConsumer <InternalEngine , Engine .Delete , IOException > consumer ) throws IOException {
5818
+ engine .close ();
5819
+ final Settings settings = Settings .builder ()
5820
+ .put (defaultSettings .getSettings ())
5821
+ .put (IndexSettings .INDEX_SOFT_DELETES_SETTING .getKey (), softDeletesEnabled ).build ();
5822
+ final IndexSettings indexSettings = IndexSettingsModule .newIndexSettings (
5823
+ IndexMetaData .builder (defaultSettings .getIndexMetaData ()).settings (settings ).build ());
5824
+ final AtomicReference <ThrowingIndexWriter > iw = new AtomicReference <>();
5825
+ try (Store store = createStore ();
5826
+ InternalEngine engine = createEngine (
5827
+ (dir , iwc ) -> {
5828
+ iw .set (new ThrowingIndexWriter (dir , iwc ));
5829
+ return iw .get ();
5830
+ },
5831
+ null ,
5832
+ null ,
5833
+ config (indexSettings , store , createTempDir (), NoMergePolicy .INSTANCE , null ))) {
5834
+ engine .index (new Engine .Index (newUid ("0" ), primaryTerm .get (), InternalEngineTests .createParsedDoc ("0" , null )));
5835
+ final Engine .Delete op = new Engine .Delete ("_doc" , "0" , newUid ("0" ), primaryTerm .get ());
5836
+ consumer .accept (engine , op );
5837
+ iw .get ().setThrowFailure (() -> new IllegalArgumentException ("fatal" ));
5838
+ final IllegalArgumentException e = expectThrows (IllegalArgumentException . class , () -> engine .delete (op ));
5839
+ assertThat (e .getMessage (), equalTo ("fatal" ));
5840
+ assertTrue (engine .isClosed .get ());
5841
+ assertThat (engine .failedEngine .get (), not (nullValue ()));
5842
+ assertThat (engine .failedEngine .get (), instanceOf (IllegalArgumentException .class ));
5843
+ assertThat (engine .failedEngine .get ().getMessage (), equalTo ("fatal" ));
5844
+ }
5845
+ }
5846
+
5818
5847
}
0 commit comments