From 8cfba5b092cddbcd91d5761a67ea7a367b366097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Mon, 1 Mar 2021 17:39:00 +0000 Subject: [PATCH] renames and polish. --- blockstore/splitstore/liveset.go | 4 ++-- blockstore/splitstore/liveset_bloom.go | 2 +- blockstore/splitstore/liveset_test.go | 2 +- blockstore/splitstore/splitstore.go | 23 +++++++++++------------ blockstore/splitstore/tracking.go | 4 ++-- blockstore/splitstore/tracking_bolt.go | 14 +++++++------- blockstore/splitstore/tracking_test.go | 4 ++-- node/modules/blockstore.go | 16 ++++++++-------- 8 files changed, 34 insertions(+), 35 deletions(-) diff --git a/blockstore/splitstore/liveset.go b/blockstore/splitstore/liveset.go index 543c41371..2678d16d9 100644 --- a/blockstore/splitstore/liveset.go +++ b/blockstore/splitstore/liveset.go @@ -14,14 +14,14 @@ type LiveSet interface { Close() error } -var markBytes = []byte{} +var markBytes []byte type LiveSetEnv interface { NewLiveSet(name string, sizeHint int64) (LiveSet, error) Close() error } -func NewLiveSetEnv(path string, liveSetType string) (LiveSetEnv, error) { +func OpenLiveSetEnv(path string, liveSetType string) (LiveSetEnv, error) { switch liveSetType { case "", "bloom": return NewBloomLiveSetEnv() diff --git a/blockstore/splitstore/liveset_bloom.go b/blockstore/splitstore/liveset_bloom.go index 110dc6b81..06dc2e1f7 100644 --- a/blockstore/splitstore/liveset_bloom.go +++ b/blockstore/splitstore/liveset_bloom.go @@ -42,7 +42,7 @@ func (e *BloomLiveSetEnv) NewLiveSet(name string, sizeHint int64) (LiveSet, erro return nil, xerrors.Errorf("error reading salt: %w", err) } - bf, err := bbloom.New(float64(size), float64(BloomFilterProbability)) + bf, err := bbloom.New(float64(size), BloomFilterProbability) if err != nil { return nil, xerrors.Errorf("error creating bloom filter: %w", err) } diff --git a/blockstore/splitstore/liveset_test.go b/blockstore/splitstore/liveset_test.go index 0a1dd30da..07c37a21d 100644 --- a/blockstore/splitstore/liveset_test.go +++ b/blockstore/splitstore/liveset_test.go @@ -26,7 +26,7 @@ func testLiveSet(t *testing.T, lsType string) { t.Fatal(err) } - env, err := NewLiveSetEnv(path, lsType) + env, err := OpenLiveSetEnv(path, lsType) if err != nil { t.Fatal(err) } diff --git a/blockstore/splitstore/splitstore.go b/blockstore/splitstore/splitstore.go index bed879aaf..d3318b39c 100644 --- a/blockstore/splitstore/splitstore.go +++ b/blockstore/splitstore/splitstore.go @@ -31,13 +31,12 @@ var ( var ( baseEpochKey = dstore.NewKey("/splitstore/baseEpoch") warmupEpochKey = dstore.NewKey("/splitstore/warmupEpoch") + log = logging.Logger("splitstore") ) -var log = logging.Logger("splitstore") - func init() { // TODO temporary for debugging purposes; to be removed for merge. - logging.SetLogLevel("splitstore", "DEBUG") + _ = logging.SetLogLevel("splitstore", "DEBUG") } type Config struct { @@ -94,20 +93,20 @@ type SplitStore struct { var _ bstore.Blockstore = (*SplitStore)(nil) -// NewSplitStore creates a new SplitStore instance, given a path for the hotstore dbs and a cold -// blockstore. The SplitStore must be attached to the ChainStore with Start in order to trigger -// compaction. -func NewSplitStore(path string, ds dstore.Datastore, cold, hot bstore.Blockstore, cfg *Config) (*SplitStore, error) { +// Open opens an existing splistore, or creates a new splitstore. The splitstore +// is backed by the provided hot and cold stores. The returned SplitStore MUST be +// attached to the ChainStore with Start in order to trigger compaction. +func Open(path string, ds dstore.Datastore, hot, cold bstore.Blockstore, cfg *Config) (*SplitStore, error) { // the tracking store - snoop, err := NewTrackingStore(path, cfg.TrackingStoreType) + snoop, err := OpenTrackingStore(path, cfg.TrackingStoreType) if err != nil { return nil, err } // the liveset env - env, err := NewLiveSetEnv(path, cfg.LiveSetType) + env, err := OpenLiveSetEnv(path, cfg.LiveSetType) if err != nil { - snoop.Close() //nolint:errcheck + _ = snoop.Close() return nil, err } @@ -129,7 +128,7 @@ func NewSplitStore(path string, ds dstore.Datastore, cold, hot bstore.Blockstore } // Blockstore interface -func (s *SplitStore) DeleteBlock(cid cid.Cid) error { +func (s *SplitStore) DeleteBlock(_ cid.Cid) error { // afaict we don't seem to be using this method, so it's not implemented return errors.New("DeleteBlock not implemented on SplitStore; don't do this Luke!") //nolint } @@ -377,7 +376,7 @@ func (s *SplitStore) warmup(curTs *types.TipSet) { epoch := curTs.Height() count := int64(0) - err := s.cs.WalkSnapshot(context.Background(), curTs, 1, s.skipOldMsgs, s.skipMsgReceipts, + err := s.chain.WalkSnapshot(context.Background(), curTs, 1, s.skipOldMsgs, s.skipMsgReceipts, func(cid cid.Cid) error { count++ diff --git a/blockstore/splitstore/tracking.go b/blockstore/splitstore/tracking.go index 3fdbcf0ac..56f9294e7 100644 --- a/blockstore/splitstore/tracking.go +++ b/blockstore/splitstore/tracking.go @@ -20,10 +20,10 @@ type TrackingStore interface { Close() error } -func NewTrackingStore(path string, trackingStoreType string) (TrackingStore, error) { +func OpenTrackingStore(path string, trackingStoreType string) (TrackingStore, error) { switch trackingStoreType { case "", "bolt": - return NewBoltTrackingStore(filepath.Join(path, "snoop.bolt")) + return OpenBoltTrackingStore(filepath.Join(path, "snoop.bolt")) default: return nil, xerrors.Errorf("unknown tracking store type %s", trackingStoreType) } diff --git a/blockstore/splitstore/tracking_bolt.go b/blockstore/splitstore/tracking_bolt.go index 2fc5d4f6d..5cc50e05e 100644 --- a/blockstore/splitstore/tracking_bolt.go +++ b/blockstore/splitstore/tracking_bolt.go @@ -18,12 +18,12 @@ type BoltTrackingStore struct { var _ TrackingStore = (*BoltTrackingStore)(nil) -func NewBoltTrackingStore(path string) (*BoltTrackingStore, error) { - db, err := bolt.Open(path, 0644, - &bolt.Options{ - Timeout: 1 * time.Second, - NoSync: true, - }) +func OpenBoltTrackingStore(path string) (*BoltTrackingStore, error) { + opts := &bolt.Options{ + Timeout: 1 * time.Second, + NoSync: true, + } + db, err := bolt.Open(path, 0644, opts) if err != nil { return nil, err } @@ -38,7 +38,7 @@ func NewBoltTrackingStore(path string) (*BoltTrackingStore, error) { }) if err != nil { - db.Close() //nolint:errcheck + _ = db.Close() return nil, err } diff --git a/blockstore/splitstore/tracking_test.go b/blockstore/splitstore/tracking_test.go index 3d5d2ff64..55b520133 100644 --- a/blockstore/splitstore/tracking_test.go +++ b/blockstore/splitstore/tracking_test.go @@ -51,7 +51,7 @@ func testTrackingStore(t *testing.T, tsType string) { t.Fatal(err) } - s, err := NewTrackingStore(path, tsType) + s, err := OpenTrackingStore(path, tsType) if err != nil { t.Fatal(err) } @@ -118,7 +118,7 @@ func testTrackingStore(t *testing.T, tsType string) { t.Fatal(err) } - s, err = NewTrackingStore(path, tsType) + s, err = OpenTrackingStore(path, tsType) if err != nil { t.Fatal(err) } diff --git a/node/modules/blockstore.go b/node/modules/blockstore.go index c79553490..8fffb1536 100644 --- a/node/modules/blockstore.go +++ b/node/modules/blockstore.go @@ -74,14 +74,14 @@ func SplitBlockstore(cfg *config.Blockstore) func(lc fx.Lifecycle, r repo.Locked return nil, err } - ss, err := splitstore.NewSplitStore(path, ds, cold, hot, - &splitstore.Config{ - TrackingStoreType: cfg.Splitstore.TrackingStoreType, - LiveSetType: cfg.Splitstore.LiveSetType, - EnableFullCompaction: cfg.Splitstore.EnableFullCompaction, - EnableGC: cfg.Splitstore.EnableGC, - Archival: cfg.Splitstore.Archival, - }) + cfg := &splitstore.Config{ + TrackingStoreType: cfg.Splitstore.TrackingStoreType, + LiveSetType: cfg.Splitstore.LiveSetType, + EnableFullCompaction: cfg.Splitstore.EnableFullCompaction, + EnableGC: cfg.Splitstore.EnableGC, + Archival: cfg.Splitstore.Archival, + } + ss, err := splitstore.Open(path, ds, hot, cold, cfg) if err != nil { return nil, err }