Skip to content

Commit d7687c2

Browse files
committed
stops uploading raw snapshots to R2
lotus now support directly importing zstd compressed car files. stop uploading raw snapshots, as they are too big, and no longer needed
1 parent 1e25ee8 commit d7687c2

File tree

2 files changed

+6
-73
lines changed

2 files changed

+6
-73
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
config.toml
2+
filecoin-chain-archiver
3+
token

cmd/filecoin-chain-archiver/cmds/create.go

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,6 @@ func Compress(in io.Reader, out io.Writer) error {
4141
return enc.Close()
4242
}
4343

44-
type autocloser struct {
45-
rc io.ReadCloser
46-
}
47-
48-
func (ac autocloser) Read(p []byte) (n int, err error) {
49-
n, err = ac.rc.Read(p)
50-
if err != nil {
51-
_ = ac.rc.Close()
52-
}
53-
return
54-
}
55-
56-
func AutoCloser(rc io.ReadCloser) io.Reader {
57-
return &autocloser{rc}
58-
}
59-
6044
type multi struct {
6145
io.Writer
6246
cs []io.Closer
@@ -340,10 +324,9 @@ var cmdCreate = &cli.Command{
340324
return xerrors.Errorf("failed to aquire lock")
341325
}
342326

343-
rr, wr := io.Pipe()
344327
rc, wc := io.Pipe()
345328

346-
mw := MultiWriteCloser(wr, wc)
329+
mw := MultiWriteCloser(wc)
347330

348331
e := export.NewExport(node, tsk, abi.ChainEpoch(flagStaterootCount), true, mw)
349332
errCh := make(chan error)
@@ -396,10 +379,6 @@ var cmdCreate = &cli.Command{
396379
logger.Infow("discarding output")
397380
g, _ := errgroup.WithContext(ctx)
398381

399-
g.Go(func() error {
400-
_, err := io.Copy(io.Discard, rr)
401-
return err
402-
})
403382
g.Go(func() error {
404383
_, err := io.Copy(io.Discard, rc)
405384
return err
@@ -439,13 +418,8 @@ var cmdCreate = &cli.Command{
439418
logger.Infow("object", "name", name)
440419

441420
g, ctxGroup := errgroup.WithContext(ctx)
442-
var siRaw *snapshotInfo
443421
var siCompressed *snapshotInfo
444-
g.Go(func() error {
445-
var err error
446-
siRaw, err = runUploadRaw(ctxGroup, minioClient, flagBucket, flagNamePrefix, flagRetrievalEndpointPrefix, name, peerID, bt, rr)
447-
return err
448-
})
422+
449423
g.Go(func() error {
450424
var err error
451425
siCompressed, err = runUploadCompressed(ctxGroup, minioClient, flagBucket, flagNamePrefix, flagRetrievalEndpointPrefix, name, peerID, bt, rc)
@@ -458,7 +432,7 @@ var cmdCreate = &cli.Command{
458432
return err
459433
}
460434

461-
sis := []*snapshotInfo{siRaw, siCompressed}
435+
sis := []*snapshotInfo{siCompressed}
462436

463437
var sb strings.Builder
464438
for _, x := range sis {
@@ -502,50 +476,6 @@ var cmdCreate = &cli.Command{
502476
},
503477
}
504478

505-
func runUploadRaw(ctx context.Context, minioClient *minio.Client, flagBucket, flagNamePrefix, flagRetrievalEndpointPrefix, name, peerID string, bt time.Time, source io.Reader) (*snapshotInfo, error) {
506-
h := sha256.New()
507-
r := io.TeeReader(source, h)
508-
509-
filename := fmt.Sprintf("%s.car", name)
510-
511-
info, err := minioClient.PutObject(ctx, flagBucket, fmt.Sprintf("%s%s", flagNamePrefix, filename), r, -1, minio.PutObjectOptions{
512-
ContentDisposition: fmt.Sprintf("attachment; filename=\"%s\"", filename),
513-
ContentType: "application/octet-stream",
514-
})
515-
if err != nil {
516-
return nil, fmt.Errorf("failed to upload object (%s): %w", fmt.Sprintf("%s%s", flagNamePrefix, filename), err)
517-
}
518-
519-
logger.Infow("snapshot upload",
520-
"bucket", info.Bucket,
521-
"key", info.Key,
522-
"etag", info.ETag,
523-
"size", info.Size,
524-
"location", info.Location,
525-
"version_id", info.VersionID,
526-
"expiration", info.Expiration,
527-
"expiration_rule_id", info.ExpirationRuleID,
528-
)
529-
530-
snapshotSize := info.Size
531-
532-
latestLocation, err := url.JoinPath(flagRetrievalEndpointPrefix, info.Key)
533-
if err != nil {
534-
logger.Errorw("failed to join request path", "request_prefix", flagRetrievalEndpointPrefix, "key", info.Key)
535-
return nil, fmt.Errorf("failed to join request path: %w", err)
536-
}
537-
538-
digest := fmt.Sprintf("%x", h.Sum(nil))
539-
540-
return &snapshotInfo{
541-
digest: digest,
542-
size: snapshotSize,
543-
filename: filename,
544-
latestIndex: "latest",
545-
latestLocation: latestLocation,
546-
}, nil
547-
}
548-
549479
func runUploadCompressed(ctx context.Context, minioClient *minio.Client, flagBucket, flagNamePrefix, flagRetrievalEndpointPrefix, name, peerID string, bt time.Time, source io.Reader) (*snapshotInfo, error) {
550480

551481
r1, w1 := io.Pipe()

0 commit comments

Comments
 (0)