Skip to content

Commit

Permalink
Improve debug
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Sep 5, 2023
1 parent 10da770 commit 4056a2a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
23 changes: 17 additions & 6 deletions epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,12 @@ func (s *Epoch) GetNodeByOffset(ctx context.Context, wantedCid cid.Cid, offset u
return data, nil
}

func (ser *Epoch) FindCidFromSlot(ctx context.Context, slot uint64) (cid.Cid, error) {
func (ser *Epoch) FindCidFromSlot(ctx context.Context, slot uint64) (o cid.Cid, e error) {
startedAt := time.Now()
defer func() {
klog.Infof("Found CID for slot %d in %s: %s", slot, time.Since(startedAt), o)
}()

// try from cache
if c, err, has := ser.getSlotToCidFromCache(slot); err != nil {
return cid.Undef, err
Expand All @@ -383,11 +388,20 @@ func (ser *Epoch) FindCidFromSlot(ctx context.Context, slot uint64) (cid.Cid, er
return found, nil
}

func (ser *Epoch) FindCidFromSignature(ctx context.Context, sig solana.Signature) (cid.Cid, error) {
func (ser *Epoch) FindCidFromSignature(ctx context.Context, sig solana.Signature) (o cid.Cid, e error) {
startedAt := time.Now()
defer func() {
klog.Infof("Found CID for signature %s in %s: %s", sig, time.Since(startedAt), o)
}()
return findCidFromSignature(ser.sigToCidIndex, sig)
}

func (ser *Epoch) FindOffsetFromCid(ctx context.Context, cid cid.Cid) (uint64, error) {
func (ser *Epoch) FindOffsetFromCid(ctx context.Context, cid cid.Cid) (o uint64, e error) {
startedAt := time.Now()
defer func() {
klog.Infof("Found offset for CID %s in %s: %d", cid, time.Since(startedAt), o)
}()

// try from cache
if offset, err, has := ser.getCidToOffsetFromCache(cid); err != nil {
return 0, err
Expand All @@ -398,7 +412,6 @@ func (ser *Epoch) FindOffsetFromCid(ctx context.Context, cid cid.Cid) (uint64, e
if err != nil {
return 0, err
}
klog.Infof("found offset for CID %s: %d", cid, found)
ser.putCidToOffsetInCache(cid, found)
return found, nil
}
Expand All @@ -410,7 +423,6 @@ func (ser *Epoch) GetBlock(ctx context.Context, slot uint64) (*ipldbindcode.Bloc
klog.Errorf("failed to find CID for slot %d: %v", slot, err)
return nil, err
}
klog.Infof("found CID for slot %d: %s", slot, wantedCid)
{
doPrefetch := getValueFromContext(ctx, "prefetch")
if doPrefetch != nil && doPrefetch.(bool) {
Expand Down Expand Up @@ -500,7 +512,6 @@ func (ser *Epoch) GetTransaction(ctx context.Context, sig solana.Signature) (*ip
klog.Errorf("failed to find CID for signature %s: %v", sig, err)
return nil, err
}
klog.Infof("found CID for signature %s: %s", sig, wantedCid)
{
doPrefetch := getValueFromContext(ctx, "prefetch")
if doPrefetch != nil && doPrefetch.(bool) {
Expand Down
19 changes: 14 additions & 5 deletions http-range.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,32 @@ func remoteReadAt(client *http.Client, url string, p []byte, off int64) (n int,
}

type readCloserWrapper struct {
rac ReaderAtCloser
name string
rac ReaderAtCloser
isRemote bool
name string
}

// when reading print a dot
func (r *readCloserWrapper) ReadAt(p []byte, off int64) (n int, err error) {
startedAt := time.Now()
defer func() {
if DebugMode {
prefix := "[READ-UNKNOWN]"
var icon string
if r.isRemote {
// add internet icon
icon = "🌐 "
} else {
// add disk icon
icon = "💾 "
}
prefix := icon + "[READ-UNKNOWN]"
// if has suffix .index, then it's an index file
if strings.HasSuffix(r.name, ".index") {
prefix = azureBG("[READ-INDEX]")
prefix = icon + azureBG("[READ-INDEX]")
}
// if has suffix .car, then it's a car file
if strings.HasSuffix(r.name, ".car") {
prefix = purpleBG("[READ-CAR]")
prefix = icon + purpleBG("[READ-CAR]")
}
fmt.Fprintf(os.Stderr, prefix+" %s:%d+%d (%s)\n", filepath.Base(r.name), off, len(p), time.Since(startedAt))
}
Expand Down
10 changes: 6 additions & 4 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ func openIndexStorage(
return rac, nil
}
return &readCloserWrapper{
rac: rac,
name: where,
rac: rac,
name: where,
isRemote: true,
}, nil
}
// TODO: add support for IPFS gateways.
Expand All @@ -54,8 +55,9 @@ func openIndexStorage(
return rac, nil
}
return &readCloserWrapper{
rac: rac,
name: where,
rac: rac,
name: where,
isRemote: false,
}, nil
}

Expand Down

0 comments on commit 4056a2a

Please sign in to comment.