@@ -131,7 +131,6 @@ type raft struct {
131
131
created time.Time // Time that the group was created
132
132
accName string // Account name of the asset this raft group is for
133
133
acc * Account // Account that NRG traffic will be sent/received in
134
- inAcc bool // Is the NRG traffic in-account right now?
135
134
group string // Raft group
136
135
sd string // Store directory
137
136
id string // Node ID
@@ -530,10 +529,11 @@ func (s *Server) startRaftNode(accName string, cfg *RaftConfig, labels pprofLabe
530
529
// Returns whether peers within this group claim to support
531
530
// moving NRG traffic into the asset account.
532
531
// Lock must be held.
533
- func (n * raft ) checkAccountNRGStatus (enabled bool ) bool {
534
- if ! enabled {
532
+ func (n * raft ) checkAccountNRGStatus () bool {
533
+ if ! n . s . accountNRGAllowed . Load () {
535
534
return false
536
535
}
536
+ enabled := true
537
537
for pn := range n .peers {
538
538
if si , ok := n .s .nodeToInfo .Load (pn ); ok && si != nil {
539
539
enabled = enabled && si .(nodeInfo ).accountNRG
@@ -549,26 +549,31 @@ func (n *raft) RecreateInternalSubs() error {
549
549
}
550
550
551
551
func (n * raft ) recreateInternalSubsLocked () error {
552
- // Is account NRG enabled in this account?
553
- acc := n .s .accountNRGAllowed .Load ()
554
- if acc {
555
- // Check whether the specific account has account NRG enabled.
552
+ // Default is the system account.
553
+ nrgAcc := n .s .sys .account
554
+
555
+ // Is account NRG enabled in this account and do all group
556
+ // peers claim to also support account NRG?
557
+ if n .checkAccountNRGStatus () {
558
+ // Check whether the account that the asset belongs to
559
+ // has volunteered a different NRG account.
560
+ target := nrgAcc .Name
556
561
if a , _ := n .s .lookupAccount (n .accName ); a != nil {
557
562
a .mu .RLock ()
558
- ajs := a .js
563
+ if a .js != nil {
564
+ target = a .js .nrgAccount
565
+ }
559
566
a .mu .RUnlock ()
560
- // Check whether the specific account has JetStream enabled.
561
- if ajs != nil {
562
- acc = ajs .accountNRG .Load ()
567
+ }
568
+
569
+ // If the target account exists, then we'll use that.
570
+ if target != _EMPTY_ {
571
+ if a , _ := n .s .lookupAccount (target ); a != nil {
572
+ nrgAcc = a
563
573
}
564
574
}
565
575
}
566
- if acc {
567
- // Check whether the peers in this group all claim to support
568
- // moving the NRG traffic into the account.
569
- acc = n .checkAccountNRGStatus (acc )
570
- }
571
- if n .aesub != nil && n .inAcc == acc {
576
+ if n .aesub != nil && n .acc == nrgAcc {
572
577
// Subscriptions already exist and the account NRG state
573
578
// hasn't changed.
574
579
return nil
@@ -594,19 +599,6 @@ func (n *raft) recreateInternalSubsLocked() error {
594
599
c .closeConnection (InternalClient )
595
600
}
596
601
597
- // Look up which account we think we should be participating
598
- // on. This will either be the system account (default) or it
599
- // will be the account that the asset is resident in.
600
- var nrgAcc * Account
601
- if n .s .sys != nil {
602
- nrgAcc = n .s .sys .account
603
- }
604
- if acc { // Should we setup in the asset account?
605
- var err error
606
- if nrgAcc , err = n .s .lookupAccount (n .accName ); err != nil {
607
- return err
608
- }
609
- }
610
602
if n .acc != nrgAcc {
611
603
n .debug ("Subscribing in '%s'" , nrgAcc .GetName ())
612
604
}
@@ -619,7 +611,6 @@ func (n *raft) recreateInternalSubsLocked() error {
619
611
n .c = c
620
612
n .sq = nrgAcc .sq
621
613
n .acc = nrgAcc
622
- n .inAcc = acc
623
614
624
615
// Recreate any internal subscriptions for voting, append
625
616
// entries etc in the new account.
0 commit comments