Skip to content

Commit

Permalink
fix: unit tests and integration tests after patch (#4496)
Browse files Browse the repository at this point in the history
  • Loading branch information
istae authored Dec 7, 2023
1 parent ed24b89 commit 32fb85f
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 38 deletions.
4 changes: 4 additions & 0 deletions .github/patches/minradius.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
190c190
< reserveMinimumRadius = 9
---
> reserveMinimumRadius = 0
4 changes: 0 additions & 4 deletions .github/patches/postagecontract.patch

This file was deleted.

4 changes: 0 additions & 4 deletions .github/patches/postagereserve_gc.patch

This file was deleted.

4 changes: 0 additions & 4 deletions .github/patches/postageservice.patch

This file was deleted.

8 changes: 1 addition & 7 deletions .github/workflows/beekeeper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,11 @@ jobs:
mv dist/bee bee-0
- name: Apply patches and build - 1
run: |
# patch pkg/postage/postagecontract/contract.go .github/patches/postagecontract.patch
# patch pkg/postage/service.go .github/patches/postageservice.patch
patch pkg/api/postage.go .github/patches/postage_api.patch
patch pkg/retrieval/retrieval.go .github/patches/retrieval.patch
patch pkg/node/node.go .github/patches/minradius.patch
make binary
mv dist/bee bee-1
- name: Apply patches and build - 2
run: |
# patch pkg/postage/batchstore/reserve.go .github/patches/postagereserve_gc.patch
make binary
mv dist/bee bee-2
- name: Install beekeeper
run: |
export PATH=$(pwd):$PATH
Expand Down
2 changes: 2 additions & 0 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ const (
ReserveCapacity = 4_194_304 // 2^22 chunks
reserveWakeUpDuration = 15 * time.Minute // time to wait before waking up reserveWorker
reserveTreshold = ReserveCapacity * 5 / 10
reserveMinimumRadius = 9
)

func NewBee(
Expand Down Expand Up @@ -760,6 +761,7 @@ func NewBee(
lo.ReserveCapacity = ReserveCapacity
lo.ReserveWakeUpDuration = reserveWakeUpDuration
lo.RadiusSetter = kad
lo.ReserveMinimumRadius = reserveMinimumRadius
}

localStore, err := storer.New(ctx, path, lo)
Expand Down
26 changes: 13 additions & 13 deletions pkg/storer/internal/reserve/reserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@ import (
const loggerName = "reserve"
const reserveNamespace = "reserve"

// hack: make sures the network's storage radius does not fall below a certain value
const minRadius = 9

/*
pull by bin - binID
evict by bin - batchID
sample by bin
*/

type Reserve struct {
baseAddr swarm.Address
radiusSetter topology.SetStorageRadiuser
logger log.Logger
baseAddr swarm.Address
radiusSetter topology.SetStorageRadiuser
minimumRadius uint8
logger log.Logger

capacity int
size atomic.Int64
Expand All @@ -54,24 +52,26 @@ func New(
store storage.Store,
capacity int,
radiusSetter topology.SetStorageRadiuser,
minimumRadius uint8,
logger log.Logger,
cb func(context.Context, internal.Storage, ...swarm.Address) error,
) (*Reserve, error) {

rs := &Reserve{
baseAddr: baseAddr,
capacity: capacity,
radiusSetter: radiusSetter,
logger: logger.WithName(loggerName).Register(),
cacheCb: cb,
baseAddr: baseAddr,
capacity: capacity,
radiusSetter: radiusSetter,
minimumRadius: minimumRadius,
logger: logger.WithName(loggerName).Register(),
cacheCb: cb,
}

rItem := &radiusItem{}
err := store.Get(rItem)
if err != nil && !errors.Is(err, storage.ErrNotFound) {
return nil, err
}
rs.radius.Store(uint32(max(rItem.Radius, minRadius)))
rs.radius.Store(uint32(max(rItem.Radius, minimumRadius)))

epochItem := &EpochItem{}
err = store.Get(epochItem)
Expand Down Expand Up @@ -465,7 +465,7 @@ func (r *Reserve) EvictionTarget() int {
}

func (r *Reserve) SetRadius(store storage.Store, rad uint8) error {
rad = max(rad, minRadius)
rad = max(rad, r.minimumRadius)
r.radius.Store(uint32(rad))
r.radiusSetter.SetStorageRadius(rad)
return store.Put(&radiusItem{Radius: rad})
Expand Down
10 changes: 5 additions & 5 deletions pkg/storer/internal/reserve/reserve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestReserve(t *testing.T) {
r, err := reserve.New(
baseAddr,
ts.IndexStore(),
0, kademlia.NewTopologyDriver(),
0, kademlia.NewTopologyDriver(), 0,
log.Noop,
noopCacher,
)
Expand Down Expand Up @@ -101,7 +101,7 @@ func TestReserveChunkType(t *testing.T) {
r, err := reserve.New(
baseAddr,
ts.IndexStore(),
0, kademlia.NewTopologyDriver(),
0, kademlia.NewTopologyDriver(), 0,
log.Noop,
noopCacher,
)
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestReplaceOldIndex(t *testing.T) {
r, err := reserve.New(
baseAddr,
ts.IndexStore(),
0, kademlia.NewTopologyDriver(),
0, kademlia.NewTopologyDriver(), 0,
log.Noop,
func(ctx context.Context, st internal.Storage, addrs ...swarm.Address) error {
for _, addr := range addrs {
Expand Down Expand Up @@ -233,7 +233,7 @@ func TestEvict(t *testing.T) {
r, err := reserve.New(
baseAddr,
ts.IndexStore(),
0, kademlia.NewTopologyDriver(),
0, kademlia.NewTopologyDriver(), 0,
log.Noop,
func(ctx context.Context, st internal.Storage, addrs ...swarm.Address) error {
for _, addr := range addrs {
Expand Down Expand Up @@ -318,7 +318,7 @@ func TestIterate(t *testing.T) {
r, err := reserve.New(
baseAddr,
ts.IndexStore(),
0, kademlia.NewTopologyDriver(),
0, kademlia.NewTopologyDriver(), 0,
log.Noop,
noopCacher,
)
Expand Down
4 changes: 3 additions & 1 deletion pkg/storer/storer.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func performEpochMigration(ctx context.Context, basePath string, opts *Options)
opts.Address,
store,
opts.ReserveCapacity,
noopRadiusSetter{},
noopRadiusSetter{}, 0,
logger,
func(_ context.Context, _ internal.Storage, _ ...swarm.Address) error {
return nil
Expand Down Expand Up @@ -454,6 +454,7 @@ type Options struct {

ReserveCapacity int
ReserveWakeUpDuration time.Duration
ReserveMinimumRadius uint8
}

func defaultOptions() *Options {
Expand Down Expand Up @@ -616,6 +617,7 @@ func New(ctx context.Context, dirPath string, opts *Options) (*DB, error) {
repo.IndexStore(),
opts.ReserveCapacity,
opts.RadiusSetter,
opts.ReserveMinimumRadius,
logger,
db.CacheShallowCopy,
)
Expand Down
1 change: 1 addition & 0 deletions pkg/storer/storer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func dbTestOps(baseAddr swarm.Address, reserveCapacity int, bs postage.Storer, r
opts.Address = baseAddr
opts.RadiusSetter = radiusSetter
opts.ReserveCapacity = reserveCapacity
opts.ReserveMinimumRadius = 0
opts.Batchstore = bs
opts.ReserveWakeUpDuration = reserveWakeUpTime
opts.Logger = log.Noop
Expand Down

0 comments on commit 32fb85f

Please sign in to comment.