@@ -3602,8 +3602,13 @@ func (s *StateStore) UpdateAllocsFromClient(msgType structs.MessageType, index u
3602
3602
txn := s .db .WriteTxnMsgT (msgType , index )
3603
3603
defer txn .Abort ()
3604
3604
3605
+ // Capture all nodes being affected. Alloc updates from clients are batched
3606
+ // so this request may include allocs from several nodes.
3607
+ nodeIDs := make (map [string ]interface {})
3608
+
3605
3609
// Handle each of the updated allocations
3606
3610
for _ , alloc := range allocs {
3611
+ nodeIDs [alloc .NodeID ] = struct {}{}
3607
3612
if err := s .nestedUpdateAllocFromClient (txn , index , alloc ); err != nil {
3608
3613
return err
3609
3614
}
@@ -3614,6 +3619,13 @@ func (s *StateStore) UpdateAllocsFromClient(msgType structs.MessageType, index u
3614
3619
return fmt .Errorf ("index update failed: %v" , err )
3615
3620
}
3616
3621
3622
+ // Update the index of when nodes last updated their allocs.
3623
+ for nodeID := range nodeIDs {
3624
+ if err := s .updateClientAllocUpdateIndex (txn , index , nodeID ); err != nil {
3625
+ return fmt .Errorf ("node update failed: %v" , err )
3626
+ }
3627
+ }
3628
+
3617
3629
return txn .Commit ()
3618
3630
}
3619
3631
@@ -3705,6 +3717,28 @@ func (s *StateStore) nestedUpdateAllocFromClient(txn *txn, index uint64, alloc *
3705
3717
return nil
3706
3718
}
3707
3719
3720
+ func (s * StateStore ) updateClientAllocUpdateIndex (txn * txn , index uint64 , nodeID string ) error {
3721
+ existing , err := txn .First ("nodes" , "id" , nodeID )
3722
+ if err != nil {
3723
+ return fmt .Errorf ("node lookup failed: %v" , err )
3724
+ }
3725
+ if existing == nil {
3726
+ return nil
3727
+ }
3728
+
3729
+ node := existing .(* structs.Node )
3730
+ copyNode := node .Copy ()
3731
+ copyNode .LastAllocUpdateIndex = index
3732
+
3733
+ if err := txn .Insert ("nodes" , copyNode ); err != nil {
3734
+ return fmt .Errorf ("node update failed: %v" , err )
3735
+ }
3736
+ if err := txn .Insert ("index" , & IndexEntry {"nodes" , txn .Index }); err != nil {
3737
+ return fmt .Errorf ("index update failed: %v" , err )
3738
+ }
3739
+ return nil
3740
+ }
3741
+
3708
3742
// UpsertAllocs is used to evict a set of allocations and allocate new ones at
3709
3743
// the same time.
3710
3744
func (s * StateStore ) UpsertAllocs (msgType structs.MessageType , index uint64 , allocs []* structs.Allocation ) error {
0 commit comments