Skip to content

Commit

Permalink
Beginning cleanup for review
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenGround0 committed Aug 3, 2022
1 parent a44366d commit 699f315
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 51 deletions.
27 changes: 7 additions & 20 deletions blockstore/idstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package blockstore

import (
"context"
"fmt"
"io"

blocks "github.com/ipfs/go-block-format"
Expand Down Expand Up @@ -103,29 +102,17 @@ func (b *idstore) Put(ctx context.Context, blk blocks.Block) error {
return b.bs.Put(ctx, blk)
}

func (b *idstore) ForEachKey(f func(cid.Cid) error) error {
iterBstore, ok := b.bs.(BlockstoreIterator)
if !ok {
return xerrors.Errorf("underlying blockstore (type %T) doesn't support fast iteration", b.bs)
}
return iterBstore.ForEachKey(f)
}

func isTestCid(c cid.Cid) bool {
testCid, err := cid.Decode("bafy2bzacec4ek45pyx2ihisbmbhbit5htk2ovrry4mpmxkhjasbln3ikvzanu")
if err != nil {
panic(err)
}

return c.Hash().HexString() == testCid.Hash().HexString()
}
// func (b *idstore) ForEachKey(f func(cid.Cid) error) error {
// iterBstore, ok := b.bs.(BlockstoreIterator)
// if !ok {
// return xerrors.Errorf("underlying blockstore (type %T) doesn't support fast iteration", b.bs)
// }
// return iterBstore.ForEachKey(f)
// }

func (b *idstore) PutMany(ctx context.Context, blks []blocks.Block) error {
toPut := make([]blocks.Block, 0, len(blks))
for _, blk := range blks {
if isTestCid(blk.Cid()) {
fmt.Printf("[ID STORE]: putting the test cid\n\n")
}
inline, _, err := decodeCid(blk.Cid())
if err != nil {
return xerrors.Errorf("error decoding Cid: %w", err)
Expand Down
31 changes: 0 additions & 31 deletions blockstore/splitstore/splitstore_prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package splitstore

import (
"bytes"
"fmt"
"os"
"runtime"
"sync"
Expand Down Expand Up @@ -50,8 +49,6 @@ func (s *SplitStore) PruneChain(opts map[string]interface{}) error {
var onlineGC, movingGC bool
var retainState int64 = -1

fmt.Printf("opts: %v\n", opts)

for k, v := range opts {
switch k {
case PruneOnlineGC:
Expand Down Expand Up @@ -86,7 +83,6 @@ func (s *SplitStore) PruneChain(opts map[string]interface{}) error {
doGC := func() error { return s.gcBlockstore(s.cold, gcOpts) }

var retainStateP func(int64) bool
fmt.Printf("[PRUNE]: retainState %d\n", retainState)
switch {
case retainState > 0:
retainStateP = func(depth int64) bool {
Expand All @@ -101,7 +97,6 @@ func (s *SplitStore) PruneChain(opts map[string]interface{}) error {
}

if _, ok := s.cold.(bstore.BlockstoreIterator); !ok {
fmt.Printf("cold store type: %T\n", s.cold)
return xerrors.Errorf("coldstore does not support efficient iteration")
}

Expand Down Expand Up @@ -151,22 +146,12 @@ func (s *SplitStore) pruneChain(retainStateP func(int64) bool, doGC func() error
return nil
}

func isTestCid(c cid.Cid) bool {
testCid, err := cid.Decode("bafy2bzacec4ek45pyx2ihisbmbhbit5htk2ovrry4mpmxkhjasbln3ikvzanu")
if err != nil {
panic(err)
}

return c.Hash().HexString() == testCid.Hash().HexString()
}

func (s *SplitStore) prune(curTs *types.TipSet, retainStateP func(int64) bool, doGC func() error) {
log.Info("waiting for active views to complete")
start := time.Now()
s.viewWait()
log.Infow("waiting for active views done", "took", time.Since(start))

fmt.Printf("[PRUNE]: starting\n")
err := s.doPrune(curTs, retainStateP, doGC)
if err != nil {
log.Errorf("PRUNE ERROR: %s", err)
Expand Down Expand Up @@ -200,17 +185,13 @@ func (s *SplitStore) doPrune(curTs *types.TipSet, retainStateP func(int64) bool,
// and chain headers; state and reciepts are retained only if it is within retention policy scope
log.Info("marking reachable objects")
startMark := time.Now()
fmt.Printf("[PRUNE]: marking\n")

count := new(int64)
err = s.walkChainDeep(curTs, retainStateP,
func(c cid.Cid) error {
if isUnitaryObject(c) {
return errStopWalk
}
if isTestCid(c) {
fmt.Printf("found test cid while doing the deep chain walk...\n")
}

mark, err := markSet.Has(c)
if err != nil {
Expand Down Expand Up @@ -245,8 +226,6 @@ func (s *SplitStore) doPrune(curTs *types.TipSet, retainStateP func(int64) bool,
return err
}

fmt.Printf("[PRUNE]: iter cold store to find dead\n")

// 2. iterate through the coldstore to collect dead objects
log.Info("collecting dead objects")
startCollect := time.Now()
Expand All @@ -262,19 +241,13 @@ func (s *SplitStore) doPrune(curTs *types.TipSet, retainStateP func(int64) bool,

err = s.cold.(bstore.BlockstoreIterator).ForEachKey(func(c cid.Cid) error {
// was it marked?
if isTestCid(c) {
fmt.Printf("[PRUNE] found test cid %s in deadset collection iteration\n", c)
}
mark, err := markSet.Has(c)
if err != nil {
return xerrors.Errorf("error checking mark set for %s: %w", c, err)
}

if mark {
liveCnt++
if isTestCid(c) {
fmt.Printf("[PRUNE] huh found the test cid as marked, no prune for us...\n")
}
return nil
}

Expand Down Expand Up @@ -322,8 +295,6 @@ func (s *SplitStore) doPrune(curTs *types.TipSet, retainStateP func(int64) bool,
}
defer deadr.Close() //nolint:errcheck

fmt.Printf("[PRUNE]: purge the dead\n")

// 3. Purge dead objects with checkpointing for recovery.
// This is the critical section of prune, whereby any dead object not in the markSet is
// considered already deleted.
Expand All @@ -334,7 +305,6 @@ func (s *SplitStore) doPrune(curTs *types.TipSet, retainStateP func(int64) bool,
if err := s.beginCriticalSection(markSet); err != nil {
return xerrors.Errorf("error beginning critical section: %w", err)
}
fmt.Printf("[PRUNE]: critical\n")

if err := s.checkClosing(); err != nil {
return err
Expand All @@ -355,7 +325,6 @@ func (s *SplitStore) doPrune(curTs *types.TipSet, retainStateP func(int64) bool,
log.Infow("purging dead objects from coldstore done", "took", time.Since(startPurge))

s.endCriticalSection()
fmt.Printf("[PRUNE]: done with critical\n")

if err := checkpoint.Close(); err != nil {
log.Warnf("error closing checkpoint: %s", err)
Expand Down

0 comments on commit 699f315

Please sign in to comment.