Skip to content

Commit 539cf29

Browse files
authored
fix: FixRawSize SQL column name, join, and filetype bugs (#1037)
Four SQL bugs in task_fix_rawSize.go, all introduced in #855: 1. CanAccept: mpd.miner_id → l.miner_id market_piece_deal has no miner_id column; join should reference sector_location.miner_id. Error: column mpd.miner_id does not exist (SQLSTATE 42703) 2. Do + CanAccept: mpd.sector_number → mpd.sector_num market_piece_deal column is sector_num, not sector_number. Masked in Do() because CanAccept always fails first. 3. Do: same sector_number fix in sectors_meta join condition. 4. CanAccept: sector_filetype = 4 → sector_filetype = 1 Restored to FTUnsealed (original value before #855). The task reads piece data via ReadPiece() which requires unsealed sector data, not cache. The existing panic guard (storiface.FTUnsealed != 1) confirms the original intent. Changed to 4 (FTCache) during the #855 rewrite by copying the pattern from task_treed.go (which correctly uses FTCache for its own purposes). Every other query against market_piece_deal in the codebase correctly uses sector_num (task_check_indexes.go, cachedreader.go, market.go). Full column-by-column audit performed against schema definitions in: 20260211-fix-raw-size-table.sql, 20240731-market-migration.sql, 20240425-sector_meta.sql, 20230712-sector_index.sql. All 7 queries in the file verified. Follow-up to #1035 (array cast fix).
1 parent 404589e commit 539cf29

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

tasks/storage-market/task_fix_rawSize.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ func (f *FixRawSize) Do(taskID harmonytask.TaskID, stillOwned func() bool) (done
4040

4141
var id, pieceCidStr string
4242
var spID, sectorNumer, pieceOffset, pieceSize, proof int64
43-
err = f.db.QueryRow(ctx, `SELECT f.id, mpd.sp_id, mpd.sector_number, mpd.piece_cid, mpd.piece_offset, mpd.piece_length, m.reg_seal_proof
43+
err = f.db.QueryRow(ctx, `SELECT f.id, mpd.sp_id, mpd.sector_num, mpd.piece_cid, mpd.piece_offset, mpd.piece_length, m.reg_seal_proof
4444
FROM market_fix_raw_size f
4545
INNER JOIN market_piece_deal mpd ON f.id = mpd.id
46-
INNER JOIN sectors_meta m ON mpd.sp_id = m.sp_id AND mpd.sector_number = m.sector_num
46+
INNER JOIN sectors_meta m ON mpd.sp_id = m.sp_id AND mpd.sector_num = m.sector_num
4747
WHERE f.task_id = $1 AND mpd.raw_size = 0
4848
AND piece_offset IS NOT NULL
4949
LIMIT 1`, taskID).Scan(&id, &spID, &sectorNumer, &pieceCidStr, &pieceOffset, &pieceSize, &proof)
@@ -129,7 +129,7 @@ func (f *FixRawSize) CanAccept(ids []harmonytask.TaskID, engine *harmonytask.Tas
129129
err := f.db.QueryRow(ctx, `SELECT COALESCE(array_agg(task_id), '{}')::bigint[] AS task_ids FROM (
130130
SELECT f.task_id FROM market_fix_raw_size f
131131
INNER JOIN market_piece_deal mpd ON f.id = mpd.id
132-
INNER JOIN sector_location l ON mpd.sp_id = mpd.miner_id AND mpd.sector_number = l.sector_num AND l.sector_filetype = 4
132+
INNER JOIN sector_location l ON mpd.sp_id = l.miner_id AND mpd.sector_num = l.sector_num AND l.sector_filetype = 1
133133
INNER JOIN storage_path sp ON sp.storage_id = l.storage_id
134134
WHERE f.task_id = ANY($1::bigint[]) AND sp.urls IS NOT NULL AND sp.urls LIKE '%' || $2 || '%' LIMIT 100) s`, indIDs, engine.Host()).Scan(&acceptedIDs)
135135
if err != nil {

0 commit comments

Comments
 (0)