Skip to content

Commit 7c0978e

Browse files
authored
Merge pull request #2017 from hashicorp/b-sticky
Not moving alloc data when sticky is turned off
2 parents cd3dab9 + 0182b85 commit 7c0978e

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

client/client.go

+23-18
Original file line numberDiff line numberDiff line change
@@ -1069,13 +1069,34 @@ func (c *Client) updateNodeStatus() error {
10691069

10701070
// updateAllocStatus is used to update the status of an allocation
10711071
func (c *Client) updateAllocStatus(alloc *structs.Allocation) {
1072-
// Only send the fields that are updatable by the client.
1072+
// If this alloc was blocking another alloc and transitioned to a
1073+
// terminal state then start the blocked allocation
1074+
c.blockedAllocsLock.Lock()
1075+
if blockedAlloc, ok := c.blockedAllocations[alloc.ID]; ok && alloc.Terminated() {
1076+
var prevAllocDir *allocdir.AllocDir
1077+
if ar, ok := c.getAllocRunners()[alloc.ID]; ok {
1078+
tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
1079+
if tg != nil && tg.EphemeralDisk != nil && tg.EphemeralDisk.Sticky {
1080+
prevAllocDir = ar.GetAllocDir()
1081+
}
1082+
}
1083+
if err := c.addAlloc(blockedAlloc, prevAllocDir); err != nil {
1084+
c.logger.Printf("[ERR] client: failed to add alloc which was previously blocked %q: %v",
1085+
blockedAlloc.ID, err)
1086+
}
1087+
delete(c.blockedAllocations, blockedAlloc.PreviousAllocation)
1088+
}
1089+
c.blockedAllocsLock.Unlock()
1090+
1091+
// Strip all the information that can be reconstructed at the server. Only
1092+
// send the fields that are updatable by the client.
10731093
stripped := new(structs.Allocation)
10741094
stripped.ID = alloc.ID
10751095
stripped.NodeID = c.Node().ID
10761096
stripped.TaskStates = alloc.TaskStates
10771097
stripped.ClientStatus = alloc.ClientStatus
10781098
stripped.ClientDescription = alloc.ClientDescription
1099+
10791100
select {
10801101
case c.allocUpdates <- stripped:
10811102
case <-c.shutdownCh:
@@ -1096,22 +1117,6 @@ func (c *Client) allocSync() {
10961117
case alloc := <-c.allocUpdates:
10971118
// Batch the allocation updates until the timer triggers.
10981119
updates[alloc.ID] = alloc
1099-
1100-
// If this alloc was blocking another alloc and transitioned to a
1101-
// terminal state then start the blocked allocation
1102-
c.blockedAllocsLock.Lock()
1103-
if blockedAlloc, ok := c.blockedAllocations[alloc.ID]; ok && alloc.Terminated() {
1104-
var prevAllocDir *allocdir.AllocDir
1105-
if ar, ok := c.getAllocRunners()[alloc.ID]; ok {
1106-
prevAllocDir = ar.GetAllocDir()
1107-
}
1108-
if err := c.addAlloc(blockedAlloc, prevAllocDir); err != nil {
1109-
c.logger.Printf("[ERR] client: failed to add alloc which was previously blocked %q: %v",
1110-
blockedAlloc.ID, err)
1111-
}
1112-
delete(c.blockedAllocations, blockedAlloc.PreviousAllocation)
1113-
}
1114-
c.blockedAllocsLock.Unlock()
11151120
case <-syncTicker.C:
11161121
// Fast path if there are no updates
11171122
if len(updates) == 0 {
@@ -1403,7 +1408,7 @@ func (c *Client) runAllocs(update *allocUpdates) {
14031408
// previous allocation
14041409
var prevAllocDir *allocdir.AllocDir
14051410
tg := add.Job.LookupTaskGroup(add.TaskGroup)
1406-
if tg != nil && tg.EphemeralDisk != nil && tg.EphemeralDisk.Sticky == true && ar != nil {
1411+
if tg != nil && tg.EphemeralDisk != nil && tg.EphemeralDisk.Sticky && ar != nil {
14071412
prevAllocDir = ar.GetAllocDir()
14081413
}
14091414

0 commit comments

Comments
 (0)