Skip to content

Commit

Permalink
carlog: Don't panic in data reload
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Nov 12, 2023
1 parent 49a6d72 commit 8383351
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 10 additions & 5 deletions carlog/carlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -1088,9 +1088,14 @@ func (j *CarLog) Finalize(ctx context.Context) error {
}
}

ents, err := j.rIdx.Entries()
if err != nil {
return xerrors.Errorf("getting ridx ent count: %w", err)
}

// dfs bsst
iprov := &carIdxSource{
base: j.rIdx,
entries: ents,
carSource: j.WriteCar,
}

Expand Down Expand Up @@ -1203,7 +1208,7 @@ func (j *CarLog) LoadData(ctx context.Context, car io.Reader, sz int64) error {
return nil
}

func (j *CarLog) FinDataReload(ctx context.Context) error {
func (j *CarLog) FinDataReload(ctx context.Context, blkEnts int64) error {
j.idxLk.Lock()
defer j.idxLk.Unlock()

Expand All @@ -1227,7 +1232,7 @@ func (j *CarLog) FinDataReload(ctx context.Context) error {
{
// dfs bsst
iprov := &carIdxSource{
base: j.rIdx,
entries: blkEnts,
carSource: func(w io.Writer) (int64, cid.Cid, error) {
_, err := io.CopyBuffer(w, df, make([]byte, 1<<20))
return -1, cid.Undef, err
Expand Down Expand Up @@ -1610,7 +1615,7 @@ type cardata struct {
}

type carIdxSource struct {
base ReadableIndex
entries int64
carSource func(w io.Writer) (int64, cid.Cid, error)

statReader *statRead
Expand Down Expand Up @@ -1688,7 +1693,7 @@ func (c *carIdxSource) List(f func(c mh.Multihash, offs []int64) error) error {
}

func (c *carIdxSource) Entries() (int64, error) {
return c.base.Entries()
return c.entries, nil
}

var _ IndexSource = &carIdxSource{}
Expand Down
7 changes: 6 additions & 1 deletion rbstor/group_finalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ func (m *Group) FinDataReload(ctx context.Context) error {
return xerrors.Errorf("group not in state for finishing data reload: %d", m.state)
}

if err := m.jb.FinDataReload(context.Background()); err != nil {
gm, err := m.db.GroupMeta(m.id)
if err != nil {
return xerrors.Errorf("getting group meta: %w", err)
}

if err := m.jb.FinDataReload(context.Background(), gm.Blocks); err != nil {
return xerrors.Errorf("carlog finalize data reload: %w", err)
}

Expand Down

0 comments on commit 8383351

Please sign in to comment.