Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: unreserve on-demand #2071

Merged
merged 26 commits into from
Jun 19, 2021
Merged

feat: unreserve on-demand #2071

merged 26 commits into from
Jun 19, 2021

Conversation

acud
Copy link
Member

@acud acud commented Jun 12, 2021

#2040

This change is Reviewable

TODO:

  • on batchstore reset we should delete all the fifo queue items (already implicitly done by the Reset method)
  • retrieval protocol has to check postage stamp validity and force cache in case the stamp is invalid

@acud acud force-pushed the unreserve-queue branch 5 times, most recently from bf8e10a to 421ad0a Compare June 12, 2021 21:16
Copy link
Member

@zelig zelig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 11 of 11 files at r1.
Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @acud)


pkg/localstore/gc.go, line 47 at r1 (raw file):

	// not to overwhelm the cache with too many chunks which it will flush
	// anyway.
	reserveCollectionRatio = 0.5

this should be more like 10% max


pkg/localstore/gc_test.go, line 1017 at r1 (raw file):

	})
	db.SetUnreserveFunc(unres)
	fmt.Println(1)

debug code


pkg/postage/batchstore/reserve.go, line 52 at r1 (raw file):

var Capacity = exp2(22)

const unreservePage = 50 // how many entries to ask for deletion

what is the purpose of this?


pkg/postage/batchstore/reserve.go, line 73 at r1 (raw file):

// dequeued by the localstore once the storage fills up.
func (s *store) unreserve(b *postage.Batch, radius uint8) error {
	c, err := s.getQueueCardinality()

this need not be peristed in fact. just make sure its a value on s atomically incremented


pkg/postage/batchstore/reserve.go, line 88 at r1 (raw file):

}

