Skip to content

Commit

Permalink
fix: remove epoch migration code (#4563)
Browse files Browse the repository at this point in the history
  • Loading branch information
notanatol authored Feb 5, 2024
1 parent 771a40b commit 0a7fd5c
Show file tree
Hide file tree
Showing 15 changed files with 4 additions and 1,814 deletions.
35 changes: 1 addition & 34 deletions pkg/node/statestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/ethersphere/bee/pkg/log"
"github.com/ethersphere/bee/pkg/metrics"
"github.com/ethersphere/bee/pkg/postage"
"github.com/ethersphere/bee/pkg/statestore/storeadapter"
"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/storage/cache"
Expand Down Expand Up @@ -55,12 +54,7 @@ func InitStamperStore(logger log.Logger, dataDir string, stateStore storage.Stat
if err != nil {
return nil, err
}
// TODO: remove migration after it has been a few months after the localstoreV2 release
err = migrateStamperData(stateStore, stamperStore)
if err != nil {
stamperStore.Close()
return nil, fmt.Errorf("migrating stamper data: %w", err)
}

return stamperStore, nil
}

Expand Down Expand Up @@ -105,30 +99,3 @@ func setOverlay(s storage.StateStorer, overlay swarm.Address, nonce []byte) erro
s.Put(noncedOverlayKey, overlay),
)
}

func migrateStamperData(stateStore storage.StateStorer, stamperStore storage.Store) error {
var keys []string
err := stateStore.Iterate("postage", func(key, value []byte) (bool, error) {
keys = append(keys, string(key))
st := &postage.StampIssuer{}
if err := st.UnmarshalBinary(value); err != nil {
return false, err
}
if err := stamperStore.Put(&postage.StampIssuerItem{
Issuer: st,
}); err != nil {
return false, err
}
return false, nil
})
if err != nil {
return err
}

for _, key := range keys {
if err = stateStore.Delete(key); err != nil {
return err
}
}
return nil
}
81 changes: 0 additions & 81 deletions pkg/node/statestore_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/postage/batchstore/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func TestBatchStore_Reset(t *testing.T) {

// we expect one key in the statestore since the schema name
// will always be there.
if c != 1 {
if c != 0 {
t.Fatalf("expected only one key in statestore, got %d", c)
}
}
Expand Down
7 changes: 0 additions & 7 deletions pkg/statestore/leveldb/export_test.go

This file was deleted.

49 changes: 1 addition & 48 deletions pkg/statestore/leveldb/leveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import (
const loggerName = "leveldb"

var (
_ storage.StateStorer = (*Store)(nil)
_ storage.StateStorerCleaner = (*Store)(nil)
_ storage.StateStorer = (*Store)(nil)
)

// Store uses LevelDB to store values.
Expand All @@ -46,10 +45,6 @@ func NewInMemoryStateStore(l log.Logger) (*Store, error) {
logger: l.WithName(loggerName).Register(),
}

if err := migrate(s); err != nil {
return nil, err
}

return s, nil
}

Expand All @@ -76,36 +71,9 @@ func NewStateStore(path string, l log.Logger) (*Store, error) {
logger: l,
}

if err := migrate(s); err != nil {
return nil, err
}

return s, nil
}

func migrate(s *Store) error {
sn, err := s.getSchemaName()
if err != nil {
if !errors.Is(err, storage.ErrNotFound) {
_ = s.Close()
return fmt.Errorf("get schema name: %w", err)
}
// new statestore - put schema key with current name
if err := s.putSchemaName(dbSchemaCurrent); err != nil {
_ = s.Close()
return fmt.Errorf("put schema name: %w", err)
}
sn = dbSchemaCurrent
}

if err = s.migrate(sn); err != nil {
_ = s.Close()
return fmt.Errorf("migrate: %w", err)
}

return nil
}

// Get retrieves a value of the requested key. If no results are found,
// storage.ErrNotFound will be returned.
func (s *Store) Get(key string, i interface{}) error {
Expand Down Expand Up @@ -161,21 +129,6 @@ func (s *Store) Iterate(prefix string, iterFunc storage.StateIterFunc) (err erro
return iter.Error()
}

func (s *Store) getSchemaName() (string, error) {
name, err := s.db.Get([]byte(dbSchemaKey), nil)
if err != nil {
if errors.Is(err, leveldb.ErrNotFound) {
return "", storage.ErrNotFound
}
return "", err
}
return string(name), nil
}

func (s *Store) putSchemaName(val string) error {
return s.db.Put([]byte(dbSchemaKey), []byte(val), nil)
}

// Close releases the resources used by the store.
func (s *Store) Close() error {
return s.db.Close()
Expand Down
21 changes: 0 additions & 21 deletions pkg/statestore/leveldb/leveldb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,3 @@ func TestPersistentStateStore(t *testing.T) {
return store
})
}

func TestGetSchemaName(t *testing.T) {
dir := t.TempDir()

store, err := leveldb.NewStateStore(dir, log.Noop)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
if err := store.Close(); err != nil {
t.Fatal(err)
}
})
n, err := store.GetSchemaName() // expect current
if err != nil {
t.Fatal(err)
}
if n != leveldb.DbSchemaCurrent {
t.Fatalf("wanted current db schema but got '%s'", n)
}
}
Loading

0 comments on commit 0a7fd5c

Please sign in to comment.