From 5dfec4ab36f0e57d695a2e99104e8dd368d0456e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 14 Mar 2024 14:44:58 +0100 Subject: [PATCH] lppiece: Fix piece cleanup task --- cmd/lotus-shed/lpdeal.go | 4 ++-- lib/harmony/harmonydb/sql/20240228-piece-park.sql | 1 + provider/lppiece/task_cleanup_piece.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/lotus-shed/lpdeal.go b/cmd/lotus-shed/lpdeal.go index b6237e13f..0819ddc13 100644 --- a/cmd/lotus-shed/lpdeal.go +++ b/cmd/lotus-shed/lpdeal.go @@ -3,7 +3,6 @@ package main import ( "bytes" "context" - "database/sql" "fmt" "io" "net" @@ -16,6 +15,7 @@ import ( "github.com/fatih/color" "github.com/google/uuid" + "github.com/jackc/pgx/v5" "github.com/mitchellh/go-homedir" manet "github.com/multiformats/go-multiaddr/net" "github.com/urfave/cli/v2" @@ -475,7 +475,7 @@ var lpBoostProxyCmd = &cli.Command{ err = tx.QueryRow(`SELECT id FROM parked_pieces WHERE piece_cid = $1`, deal.DealProposal.PieceCID.String()).Scan(&pieceID) if err != nil { - if err == sql.ErrNoRows { + if err == pgx.ErrNoRows { // Piece does not exist, attempt to insert err = tx.QueryRow(` INSERT INTO parked_pieces (piece_cid, piece_padded_size, piece_raw_size) diff --git a/lib/harmony/harmonydb/sql/20240228-piece-park.sql b/lib/harmony/harmonydb/sql/20240228-piece-park.sql index 95792628a..9ee6b447f 100644 --- a/lib/harmony/harmonydb/sql/20240228-piece-park.sql +++ b/lib/harmony/harmonydb/sql/20240228-piece-park.sql @@ -12,6 +12,7 @@ create table parked_pieces ( cleanup_task_id bigint default null, foreign key (task_id) references harmony_task (id) on delete set null, + foreign key (cleanup_task_id) references harmony_task (id) on delete set null, unique (piece_cid) ); diff --git a/provider/lppiece/task_cleanup_piece.go b/provider/lppiece/task_cleanup_piece.go index d7f24037a..eeb4a44f0 100644 --- a/provider/lppiece/task_cleanup_piece.go +++ b/provider/lppiece/task_cleanup_piece.go @@ -76,7 +76,7 @@ func (c *CleanupPieceTask) Do(taskID harmonytask.TaskID, stillOwned func() bool) // select by cleanup_task_id var pieceID int64 - err = c.db.QueryRow(ctx, "SELECT piece_id FROM parked_pieces WHERE cleanup_task_id = $1", taskID).Scan(&pieceID) + err = c.db.QueryRow(ctx, "SELECT id FROM parked_pieces WHERE cleanup_task_id = $1", taskID).Scan(&pieceID) if err != nil { return false, xerrors.Errorf("query parked_piece: %w", err) }