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

perf: include height restrictions in update clauses of leasing queries #189

Merged
merged 1 commit into from
Nov 2, 2020
Merged
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
18 changes: 12 additions & 6 deletions storage/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,11 @@ WITH leased AS (
FOR UPDATE SKIP LOCKED
) candidates
WHERE visor_processing_tipsets.tip_set = candidates.tip_set AND visor_processing_tipsets.height = candidates.height
AND visor_processing_tipsets.height >= ? AND visor_processing_tipsets.height <= ?
RETURNING visor_processing_tipsets.tip_set, visor_processing_tipsets.height
)
SELECT tip_set,height FROM leased;
`, claimUntil, d.Clock.Now(), minHeight, maxHeight, batchSize)
`, claimUntil, d.Clock.Now(), minHeight, maxHeight, batchSize, minHeight, maxHeight)
if err != nil {
return err
}
Expand Down Expand Up @@ -376,9 +377,10 @@ WITH leased AS (
FOR UPDATE SKIP LOCKED
) candidates
WHERE a.head = candidates.head AND a.code = candidates.code
RETURNING a.head, a.code, a.nonce, a.balance, a.address, a.parent_state_root, a.tip_set, a.parent_tip_set, a.height)
AND a.height >= ? AND a.height <= ?
RETURNING a.head, a.code, a.nonce, a.balance, a.address, a.parent_state_root, a.tip_set, a.parent_tip_set, a.height)
SELECT head, code, nonce, balance, address, parent_state_root, tip_set, parent_tip_set, height from leased;
`, claimUntil, d.Clock.Now(), minHeight, maxHeight, pg.In(codes), batchSize)
`, claimUntil, d.Clock.Now(), minHeight, maxHeight, pg.In(codes), batchSize, minHeight, maxHeight)
if err != nil {
return err
}
Expand Down Expand Up @@ -474,10 +476,11 @@ WITH leased AS (
FOR UPDATE SKIP LOCKED
) candidates
WHERE visor_processing_tipsets.tip_set = candidates.tip_set AND visor_processing_tipsets.height = candidates.height
AND visor_processing_tipsets.height >= ? AND visor_processing_tipsets.height <= ?
RETURNING visor_processing_tipsets.tip_set, visor_processing_tipsets.height
)
SELECT tip_set,height FROM leased;
`, claimUntil, d.Clock.Now(), minHeight, maxHeight, batchSize)
`, claimUntil, d.Clock.Now(), minHeight, maxHeight, batchSize, minHeight, maxHeight)
if err != nil {
return err
}
Expand Down Expand Up @@ -540,12 +543,14 @@ WITH leased AS (
pm.height >= ? AND pm.height <= ?
ORDER BY pm.height DESC
LIMIT ?
FOR UPDATE SKIP LOCKED
) candidates
WHERE pm.cid = candidates.cid
AND pm.height >= ? AND pm.height <= ?
RETURNING pm.cid, candidates.*
)
SELECT * FROM leased;
`, claimUntil, d.Clock.Now(), minHeight, maxHeight, batchSize)
`, claimUntil, d.Clock.Now(), minHeight, maxHeight, batchSize, minHeight, maxHeight)
if err != nil {
return err
}
Expand Down Expand Up @@ -598,10 +603,11 @@ WITH leased AS (
FOR UPDATE SKIP LOCKED
) candidates
WHERE visor_processing_tipsets.tip_set = candidates.tip_set AND visor_processing_tipsets.height = candidates.height
AND visor_processing_tipsets.height >= ? AND visor_processing_tipsets.height <= ?
RETURNING visor_processing_tipsets.tip_set, visor_processing_tipsets.height
)
SELECT tip_set,height FROM leased;
`, claimUntil, d.Clock.Now(), minHeight, maxHeight, batchSize)
`, claimUntil, d.Clock.Now(), minHeight, maxHeight, batchSize, minHeight, maxHeight)
if err != nil {
return err
}
Expand Down