shibd commented on code in PR #991:
URL: https://github.com/apache/pulsar-client-go/pull/991#discussion_r1145767777
##########
pulsar/internal/memory_limit_controller.go:
##########
@@ -31,18 +31,41 @@ type MemoryLimitController interface {
CurrentUsage() int64
CurrentUsagePercent() float64
IsMemoryLimited() bool
+ RegisterTrigger(trigger func())
}
type memoryLimitController struct {
limit int64
chCond *chCond
currentUsage int64
+
+ triggers []*thresholdTrigger
+ // valid range is (0, 1.0)
+ triggerThreshold float64
+}
+
+type thresholdTrigger struct {
+ triggerFunc func()
+ triggerRunning int32
+}
+
+func (t *thresholdTrigger) canTryRunning() bool {
+ return atomic.CompareAndSwapInt32(&t.triggerRunning, 0, 1)
+}
+
+func (t *thresholdTrigger) setRunning(isRunning bool) {
+ if isRunning {
+ atomic.StoreInt32(&t.triggerRunning, 1)
+ }
+ atomic.StoreInt32(&t.triggerRunning, 0)
Review Comment:
```suggestion
} else {
atomic.StoreInt32(&t.triggerRunning, 0)
}
```
--
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]