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
statedb: Simplify integration with Hive #28892
Conversation
13ddc7a
to
bdd9f83
Compare
bdd9f83
to
9f3b6e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the potential panic
s in NewTable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
9f3b6e4
to
1077f33
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
/test |
1077f33
to
fe8571a
Compare
/test |
1bd731f
to
1e7845a
Compare
/test |
CI triage:
|
1e7845a
to
033cfbb
Compare
/test |
Instead of relying on the group values use an explicit registration ((*DB).RegisterTable) for the tables. This allows more flexibility for how to create the tables and how to for example scope them to a module or even to keep RWTable[T] hidden inside an object. Example code: // A constructor function for a table. Used by the real implementation // and integration tests of components that depend on this table can // use this to create and populate it. func NewExampleTable() statedb.RWTable[*Example] { return statedb.NewTable[*Example]("test", ExampleIDIndex, ExampleNameIndex) } func example() { hive.New( statedb.Cell, cell.Module("example", "Example", cell.ProvidePrivate(NewExampleTable), // Provides RWTable[*Example] just to this module. // 1st way to register a table. cell.Invoke(statedb.RegisterTable[*Example]), // 2nd longer way to register a table cell.Invoke(func(db *statedb.DB, table statedb.RWTable[*Example]) error { return db.RegisterTable(table) }), // Provide the read-only "Table[*Example]" API to the whole hive. Here or from a start // hook we can for example populate it before anything reads it. We get the guarantee // that the start hook is called before any readers if we append the hook from this constructor. cell.Provide(func(table statedb.RWTable[*Example]) statedb.Table[*Example] { return table }), // Shorter way to provide Table[*Example] using ToTable. // This method referenced this way has type "func(table RWTable[*Example]) Table[*Example]" cell.Provide(statedb.RWTable[*Example].ToTable), ) } Signed-off-by: Jussi Maki <jussi@isovalent.com>
Since with RegisterTable we can now create and register tables at runtime it's better to avoid panics on user-data in the public API. Added MustNewTable for tests. Signed-off-by: Jussi Maki <jussi@isovalent.com>
033cfbb
to
690f6d7
Compare
/test (rebased to fix conflicts) |
CI triage:
|
Instead of relying on the group values use an explicit registration for the tables. This allows more flexibility for how to create the tables and how to for example scope them to a module or even to keep RWTable[T] hidden inside an object without having the complicated
NewProtectedTableCell
and so on helpers which obfuscate what is going on.