Skip to content

Commit

Permalink
return written blocks in closing deltasession
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Dec 16, 2024
1 parent aa67633 commit 8f492f7
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion carstore/bs.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,11 @@ func (ds *DeltaSession) CloseWithRoot(ctx context.Context, root cid.Cid, rev str
case *FileCarStore:
return ocs.writeNewShard(ctx, root, rev, ds.user, ds.seq, ds.blks, ds.rmcids)
case *NonArchivalCarstore:
return nil, ocs.updateLastCommit(ctx, ds.user, rev, root)
slice, err := blocksToCar(ctx, root, rev, ds.blks)
if err != nil {
return nil, err
}
return slice, ocs.updateLastCommit(ctx, ds.user, rev, root)
default:
return nil, fmt.Errorf("unsupported carstore type")
}
Expand All @@ -631,6 +635,23 @@ func WriteCarHeader(w io.Writer, root cid.Cid) (int64, error) {
return hnw, nil
}

func blocksToCar(ctx context.Context, root cid.Cid, rev string, blks map[cid.Cid]blockformat.Block) ([]byte, error) {
buf := new(bytes.Buffer)
_, err := WriteCarHeader(buf, root)
if err != nil {
return nil, fmt.Errorf("failed to write car header: %w", err)
}

for k, blk := range blks {
_, err := LdWrite(buf, k.Bytes(), blk.RawData())
if err != nil {
return nil, fmt.Errorf("failed to write block: %w", err)
}
}

return buf.Bytes(), nil
}

func (cs *FileCarStore) writeNewShard(ctx context.Context, root cid.Cid, rev string, user models.Uid, seq int, blks map[cid.Cid]blockformat.Block, rmcids map[cid.Cid]bool) ([]byte, error) {

buf := new(bytes.Buffer)
Expand Down

0 comments on commit 8f492f7

Please sign in to comment.