Skip to content
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

Refactor persistence task serializer #2555

Merged
merged 1 commit into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 36 additions & 23 deletions common/persistence/execution_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,12 +716,13 @@ func (m *executionManagerImpl) GetHistoryTask(
if err != nil {
return nil, err
}
tasks, err := m.serializer.DeserializeTasks(request.TaskCategory, []commonpb.DataBlob{resp.Task})

task, err := m.serializer.DeserializeTask(request.TaskCategory, resp.Task)
if err != nil {
return nil, err
}
return &GetHistoryTaskResponse{
Task: tasks[0],
Task: task,
}, nil
}

Expand All @@ -740,10 +741,16 @@ func (m *executionManagerImpl) GetHistoryTasks(
if err != nil {
return nil, err
}
tasks, err := m.serializer.DeserializeTasks(request.TaskCategory, resp.Tasks)
if err != nil {
return nil, err

tasks := make([]tasks.Task, 0, len(resp.Tasks))
for _, blob := range resp.Tasks {
task, err := m.serializer.DeserializeTask(request.TaskCategory, blob)
if err != nil {
return nil, err
}
tasks = append(tasks, task)
}

return &GetHistoryTasksResponse{
Tasks: tasks,
NextPageToken: resp.NextPageToken,
Expand Down Expand Up @@ -783,11 +790,21 @@ func (m *executionManagerImpl) GetReplicationTasksFromDLQ(
if err != nil {
return nil, err
}
tasks, err := m.serializer.DeserializeTasks(tasks.CategoryReplication, resp.Tasks)
if err != nil {
return nil, err

category := tasks.CategoryReplication
tasks := make([]tasks.Task, 0, len(resp.Tasks))
for _, blob := range resp.Tasks {
task, err := m.serializer.DeserializeTask(category, blob)
if err != nil {
return nil, err
}
tasks = append(tasks, task)
}
return &GetReplicationTasksFromDLQResponse{Tasks: tasks, NextPageToken: resp.NextPageToken}, nil

return &GetReplicationTasksFromDLQResponse{
Tasks: tasks,
NextPageToken: resp.NextPageToken,
}, nil
}

func (m *executionManagerImpl) DeleteReplicationTaskFromDLQ(
Expand Down Expand Up @@ -962,23 +979,19 @@ func serializeTasks(
inputTasks map[tasks.Category][]tasks.Task,
) (map[tasks.Category][]InternalHistoryTask, error) {
outputTasks := make(map[tasks.Category][]InternalHistoryTask)
for category, tasksByQueueType := range inputTasks {
// TODO: update serializer interface to serialize & deserialize one task at a time
// ideally, SerializeTasks should return a list of []InternalHistoryTask, which groups
// serialized task with it's key, howeve that will result in a cycle dependency issue
// between persistence and serializer package.
serializedTasks, err := serializer.SerializeTasks(tasksByQueueType)
if err != nil {
return nil, err
}

outputTasks[category] = make([]InternalHistoryTask, 0, len(serializedTasks))
for key, blob := range serializedTasks {
outputTasks[category] = append(outputTasks[category], InternalHistoryTask{
Key: key,
for category, tasks := range inputTasks {
serializedTasks := make([]InternalHistoryTask, 0, len(tasks))
for _, task := range tasks {
blob, err := serializer.SerializeTask(task)
if err != nil {
return nil, err
}
serializedTasks = append(serializedTasks, InternalHistoryTask{
Key: task.GetKey(),
Blob: blob,
})
}
outputTasks[category] = serializedTasks
}
return outputTasks, nil
}
Expand Down
4 changes: 2 additions & 2 deletions common/persistence/serialization/serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ type (
ReplicationTaskToBlob(replicationTask *replicationspb.ReplicationTask, encodingType enumspb.EncodingType) (*commonpb.DataBlob, error)
ReplicationTaskFromBlob(data *commonpb.DataBlob) (*replicationspb.ReplicationTask, error)

SerializeTasks(taskSlice []tasks.Task) (map[tasks.Key]commonpb.DataBlob, error)
DeserializeTasks(category tasks.Category, blobSlice []commonpb.DataBlob) ([]tasks.Task, error)
SerializeTask(task tasks.Task) (commonpb.DataBlob, error)
DeserializeTask(category tasks.Category, blob commonpb.DataBlob) (tasks.Task, error)
}

// SerializationError is an error type for serialization
Expand Down