-
Notifications
You must be signed in to change notification settings - Fork 776
/
interfaces.go
403 lines (378 loc) · 15.8 KB
/
interfaces.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
// The MIT License (MIT)
//
// Copyright (c) 2017-2020 Uber Technologies Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
package serialization
import (
"time"
"go.uber.org/thriftrw/protocol/stream"
"go.uber.org/thriftrw/wire"
"github.com/uber/cadence/.gen/go/sqlblobs"
"github.com/uber/cadence/common"
"github.com/uber/cadence/common/persistence"
"github.com/uber/cadence/common/types"
)
type (
// ShardInfo blob in a serialization agnostic format
ShardInfo struct {
StolenSinceRenew int32
UpdatedAt time.Time
ReplicationAckLevel int64
TransferAckLevel int64
TimerAckLevel time.Time
DomainNotificationVersion int64
ClusterTransferAckLevel map[string]int64
ClusterTimerAckLevel map[string]time.Time
Owner string
ClusterReplicationLevel map[string]int64
PendingFailoverMarkers []byte
PendingFailoverMarkersEncoding string
ReplicationDlqAckLevel map[string]int64
TransferProcessingQueueStates []byte
TransferProcessingQueueStatesEncoding string
CrossClusterProcessingQueueStates []byte
CrossClusterProcessingQueueStatesEncoding string
TimerProcessingQueueStates []byte
TimerProcessingQueueStatesEncoding string
}
// DomainInfo blob in a serialization agnostic format
DomainInfo struct {
Name string // TODO: This field seems not to be required. We already store domain name in another column.
Description string
Owner string
Status int32
Retention time.Duration
EmitMetric bool
ArchivalBucket string
ArchivalStatus int16
ConfigVersion int64
NotificationVersion int64
FailoverNotificationVersion int64
FailoverVersion int64
ActiveClusterName string
Clusters []string
Data map[string]string
BadBinaries []byte
BadBinariesEncoding string
HistoryArchivalStatus int16
HistoryArchivalURI string
VisibilityArchivalStatus int16
VisibilityArchivalURI string
FailoverEndTimestamp *time.Time // TODO: There is logic checking if it's nil, should revisit this
PreviousFailoverVersion int64
LastUpdatedTimestamp time.Time
IsolationGroups []byte
IsolationGroupsEncoding string
}
// HistoryBranchRange blob in a serialization agnostic format
HistoryBranchRange struct {
BranchID string
BeginNodeID int64
EndNodeID int64
}
// HistoryTreeInfo blob in a serialization agnostic format
HistoryTreeInfo struct {
CreatedTimestamp time.Time
Ancestors []*types.HistoryBranchRange
Info string
}
// WorkflowExecutionInfo blob in a serialization agnostic format
WorkflowExecutionInfo struct {
ParentDomainID UUID
ParentWorkflowID string
ParentRunID UUID
InitiatedID int64
CompletionEventBatchID *int64 // TODO: This is not updated because of backward compatibility issue. Should revisit it later.
CompletionEvent []byte
CompletionEventEncoding string
TaskList string
IsCron bool
WorkflowTypeName string
WorkflowTimeout time.Duration
DecisionTaskTimeout time.Duration
ExecutionContext []byte
State int32
CloseStatus int32
StartVersion int64
LastWriteEventID *int64 // TODO: We have logic checking if LastWriteEventID != nil. The field seems to be deprecated. Should revisit it later.
LastEventTaskID int64
LastFirstEventID int64
LastProcessedEvent int64
StartTimestamp time.Time
LastUpdatedTimestamp time.Time
DecisionVersion int64
DecisionScheduleID int64
DecisionStartedID int64
DecisionTimeout time.Duration
DecisionAttempt int64
DecisionStartedTimestamp time.Time
DecisionScheduledTimestamp time.Time
CancelRequested bool
DecisionOriginalScheduledTimestamp time.Time
CreateRequestID string
DecisionRequestID string
CancelRequestID string
StickyTaskList string
StickyScheduleToStartTimeout time.Duration
RetryAttempt int64
RetryInitialInterval time.Duration
RetryMaximumInterval time.Duration
RetryMaximumAttempts int32
RetryExpiration time.Duration
RetryBackoffCoefficient float64
RetryExpirationTimestamp time.Time
RetryNonRetryableErrors []string
HasRetryPolicy bool
CronSchedule string
EventStoreVersion int32
EventBranchToken []byte
SignalCount int64
HistorySize int64
ClientLibraryVersion string
ClientFeatureVersion string
ClientImpl string
AutoResetPoints []byte
AutoResetPointsEncoding string
SearchAttributes map[string][]byte
Memo map[string][]byte
VersionHistories []byte
VersionHistoriesEncoding string
FirstExecutionRunID UUID
PartitionConfig map[string]string
}
// ActivityInfo blob in a serialization agnostic format
ActivityInfo struct {
Version int64
ScheduledEventBatchID int64
ScheduledEvent []byte
ScheduledEventEncoding string
ScheduledTimestamp time.Time
StartedID int64
StartedEvent []byte
StartedEventEncoding string
StartedTimestamp time.Time
ActivityID string
RequestID string
ScheduleToStartTimeout time.Duration
ScheduleToCloseTimeout time.Duration
StartToCloseTimeout time.Duration
HeartbeatTimeout time.Duration
CancelRequested bool
CancelRequestID int64
TimerTaskStatus int32
Attempt int32
TaskList string
StartedIdentity string
HasRetryPolicy bool
RetryInitialInterval time.Duration
RetryMaximumInterval time.Duration
RetryMaximumAttempts int32
RetryExpirationTimestamp time.Time
RetryBackoffCoefficient float64
RetryNonRetryableErrors []string
RetryLastFailureReason string
RetryLastWorkerIdentity string
RetryLastFailureDetails []byte
}
// ChildExecutionInfo blob in a serialization agnostic format
ChildExecutionInfo struct {
Version int64
InitiatedEventBatchID int64
StartedID int64
InitiatedEvent []byte
InitiatedEventEncoding string
StartedWorkflowID string
StartedRunID UUID
StartedEvent []byte
StartedEventEncoding string
CreateRequestID string
DomainID string
DomainNameDEPRECATED string
WorkflowTypeName string
ParentClosePolicy int32
}
// SignalInfo blob in a serialization agnostic format
SignalInfo struct {
Version int64
InitiatedEventBatchID int64
RequestID string
Name string
Input []byte
Control []byte
}
// RequestCancelInfo blob in a serialization agnostic format
RequestCancelInfo struct {
Version int64
InitiatedEventBatchID int64
CancelRequestID string
}
// TimerInfo blob in a serialization agnostic format
TimerInfo struct {
Version int64
StartedID int64
ExpiryTimestamp time.Time
TaskID int64
}
// TaskInfo blob in a serialization agnostic format
TaskInfo struct {
WorkflowID string
RunID UUID
ScheduleID int64
ExpiryTimestamp time.Time
CreatedTimestamp time.Time
PartitionConfig map[string]string
}
// TaskListInfo blob in a serialization agnostic format
TaskListInfo struct {
Kind int16
AckLevel int64
ExpiryTimestamp time.Time
LastUpdated time.Time
}
// TransferTaskInfo blob in a serialization agnostic format
TransferTaskInfo struct {
DomainID UUID
WorkflowID string
RunID UUID
TaskType int16
TargetDomainID UUID
TargetDomainIDs []UUID
TargetWorkflowID string
TargetRunID UUID
TaskList string
TargetChildWorkflowOnly bool
ScheduleID int64
Version int64
VisibilityTimestamp time.Time
}
// CrossClusterTaskInfo blob in a serialization agnostic format
// Cross cluster tasks are exactly like transfer tasks so
// instead of creating another struct and duplicating the same
// logic everywhere. We reuse TransferTaskInfo
CrossClusterTaskInfo = TransferTaskInfo
sqlblobsCrossClusterTaskInfo = sqlblobs.TransferTaskInfo
// TimerTaskInfo blob in a serialization agnostic format
TimerTaskInfo struct {
DomainID UUID
WorkflowID string
RunID UUID
TaskType int16
TimeoutType *int16 // TODO: The default value for TimeoutType doesn't make sense. No equivalent value for nil.
Version int64
ScheduleAttempt int64
EventID int64
}
// ReplicationTaskInfo blob in a serialization agnostic format
ReplicationTaskInfo struct {
DomainID UUID
WorkflowID string
RunID UUID
TaskType int16
Version int64
FirstEventID int64
NextEventID int64
ScheduledID int64
EventStoreVersion int32
NewRunEventStoreVersion int32
BranchToken []byte
NewRunBranchToken []byte
CreationTimestamp time.Time
}
)
type (
// Parser is used to do serialization and deserialization. A parser is backed by a
// a single encoder which encodes into one format and a collection of decoders.
// Parser selects the appropriate decoder for the provided blob.
Parser interface {
ShardInfoToBlob(*ShardInfo) (persistence.DataBlob, error)
DomainInfoToBlob(*DomainInfo) (persistence.DataBlob, error)
HistoryTreeInfoToBlob(*HistoryTreeInfo) (persistence.DataBlob, error)
WorkflowExecutionInfoToBlob(*WorkflowExecutionInfo) (persistence.DataBlob, error)
ActivityInfoToBlob(*ActivityInfo) (persistence.DataBlob, error)
ChildExecutionInfoToBlob(*ChildExecutionInfo) (persistence.DataBlob, error)
SignalInfoToBlob(*SignalInfo) (persistence.DataBlob, error)
RequestCancelInfoToBlob(*RequestCancelInfo) (persistence.DataBlob, error)
TimerInfoToBlob(*TimerInfo) (persistence.DataBlob, error)
TaskInfoToBlob(*TaskInfo) (persistence.DataBlob, error)
TaskListInfoToBlob(*TaskListInfo) (persistence.DataBlob, error)
TransferTaskInfoToBlob(*TransferTaskInfo) (persistence.DataBlob, error)
CrossClusterTaskInfoToBlob(*CrossClusterTaskInfo) (persistence.DataBlob, error)
TimerTaskInfoToBlob(*TimerTaskInfo) (persistence.DataBlob, error)
ReplicationTaskInfoToBlob(*ReplicationTaskInfo) (persistence.DataBlob, error)
ShardInfoFromBlob([]byte, string) (*ShardInfo, error)
DomainInfoFromBlob([]byte, string) (*DomainInfo, error)
HistoryTreeInfoFromBlob([]byte, string) (*HistoryTreeInfo, error)
WorkflowExecutionInfoFromBlob([]byte, string) (*WorkflowExecutionInfo, error)
ActivityInfoFromBlob([]byte, string) (*ActivityInfo, error)
ChildExecutionInfoFromBlob([]byte, string) (*ChildExecutionInfo, error)
SignalInfoFromBlob([]byte, string) (*SignalInfo, error)
RequestCancelInfoFromBlob([]byte, string) (*RequestCancelInfo, error)
TimerInfoFromBlob([]byte, string) (*TimerInfo, error)
TaskInfoFromBlob([]byte, string) (*TaskInfo, error)
TaskListInfoFromBlob([]byte, string) (*TaskListInfo, error)
TransferTaskInfoFromBlob([]byte, string) (*TransferTaskInfo, error)
CrossClusterTaskInfoFromBlob([]byte, string) (*CrossClusterTaskInfo, error)
TimerTaskInfoFromBlob([]byte, string) (*TimerTaskInfo, error)
ReplicationTaskInfoFromBlob([]byte, string) (*ReplicationTaskInfo, error)
}
// encoder is used to serialize structs. Each encoder implementation uses one serialization format.
encoder interface {
shardInfoToBlob(*ShardInfo) ([]byte, error)
domainInfoToBlob(*DomainInfo) ([]byte, error)
historyTreeInfoToBlob(*HistoryTreeInfo) ([]byte, error)
workflowExecutionInfoToBlob(*WorkflowExecutionInfo) ([]byte, error)
activityInfoToBlob(*ActivityInfo) ([]byte, error)
childExecutionInfoToBlob(*ChildExecutionInfo) ([]byte, error)
signalInfoToBlob(*SignalInfo) ([]byte, error)
requestCancelInfoToBlob(*RequestCancelInfo) ([]byte, error)
timerInfoToBlob(*TimerInfo) ([]byte, error)
taskInfoToBlob(*TaskInfo) ([]byte, error)
taskListInfoToBlob(*TaskListInfo) ([]byte, error)
transferTaskInfoToBlob(*TransferTaskInfo) ([]byte, error)
crossClusterTaskInfoToBlob(*CrossClusterTaskInfo) ([]byte, error)
timerTaskInfoToBlob(*TimerTaskInfo) ([]byte, error)
replicationTaskInfoToBlob(*ReplicationTaskInfo) ([]byte, error)
encodingType() common.EncodingType
}
// decoder is used to deserialize structs. Each decoder implementation uses one serialization format.
decoder interface {
shardInfoFromBlob([]byte) (*ShardInfo, error)
domainInfoFromBlob([]byte) (*DomainInfo, error)
historyTreeInfoFromBlob([]byte) (*HistoryTreeInfo, error)
workflowExecutionInfoFromBlob([]byte) (*WorkflowExecutionInfo, error)
activityInfoFromBlob([]byte) (*ActivityInfo, error)
childExecutionInfoFromBlob([]byte) (*ChildExecutionInfo, error)
signalInfoFromBlob([]byte) (*SignalInfo, error)
requestCancelInfoFromBlob([]byte) (*RequestCancelInfo, error)
timerInfoFromBlob([]byte) (*TimerInfo, error)
taskInfoFromBlob([]byte) (*TaskInfo, error)
taskListInfoFromBlob([]byte) (*TaskListInfo, error)
transferTaskInfoFromBlob([]byte) (*TransferTaskInfo, error)
crossClusterTaskInfoFromBlob([]byte) (*CrossClusterTaskInfo, error)
timerTaskInfoFromBlob([]byte) (*TimerTaskInfo, error)
replicationTaskInfoFromBlob([]byte) (*ReplicationTaskInfo, error)
}
thriftRWType interface {
ToWire() (wire.Value, error)
FromWire(w wire.Value) error
Encode(stream.Writer) error
Decode(stream.Reader) error
}
)