lppiece: Fix piece cleanup task
This commit is contained in:
parent
ad37cf5ead
commit
5dfec4ab36
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
@ -16,6 +15,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/mitchellh/go-homedir"
|
"github.com/mitchellh/go-homedir"
|
||||||
manet "github.com/multiformats/go-multiaddr/net"
|
manet "github.com/multiformats/go-multiaddr/net"
|
||||||
"github.com/urfave/cli/v2"
|
"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)
|
err = tx.QueryRow(`SELECT id FROM parked_pieces WHERE piece_cid = $1`, deal.DealProposal.PieceCID.String()).Scan(&pieceID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == pgx.ErrNoRows {
|
||||||
// Piece does not exist, attempt to insert
|
// Piece does not exist, attempt to insert
|
||||||
err = tx.QueryRow(`
|
err = tx.QueryRow(`
|
||||||
INSERT INTO parked_pieces (piece_cid, piece_padded_size, piece_raw_size)
|
INSERT INTO parked_pieces (piece_cid, piece_padded_size, piece_raw_size)
|
||||||
|
@ -12,6 +12,7 @@ create table parked_pieces (
|
|||||||
cleanup_task_id bigint default null,
|
cleanup_task_id bigint default null,
|
||||||
|
|
||||||
foreign key (task_id) references harmony_task (id) on delete set 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)
|
unique (piece_cid)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ func (c *CleanupPieceTask) Do(taskID harmonytask.TaskID, stillOwned func() bool)
|
|||||||
// select by cleanup_task_id
|
// select by cleanup_task_id
|
||||||
var pieceID int64
|
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 {
|
if err != nil {
|
||||||
return false, xerrors.Errorf("query parked_piece: %w", err)
|
return false, xerrors.Errorf("query parked_piece: %w", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user