Conversation
|
!bench !large |
There was a problem hiding this comment.
Pull Request Overview
This pull request refactors the Redis backend to use atomic Lua scripts for workflow and activity event operations, replacing Go-side pipelining with server-side execution. This improves transactional safety and consistency when persisting events, completing activities, canceling instances, and handling signals.
Key changes:
- Introduces four new Lua scripts for atomic operations:
signal_workflow.lua,delete_instance.lua,complete_activity_task.lua, andcancel_workflow_instance.lua - Removes helper methods
addWorkflowInstanceEventP,addEventPayloadsP, andaddEventToStreamPthat are now replaced by Lua scripts - Standardizes event marshaling by consistently using
marshalEventinstead of splitting marshaling logic
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
backend/redis/workflow.go |
Updated CompleteWorkflowTask to use unified marshalEvent helper and removed deprecated addWorkflowInstanceEventP method |
backend/redis/signal.go |
Replaced pipelined operations with atomic signalWorkflowCmd Lua script execution |
backend/redis/scripts/signal_workflow.lua |
New Lua script for atomically adding signal events and queueing workflow tasks |
backend/redis/scripts/delete_instance.lua |
New Lua script for atomic instance deletion |
backend/redis/scripts/complete_activity_task.lua |
New Lua script combining activity completion, event addition, and workflow queueing |
backend/redis/scripts/cancel_workflow_instance.lua |
New Lua script for atomic workflow cancellation |
backend/redis/redis.go |
Updated script loading to include new Lua scripts and removed obsolete script preloading logic |
backend/redis/instance.go |
Refactored CreateWorkflowInstance and CancelWorkflowInstance to use marshalEvent and new Lua scripts |
backend/redis/events.go |
Removed deprecated helper methods replaced by Lua scripts |
backend/redis/delete.go |
Migrated from inline script to external deleteInstanceCmd Lua script |
backend/redis/activity.go |
Replaced pipelined activity completion with atomic completeActivityTaskCmd Lua script |
| local instanceSegment = ARGV[4] | ||
|
|
||
| -- Add event payload | ||
| redis.pcall("HSETNX", payloadHashKey, eventId, payload) |
There was a problem hiding this comment.
Inconsistent error handling: Line 24 uses redis.pcall (which suppresses errors) while lines 27, 30, and 32 use redis.call (which propagates errors). Since payload storage is critical for event processing, use redis.call here for consistent error propagation.
| redis.pcall("HSETNX", payloadHashKey, eventId, payload) | |
| redis.call("HSETNX", payloadHashKey, eventId, payload) |
| local instanceSegment = ARGV[4] | ||
|
|
||
| -- Add event payload | ||
| redis.pcall("HSETNX", payloadHashKey, eventId, payload) |
There was a problem hiding this comment.
Inconsistent error handling: Line 12 uses redis.pcall (which suppresses errors) while lines 15, 18, and 20 use redis.call (which propagates errors). Since payload storage is critical for event processing, use redis.call here for consistent error propagation.
| redis.pcall("HSETNX", payloadHashKey, eventId, payload) | |
| redis.call("HSETNX", payloadHashKey, eventId, payload) |
|
|
||
| -- Store payload if provided (only if not empty) | ||
| if ARGV[5] ~= "" then | ||
| redis.pcall("HSETNX", KEYS[4], ARGV[3], ARGV[5]) |
There was a problem hiding this comment.
Inconsistent error handling: Line 33 uses redis.pcall (which suppresses errors) while other Redis operations use redis.call (which propagates errors). Since payload storage is critical for event processing, use redis.call here for consistent error propagation.
| redis.pcall("HSETNX", KEYS[4], ARGV[3], ARGV[5]) | |
| redis.call("HSETNX", KEYS[4], ARGV[3], ARGV[5]) |
Benchmark ResultsSQLite run
Large SQLite payload run (1MB)
Redis run
Large Redis payload run (1MB)
|
This pull request refactors how workflow and activity events are persisted and queued in the Redis backend by replacing multi-step Go-side pipelining with new atomic Lua scripts. The changes improve consistency, reliability, and transactional safety when handling workflow events, activity completions, instance cancellations, and signals. The update also removes now-unnecessary helper methods and streamlines event marshaling.
Fixes: #440