Try to pack deals into existing unsealed sectors before creating new ones
This commit is contained in:
parent
81a2792e37
commit
a3c686d317
22
sealing.go
22
sealing.go
@ -103,12 +103,13 @@ func (m *Sealing) AddPieceToAnySector(ctx context.Context, size abi.UnpaddedPiec
|
|||||||
return 0, 0, xerrors.Errorf("piece cannot fit into a sector")
|
return 0, 0, xerrors.Errorf("piece cannot fit into a sector")
|
||||||
}
|
}
|
||||||
|
|
||||||
sid, err := m.newSector() // TODO: Put more than one thing in a sector
|
sid, err := m.getAvailableSector(size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, xerrors.Errorf("creating new sector: %w", err)
|
return 0, 0, xerrors.Errorf("creating new sector: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ppi, err := m.sealer.AddPiece(sectorstorage.WithPriority(ctx, DealSectorPriority), m.minerSector(sid), []abi.UnpaddedPieceSize{}, size, r)
|
offset := m.unsealedInfos[sid].stored
|
||||||
|
ppi, err := m.sealer.AddPiece(sectorstorage.WithPriority(ctx, DealSectorPriority), m.minerSector(sid), m.unsealedInfos[sid].pieceSizes, size, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, xerrors.Errorf("writing piece: %w", err)
|
return 0, 0, xerrors.Errorf("writing piece: %w", err)
|
||||||
}
|
}
|
||||||
@ -122,8 +123,7 @@ func (m *Sealing) AddPieceToAnySector(ctx context.Context, size abi.UnpaddedPiec
|
|||||||
return 0, 0, xerrors.Errorf("adding piece to sector: %w", err)
|
return 0, 0, xerrors.Errorf("adding piece to sector: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// offset hard-coded to 0 since we only put one thing in a sector for now
|
return sid, offset, nil
|
||||||
return sid, 0, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Sealing) addPiece(sectorID abi.SectorNumber, piece Piece) error {
|
func (m *Sealing) addPiece(sectorID abi.SectorNumber, piece Piece) error {
|
||||||
@ -158,6 +158,20 @@ func (m *Sealing) StartPacking(sectorID abi.SectorNumber) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Sealing) getAvailableSector(size abi.UnpaddedPieceSize) (abi.SectorNumber, error) {
|
||||||
|
ss := m.sealer.SectorSize()
|
||||||
|
for k, v := range m.unsealedInfos {
|
||||||
|
if v.stored+uint64(size) <= uint64(ss) {
|
||||||
|
// TODO: Support multiple deal sizes in the same sector
|
||||||
|
if len(v.pieceSizes) == 0 || v.pieceSizes[0] == size {
|
||||||
|
return k, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return m.newSector()
|
||||||
|
}
|
||||||
|
|
||||||
// newSector creates a new sector for deal storage
|
// newSector creates a new sector for deal storage
|
||||||
func (m *Sealing) newSector() (abi.SectorNumber, error) {
|
func (m *Sealing) newSector() (abi.SectorNumber, error) {
|
||||||
sid, err := m.sc.Next()
|
sid, err := m.sc.Next()
|
||||||
|
Loading…
Reference in New Issue
Block a user