InsertChatTask and EnqueueCallTask computed MAX(issue_number)+1, so concurrent inserts in one repository took the same number and the second failed on the unique key. Both now bump a chat_issue_numbers row, seeded from the existing maxima, whose row lock serializes allocation.
20 lines
649 B
SQL
20 lines
649 B
SQL
-- chat_issue_numbers holds the last synthetic issue number allocated in each
|
|
-- repository. Chat and workflow.call tasks take theirs by bumping this row,
|
|
-- whose row lock serializes concurrent inserts in one repository, which a
|
|
-- MAX(issue_number) read under READ COMMITTED cannot.
|
|
|
|
-- +goose Up
|
|
|
|
CREATE TABLE chat_issue_numbers (
|
|
owner text NOT NULL,
|
|
repo text NOT NULL,
|
|
last_number bigint NOT NULL,
|
|
PRIMARY KEY (owner, repo)
|
|
);
|
|
INSERT INTO chat_issue_numbers (owner, repo, last_number)
|
|
SELECT owner, repo, MAX(issue_number) FROM tasks WHERE source = 'chat' GROUP BY owner, repo;
|
|
|
|
-- +goose Down
|
|
|
|
DROP TABLE chat_issue_numbers;
|