Skip to content

Commit ee54b5e

Browse files
authored
fix raw_size in migration (#2042)
* fix raw_size in migration * make lid mandatory
1 parent e3170ea commit ee54b5e

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

cmd/migrate-curio/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ func main() {
6464
EnvVars: []string{"CURIO_DB_PORT", "CURIO_HARMONYDB_PORT"},
6565
Value: "5433",
6666
},
67+
&cli.StringFlag{
68+
Name: "api-lid",
69+
Usage: "Boostd-data service API endpoint. Service must be running.",
70+
Required: true,
71+
},
6772
},
6873
Commands: []*cli.Command{
6974
migrateCmd,

cmd/migrate-curio/migrate.go

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/filecoin-project/boost/db"
14+
bdclient "github.com/filecoin-project/boost/extern/boostd-data/client"
1415
"github.com/filecoin-project/boost/lib/legacy"
1516
"github.com/filecoin-project/boost/node/repo"
1617
"github.com/filecoin-project/boost/storagemarket/types"
@@ -148,8 +149,20 @@ func migrate(cctx *cli.Context, repoDir string) error {
148149
return fmt.Errorf("merging bitfields to generate all sealed sectors on miner %s: %w", maddr, err)
149150
}
150151

152+
cl := bdclient.NewStore()
153+
defer cl.Close(ctx)
154+
err = cl.Dial(ctx, cctx.String("api-lid"))
155+
if err != nil {
156+
return fmt.Errorf("connecting to local index directory service: %w", err)
157+
}
158+
159+
_, err = cl.ListPieces(ctx)
160+
if err != nil {
161+
return fmt.Errorf("listing pieces from local index directory service: %w", err)
162+
}
163+
151164
// Migrate Boost deals
152-
if err := migrateBoostDeals(ctx, activeSectors, maddr, hdb, sqldb, mdb); err != nil {
165+
if err := migrateBoostDeals(ctx, activeSectors, maddr, hdb, sqldb, mdb, cl); err != nil {
153166
return xerrors.Errorf("failed to migrate boost deals: %w", err)
154167
}
155168

@@ -166,7 +179,7 @@ func migrate(cctx *cli.Context, repoDir string) error {
166179
return nil
167180
}
168181

169-
func migrateBoostDeals(ctx context.Context, activeSectors bitfield.BitField, maddr address.Address, hdb *harmonydb.DB, sqldb, mdb *sql.DB) error {
182+
func migrateBoostDeals(ctx context.Context, activeSectors bitfield.BitField, maddr address.Address, hdb *harmonydb.DB, sqldb, mdb *sql.DB, bdclient *bdclient.Store) error {
170183
sdb := db.NewDealsDB(sqldb)
171184

172185
mid, err := address.IDFromAddress(maddr)
@@ -291,17 +304,38 @@ func migrateBoostDeals(ctx context.Context, activeSectors bitfield.BitField, mad
291304

292305
}
293306

307+
if deal.NBytesReceived == 0 {
308+
if deal.Transfer.Size > 0 {
309+
deal.NBytesReceived = int64(deal.Transfer.Size)
310+
} else {
311+
pds, err := bdclient.GetPieceDeals(ctx, prop.PieceCID)
312+
if err != nil {
313+
return fmt.Errorf("failed to get piece deals from LID: %w", err)
314+
}
315+
for _, pd := range pds {
316+
if pd.CarLength > 0 {
317+
deal.NBytesReceived = int64(pd.CarLength)
318+
break
319+
}
320+
}
321+
}
322+
}
323+
324+
if deal.NBytesReceived == 0 {
325+
return fmt.Errorf("deal: %s: failed to get raw size from SQL or LID", deal.DealUuid.String())
326+
}
327+
294328
_, err = hdb.BeginTransaction(ctx, func(tx *harmonydb.Tx) (bool, error) {
295329
// Add deal to HarmonyDB
296330
if !a {
297331
_, err = tx.Exec(`INSERT INTO market_mk12_deals (uuid, sp_id, signed_proposal_cid,
298332
proposal_signature, proposal, proposal_cid, piece_cid,
299-
piece_size, offline, verified, start_epoch, end_epoch,
333+
piece_size, raw_size, offline, verified, start_epoch, end_epoch,
300334
client_peer_id, fast_retrieval, announce_to_ipni, url, url_headers, chain_deal_id, publish_cid, created_at, label)
301-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)
335+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22)
302336
ON CONFLICT (uuid) DO NOTHING`,
303337
deal.DealUuid.String(), mid, sProp.String(), sigByte, propJson, propCid, prop.PieceCID.String(),
304-
prop.PieceSize, deal.IsOffline, prop.VerifiedDeal, prop.StartEpoch, prop.EndEpoch, deal.ClientPeerID.String(),
338+
prop.PieceSize, deal.NBytesReceived, deal.IsOffline, prop.VerifiedDeal, prop.StartEpoch, prop.EndEpoch, deal.ClientPeerID.String(),
305339
deal.FastRetrieval, deal.AnnounceToIPNI, tInfo.URL, headers, int64(deal.ChainDealID), deal.PublishCID.String(), deal.CreatedAt, buf.Bytes())
306340

307341
if err != nil {
@@ -554,15 +588,19 @@ func migrateDDODeals(ctx context.Context, full v1api.FullNode, activeSectors bit
554588
continue
555589
}
556590

591+
if deal.InboundFileSize == 0 {
592+
return fmt.Errorf("deal: %s: inbound file size is 0", deal.ID.String())
593+
}
594+
557595
_, err = hdb.BeginTransaction(ctx, func(tx *harmonydb.Tx) (bool, error) {
558596
if !a {
559597
// Add DDO deal to harmonyDB
560598
_, err = tx.Exec(`INSERT INTO market_direct_deals (uuid, sp_id, created_at, client, offline, verified,
561-
start_epoch, end_epoch, allocation_id, piece_cid, piece_size, fast_retrieval, announce_to_ipni)
562-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
599+
start_epoch, end_epoch, allocation_id, piece_cid, piece_size, raw_size, fast_retrieval, announce_to_ipni)
600+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
563601
ON CONFLICT (uuid) DO NOTHING`,
564602
deal.ID.String(), mid, deal.CreatedAt, deal.Client.String(), true, true, deal.StartEpoch, deal.EndEpoch, deal.AllocationID,
565-
deal.PieceCID.String(), deal.PieceSize, true, true)
603+
deal.PieceCID.String(), deal.PieceSize, deal.InboundFileSize, true, true)
566604

567605
if err != nil {
568606
return false, fmt.Errorf("deal: %s: failed to add the DDO deal to harmonyDB: %w", deal.ID.String(), err)

0 commit comments

Comments
 (0)