func (s *store) Unreserve() error {

not sure why this is not an actual iterator. Make it an iterator and you can

  • eliminate the page constant,
  • get rid of unreserveFunc and its settter
  • take onset as a parameter, then you can move pruning to an async routine

pkg/postage/batchstore/reserve.go, line 106 at r1 (raw file):

		entries[i] = string(key)
		i++
		if i == unreservePage {

return i==unreserePage, nil


pkg/postage/batchstore/reserve.go, line 114 at r1 (raw file):

		return err
	}
	for _, v := range entries {

this better be asynchronous and done on demand


pkg/postage/batchstore/reserve.go, line 366 at r1 (raw file):

}

func (s *store) getQueueCardinality() (val uint64, err error) {

just needs to be initialised as the the topmost index


pkg/postage/batchstore/reserve.go, line 375 at r1 (raw file):

}

func (s *store) putQueueCardinality(val uint64) error {

same


pkg/postage/batchstore/reserve_test.go, line 839 at r1 (raw file):

}

func TestUnreserveItemSequence(t *testing.T) {

what is this testing. seems a bit complex

@zelig
Copy link
Member

zelig commented Jun 13, 2021

  • mock batchstore now fails on interface (no Unreserve)
  • Unreserve function (hopefully iterator) can take onset and bucketDepth

TODO:

  • let r be radius part of latest unreserveItem picked up by localstore via iterator call
  • r+1 to be saved as storage radius within reserveState to expose it through the API for price oracle?
  • remember cursor sequence count (at constructor call initialise from the queue), so that it is not taken from level db at every call

@acud acud force-pushed the unreserve-queue branch 3 times, most recently from 2c835f9 to d87d4a2 Compare June 13, 2021 12:34
Copy link
Member

@zelig zelig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 14 of 14 files at r2.
Reviewable status: all files reviewed, 12 unresolved discussions (waiting on @acud)


pkg/postage/interface.go, line 37 at r2 (raw file):

	GetReserveState() *ReserveState
	SetRadiusSetter(RadiusSetter)
	Unreserve(UnreserveIteratorFn) error

this should be a nother interface


pkg/postage/batchstore/reserve.go, line 71 at r2 (raw file):

// dequeued by the localstore once the storage fills up.
func (s *store) unreserve(b []byte, radius uint8) error {
	c, err := s.getQueueCardinality()

this can be optimised


pkg/postage/batchstore/mock/store.go, line 143 at r2 (raw file):

	return rs
}
func (bs *BatchStore) Unreserve(_ postage.UnreserveIteratorFn) {

not needed if on a different interface

@zelig
Copy link
Member

zelig commented Jun 13, 2021

LGTM when tests pass

@acud acud force-pushed the unreserve-queue branch 6 times, most recently from 4f71526 to 4c9443b Compare June 15, 2021 07:14
@acud acud requested a review from zelig June 15, 2021 07:30
@acud acud force-pushed the unreserve-queue branch 3 times, most recently from 0850008 to 628f756 Compare June 15, 2021 15:38
Copy link
Member

@zelig zelig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6 of 8 files at r3, 12 of 12 files at r4.
Reviewable status: all files reviewed, 17 unresolved discussions (waiting on @acud)


pkg/localstore/reserve_test.go, line 302 at r4 (raw file):

			t.Fatal(err)
		}
		mtx.Lock()

this lock is not needed right?


pkg/localstore/reserve_test.go, line 389 at r4 (raw file):

	unres := func(f postage.UnreserveIteratorFn) error {
		mtx.Lock()

why lock is needed


pkg/node/node.go, line 334 at r4 (raw file):

	b.p2pHalter = p2ps

	var unreserveFn func([]byte, uint8) (uint64, error)

maybe comment here about this black magic going on to make reciprocal dependency painless


pkg/postage/batchstore/reserve.go, line 60 at r4 (raw file):

	// would like to guarantee that all chunks are stored
	Radius        uint8 `json:"radius"`
	StorageRadius uint8 `json:"storageRadius"`

add comment: the current actual radius of eviction/storage


pkg/postage/batchstore/reserve.go, line 110 at r4 (raw file):

v.Radius != swarm.MaxPO+1

this condition is no longer needed

Copy link
Member Author

@acud acud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 17 unresolved discussions (waiting on @acud and @zelig)


pkg/localstore/gc.go, line 47 at r1 (raw file):

Previously, zelig (Viktor Trón) wrote…

this should be more like 10% max

Done.


pkg/localstore/gc_test.go, line 1017 at r1 (raw file):

Previously, zelig (Viktor Trón) wrote…

debug code

Done.


pkg/localstore/reserve_test.go, line 302 at r4 (raw file):

Previously, zelig (Viktor Trón) wrote…

this lock is not needed right?

race detector


pkg/localstore/reserve_test.go, line 389 at r4 (raw file):

Previously, zelig (Viktor Trón) wrote…

why lock is needed

race detector


pkg/postage/batchstore/reserve.go, line 106 at r1 (raw file):

Previously, zelig (Viktor Trón) wrote…

return i==unreserePage, nil

Done.


pkg/postage/batchstore/reserve.go, line 110 at r4 (raw file):

Previously, zelig (Viktor Trón) wrote…
v.Radius != swarm.MaxPO+1

this condition is no longer needed

Done.


pkg/postage/batchstore/reserve_test.go, line 839 at r1 (raw file):

Previously, zelig (Viktor Trón) wrote…

what is this testing. seems a bit complex

Done.


pkg/postage/batchstore/mock/store.go, line 143 at r2 (raw file):

Previously, zelig (Viktor Trón) wrote…

not needed if on a different interface

Done.

@Eknir Eknir added this to the 42 milestone Jun 16, 2021
@zelig zelig added the ready for review The PR is ready to be reviewed label Jun 16, 2021
Copy link
Member

@zelig zelig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 5 of 5 files at r5.
Reviewable status: all files reviewed, 12 unresolved discussions (waiting on @acud and @zelig)


pkg/postage/batchstore/reserve.go, line 110 at r4 (raw file):

Previously, acud (acud) wrote…

Done.

not done

Copy link
Member

@zelig zelig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 5 files at r8, 12 of 12 files at r9.
Reviewable status: all files reviewed, 9 unresolved discussions (waiting on @acud and @zelig)


pkg/localstore/localstore.go, line 210 at r9 (raw file):

	db = &DB{
		stateStore:      ss,

why


pkg/node/node.go, line 359 at r9 (raw file):

	}

	fmt.Println("starting bee...")

?

@acud acud merged commit c691009 into master Jun 19, 2021
@acud acud deleted the unreserve-queue branch June 19, 2021 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pull-request ready for review The PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants