Merge remote-tracking branch 'origin/main' into feat/47-H2
This commit is contained in:
@@ -213,6 +213,8 @@ type Conn struct {
|
||||
bound map[string]*binding
|
||||
// bind binds one bucket: jetstream's KeyValue (a stream-info request on the bus) unless a test replaces it.
|
||||
bind func(ctx context.Context, bucket string) (jetstream.KeyValue, error)
|
||||
// pulls are the workers bound and the messages pulled on this connection (seat_pull.go).
|
||||
pulls pulls
|
||||
}
|
||||
|
||||
// answered is one subject the runtime answers on: what to subscribe again with, and how often it was
|
||||
@@ -426,29 +428,33 @@ func (c *Conn) issue(module string, m Membership) {
|
||||
// right after its boot, a timeout), is said once and read again, with a growing wait, until it can be or the
|
||||
// connection closes: Follow runs once per module, so nothing else would ever read it again.
|
||||
func (c *Conn) followGrants(module string) {
|
||||
if c.watchGrants(module, true) {
|
||||
// Read here, not in the loop: the loop outlives Follow, and a test sets them back as it ends (design 47 H, H-A-363).
|
||||
patience, timeout := GrantsPatience, StateTimeout
|
||||
if c.watchGrants(module, true, patience, timeout) {
|
||||
return
|
||||
}
|
||||
wait, most := GrantsRetry, GrantsRetryMost
|
||||
go func() {
|
||||
wait := GrantsRetry
|
||||
for !c.nc.IsClosed() {
|
||||
time.Sleep(wait)
|
||||
if c.nc.IsClosed() {
|
||||
return
|
||||
}
|
||||
if c.watchGrants(module, false) {
|
||||
if c.watchGrants(module, false, patience, timeout) {
|
||||
c.Logf("[mesh-tools] the grants part's memberships are read again; %s on %s follows its key", module, c.node)
|
||||
return
|
||||
}
|
||||
if wait *= 2; wait > GrantsRetryMost {
|
||||
wait = GrantsRetryMost
|
||||
if wait *= 2; wait > most {
|
||||
wait = most
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// watchGrants is one attempt of followGrants: true once the key is watched. A failure is said when say is true.
|
||||
func (c *Conn) watchGrants(module string, say bool) bool {
|
||||
// watchGrants is one attempt of followGrants: true once the key is watched. A failure is said when say is true. Its
|
||||
// bounds, patience for the key's direct get and timeout for the bucket and its current value, are GrantsPatience and
|
||||
// StateTimeout as they stood when followGrants began.
|
||||
func (c *Conn) watchGrants(module string, say bool, patience, timeout time.Duration) bool {
|
||||
logf := func(format string, a ...any) {
|
||||
if say {
|
||||
c.Logf(format, a...)
|
||||
@@ -458,7 +464,7 @@ func (c *Conn) watchGrants(module string, say bool) bool {
|
||||
// First the key's direct get, which the account is granted alone: a bus that refuses it, or a state not there yet,
|
||||
// answers at once, where binding the bucket would wait out its bound on a refusal.
|
||||
bucket := membership.GrantsBucket
|
||||
probe, err := c.nc.Request("$JS.API.DIRECT.GET.KV_"+bucket+".$KV."+bucket+"."+key, nil, GrantsPatience)
|
||||
probe, err := c.nc.Request("$JS.API.DIRECT.GET.KV_"+bucket+".$KV."+bucket+"."+key, nil, patience)
|
||||
if err != nil || probe.Header.Get("Status") == "503" {
|
||||
why := "it did not answer"
|
||||
if err != nil {
|
||||
@@ -472,7 +478,7 @@ func (c *Conn) watchGrants(module string, say bool) bool {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), StateTimeout)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
kv, err := js.KeyValue(ctx, bucket)
|
||||
if err != nil {
|
||||
@@ -505,7 +511,7 @@ func (c *Conn) watchGrants(module string, say bool) bool {
|
||||
}
|
||||
c.issue(module, m)
|
||||
}
|
||||
timer := time.NewTimer(StateTimeout)
|
||||
timer := time.NewTimer(timeout)
|
||||
defer timer.Stop()
|
||||
for current := true; current; {
|
||||
select {
|
||||
@@ -521,7 +527,7 @@ func (c *Conn) watchGrants(module string, say bool) bool {
|
||||
case <-timer.C:
|
||||
_ = w.Stop()
|
||||
logf("[mesh-tools] %s's key %s of the grants part's memberships did not answer in %s; %s has no membership "+
|
||||
"until it can be", module, key, StateTimeout, module)
|
||||
"until it can be", module, key, timeout, module)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user