Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,9 @@ func (be *postgresBackend) GetOrchestrationWorkItem(ctx context.Context) (*backe
SELECT 1 FROM NewEvents E
WHERE E.InstanceID = I.InstanceID AND (E.VisibleTime IS NULL OR E.VisibleTime < $4)
)
ORDER BY I.SequenceNumber ASC
LIMIT 1
FOR UPDATE SKIP LOCKED
) RETURNING InstanceID`,
be.workerName, // LockedBy for Instances table
newLockExpiration, // Updated LockExpiration for Instances table
Expand Down Expand Up @@ -864,7 +866,9 @@ func (be *postgresBackend) GetActivityWorkItem(ctx context.Context) (*backend.Ac
WHERE SequenceNumber = (
SELECT SequenceNumber FROM NewTasks T
WHERE T.LockExpiration IS NULL OR T.LockExpiration < $3
ORDER BY T.SequenceNumber ASC
LIMIT 1
FOR UPDATE SKIP LOCKED
) RETURNING SequenceNumber, InstanceID, EventPayload`,
be.workerName,
newLockExpiration,
Expand Down
3 changes: 3 additions & 0 deletions backend/postgres/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ CREATE TABLE IF NOT EXISTS Instances (
ParentInstanceID TEXT NULL
);

-- This index is used to improve queries with ORDER BY Instances.SequenceNumber
CREATE INDEX IF NOT EXISTS IX_Instances_SequenceNumber ON Instances(SequenceNumber);

-- This index is used by LockNext and Purge logic
CREATE INDEX IF NOT EXISTS IX_Instances_RuntimeStatus ON Instances(RuntimeStatus);

Expand Down
1 change: 1 addition & 0 deletions backend/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ func (be *sqliteBackend) GetActivityWorkItem(ctx context.Context) (*backend.Acti
WHERE [SequenceNumber] = (
SELECT [SequenceNumber] FROM NewTasks T
WHERE T.[LockExpiration] IS NULL OR T.[LockExpiration] < ?
ORDER BY T.[SequenceNumber] ASC
LIMIT 1
) RETURNING [SequenceNumber], [InstanceID], [EventPayload]`,
be.workerName,
Expand Down
Loading