-
Notifications
You must be signed in to change notification settings - Fork 805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
buffer events when decision task is inflight #386
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -268,7 +268,7 @@ const ( | |
`and task_id = ? ` + | ||
`IF range_id = ?` | ||
|
||
templateGetWorkflowExecutionQuery = `SELECT execution, activity_map, timer_map, child_executions_map, request_cancel_map ` + | ||
templateGetWorkflowExecutionQuery = `SELECT execution, activity_map, timer_map, child_executions_map, request_cancel_map, buffered_events_list ` + | ||
`FROM executions ` + | ||
`WHERE shard_id = ? ` + | ||
`and type = ? ` + | ||
|
@@ -343,6 +343,28 @@ const ( | |
`and task_id = ? ` + | ||
`IF next_event_id = ?` | ||
|
||
templateAppendBufferedEventsQuery = `UPDATE executions ` + | ||
`SET buffered_events_list = buffered_events_list + ? ` + | ||
`WHERE shard_id = ? ` + | ||
`and type = ? ` + | ||
`and domain_id = ? ` + | ||
`and workflow_id = ? ` + | ||
`and run_id = ? ` + | ||
`and visibility_ts = ? ` + | ||
`and task_id = ? ` + | ||
`IF next_event_id = ?` | ||
|
||
templateDeleteBufferedEventsQuery = `UPDATE executions ` + | ||
`SET buffered_events_list = [] ` + | ||
`WHERE shard_id = ? ` + | ||
`and type = ? ` + | ||
`and domain_id = ? ` + | ||
`and workflow_id = ? ` + | ||
`and run_id = ? ` + | ||
`and visibility_ts = ? ` + | ||
`and task_id = ? ` + | ||
`IF next_event_id = ?` | ||
|
||
templateDeleteActivityInfoQuery = `DELETE activity_map[ ? ] ` + | ||
`FROM executions ` + | ||
`WHERE shard_id = ? ` + | ||
|
@@ -942,6 +964,14 @@ func (d *cassandraPersistence) GetWorkflowExecution(request *GetWorkflowExecutio | |
} | ||
state.RequestCancelInfos = requestCancelInfos | ||
|
||
eList := result["buffered_events_list"].([]map[string]interface{}) | ||
bufferedEvents := make([]*SerializedHistoryEventBatch, 0, len(eList)) | ||
for _, v := range eList { | ||
eventBatch := createSerializedHistoryEventBatch(v) | ||
bufferedEvents = append(bufferedEvents, eventBatch) | ||
} | ||
state.BufferedEvents = bufferedEvents | ||
|
||
return &GetWorkflowExecutionResponse{State: state}, nil | ||
} | ||
|
||
|
@@ -1005,6 +1035,9 @@ func (d *cassandraPersistence) UpdateWorkflowExecution(request *UpdateWorkflowEx | |
d.updateRequestCancelInfos(batch, request.UpsertRequestCancelInfos, request.DeleteRequestCancelInfo, | ||
executionInfo.DomainID, executionInfo.WorkflowID, executionInfo.RunID, request.Condition, request.RangeID) | ||
|
||
d.updateBufferedEvents(batch, request.NewBufferedEvents, request.ClearBufferedEvents, | ||
executionInfo.DomainID, executionInfo.WorkflowID, executionInfo.RunID, request.Condition, request.RangeID) | ||
|
||
if request.ContinueAsNew != nil { | ||
startReq := request.ContinueAsNew | ||
d.CreateWorkflowExecutionWithinBatch(startReq, batch, cqlNowTimestamp) | ||
|
@@ -1837,6 +1870,38 @@ func (d *cassandraPersistence) updateRequestCancelInfos(batch *gocql.Batch, requ | |
} | ||
} | ||
|
||
func (d *cassandraPersistence) updateBufferedEvents(batch *gocql.Batch, newBufferedEvents *SerializedHistoryEventBatch, | ||
clearBufferedEvents bool, domainID, workflowID, runID string, condition int64, rangeID int64) { | ||
|
||
if clearBufferedEvents { | ||
batch.Query(templateDeleteBufferedEventsQuery, | ||
d.shardID, | ||
rowTypeExecution, | ||
domainID, | ||
workflowID, | ||
runID, | ||
defaultVisibilityTimestamp, | ||
rowTypeExecutionTaskID, | ||
condition) | ||
} else if newBufferedEvents != nil { | ||
values := make(map[string]interface{}) | ||
values["encoding_type"] = newBufferedEvents.EncodingType | ||
values["version"] = newBufferedEvents.Version | ||
values["data"] = newBufferedEvents.Data | ||
newEventValues := []map[string]interface{}{values} | ||
batch.Query(templateAppendBufferedEventsQuery, | ||
newEventValues, | ||
d.shardID, | ||
rowTypeExecution, | ||
domainID, | ||
workflowID, | ||
runID, | ||
defaultVisibilityTimestamp, | ||
rowTypeExecutionTaskID, | ||
condition) | ||
} | ||
} | ||
|
||
func createShardInfo(result map[string]interface{}) *ShardInfo { | ||
info := &ShardInfo{} | ||
for k, v := range result { | ||
|
@@ -2048,6 +2113,21 @@ func createRequestCancelInfo(result map[string]interface{}) *RequestCancelInfo { | |
return info | ||
} | ||
|
||
func createSerializedHistoryEventBatch(result map[string]interface{}) *SerializedHistoryEventBatch { | ||
// TODO: default to JSON, update this when we support different encoding types. | ||
eventBatch := &SerializedHistoryEventBatch{EncodingType: common.EncodingTypeJSON} | ||
for k, v := range result { | ||
switch k { | ||
case "version": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with the default but why are you not reading the encoding_type? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since the value is already set to JSON when create the struct in this method, so there is no need to read the encoding_type, unless we support other encoding type. |
||
eventBatch.Version = v.(int) | ||
case "data": | ||
eventBatch.Data = v.([]byte) | ||
} | ||
} | ||
|
||
return eventBatch | ||
} | ||
|
||
func createTaskInfo(result map[string]interface{}) *TaskInfo { | ||
info := &TaskInfo{} | ||
for k, v := range result { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you refactor this logic in a helper method. For example look at 'createTimerTaskInfo'. We create a helper method to deserialize each of these custom types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the logic is already put in a help function createSerializedHistoryEventBatch().