@@ -49,11 +49,10 @@ import (
49
49
"go.temporal.io/server/common/persistence/visibility/store/elasticsearch/client"
50
50
"go.temporal.io/server/common/persistence/visibility/store/query"
51
51
"go.temporal.io/server/common/searchattribute"
52
- "go.temporal.io/server/common/util"
53
52
)
54
53
55
54
const (
56
- persistenceName = "elasticsearch"
55
+ PersistenceName = "elasticsearch"
57
56
58
57
delimiter = "~"
59
58
pointInTimeKeepAliveInterval = "1m"
@@ -128,7 +127,7 @@ func (s *visibilityStore) Close() {
128
127
}
129
128
130
129
func (s * visibilityStore ) GetName () string {
131
- return persistenceName
130
+ return PersistenceName
132
131
}
133
132
134
133
func (s * visibilityStore ) RecordWorkflowExecutionStarted (
@@ -232,32 +231,30 @@ func (s *visibilityStore) addBulkIndexRequestAndWait(
232
231
}
233
232
234
233
func (s * visibilityStore ) addBulkRequestAndWait (
235
- ctx context.Context ,
234
+ _ context.Context ,
236
235
bulkRequest * client.BulkableRequest ,
237
236
visibilityTaskKey string ,
238
237
) error {
239
238
s .checkProcessor ()
240
239
241
240
// Add method is blocking. If bulk processor is busy flushing previous bulk, request will wait here.
242
- // Therefore, ackTimeoutTimer in fact wait for request to be committed after it was added to bulk processor.
243
- // TODO: this also means ctx is not respected if bulk processor is busy. Shall we make Add non-blocking or
244
- // respecting the context?
245
- future := s .processor .Add (bulkRequest , visibilityTaskKey )
246
-
247
- ackTimeout := s .processorAckTimeout ()
248
- if deadline , ok := ctx .Deadline (); ok {
249
- ackTimeout = util .Min (ackTimeout , time .Until (deadline ))
250
- }
251
- subCtx , subCtxCancelFn := context .WithTimeout (context .Background (), ackTimeout )
252
- defer subCtxCancelFn ()
253
-
254
- ack , err := future .Get (subCtx )
241
+ ackF := s .processor .Add (bulkRequest , visibilityTaskKey )
255
242
256
- if errors .Is (err , context .DeadlineExceeded ) {
257
- return & persistence.TimeoutError {Msg : fmt .Sprintf ("visibility task %s timedout waiting for ACK after %v" , visibilityTaskKey , s .processorAckTimeout ())}
258
- }
243
+ // processorAckTimeout is a maximum duration for bulk processor to commit the bulk and unblock the `ackF`.
244
+ // Default value is 30s and this timeout should never have happened,
245
+ // because Elasticsearch must process a bulk within 30s.
246
+ // Parent context is not respected here because it has shorter timeout (3s),
247
+ // which might already expired here due to wait at Add method above.
248
+ ctx , cancel := context .WithTimeout (context .Background (), s .processorAckTimeout ())
249
+ defer cancel ()
250
+ ack , err := ackF .Get (ctx )
259
251
260
252
if err != nil {
253
+ if errors .Is (err , context .DeadlineExceeded ) {
254
+ return & persistence.TimeoutError {Msg : fmt .Sprintf ("visibility task %s timed out waiting for ACK after %v" , visibilityTaskKey , s .processorAckTimeout ())}
255
+ }
256
+ // Returns non-retryable Internal error here because these errors are unexpected.
257
+ // Visibility task processor retries all errors though, therefore new request will be generated for the same task.
261
258
return serviceerror .NewInternal (fmt .Sprintf ("visibility task %s received error %v" , visibilityTaskKey , err ))
262
259
}
263
260
@@ -900,7 +897,7 @@ func (s *visibilityStore) parseESDoc(docID string, docSource json.RawMessage, sa
900
897
// Very important line. See finishParseJSONValue bellow.
901
898
d .UseNumber ()
902
899
if err := d .Decode (& sourceMap ); err != nil {
903
- s .metricsHandler .Counter (metrics .ElasticsearchDocumentParseFailuresCount .GetMetricName ()) // .Record(1)
900
+ s .metricsHandler .Counter (metrics .ElasticsearchDocumentParseFailuresCount .GetMetricName ()).Record (1 )
904
901
return nil , serviceerror .NewInternal (fmt .Sprintf ("Unable to unmarshal JSON from Elasticsearch document(%s): %v" , docID , err ))
905
902
}
906
903
0 commit comments