sjwiesman commented on pull request #303:
URL: https://github.com/apache/flink-statefun/pull/303#issuecomment-1050044752
By "us" I am referring to the StateFun SDK. Let's suppose in a future
version we add the pair `a=b` as a default bit of information to the
context[^1]. In the current implementation, where we are deriving a new context
with the pair `c=d`, that new `statefun.Context` will lose the original pair
`a=b`. This behavior differs from `context.Context.WithValue` which retains the
existing kv pairs when new ones are added. Maybe my example code should be
changed to create a new statefun context that contains the underlying contexts
and the new one, something like:
```go
type statefunContext struct {
*sync.Mutex
context.Context
merged []context.Context
self Address
caller *Address
storage *storage
response *protocol.FromFunction_InvocationResponse
}
func (s *statefunContext) WithAllValues(other context.Context) Context {
s.Lock()
defer s.Unlock()
return &statefunContext{
s.Mutex,
s.Context,
append(s.merged, other),
s.self,
s.caller,
s.storage,
s.response,
}
}
func (s *statefunContext) Value(key interface{}) interface{} {
for i := len(s.merged) - 1; i >= 0; i-- {
if result := s.merged[i].Value(key); result != nil {
return result
}
}
return s.Context.Value(key)
}
```
While I realize in go you can at any point create a new context that
discards all underlying data, that doesn't seem like a usage pattern we want to
encourage.
[^1]: A real example, I can imagine adding tracing information into the
invocations in the near future.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]