shibd commented on code in PR #1033:
URL: https://github.com/apache/pulsar-client-go/pull/1033#discussion_r1247323891
##########
pulsar/schema.go:
##########
@@ -66,13 +67,21 @@ type SchemaInfo struct {
Schema string
Type SchemaType
Properties map[string]string
+ hashVal atomic.Uint64
}
-func (s SchemaInfo) hash() uint64 {
+func (s *SchemaInfo) hash() uint64 {
+ oldHash := s.hashVal.Load()
+ if oldHash != 0 {
+ return oldHash
+ }
+
h := maphash.Hash{}
h.SetSeed(seed)
h.Write([]byte(s.Schema))
- return h.Sum64()
+ newHash := h.Sum64()
+ s.hashVal.CompareAndSwap(oldHash, newHash)
Review Comment:
But, Using `sync.once` is more intuitive.
And, In multi-thread, your implementation of this is not guaranteed to be
hashed only once.
--
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]