@@ -40,138 +40,8 @@ class DocLevelMonitorFanOutRequest : ActionRequest, ToXContentObject {
4040 val workflowRunContext: WorkflowRunContext ?
4141 val hasSerializationFailed: Boolean
4242
43- init {
44- serializationFailedFlag = false
45- }
4643 companion object {
47- // flag flipped to true whenever a safeRead*() method fails to serialize a field correctly
48- private var serializationFailedFlag: Boolean = false
4944 val log = LogManager .getLogger(DocLevelMonitorFanOutRequest ::class .java)
50- private fun safeReadMonitor (sin : StreamInput ): Monitor =
51- try {
52- Monitor .readFrom(sin)!!
53- } catch (e: Exception ) {
54- serializationFailedFlag = true
55- log.error(" Error parsing monitor in Doc level monitor fanout request" , e)
56- Monitor (
57- " failed_serde" , NO_VERSION , " failed_serde" , true ,
58- IntervalSchedule (1 , ChronoUnit .MINUTES ), Instant .now(), Instant .now(), " " ,
59- null , NO_SCHEMA_VERSION , emptyList(), emptyList(), emptyMap(),
60- DataSources (), false , false , " failed"
61- )
62- }
63-
64- private fun safeReadBoolean (sin : StreamInput ): Boolean =
65- try {
66- sin.readBoolean()
67- } catch (e: Exception ) {
68- serializationFailedFlag = true
69- log.error(" Error parsing boolean in Doc level monitor fanout request" , e)
70- false
71- }
72-
73- private fun safeReadMonitorMetadata (sin : StreamInput ): MonitorMetadata =
74- try {
75- MonitorMetadata .readFrom(sin)
76- } catch (e: Exception ) {
77- serializationFailedFlag = true
78- log.error(" Error parsing monitor in Doc level monitor fanout request" , e)
79- MonitorMetadata (
80- " failed_serde" ,
81- SequenceNumbers .UNASSIGNED_SEQ_NO ,
82- SequenceNumbers .UNASSIGNED_PRIMARY_TERM ,
83- " failed_serde" ,
84- emptyList(),
85- emptyMap(),
86- mutableMapOf ()
87- )
88- }
89-
90- private fun safeReadString (sin : StreamInput ): String =
91- try {
92- sin.readString()
93- } catch (e: Exception ) {
94- serializationFailedFlag = true
95- log.error(" Error parsing string in Doc level monitor fanout request" , e)
96- " "
97- }
98-
99- private fun safeReadShardIds (sin : StreamInput ): List <ShardId > =
100- try {
101- sin.readList(::ShardId )
102- } catch (e: Exception ) {
103- serializationFailedFlag = true
104- log.error(" Error parsing shardId list in Doc level monitor fanout request" , e)
105- emptyList()
106- }
107-
108- private fun safeReadStringList (sin : StreamInput ): List <String > =
109- try {
110- sin.readStringList()
111- } catch (e: Exception ) {
112- serializationFailedFlag = true
113- log.error(" Error parsing string list in Doc level monitor fanout request" , e)
114- emptyList()
115- }
116-
117- private fun safeReadWorkflowRunContext (sin : StreamInput ): WorkflowRunContext ? =
118- try {
119- if (sin.readBoolean()) WorkflowRunContext (sin) else null
120- } catch (e: Exception ) {
121- serializationFailedFlag = true
122- log.error(" Error parsing workflow context in Doc level monitor fanout request" , e)
123- null
124- }
125-
126- private fun safeReadIndexExecutionContext (sin : StreamInput ): IndexExecutionContext ? {
127- var indexExecutionContext: IndexExecutionContext ? = null
128- return try {
129- indexExecutionContext = IndexExecutionContext (sin)
130- while (sin.read() != 0 ) {
131- serializationFailedFlag = true
132- // read and discard bytes until stream is entirely consumed
133- try {
134- sin.readByte()
135- } catch (_: EOFException ) {
136- }
137- }
138- return indexExecutionContext
139- } catch (e: EOFException ) {
140- indexExecutionContext
141- } catch (e: Exception ) {
142- serializationFailedFlag = true
143- log.error(" Error parsing index execution context in Doc level monitor fanout request" , e)
144- while (sin.read() != 0 ) {
145- try { // read and throw bytes until stream is entirely consumed
146- sin.readByte()
147- } catch (_: EOFException ) {
148- }
149- }
150- null
151- }
152- }
153- }
154-
155- private constructor (
156- monitor: Monitor ,
157- dryRun: Boolean ,
158- monitorMetadata: MonitorMetadata ,
159- executionId: String ,
160- indexExecutionContext: IndexExecutionContext ? ,
161- shardIds: List <ShardId >,
162- concreteIndicesSeenSoFar: List <String >,
163- workflowRunContext: WorkflowRunContext ? ,
164- hasSerializationFailed: Boolean
165- ) : super () {
166- this .monitor = monitor
167- this .dryRun = dryRun
168- this .monitorMetadata = monitorMetadata
169- this .executionId = executionId
170- this .indexExecutionContext = indexExecutionContext
171- this .shardIds = shardIds
172- this .concreteIndicesSeenSoFar = concreteIndicesSeenSoFar
173- this .workflowRunContext = workflowRunContext
174- this .hasSerializationFailed = hasSerializationFailed ? : false
17545 }
17646
17747 constructor (
@@ -196,16 +66,63 @@ class DocLevelMonitorFanOutRequest : ActionRequest, ToXContentObject {
19666 }
19767
19868 @Throws(IOException ::class )
199- constructor (sin: StreamInput ) : this (
200- monitor = safeReadMonitor(sin),
201- dryRun = safeReadBoolean(sin),
202- monitorMetadata = safeReadMonitorMetadata(sin),
203- executionId = safeReadString(sin),
204- shardIds = safeReadShardIds(sin),
205- concreteIndicesSeenSoFar = safeReadStringList(sin),
206- workflowRunContext = safeReadWorkflowRunContext(sin),
207- indexExecutionContext = safeReadIndexExecutionContext(sin),
208- hasSerializationFailed = serializationFailedFlag
69+ constructor (sin: StreamInput ) : super () {
70+ var monitorSerializationSucceeded = true
71+ var parsedMonitor = getDummyMonitor()
72+ try {
73+ parsedMonitor = Monitor (sin)
74+ } catch (e: Exception ) {
75+ log.error(" Error parsing monitor in Doc level monitor fanout request" , e)
76+ monitorSerializationSucceeded = false
77+ log.info(" Force consuming stream in Doc level monitor fanout request" )
78+ while (sin.read() != 0 ) {
79+ // read and discard bytes until stream is entirely consumed
80+ try {
81+ sin.readByte()
82+ } catch (_: EOFException ) {
83+ }
84+ }
85+ }
86+ if (monitorSerializationSucceeded) {
87+ this .monitor = parsedMonitor
88+ this .dryRun = sin.readBoolean()
89+ this .monitorMetadata = MonitorMetadata .readFrom(sin)
90+ this .executionId = sin.readString()
91+ this .shardIds = sin.readList(::ShardId )
92+ this .concreteIndicesSeenSoFar = sin.readStringList()
93+ this .workflowRunContext = if (sin.readBoolean()) {
94+ WorkflowRunContext (sin)
95+ } else {
96+ null
97+ }
98+ indexExecutionContext = IndexExecutionContext (sin)
99+ this .hasSerializationFailed = false == monitorSerializationSucceeded
100+ } else {
101+ this .monitor = parsedMonitor
102+ this .dryRun = false
103+ this .monitorMetadata = MonitorMetadata (
104+ " failed_serde" ,
105+ SequenceNumbers .UNASSIGNED_SEQ_NO ,
106+ SequenceNumbers .UNASSIGNED_PRIMARY_TERM ,
107+ " failed_serde" ,
108+ emptyList(),
109+ emptyMap(),
110+ mutableMapOf ()
111+ )
112+ this .executionId = " "
113+ this .shardIds = emptyList()
114+ this .concreteIndicesSeenSoFar = emptyList()
115+ this .workflowRunContext = null
116+ this .indexExecutionContext = null
117+ this .hasSerializationFailed = false == monitorSerializationSucceeded
118+ }
119+ }
120+
121+ private fun getDummyMonitor () = Monitor (
122+ " failed_serde" , NO_VERSION , " failed_serde" , true ,
123+ IntervalSchedule (1 , ChronoUnit .MINUTES ), Instant .now(), Instant .now(), " " ,
124+ null , NO_SCHEMA_VERSION , emptyList(), emptyList(), emptyMap(),
125+ DataSources (), false , false , " failed"
209126 )
210127
211128 @Throws(IOException ::class )
0 commit comments