-
Notifications
You must be signed in to change notification settings - Fork 3.4k
statedb: Derive, Observable and Map #30246
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 tasks
dylandreimerink
approved these changes
Jan 15, 2024
ad9bed9
to
f9addee
Compare
/test |
Table[T].NumObjects() returns the number of objects in the table in O(1) time. Derive transforms objects from an input table to an output table. Useful in conjunction with a reconciler where the desired state is derived from a single input table. Example: // Assuming we have Table[*Foo] and RWTable[*Bar] and that // *Bar is an object we want reconciled. cell.Invoke( statedb.Derive[*Foo, *Bar]( func(foo *Foo, deleted bool) (*Bar, statedb.DeriveResult) { if deleted { return &Bar{ ID: foo.ID, // Only need enough for primary key Status: reconciler.StatusPendingDelete(), }, statedb.DeriveUpdate } return &Bar{ ID: foo.ID, Quux: foo.Quux, Status: reconciler.StatusPending(), }, statedb.DeriveInsert }, ), ) Signed-off-by: Jussi Maki <jussi@isovalent.com>
Memory profiling showed that we were allocating fair bit in NewKeySet. This can be avoided in cases where the indexer only returns a single key by using a special case implementation. This replaces KeySet with a struct of head & tail. This allows writing indexers that can return a constant and avoid all memory allocation for the key. Signed-off-by: Jussi Maki <jussi@isovalent.com>
Useful when combined with CollectSet: type Foo struct { Key string } var iter Iterator[Foo] var keys sets.Set[string] keys = CollectSet( Map( iter, func(f Foo) string { return f.Key })) Signed-off-by: Jussi Maki <jussi@isovalent.com>
As we already have lots of code doing processing via event streams (e.g. Resource[T]), make it easier to migrate to the Kubernetes source from Resource[T] by making it possible to observe the table as a stream.Observable. The workqueue that Resource[T] is not supported. It wasn't used in many cases anyway and for those the workqueue can be implemented directly. Signed-off-by: Jussi Maki <jussi@isovalent.com>
f9addee
to
1b08bf5
Compare
/test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
ready-to-merge
This PR has passed all tests and received consensus from code owners to merge.
release-note/misc
This PR makes changes that have no direct user impact.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This upstreams the improvements to pkg/statedb that arose as part of #30024.
statedb.Map
function for transforming iteratorsstatedb.Observable
function for making astream.Observable
out of a tablestatedb.Derive
function for deriving one table from another with a transform functionindex.KeySet
to reduce amount of allocation