diff --git a/carserver/station_api_impl.go b/carserver/station_api_impl.go index 46a088b..f98aa67 100644 --- a/carserver/station_api_impl.go +++ b/carserver/station_api_impl.go @@ -76,7 +76,7 @@ func (s *StationAPIImpl) createOrUpdateReqStatsUnlocked(ctx context.Context, cre if err == datastore.ErrNotFound { stats := station.ReqStats{} createFn(&stats) - bz, err = json.Marshal(stats) + bz, err := json.Marshal(stats) if err != nil { return fmt.Errorf("failed to marshal retrieval stats to json: %w", err) } diff --git a/carstore/carstore_test.go b/carstore/carstore_test.go index c1ce699..2a11222 100644 --- a/carstore/carstore_test.go +++ b/carstore/carstore_test.go @@ -3,10 +3,13 @@ package carstore import ( "context" "errors" + "fmt" "sync" "testing" "time" + "golang.org/x/sync/errgroup" + "github.com/ipld/go-ipld-prime/codec/dagcbor" "github.com/ipld/go-ipld-prime/multicodec" @@ -14,8 +17,6 @@ import ( cid "github.com/ipfs/go-cid" - "golang.org/x/sync/errgroup" - "github.com/filecoin-project/dagstore" "github.com/filecoin-project/saturn-l2/logs" @@ -47,20 +48,25 @@ func TestPersistentCache(t *testing.T) { csh.assertStorageStats(t, station.StorageStats{BytesCurrentlyStored: 0}) // first hit -> not found csh.fetchAndAssertNotFound(reqID, rootcid) + fmt.Println("\n data downloaded after first hit is", csh.ms.nDownloaded()) // second hit -> not found csh.fetchAndAssertNotFound(reqID, rootcid) + fmt.Println("\n data downloaded after second hit is", csh.ms.nDownloaded()) // wait till l2 has fetched and cached it csh.assertAvailable(t, ctx, rootcid) + fmt.Println("\n data downloaded after caching is", csh.ms.nDownloaded()) // third hit -> found csh.fetchAndAssertFound(ctx, reqID, rootcid) require.EqualValues(t, len(bz), csh.ms.nDownloaded()) + fmt.Println("\n data downloaded is after third hit", csh.ms.nDownloaded()) // fourth hit -> found csh.fetchAndAssertFound(ctx, reqID, rootcid) require.EqualValues(t, len(bz), csh.ms.nDownloaded()) + fmt.Println("\n data downloaded after fetching success is", csh.ms.nDownloaded()) // wait for shard to become reclaimable again require.Eventually(t, func() bool { @@ -76,14 +82,18 @@ func TestPersistentCache(t *testing.T) { require.Len(t, res.Shards, 1) csh.assertStorageStats(t, station.StorageStats{BytesCurrentlyStored: 0}) + fmt.Println("\n data downloaded after dagstore GC is", csh.ms.nDownloaded()) + // fetch car -> fails as we do not have it but will trigger a fetch again csh.fetchAndAssertNotFound(reqID, rootcid) + fmt.Println("\n data downloaded after fetch trigger fails is", csh.ms.nDownloaded()) // fetch car -> works now as car file was downloaded in the previous fetch require.Eventually(t, func() bool { err = csh.cs.FetchAndWriteCAR(reqID, rootcid, func(_ bstore.Blockstore) error { return nil }) + fmt.Println("\n data downloaded after a cycle is", csh.ms.nDownloaded()) return err == nil }, 50*time.Second, 200*time.Millisecond) diff --git a/carstore/gateway_api.go b/carstore/gateway_api.go index 7f3ee27..a47e522 100644 --- a/carstore/gateway_api.go +++ b/carstore/gateway_api.go @@ -94,6 +94,7 @@ func (gw *GatewayReader) Read(p []byte) (int, error) { } func (gw *GatewayReader) Close() error { + fmt.Println("\n Recoding downloaded data", gw.n) if err := gw.sapi.RecordDataDownloaded(gw.ctx, gw.n); err != nil { log.Errorw("failed to record download stats", "err", err) return err