mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-20 03:45:02 +00:00
The watcher indexing listener didn't handle document level exceptions. (#51466)
Prior to the change the watcher index listener didn't implement the `postIndex(ShardId, Engine.Index, Engine.IndexResult)` method. This caused document level exceptions like VersionConflictEngineException to be ignored. This commit fixes this. The watcher indexing listener did implement the `postIndex(ShardId, Engine.Index, Exception)` method, but that only handles engine level exceptions. This change also unmutes the SmokeTestWatcherTestSuiteIT#testMonitorClusterHealth test again. Relates to #32299
This commit is contained in:
parent
206c8ac3e9
commit
b253af36f3
@ -135,8 +135,19 @@ final class WatcherIndexingListener implements IndexingOperationListener, Cluste
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* In case of a document related failure (for example version conflict), then clean up resources for a watch
|
||||||
* In case of an error, we have to ensure that the triggerservice does not leave anything behind
|
* in the trigger service.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void postIndex(ShardId shardId, Engine.Index index, Engine.IndexResult result) {
|
||||||
|
if (result.getResultType() == Engine.Result.Type.FAILURE) {
|
||||||
|
assert result.getFailure() != null;
|
||||||
|
postIndex(shardId, index, result.getFailure());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In case of an engine related error, we have to ensure that the triggerservice does not leave anything behind
|
||||||
*
|
*
|
||||||
* TODO: If the configuration changes between preindex and postindex methods and we add a
|
* TODO: If the configuration changes between preindex and postindex methods and we add a
|
||||||
* watch, that could not be indexed
|
* watch, that could not be indexed
|
||||||
|
@ -45,6 +45,7 @@ import org.junit.Before;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -200,7 +201,40 @@ public class WatcherIndexingListenerTests extends ESTestCase {
|
|||||||
assertThat(exc.getMessage(), containsString(id));
|
assertThat(exc.getMessage(), containsString(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPostIndexRemoveTriggerOnException() throws Exception {
|
public void testPostIndexRemoveTriggerOnDocumentRelatedException() throws Exception {
|
||||||
|
when(operation.id()).thenReturn("_id");
|
||||||
|
when(result.getResultType()).thenReturn(Engine.Result.Type.FAILURE);
|
||||||
|
when(result.getFailure()).thenReturn(new RuntimeException());
|
||||||
|
when(shardId.getIndexName()).thenReturn(Watch.INDEX);
|
||||||
|
|
||||||
|
listener.postIndex(shardId, operation, result);
|
||||||
|
verify(triggerService).remove(eq("_id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPostIndexRemoveTriggerOnDocumentRelatedException_ignoreOtherEngineResultTypes() throws Exception {
|
||||||
|
List<Engine.Result.Type> types = new ArrayList<>(Arrays.asList(Engine.Result.Type.values()));
|
||||||
|
types.remove(Engine.Result.Type.FAILURE);
|
||||||
|
|
||||||
|
when(operation.id()).thenReturn("_id");
|
||||||
|
when(result.getResultType()).thenReturn(randomFrom(types));
|
||||||
|
when(result.getFailure()).thenReturn(new RuntimeException());
|
||||||
|
when(shardId.getIndexName()).thenReturn(Watch.INDEX);
|
||||||
|
|
||||||
|
listener.postIndex(shardId, operation, result);
|
||||||
|
verifyZeroInteractions(triggerService);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPostIndexRemoveTriggerOnDocumentRelatedException_ignoreNonWatcherDocument() throws Exception {
|
||||||
|
when(operation.id()).thenReturn("_id");
|
||||||
|
when(result.getResultType()).thenReturn(Engine.Result.Type.FAILURE);
|
||||||
|
when(result.getFailure()).thenReturn(new RuntimeException());
|
||||||
|
when(shardId.getIndexName()).thenReturn(randomAlphaOfLength(4));
|
||||||
|
|
||||||
|
listener.postIndex(shardId, operation, result);
|
||||||
|
verifyZeroInteractions(triggerService);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPostIndexRemoveTriggerOnEngineLevelException() throws Exception {
|
||||||
when(operation.id()).thenReturn("_id");
|
when(operation.id()).thenReturn("_id");
|
||||||
when(shardId.getIndexName()).thenReturn(Watch.INDEX);
|
when(shardId.getIndexName()).thenReturn(Watch.INDEX);
|
||||||
|
|
||||||
@ -208,7 +242,7 @@ public class WatcherIndexingListenerTests extends ESTestCase {
|
|||||||
verify(triggerService).remove(eq("_id"));
|
verify(triggerService).remove(eq("_id"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPostIndexDontInvokeForOtherDocuments() throws Exception {
|
public void testPostIndexRemoveTriggerOnEngineLevelException_ignoreNonWatcherDocument() throws Exception {
|
||||||
when(operation.id()).thenReturn("_id");
|
when(operation.id()).thenReturn("_id");
|
||||||
when(shardId.getIndexName()).thenReturn("anything");
|
when(shardId.getIndexName()).thenReturn("anything");
|
||||||
when(result.getResultType()).thenReturn(Engine.Result.Type.SUCCESS);
|
when(result.getResultType()).thenReturn(Engine.Result.Type.SUCCESS);
|
||||||
|
@ -110,7 +110,6 @@ public class SmokeTestWatcherTestSuiteIT extends ESRestTestCase {
|
|||||||
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
|
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/32299")
|
|
||||||
public void testMonitorClusterHealth() throws Exception {
|
public void testMonitorClusterHealth() throws Exception {
|
||||||
final String watchId = "cluster_health_watch";
|
final String watchId = "cluster_health_watch";
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user