@@ -46,12 +46,15 @@ import (
46
46
"go.temporal.io/api/workflowservice/v1"
47
47
48
48
"go.temporal.io/server/common"
49
+ "go.temporal.io/server/common/archiver"
49
50
"go.temporal.io/server/common/convert"
50
51
"go.temporal.io/server/common/dynamicconfig"
51
52
"go.temporal.io/server/common/log/tag"
52
53
"go.temporal.io/server/common/payloads"
53
54
"go.temporal.io/server/common/persistence"
55
+ "go.temporal.io/server/common/primitives"
54
56
"go.temporal.io/server/common/primitives/timestamp"
57
+ "go.temporal.io/server/common/searchattribute"
55
58
)
56
59
57
60
const (
@@ -100,7 +103,7 @@ func (s *archivalSuite) TestArchival_TimerQueueProcessor() {
100
103
WorkflowId : workflowID ,
101
104
RunId : runID ,
102
105
}
103
- s .True (s .isHistoryArchived (s .archivalNamespace , execution ))
106
+ s .True (s .isArchived (s .archivalNamespace , execution ))
104
107
s .True (s .isHistoryDeleted (execution ))
105
108
s .True (s .isMutableStateDeleted (namespaceID , execution ))
106
109
}
@@ -121,7 +124,7 @@ func (s *archivalSuite) TestArchival_ContinueAsNew() {
121
124
WorkflowId : workflowID ,
122
125
RunId : runID ,
123
126
}
124
- s .True (s .isHistoryArchived (s .archivalNamespace , execution ))
127
+ s .True (s .isArchived (s .archivalNamespace , execution ))
125
128
s .True (s .isHistoryDeleted (execution ))
126
129
s .True (s .isMutableStateDeleted (namespaceID , execution ))
127
130
}
@@ -143,7 +146,7 @@ func (s *archivalSuite) TestArchival_ArchiverWorker() {
143
146
WorkflowId : workflowID ,
144
147
RunId : runID ,
145
148
}
146
- s .True (s .isHistoryArchived (s .archivalNamespace , execution ))
149
+ s .True (s .isArchived (s .archivalNamespace , execution ))
147
150
s .True (s .isHistoryDeleted (execution ))
148
151
s .True (s .isMutableStateDeleted (namespaceID , execution ))
149
152
}
@@ -201,18 +204,68 @@ func (s *IntegrationBase) getNamespaceID(namespace string) string {
201
204
return namespaceResp .NamespaceInfo .GetId ()
202
205
}
203
206
204
- func (s * archivalSuite ) isHistoryArchived (namespace string , execution * commonpb.WorkflowExecution ) bool {
205
- request := & workflowservice.GetWorkflowExecutionHistoryRequest {
206
- Namespace : s .archivalNamespace ,
207
- Execution : execution ,
208
- }
207
+ // isArchived returns true if both the workflow history and workflow visibility are archived.
208
+ func (s * archivalSuite ) isArchived (namespace string , execution * commonpb.WorkflowExecution ) bool {
209
+ serviceName := string (primitives .HistoryService )
210
+ historyURI , err := archiver .NewURI (s .testCluster .archiverBase .historyURI )
211
+ s .NoError (err )
212
+ historyArchiver , err := s .testCluster .archiverBase .provider .GetHistoryArchiver (
213
+ historyURI .Scheme (),
214
+ serviceName ,
215
+ )
216
+ s .NoError (err )
217
+
218
+ visibilityURI , err := archiver .NewURI (s .testCluster .archiverBase .visibilityURI )
219
+ s .NoError (err )
220
+ visibilityArchiver , err := s .testCluster .archiverBase .provider .GetVisibilityArchiver (
221
+ visibilityURI .Scheme (),
222
+ serviceName ,
223
+ )
224
+ s .NoError (err )
209
225
210
226
for i := 0 ; i < retryLimit ; i ++ {
211
- getHistoryResp , err := s .engine .GetWorkflowExecutionHistory (NewContext (), request )
212
- if err == nil && getHistoryResp != nil && getHistoryResp .GetArchived () {
227
+ ctx := NewContext ()
228
+ if i > 0 {
229
+ time .Sleep (retryBackoffTime )
230
+ }
231
+ namespaceID := s .getNamespaceID (namespace )
232
+ var historyResponse * archiver.GetHistoryResponse
233
+ historyResponse , err = historyArchiver .Get (ctx , historyURI , & archiver.GetHistoryRequest {
234
+ NamespaceID : namespaceID ,
235
+ WorkflowID : execution .GetWorkflowId (),
236
+ RunID : execution .GetRunId (),
237
+ PageSize : 1 ,
238
+ })
239
+ if err != nil {
240
+ continue
241
+ }
242
+ if len (historyResponse .HistoryBatches ) == 0 {
243
+ continue
244
+ }
245
+ var visibilityResponse * archiver.QueryVisibilityResponse
246
+ visibilityResponse , err = visibilityArchiver .Query (
247
+ ctx ,
248
+ visibilityURI ,
249
+ & archiver.QueryVisibilityRequest {
250
+ NamespaceID : namespaceID ,
251
+ PageSize : 1 ,
252
+ Query : fmt .Sprintf (
253
+ "WorkflowId = '%s' and RunId = '%s'" ,
254
+ execution .GetWorkflowId (),
255
+ execution .GetRunId (),
256
+ ),
257
+ },
258
+ searchattribute.NameTypeMap {},
259
+ )
260
+ if err != nil {
261
+ continue
262
+ }
263
+ if len (visibilityResponse .Executions ) > 0 {
213
264
return true
214
265
}
215
- time .Sleep (retryBackoffTime )
266
+ }
267
+ if err != nil {
268
+ fmt .Println ("isArchived failed with error: " , err )
216
269
}
217
270
return false
218
271
}
0 commit comments